2012-08-06 01:51:49 +04:00
|
|
|
/*
|
2018-01-01 22:16:06 +03:00
|
|
|
* Copyright 2011-2018 Branimir Karadzic. All rights reserved.
|
2016-01-01 11:11:04 +03:00
|
|
|
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
|
2012-08-06 01:51:49 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "bgfx_p.h"
|
|
|
|
|
|
|
|
#if BGFX_CONFIG_RENDERER_DIRECT3D9
|
|
|
|
# include "renderer_d3d9.h"
|
2017-04-10 05:31:24 +03:00
|
|
|
# include <bx/pixelformat.h>
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2015-03-22 08:11:59 +03:00
|
|
|
namespace bgfx { namespace d3d9
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2014-10-26 04:07:51 +03:00
|
|
|
static wchar_t s_viewNameW[BGFX_CONFIG_MAX_VIEWS][BGFX_CONFIG_MAX_VIEW_NAME];
|
2015-11-16 17:42:56 +03:00
|
|
|
static char s_viewName[BGFX_CONFIG_MAX_VIEWS][BGFX_CONFIG_MAX_VIEW_NAME];
|
2013-06-10 02:28:25 +04:00
|
|
|
|
2014-04-27 10:48:41 +04:00
|
|
|
struct PrimInfo
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2014-04-27 10:48:41 +04:00
|
|
|
D3DPRIMITIVETYPE m_type;
|
|
|
|
uint32_t m_min;
|
|
|
|
uint32_t m_div;
|
|
|
|
uint32_t m_sub;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const PrimInfo s_primInfo[] =
|
|
|
|
{
|
|
|
|
{ D3DPT_TRIANGLELIST, 3, 3, 0 },
|
|
|
|
{ D3DPT_TRIANGLESTRIP, 3, 1, 2 },
|
|
|
|
{ D3DPT_LINELIST, 2, 2, 0 },
|
2014-10-23 06:19:33 +04:00
|
|
|
{ D3DPT_LINESTRIP, 2, 1, 1 },
|
2014-04-27 10:48:41 +04:00
|
|
|
{ D3DPT_POINTLIST, 1, 1, 0 },
|
2014-09-01 22:24:51 +04:00
|
|
|
{ D3DPRIMITIVETYPE(0), 0, 0, 0 },
|
2014-04-27 10:48:41 +04:00
|
|
|
};
|
2018-05-18 03:24:10 +03:00
|
|
|
BX_STATIC_ASSERT(Topology::Count == BX_COUNTOF(s_primInfo)-1);
|
2012-08-06 01:51:49 +04:00
|
|
|
|
|
|
|
static const D3DMULTISAMPLE_TYPE s_checkMsaa[] =
|
|
|
|
{
|
|
|
|
D3DMULTISAMPLE_NONE,
|
|
|
|
D3DMULTISAMPLE_2_SAMPLES,
|
|
|
|
D3DMULTISAMPLE_4_SAMPLES,
|
|
|
|
D3DMULTISAMPLE_8_SAMPLES,
|
|
|
|
D3DMULTISAMPLE_16_SAMPLES,
|
|
|
|
};
|
|
|
|
|
|
|
|
static Msaa s_msaa[] =
|
|
|
|
{
|
|
|
|
{ D3DMULTISAMPLE_NONE, 0 },
|
|
|
|
{ D3DMULTISAMPLE_2_SAMPLES, 0 },
|
|
|
|
{ D3DMULTISAMPLE_4_SAMPLES, 0 },
|
|
|
|
{ D3DMULTISAMPLE_8_SAMPLES, 0 },
|
|
|
|
{ D3DMULTISAMPLE_16_SAMPLES, 0 },
|
|
|
|
};
|
|
|
|
|
2013-03-30 20:44:13 +04:00
|
|
|
struct Blend
|
|
|
|
{
|
|
|
|
D3DBLEND m_src;
|
|
|
|
D3DBLEND m_dst;
|
|
|
|
bool m_factor;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const Blend s_blendFactor[] =
|
|
|
|
{
|
|
|
|
{ (D3DBLEND)0, (D3DBLEND)0, false }, // ignored
|
2014-03-26 10:07:51 +04:00
|
|
|
{ D3DBLEND_ZERO, D3DBLEND_ZERO, false }, // ZERO
|
|
|
|
{ D3DBLEND_ONE, D3DBLEND_ONE, false }, // ONE
|
|
|
|
{ D3DBLEND_SRCCOLOR, D3DBLEND_SRCCOLOR, false }, // SRC_COLOR
|
|
|
|
{ D3DBLEND_INVSRCCOLOR, D3DBLEND_INVSRCCOLOR, false }, // INV_SRC_COLOR
|
|
|
|
{ D3DBLEND_SRCALPHA, D3DBLEND_SRCALPHA, false }, // SRC_ALPHA
|
|
|
|
{ D3DBLEND_INVSRCALPHA, D3DBLEND_INVSRCALPHA, false }, // INV_SRC_ALPHA
|
|
|
|
{ D3DBLEND_DESTALPHA, D3DBLEND_DESTALPHA, false }, // DST_ALPHA
|
|
|
|
{ D3DBLEND_INVDESTALPHA, D3DBLEND_INVDESTALPHA, false }, // INV_DST_ALPHA
|
|
|
|
{ D3DBLEND_DESTCOLOR, D3DBLEND_DESTCOLOR, false }, // DST_COLOR
|
|
|
|
{ D3DBLEND_INVDESTCOLOR, D3DBLEND_INVDESTCOLOR, false }, // INV_DST_COLOR
|
|
|
|
{ D3DBLEND_SRCALPHASAT, D3DBLEND_ONE, false }, // SRC_ALPHA_SAT
|
|
|
|
{ D3DBLEND_BLENDFACTOR, D3DBLEND_BLENDFACTOR, true }, // FACTOR
|
|
|
|
{ D3DBLEND_INVBLENDFACTOR, D3DBLEND_INVBLENDFACTOR, true }, // INV_FACTOR
|
2012-08-06 01:51:49 +04:00
|
|
|
};
|
|
|
|
|
2013-06-18 09:11:45 +04:00
|
|
|
static const D3DBLENDOP s_blendEquation[] =
|
|
|
|
{
|
|
|
|
D3DBLENDOP_ADD,
|
|
|
|
D3DBLENDOP_SUBTRACT,
|
|
|
|
D3DBLENDOP_REVSUBTRACT,
|
|
|
|
D3DBLENDOP_MIN,
|
|
|
|
D3DBLENDOP_MAX,
|
|
|
|
};
|
|
|
|
|
2014-02-22 20:48:30 +04:00
|
|
|
static const D3DCMPFUNC s_cmpFunc[] =
|
2012-11-11 07:59:23 +04:00
|
|
|
{
|
|
|
|
(D3DCMPFUNC)0, // ignored
|
|
|
|
D3DCMP_LESS,
|
|
|
|
D3DCMP_LESSEQUAL,
|
|
|
|
D3DCMP_EQUAL,
|
|
|
|
D3DCMP_GREATEREQUAL,
|
|
|
|
D3DCMP_GREATER,
|
|
|
|
D3DCMP_NOTEQUAL,
|
|
|
|
D3DCMP_NEVER,
|
|
|
|
D3DCMP_ALWAYS,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const D3DSTENCILOP s_stencilOp[] =
|
|
|
|
{
|
|
|
|
D3DSTENCILOP_ZERO,
|
|
|
|
D3DSTENCILOP_KEEP,
|
|
|
|
D3DSTENCILOP_REPLACE,
|
|
|
|
D3DSTENCILOP_INCR,
|
|
|
|
D3DSTENCILOP_INCRSAT,
|
|
|
|
D3DSTENCILOP_DECR,
|
|
|
|
D3DSTENCILOP_DECRSAT,
|
|
|
|
D3DSTENCILOP_INVERT,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const D3DRENDERSTATETYPE s_stencilFuncRs[] =
|
|
|
|
{
|
|
|
|
D3DRS_STENCILFUNC,
|
|
|
|
D3DRS_CCW_STENCILFUNC,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const D3DRENDERSTATETYPE s_stencilFailRs[] =
|
|
|
|
{
|
|
|
|
D3DRS_STENCILFAIL,
|
|
|
|
D3DRS_CCW_STENCILFAIL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const D3DRENDERSTATETYPE s_stencilZFailRs[] =
|
|
|
|
{
|
|
|
|
D3DRS_STENCILZFAIL,
|
|
|
|
D3DRS_CCW_STENCILZFAIL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const D3DRENDERSTATETYPE s_stencilZPassRs[] =
|
|
|
|
{
|
|
|
|
D3DRS_STENCILPASS,
|
|
|
|
D3DRS_CCW_STENCILPASS,
|
|
|
|
};
|
|
|
|
|
2012-08-06 01:51:49 +04:00
|
|
|
static const D3DCULL s_cullMode[] =
|
|
|
|
{
|
|
|
|
D3DCULL_NONE,
|
|
|
|
D3DCULL_CW,
|
|
|
|
D3DCULL_CCW,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const D3DTEXTUREADDRESS s_textureAddress[] =
|
|
|
|
{
|
|
|
|
D3DTADDRESS_WRAP,
|
|
|
|
D3DTADDRESS_MIRROR,
|
|
|
|
D3DTADDRESS_CLAMP,
|
2015-09-12 03:40:38 +03:00
|
|
|
D3DTADDRESS_BORDER,
|
2012-08-06 01:51:49 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static const D3DTEXTUREFILTERTYPE s_textureFilter[] =
|
|
|
|
{
|
|
|
|
D3DTEXF_LINEAR,
|
|
|
|
D3DTEXF_POINT,
|
|
|
|
D3DTEXF_ANISOTROPIC,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TextureFormatInfo
|
|
|
|
{
|
|
|
|
D3DFORMAT m_fmt;
|
|
|
|
};
|
|
|
|
|
2014-07-21 07:27:13 +04:00
|
|
|
static TextureFormatInfo s_textureFormat[] =
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2015-01-11 07:38:47 +03:00
|
|
|
{ D3DFMT_DXT1 }, // BC1
|
2013-09-09 08:03:03 +04:00
|
|
|
{ D3DFMT_DXT3 }, // BC2
|
|
|
|
{ D3DFMT_DXT5 }, // BC3
|
|
|
|
{ D3DFMT_UNKNOWN }, // BC4
|
|
|
|
{ D3DFMT_UNKNOWN }, // BC5
|
2014-08-02 06:24:42 +04:00
|
|
|
{ D3DFMT_UNKNOWN }, // BC6H
|
|
|
|
{ D3DFMT_UNKNOWN }, // BC7
|
2013-09-09 08:03:03 +04:00
|
|
|
{ D3DFMT_UNKNOWN }, // ETC1
|
|
|
|
{ D3DFMT_UNKNOWN }, // ETC2
|
|
|
|
{ D3DFMT_UNKNOWN }, // ETC2A
|
|
|
|
{ D3DFMT_UNKNOWN }, // ETC2A1
|
|
|
|
{ D3DFMT_UNKNOWN }, // PTC12
|
|
|
|
{ D3DFMT_UNKNOWN }, // PTC14
|
|
|
|
{ D3DFMT_UNKNOWN }, // PTC12A
|
|
|
|
{ D3DFMT_UNKNOWN }, // PTC14A
|
|
|
|
{ D3DFMT_UNKNOWN }, // PTC22
|
|
|
|
{ D3DFMT_UNKNOWN }, // PTC24
|
2018-06-11 19:17:57 +03:00
|
|
|
{ D3DFMT_UNKNOWN }, // ATC,
|
|
|
|
{ D3DFMT_UNKNOWN }, // ATCE,
|
|
|
|
{ D3DFMT_UNKNOWN }, // ATCI,
|
|
|
|
{ D3DFMT_UNKNOWN }, // ASTC4x4,
|
|
|
|
{ D3DFMT_UNKNOWN }, // ASTC5x5,
|
|
|
|
{ D3DFMT_UNKNOWN }, // ASTC6x6,
|
|
|
|
{ D3DFMT_UNKNOWN }, // ASTC8x5,
|
|
|
|
{ D3DFMT_UNKNOWN }, // ASTC8x6,
|
|
|
|
{ D3DFMT_UNKNOWN }, // ASTC10x5,
|
2013-09-09 08:03:03 +04:00
|
|
|
{ D3DFMT_UNKNOWN }, // Unknown
|
2014-08-13 08:47:01 +04:00
|
|
|
{ D3DFMT_A1 }, // R1
|
2015-08-31 20:16:36 +03:00
|
|
|
{ D3DFMT_A8 }, // A8
|
2014-03-26 10:07:51 +04:00
|
|
|
{ D3DFMT_L8 }, // R8
|
2015-08-29 03:41:24 +03:00
|
|
|
{ D3DFMT_UNKNOWN }, // R8I
|
|
|
|
{ D3DFMT_UNKNOWN }, // R8U
|
2015-08-28 02:35:27 +03:00
|
|
|
{ D3DFMT_UNKNOWN }, // R8S
|
2015-08-29 03:41:24 +03:00
|
|
|
{ D3DFMT_L16 }, // R16
|
|
|
|
{ D3DFMT_UNKNOWN }, // R16I
|
|
|
|
{ D3DFMT_UNKNOWN }, // R16U
|
2014-03-26 10:07:51 +04:00
|
|
|
{ D3DFMT_R16F }, // R16F
|
2015-08-28 02:35:27 +03:00
|
|
|
{ D3DFMT_UNKNOWN }, // R16S
|
2015-08-31 20:16:36 +03:00
|
|
|
{ D3DFMT_UNKNOWN }, // R32I
|
2015-08-29 00:48:51 +03:00
|
|
|
{ D3DFMT_UNKNOWN }, // R32U
|
2014-07-22 08:13:16 +04:00
|
|
|
{ D3DFMT_R32F }, // R32F
|
2014-07-26 10:16:11 +04:00
|
|
|
{ D3DFMT_A8L8 }, // RG8
|
2015-08-29 03:41:24 +03:00
|
|
|
{ D3DFMT_UNKNOWN }, // RG8I
|
|
|
|
{ D3DFMT_UNKNOWN }, // RG8U
|
2015-08-28 02:35:27 +03:00
|
|
|
{ D3DFMT_UNKNOWN }, // RG8S
|
2014-07-22 08:13:16 +04:00
|
|
|
{ D3DFMT_G16R16 }, // RG16
|
2015-08-29 03:41:24 +03:00
|
|
|
{ D3DFMT_UNKNOWN }, // RG16I
|
|
|
|
{ D3DFMT_UNKNOWN }, // RG16U
|
2014-07-22 08:13:16 +04:00
|
|
|
{ D3DFMT_G16R16F }, // RG16F
|
2015-08-28 02:35:27 +03:00
|
|
|
{ D3DFMT_UNKNOWN }, // RG16S
|
2015-08-31 20:16:36 +03:00
|
|
|
{ D3DFMT_UNKNOWN }, // RG32I
|
2015-08-29 00:48:51 +03:00
|
|
|
{ D3DFMT_UNKNOWN }, // RG32U
|
2014-07-22 08:13:16 +04:00
|
|
|
{ D3DFMT_G32R32F }, // RG32F
|
2016-02-25 02:51:51 +03:00
|
|
|
{ D3DFMT_UNKNOWN }, // RGB8
|
|
|
|
{ D3DFMT_UNKNOWN }, // RGB8I
|
|
|
|
{ D3DFMT_UNKNOWN }, // RGB8U
|
|
|
|
{ D3DFMT_UNKNOWN }, // RGB8S
|
2015-09-30 02:06:06 +03:00
|
|
|
{ D3DFMT_UNKNOWN }, // RGB9E5F
|
2013-09-09 08:03:03 +04:00
|
|
|
{ D3DFMT_A8R8G8B8 }, // BGRA8
|
2015-04-11 10:17:49 +03:00
|
|
|
{ D3DFMT_UNKNOWN }, // RGBA8
|
2015-08-29 03:41:24 +03:00
|
|
|
{ D3DFMT_UNKNOWN }, // RGBA8I
|
|
|
|
{ D3DFMT_UNKNOWN }, // RGBA8U
|
2015-08-28 02:35:27 +03:00
|
|
|
{ D3DFMT_UNKNOWN }, // RGBA8S
|
2013-09-09 08:03:03 +04:00
|
|
|
{ D3DFMT_A16B16G16R16 }, // RGBA16
|
2015-08-29 03:41:24 +03:00
|
|
|
{ D3DFMT_UNKNOWN }, // RGBA16I
|
|
|
|
{ D3DFMT_UNKNOWN }, // RGBA16U
|
2013-09-09 08:03:03 +04:00
|
|
|
{ D3DFMT_A16B16G16R16F }, // RGBA16F
|
2015-08-28 02:35:27 +03:00
|
|
|
{ D3DFMT_UNKNOWN }, // RGBA16S
|
2015-08-31 20:16:36 +03:00
|
|
|
{ D3DFMT_UNKNOWN }, // RGBA32I
|
2015-08-29 00:48:51 +03:00
|
|
|
{ D3DFMT_UNKNOWN }, // RGBA32U
|
2014-07-22 08:13:16 +04:00
|
|
|
{ D3DFMT_A32B32G32R32F }, // RGBA32F
|
2013-09-09 08:03:03 +04:00
|
|
|
{ D3DFMT_R5G6B5 }, // R5G6B5
|
|
|
|
{ D3DFMT_A4R4G4B4 }, // RGBA4
|
|
|
|
{ D3DFMT_A1R5G5B5 }, // RGB5A1
|
|
|
|
{ D3DFMT_A2B10G10R10 }, // RGB10A2
|
2017-04-25 06:31:58 +03:00
|
|
|
{ D3DFMT_UNKNOWN }, // RG11B10F
|
2014-01-13 01:51:26 +04:00
|
|
|
{ D3DFMT_UNKNOWN }, // UnknownDepth
|
2015-01-11 07:38:47 +03:00
|
|
|
{ D3DFMT_D16 }, // D16
|
|
|
|
{ D3DFMT_D24X8 }, // D24
|
2014-01-13 01:51:26 +04:00
|
|
|
{ D3DFMT_D24S8 }, // D24S8
|
2015-01-11 07:38:47 +03:00
|
|
|
{ D3DFMT_D32 }, // D32
|
|
|
|
{ D3DFMT_DF16 }, // D16F
|
2014-01-13 01:51:26 +04:00
|
|
|
{ D3DFMT_DF24 }, // D24F
|
|
|
|
{ D3DFMT_D32F_LOCKABLE }, // D32F
|
2014-08-13 08:47:01 +04:00
|
|
|
{ D3DFMT_S8_LOCKABLE }, // D0S8
|
2012-08-06 01:51:49 +04:00
|
|
|
};
|
2014-07-21 07:27:13 +04:00
|
|
|
BX_STATIC_ASSERT(TextureFormat::Count == BX_COUNTOF(s_textureFormat) );
|
2012-08-06 01:51:49 +04:00
|
|
|
|
|
|
|
static ExtendedFormat s_extendedFormats[ExtendedFormat::Count] =
|
|
|
|
{
|
|
|
|
{ D3DFMT_ATI1, 0, D3DRTYPE_TEXTURE, false },
|
|
|
|
{ D3DFMT_ATI2, 0, D3DRTYPE_TEXTURE, false },
|
|
|
|
{ D3DFMT_DF16, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, false },
|
|
|
|
{ D3DFMT_DF24, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, false },
|
|
|
|
{ D3DFMT_INST, 0, D3DRTYPE_SURFACE, false },
|
|
|
|
{ D3DFMT_INTZ, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, false },
|
|
|
|
{ D3DFMT_NULL, D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, false },
|
|
|
|
{ D3DFMT_RESZ, D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, false },
|
|
|
|
{ D3DFMT_RAWZ, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, false },
|
2016-03-17 01:09:15 +03:00
|
|
|
{ D3DFMT_ATOC, 0, D3DRTYPE_SURFACE, false },
|
2012-08-06 01:51:49 +04:00
|
|
|
};
|
|
|
|
|
2013-07-27 09:55:13 +04:00
|
|
|
static const GUID IID_IDirect3D9 = { 0x81bdcbca, 0x64d4, 0x426d, { 0xae, 0x8d, 0xad, 0x1, 0x47, 0xf4, 0x27, 0x5c } };
|
|
|
|
static const GUID IID_IDirect3DDevice9Ex = { 0xb18b10ce, 0x2649, 0x405a, { 0x87, 0xf, 0x95, 0xf7, 0x77, 0xd4, 0x31, 0x3a } };
|
|
|
|
|
2014-10-23 07:45:08 +04:00
|
|
|
typedef HRESULT (WINAPI *Direct3DCreate9ExFn)(UINT SDKVersion, IDirect3D9Ex**);
|
|
|
|
static Direct3DCreate9ExFn Direct3DCreate9Ex;
|
|
|
|
typedef IDirect3D9* (WINAPI *Direct3DCreate9Fn)(UINT SDKVersion);
|
|
|
|
static Direct3DCreate9Fn Direct3DCreate9;
|
2014-10-07 09:10:55 +04:00
|
|
|
static PFN_D3DPERF_SET_MARKER D3DPERF_SetMarker;
|
|
|
|
static PFN_D3DPERF_BEGIN_EVENT D3DPERF_BeginEvent;
|
|
|
|
static PFN_D3DPERF_END_EVENT D3DPERF_EndEvent;
|
|
|
|
|
2017-05-14 08:21:02 +03:00
|
|
|
static const D3DVERTEXELEMENT9 s_attrib[] =
|
|
|
|
{
|
|
|
|
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
|
|
|
|
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
|
|
|
|
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 },
|
|
|
|
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BINORMAL, 0 },
|
|
|
|
{ 0, 0, D3DDECLTYPE_UBYTE4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 },
|
|
|
|
{ 0, 0, D3DDECLTYPE_UBYTE4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 1 },
|
2017-06-07 03:25:17 +03:00
|
|
|
{ 0, 0, D3DDECLTYPE_UBYTE4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 2 },
|
|
|
|
{ 0, 0, D3DDECLTYPE_UBYTE4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 3 },
|
2017-05-14 08:21:02 +03:00
|
|
|
{ 0, 0, D3DDECLTYPE_UBYTE4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDINDICES, 0 },
|
|
|
|
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 0 },
|
|
|
|
{ 0, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
|
|
|
|
{ 0, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 },
|
|
|
|
{ 0, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 2 },
|
|
|
|
{ 0, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 3 },
|
|
|
|
{ 0, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 4 },
|
|
|
|
{ 0, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 5 },
|
|
|
|
{ 0, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 6 },
|
|
|
|
{ 0, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 7 },
|
|
|
|
D3DDECL_END()
|
|
|
|
};
|
|
|
|
BX_STATIC_ASSERT(Attrib::Count == BX_COUNTOF(s_attrib)-1);
|
|
|
|
|
|
|
|
static const uint8_t s_attribType[][4][2] =
|
|
|
|
{
|
|
|
|
{ // Uint8
|
|
|
|
{ D3DDECLTYPE_UBYTE4, D3DDECLTYPE_UBYTE4N },
|
|
|
|
{ D3DDECLTYPE_UBYTE4, D3DDECLTYPE_UBYTE4N },
|
|
|
|
{ D3DDECLTYPE_UBYTE4, D3DDECLTYPE_UBYTE4N },
|
|
|
|
{ D3DDECLTYPE_UBYTE4, D3DDECLTYPE_UBYTE4N },
|
|
|
|
},
|
|
|
|
{ // Uint10
|
|
|
|
{ D3DDECLTYPE_UDEC3, D3DDECLTYPE_DEC3N },
|
|
|
|
{ D3DDECLTYPE_UDEC3, D3DDECLTYPE_DEC3N },
|
|
|
|
{ D3DDECLTYPE_UDEC3, D3DDECLTYPE_DEC3N },
|
|
|
|
{ D3DDECLTYPE_UDEC3, D3DDECLTYPE_DEC3N },
|
|
|
|
},
|
|
|
|
{ // Int16
|
|
|
|
{ D3DDECLTYPE_SHORT2, D3DDECLTYPE_SHORT2N },
|
|
|
|
{ D3DDECLTYPE_SHORT2, D3DDECLTYPE_SHORT2N },
|
|
|
|
{ D3DDECLTYPE_SHORT4, D3DDECLTYPE_SHORT4N },
|
|
|
|
{ D3DDECLTYPE_SHORT4, D3DDECLTYPE_SHORT4N },
|
|
|
|
},
|
|
|
|
{ // Half
|
|
|
|
{ D3DDECLTYPE_FLOAT16_2, D3DDECLTYPE_FLOAT16_2 },
|
|
|
|
{ D3DDECLTYPE_FLOAT16_2, D3DDECLTYPE_FLOAT16_2 },
|
|
|
|
{ D3DDECLTYPE_FLOAT16_4, D3DDECLTYPE_FLOAT16_4 },
|
|
|
|
{ D3DDECLTYPE_FLOAT16_4, D3DDECLTYPE_FLOAT16_4 },
|
|
|
|
},
|
|
|
|
{ // Float
|
|
|
|
{ D3DDECLTYPE_FLOAT1, D3DDECLTYPE_FLOAT1 },
|
|
|
|
{ D3DDECLTYPE_FLOAT2, D3DDECLTYPE_FLOAT2 },
|
|
|
|
{ D3DDECLTYPE_FLOAT3, D3DDECLTYPE_FLOAT3 },
|
|
|
|
{ D3DDECLTYPE_FLOAT4, D3DDECLTYPE_FLOAT4 },
|
|
|
|
},
|
|
|
|
};
|
|
|
|
BX_STATIC_ASSERT(AttribType::Count == BX_COUNTOF(s_attribType) );
|
|
|
|
|
|
|
|
static D3DVERTEXELEMENT9* fillVertexDecl(uint8_t _stream, D3DVERTEXELEMENT9* _out, const VertexDecl& _decl)
|
|
|
|
{
|
|
|
|
D3DVERTEXELEMENT9* elem = _out;
|
|
|
|
|
|
|
|
for (uint32_t attr = 0; attr < Attrib::Count; ++attr)
|
|
|
|
{
|
|
|
|
if (UINT16_MAX != _decl.m_attributes[attr])
|
|
|
|
{
|
|
|
|
uint8_t num;
|
|
|
|
AttribType::Enum type;
|
|
|
|
bool normalized;
|
|
|
|
bool asInt;
|
|
|
|
_decl.decode(Attrib::Enum(attr), num, type, normalized, asInt);
|
|
|
|
|
|
|
|
bx::memCopy(elem, &s_attrib[attr], sizeof(D3DVERTEXELEMENT9) );
|
|
|
|
|
|
|
|
elem->Stream = _stream;
|
|
|
|
elem->Type = s_attribType[type][num-1][normalized];
|
|
|
|
elem->Offset = _decl.m_offset[attr];
|
|
|
|
++elem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return elem;
|
|
|
|
}
|
|
|
|
|
2016-11-16 03:57:28 +03:00
|
|
|
inline bool isLost(HRESULT _hr)
|
|
|
|
{
|
|
|
|
return false
|
|
|
|
|| _hr == D3DERR_DEVICELOST
|
|
|
|
|| _hr == D3DERR_DRIVERINTERNALERROR
|
|
|
|
#if !defined(D3D_DISABLE_9EX)
|
|
|
|
|| _hr == D3DERR_DEVICEHUNG
|
|
|
|
|| _hr == D3DERR_DEVICEREMOVED
|
|
|
|
#endif // !defined(D3D_DISABLE_9EX)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
struct RendererContextD3D9 : public RendererContextI
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2014-05-27 01:09:26 +04:00
|
|
|
RendererContextD3D9()
|
2013-09-21 09:13:58 +04:00
|
|
|
: m_d3d9(NULL)
|
|
|
|
, m_device(NULL)
|
2015-05-15 23:14:35 +03:00
|
|
|
, m_flushQuery(NULL)
|
2015-04-21 02:22:40 +03:00
|
|
|
, m_swapChain(NULL)
|
2013-09-21 09:13:58 +04:00
|
|
|
, m_captureTexture(NULL)
|
|
|
|
, m_captureSurface(NULL)
|
|
|
|
, m_captureResolve(NULL)
|
2015-01-22 07:39:42 +03:00
|
|
|
, m_maxAnisotropy(1)
|
2012-08-06 01:51:49 +04:00
|
|
|
, m_initialized(false)
|
|
|
|
, m_amd(false)
|
|
|
|
, m_nvidia(false)
|
2016-03-17 01:09:15 +03:00
|
|
|
, m_atocSupport(false)
|
2015-08-21 23:07:58 +03:00
|
|
|
, m_instancingSupport(false)
|
2015-11-02 04:28:23 +03:00
|
|
|
, m_occlusionQuerySupport(false)
|
2016-03-17 01:09:15 +03:00
|
|
|
, m_timerQuerySupport(false)
|
2012-08-06 01:51:49 +04:00
|
|
|
, m_rtMsaa(false)
|
2014-10-14 08:14:51 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~RendererContextD3D9()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-12-08 08:52:52 +03:00
|
|
|
bool init(const Init& _init)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2015-08-20 22:30:59 +03:00
|
|
|
struct ErrorState
|
|
|
|
{
|
|
|
|
enum Enum
|
|
|
|
{
|
|
|
|
Default,
|
|
|
|
LoadedD3D9,
|
|
|
|
CreatedD3D9,
|
|
|
|
CreatedDevice,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
ErrorState::Enum errorState = ErrorState::Default;
|
2015-07-31 04:36:12 +03:00
|
|
|
|
2017-06-10 07:57:08 +03:00
|
|
|
m_fbh.idx = kInvalidHandle;
|
2017-02-09 06:55:31 +03:00
|
|
|
bx::memSet(m_uniforms, 0, sizeof(m_uniforms) );
|
|
|
|
bx::memSet(&m_resolution, 0, sizeof(m_resolution) );
|
2012-08-06 01:51:49 +04:00
|
|
|
|
|
|
|
D3DFORMAT adapterFormat = D3DFMT_X8R8G8B8;
|
|
|
|
|
|
|
|
// http://msdn.microsoft.com/en-us/library/windows/desktop/bb172588%28v=vs.85%29.aspx
|
2017-02-09 06:55:31 +03:00
|
|
|
bx::memSet(&m_params, 0, sizeof(m_params) );
|
2018-04-18 01:42:18 +03:00
|
|
|
m_params.BackBufferWidth = _init.resolution.width;
|
|
|
|
m_params.BackBufferHeight = _init.resolution.height;
|
2012-08-06 01:51:49 +04:00
|
|
|
m_params.BackBufferFormat = adapterFormat;
|
|
|
|
m_params.BackBufferCount = 1;
|
|
|
|
m_params.MultiSampleType = D3DMULTISAMPLE_NONE;
|
|
|
|
m_params.MultiSampleQuality = 0;
|
|
|
|
m_params.EnableAutoDepthStencil = TRUE;
|
|
|
|
m_params.AutoDepthStencilFormat = D3DFMT_D24S8;
|
|
|
|
m_params.Flags = D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL;
|
2017-06-12 08:54:52 +03:00
|
|
|
|
2012-08-06 01:51:49 +04:00
|
|
|
m_params.FullScreen_RefreshRateInHz = 0;
|
|
|
|
m_params.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
|
|
|
|
m_params.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
2014-09-08 04:17:38 +04:00
|
|
|
m_params.hDeviceWindow = NULL;
|
2012-08-06 01:51:49 +04:00
|
|
|
m_params.Windowed = true;
|
|
|
|
|
|
|
|
RECT rect;
|
2015-04-21 02:22:40 +03:00
|
|
|
GetWindowRect( (HWND)g_platformData.nwh, &rect);
|
2015-09-10 23:29:12 +03:00
|
|
|
m_params.BackBufferWidth = rect.right-rect.left;
|
2012-08-06 01:51:49 +04:00
|
|
|
m_params.BackBufferHeight = rect.bottom-rect.top;
|
|
|
|
|
2013-07-27 09:55:13 +04:00
|
|
|
m_d3d9dll = bx::dlopen("d3d9.dll");
|
2015-07-31 04:36:12 +03:00
|
|
|
|
|
|
|
if (NULL == m_d3d9dll)
|
|
|
|
{
|
2017-07-19 09:20:57 +03:00
|
|
|
BX_TRACE("Init error: Failed to load d3d9.dll.");
|
2015-07-31 04:36:12 +03:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2015-08-20 22:30:59 +03:00
|
|
|
errorState = ErrorState::LoadedD3D9;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2017-10-02 07:18:29 +03:00
|
|
|
m_nvapi.init();
|
|
|
|
|
2014-10-07 09:10:55 +04:00
|
|
|
if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) )
|
|
|
|
{
|
|
|
|
D3DPERF_SetMarker = (PFN_D3DPERF_SET_MARKER )bx::dlsym(m_d3d9dll, "D3DPERF_SetMarker");
|
|
|
|
D3DPERF_BeginEvent = (PFN_D3DPERF_BEGIN_EVENT)bx::dlsym(m_d3d9dll, "D3DPERF_BeginEvent");
|
|
|
|
D3DPERF_EndEvent = (PFN_D3DPERF_END_EVENT )bx::dlsym(m_d3d9dll, "D3DPERF_EndEvent");
|
|
|
|
|
|
|
|
BX_CHECK(NULL != D3DPERF_SetMarker
|
|
|
|
&& NULL != D3DPERF_BeginEvent
|
|
|
|
&& NULL != D3DPERF_EndEvent
|
|
|
|
, "Failed to initialize PIX events."
|
|
|
|
);
|
|
|
|
}
|
2015-10-29 03:54:50 +03:00
|
|
|
|
|
|
|
m_d3d9ex = NULL;
|
|
|
|
m_deviceEx = NULL;
|
2013-07-27 09:55:13 +04:00
|
|
|
|
2014-10-23 07:45:08 +04:00
|
|
|
Direct3DCreate9Ex = (Direct3DCreate9ExFn)bx::dlsym(m_d3d9dll, "Direct3DCreate9Ex");
|
2015-10-29 03:54:50 +03:00
|
|
|
if (BX_ENABLED(BGFX_CONFIG_RENDERER_DIRECT3D9EX)
|
|
|
|
&& NULL != Direct3DCreate9Ex)
|
2013-07-27 09:55:13 +04:00
|
|
|
{
|
2014-10-23 07:45:08 +04:00
|
|
|
Direct3DCreate9Ex(D3D_SDK_VERSION, &m_d3d9ex);
|
2016-03-17 06:18:02 +03:00
|
|
|
if (NULL != m_d3d9ex)
|
2016-03-04 03:28:27 +03:00
|
|
|
{
|
2016-03-17 06:18:02 +03:00
|
|
|
HRESULT hr = m_d3d9ex->QueryInterface(IID_IDirect3D9, (void**)&m_d3d9);
|
|
|
|
if (FAILED(hr) )
|
|
|
|
{
|
|
|
|
BX_TRACE("Failed to query D3D9 interface 0x%08x.", hr);
|
|
|
|
DX_RELEASE(m_d3d9ex, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_pool = D3DPOOL_DEFAULT;
|
|
|
|
}
|
2016-03-04 03:28:27 +03:00
|
|
|
}
|
2013-07-27 09:55:13 +04:00
|
|
|
}
|
2016-03-04 03:28:27 +03:00
|
|
|
|
|
|
|
if (NULL == m_d3d9)
|
2013-07-27 09:55:13 +04:00
|
|
|
{
|
2014-10-23 07:45:08 +04:00
|
|
|
Direct3DCreate9 = (Direct3DCreate9Fn)bx::dlsym(m_d3d9dll, "Direct3DCreate9");
|
2015-07-31 04:36:12 +03:00
|
|
|
|
|
|
|
if (NULL == Direct3DCreate9)
|
|
|
|
{
|
2017-07-19 09:20:57 +03:00
|
|
|
BX_TRACE("Init error: Function Direct3DCreate9 not found.");
|
2015-07-31 04:36:12 +03:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2014-10-23 07:45:08 +04:00
|
|
|
m_d3d9 = Direct3DCreate9(D3D_SDK_VERSION);
|
2013-07-27 09:55:13 +04:00
|
|
|
m_pool = D3DPOOL_MANAGED;
|
|
|
|
}
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2015-07-31 04:36:12 +03:00
|
|
|
if (NULL == m_d3d9)
|
|
|
|
{
|
2017-07-19 09:20:57 +03:00
|
|
|
BX_TRACE("Init error: Unable to create Direct3D.");
|
2015-07-31 04:36:12 +03:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2015-08-20 22:30:59 +03:00
|
|
|
errorState = ErrorState::CreatedD3D9;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
|
|
|
{
|
2015-08-01 03:34:33 +03:00
|
|
|
m_adapter = D3DADAPTER_DEFAULT;
|
|
|
|
m_deviceType = BGFX_PCI_ID_SOFTWARE_RASTERIZER == g_caps.vendorId
|
|
|
|
? D3DDEVTYPE_REF
|
|
|
|
: D3DDEVTYPE_HAL
|
|
|
|
;
|
|
|
|
|
|
|
|
uint8_t numGPUs = uint8_t(bx::uint32_min(BX_COUNTOF(g_caps.gpu), m_d3d9->GetAdapterCount() ) );
|
|
|
|
for (uint32_t ii = 0; ii < numGPUs; ++ii)
|
2013-04-28 05:03:40 +04:00
|
|
|
{
|
2015-08-01 03:34:33 +03:00
|
|
|
D3DADAPTER_IDENTIFIER9 desc;
|
|
|
|
HRESULT hr = m_d3d9->GetAdapterIdentifier(ii, 0, &desc);
|
|
|
|
if (SUCCEEDED(hr) )
|
2015-03-27 01:01:47 +03:00
|
|
|
{
|
2015-08-01 03:34:33 +03:00
|
|
|
BX_TRACE("Adapter #%d", ii);
|
|
|
|
BX_TRACE("\tDriver: %s", desc.Driver);
|
|
|
|
BX_TRACE("\tDescription: %s", desc.Description);
|
|
|
|
BX_TRACE("\tDeviceName: %s", desc.DeviceName);
|
|
|
|
BX_TRACE("\tVendorId: 0x%08x, DeviceId: 0x%08x, SubSysId: 0x%08x, Revision: 0x%08x"
|
|
|
|
, desc.VendorId
|
|
|
|
, desc.DeviceId
|
|
|
|
, desc.SubSysId
|
|
|
|
, desc.Revision
|
|
|
|
);
|
|
|
|
|
|
|
|
g_caps.gpu[ii].vendorId = (uint16_t)desc.VendorId;
|
|
|
|
g_caps.gpu[ii].deviceId = (uint16_t)desc.DeviceId;
|
|
|
|
|
|
|
|
if (D3DADAPTER_DEFAULT == m_adapter)
|
2015-04-01 08:01:50 +03:00
|
|
|
{
|
2015-08-01 03:34:33 +03:00
|
|
|
if ( (BGFX_PCI_ID_NONE != g_caps.vendorId || 0 != g_caps.deviceId)
|
|
|
|
&& (BGFX_PCI_ID_NONE == g_caps.vendorId || desc.VendorId == g_caps.vendorId)
|
|
|
|
&& ( 0 == g_caps.deviceId || desc.DeviceId == g_caps.deviceId) )
|
|
|
|
{
|
|
|
|
m_adapter = ii;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BX_ENABLED(BGFX_CONFIG_DEBUG_PERFHUD)
|
2017-10-02 09:24:13 +03:00
|
|
|
&& 0 != bx::strFind(desc.Description, "PerfHUD") )
|
2015-08-01 03:34:33 +03:00
|
|
|
{
|
|
|
|
m_adapter = ii;
|
|
|
|
m_deviceType = D3DDEVTYPE_REF;
|
|
|
|
}
|
2015-04-01 08:01:50 +03:00
|
|
|
}
|
2015-03-27 01:01:47 +03:00
|
|
|
}
|
2013-04-28 05:03:40 +04:00
|
|
|
}
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2015-08-01 03:34:33 +03:00
|
|
|
DX_CHECK(m_d3d9->GetAdapterIdentifier(m_adapter, 0, &m_identifier) );
|
|
|
|
m_amd = m_identifier.VendorId == BGFX_PCI_ID_AMD;
|
|
|
|
m_nvidia = m_identifier.VendorId == BGFX_PCI_ID_NVIDIA;
|
|
|
|
g_caps.vendorId = 0 == m_identifier.VendorId
|
|
|
|
? BGFX_PCI_ID_SOFTWARE_RASTERIZER
|
|
|
|
: (uint16_t)m_identifier.VendorId
|
|
|
|
;
|
|
|
|
g_caps.deviceId = (uint16_t)m_identifier.DeviceId;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2015-08-01 03:34:33 +03:00
|
|
|
uint32_t behaviorFlags[] =
|
|
|
|
{
|
|
|
|
D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE | D3DCREATE_PUREDEVICE,
|
|
|
|
D3DCREATE_MIXED_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE,
|
|
|
|
D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE,
|
|
|
|
};
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2015-08-01 03:34:33 +03:00
|
|
|
for (uint32_t ii = 0; ii < BX_COUNTOF(behaviorFlags) && NULL == m_device; ++ii)
|
|
|
|
{
|
2015-10-29 03:54:50 +03:00
|
|
|
if (NULL != m_d3d9ex)
|
|
|
|
{
|
|
|
|
DX_CHECK(m_d3d9ex->CreateDeviceEx(m_adapter
|
|
|
|
, m_deviceType
|
|
|
|
, (HWND)g_platformData.nwh
|
|
|
|
, behaviorFlags[ii]
|
|
|
|
, &m_params
|
|
|
|
, NULL
|
|
|
|
, &m_deviceEx
|
|
|
|
) );
|
|
|
|
|
|
|
|
m_device = m_deviceEx;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DX_CHECK(m_d3d9->CreateDevice(m_adapter
|
|
|
|
, m_deviceType
|
|
|
|
, (HWND)g_platformData.nwh
|
|
|
|
, behaviorFlags[ii]
|
|
|
|
, &m_params
|
|
|
|
, &m_device
|
|
|
|
) );
|
|
|
|
}
|
2015-08-01 03:34:33 +03:00
|
|
|
}
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
|
2015-07-31 04:36:12 +03:00
|
|
|
if (NULL == m_device)
|
|
|
|
{
|
2017-07-19 09:20:57 +03:00
|
|
|
BX_TRACE("Init error: Unable to create Direct3D9 device.");
|
2015-07-31 04:36:12 +03:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2015-08-20 22:30:59 +03:00
|
|
|
errorState = ErrorState::CreatedDevice;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2014-09-08 04:17:38 +04:00
|
|
|
m_numWindows = 1;
|
|
|
|
|
2013-07-27 09:55:13 +04:00
|
|
|
if (NULL != m_d3d9ex)
|
|
|
|
{
|
|
|
|
DX_CHECK(m_device->QueryInterface(IID_IDirect3DDevice9Ex, (void**)&m_deviceEx) );
|
|
|
|
}
|
|
|
|
|
2015-11-02 04:28:23 +03:00
|
|
|
{
|
|
|
|
IDirect3DQuery9* timerQueryTest[3] = {};
|
|
|
|
m_timerQuerySupport = true
|
|
|
|
&& SUCCEEDED(m_device->CreateQuery(D3DQUERYTYPE_TIMESTAMPDISJOINT, &timerQueryTest[0]) )
|
|
|
|
&& SUCCEEDED(m_device->CreateQuery(D3DQUERYTYPE_TIMESTAMP, &timerQueryTest[1]) )
|
|
|
|
&& SUCCEEDED(m_device->CreateQuery(D3DQUERYTYPE_TIMESTAMPFREQ, &timerQueryTest[2]) )
|
|
|
|
;
|
|
|
|
DX_RELEASE(timerQueryTest[0], 0);
|
|
|
|
DX_RELEASE(timerQueryTest[1], 0);
|
|
|
|
DX_RELEASE(timerQueryTest[2], 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
IDirect3DQuery9* occlusionQueryTest;
|
|
|
|
m_occlusionQuerySupport = true
|
|
|
|
&& SUCCEEDED(m_device->CreateQuery(D3DQUERYTYPE_OCCLUSION, &occlusionQueryTest) )
|
|
|
|
;
|
|
|
|
DX_RELEASE(occlusionQueryTest, 0);
|
|
|
|
}
|
|
|
|
|
2012-08-06 01:51:49 +04:00
|
|
|
DX_CHECK(m_device->GetDeviceCaps(&m_caps) );
|
|
|
|
|
|
|
|
// For shit GPUs that can create DX9 device but can't do simple stuff. GTFO!
|
2015-07-31 04:36:12 +03:00
|
|
|
BX_WARN( (D3DPTEXTURECAPS_SQUAREONLY & m_caps.TextureCaps) == 0, "D3DPTEXTURECAPS_SQUAREONLY");
|
|
|
|
BX_WARN( (D3DPTEXTURECAPS_MIPMAP & m_caps.TextureCaps) == D3DPTEXTURECAPS_MIPMAP, "D3DPTEXTURECAPS_MIPMAP");
|
|
|
|
BX_WARN( (D3DPTEXTURECAPS_ALPHA & m_caps.TextureCaps) == D3DPTEXTURECAPS_ALPHA, "D3DPTEXTURECAPS_ALPHA");
|
|
|
|
BX_WARN(m_caps.VertexShaderVersion >= D3DVS_VERSION(2, 0) && m_caps.PixelShaderVersion >= D3DPS_VERSION(2, 1)
|
2012-08-06 01:51:49 +04:00
|
|
|
, "Shader Model Version (vs: %x, ps: %x)."
|
|
|
|
, m_caps.VertexShaderVersion
|
|
|
|
, m_caps.PixelShaderVersion
|
|
|
|
);
|
2015-07-31 04:36:12 +03:00
|
|
|
|
|
|
|
if ( (D3DPTEXTURECAPS_SQUAREONLY & m_caps.TextureCaps) != 0
|
|
|
|
|| (D3DPTEXTURECAPS_MIPMAP & m_caps.TextureCaps) != D3DPTEXTURECAPS_MIPMAP
|
|
|
|
|| (D3DPTEXTURECAPS_ALPHA & m_caps.TextureCaps) != D3DPTEXTURECAPS_ALPHA
|
|
|
|
|| !(m_caps.VertexShaderVersion >= D3DVS_VERSION(2, 0) && m_caps.PixelShaderVersion >= D3DPS_VERSION(2, 1) ) )
|
|
|
|
{
|
2017-07-19 09:20:57 +03:00
|
|
|
BX_TRACE("Init error: Min spec not satisfied.");
|
2015-07-31 04:36:12 +03:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2012-08-06 01:51:49 +04:00
|
|
|
BX_TRACE("Max vertex shader 3.0 instr. slots: %d", m_caps.MaxVertexShader30InstructionSlots);
|
|
|
|
BX_TRACE("Max vertex shader constants: %d", m_caps.MaxVertexShaderConst);
|
|
|
|
BX_TRACE("Max fragment shader 2.0 instr. slots: %d", m_caps.PS20Caps.NumInstructionSlots);
|
|
|
|
BX_TRACE("Max fragment shader 3.0 instr. slots: %d", m_caps.MaxPixelShader30InstructionSlots);
|
2014-02-06 11:07:11 +04:00
|
|
|
BX_TRACE("Num simultaneous render targets: %d", m_caps.NumSimultaneousRTs);
|
2015-04-09 05:59:48 +03:00
|
|
|
BX_TRACE("Max vertex index: %d", m_caps.MaxVertexIndex);
|
2017-05-14 20:48:51 +03:00
|
|
|
BX_TRACE("Max streams: %d", m_caps.MaxStreams);
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2014-01-13 01:51:26 +04:00
|
|
|
g_caps.supported |= ( 0
|
2015-10-17 03:42:40 +03:00
|
|
|
| BGFX_CAPS_TEXTURE_3D
|
|
|
|
| BGFX_CAPS_TEXTURE_COMPARE_LEQUAL
|
|
|
|
| BGFX_CAPS_VERTEX_ATTRIB_HALF
|
|
|
|
| BGFX_CAPS_VERTEX_ATTRIB_UINT10
|
|
|
|
| BGFX_CAPS_FRAGMENT_DEPTH
|
|
|
|
| BGFX_CAPS_SWAP_CHAIN
|
|
|
|
| ( (UINT16_MAX < m_caps.MaxVertexIndex) ? BGFX_CAPS_INDEX32 : 0)
|
2015-10-23 07:30:55 +03:00
|
|
|
| ( (m_caps.DevCaps2 & D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES) ? BGFX_CAPS_TEXTURE_BLIT : 0)
|
|
|
|
| BGFX_CAPS_TEXTURE_READ_BACK
|
2015-11-02 04:28:23 +03:00
|
|
|
| (m_occlusionQuerySupport ? BGFX_CAPS_OCCLUSION_QUERY : 0)
|
2015-10-17 03:42:40 +03:00
|
|
|
);
|
2013-10-11 05:29:57 +04:00
|
|
|
|
2017-05-14 20:48:51 +03:00
|
|
|
m_caps.NumSimultaneousRTs = bx::uint32_min(m_caps.NumSimultaneousRTs, BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS);
|
|
|
|
m_caps.MaxStreams = bx::uint32_min(m_caps.MaxStreams, BGFX_CONFIG_MAX_VERTEX_STREAMS);
|
|
|
|
m_caps.MaxAnisotropy = bx::uint32_max(m_caps.MaxAnisotropy, 1);
|
2014-02-06 11:07:11 +04:00
|
|
|
|
2017-05-14 20:48:51 +03:00
|
|
|
g_caps.limits.maxTextureSize = uint16_t(bx::uint32_min(m_caps.MaxTextureWidth, m_caps.MaxTextureHeight) );
|
|
|
|
g_caps.limits.maxFBAttachments = uint8_t(m_caps.NumSimultaneousRTs);
|
|
|
|
g_caps.limits.maxVertexStreams = uint8_t(m_caps.MaxStreams);
|
2015-01-21 09:07:30 +03:00
|
|
|
|
2014-09-24 07:35:39 +04:00
|
|
|
if (BX_ENABLED(BGFX_CONFIG_RENDERER_USE_EXTENSIONS) )
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2014-09-24 07:35:39 +04:00
|
|
|
BX_TRACE("Extended formats:");
|
|
|
|
for (uint32_t ii = 0; ii < ExtendedFormat::Count; ++ii)
|
|
|
|
{
|
|
|
|
ExtendedFormat& fmt = s_extendedFormats[ii];
|
|
|
|
fmt.m_supported = SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter, m_deviceType, adapterFormat, fmt.m_usage, fmt.m_type, fmt.m_fmt) );
|
|
|
|
const char* fourcc = (const char*)&fmt.m_fmt;
|
|
|
|
BX_TRACE("\t%2d: %c%c%c%c %s", ii, fourcc[0], fourcc[1], fourcc[2], fourcc[3], fmt.m_supported ? "supported" : "");
|
|
|
|
BX_UNUSED(fourcc);
|
|
|
|
}
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2015-08-21 23:07:58 +03:00
|
|
|
m_instancingSupport = false
|
2014-09-24 07:35:39 +04:00
|
|
|
|| s_extendedFormats[ExtendedFormat::Inst].m_supported
|
|
|
|
|| (m_caps.VertexShaderVersion >= D3DVS_VERSION(3, 0) )
|
|
|
|
;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2016-03-17 01:09:15 +03:00
|
|
|
m_atocSupport = false
|
|
|
|
|| s_extendedFormats[ExtendedFormat::Atoc].m_supported
|
|
|
|
;
|
|
|
|
|
2014-09-24 07:35:39 +04:00
|
|
|
if (m_amd
|
|
|
|
&& s_extendedFormats[ExtendedFormat::Inst].m_supported)
|
|
|
|
{ // AMD only
|
|
|
|
m_device->SetRenderState(D3DRS_POINTSIZE, D3DFMT_INST);
|
|
|
|
}
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2014-09-24 07:35:39 +04:00
|
|
|
if (s_extendedFormats[ExtendedFormat::Intz].m_supported)
|
|
|
|
{
|
|
|
|
s_textureFormat[TextureFormat::D24].m_fmt = D3DFMT_INTZ;
|
|
|
|
s_textureFormat[TextureFormat::D32].m_fmt = D3DFMT_INTZ;
|
|
|
|
}
|
2014-05-22 07:33:12 +04:00
|
|
|
|
2014-09-24 07:35:39 +04:00
|
|
|
s_textureFormat[TextureFormat::BC4].m_fmt = s_extendedFormats[ExtendedFormat::Ati1].m_supported ? D3DFMT_ATI1 : D3DFMT_UNKNOWN;
|
|
|
|
s_textureFormat[TextureFormat::BC5].m_fmt = s_extendedFormats[ExtendedFormat::Ati2].m_supported ? D3DFMT_ATI2 : D3DFMT_UNKNOWN;
|
2013-10-11 05:29:57 +04:00
|
|
|
|
2016-03-17 01:09:15 +03:00
|
|
|
g_caps.supported |= m_instancingSupport ? BGFX_CAPS_INSTANCING : 0;
|
|
|
|
g_caps.supported |= m_atocSupport ? BGFX_CAPS_ALPHA_TO_COVERAGE : 0;
|
2016-02-07 00:42:27 +03:00
|
|
|
}
|
2014-07-28 07:44:02 +04:00
|
|
|
|
2016-02-07 00:42:27 +03:00
|
|
|
for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii)
|
|
|
|
{
|
2016-06-27 23:19:26 +03:00
|
|
|
uint16_t support = BGFX_CAPS_FORMAT_TEXTURE_NONE;
|
2015-10-23 22:57:04 +03:00
|
|
|
|
2016-02-07 00:42:27 +03:00
|
|
|
support |= SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter
|
|
|
|
, m_deviceType
|
|
|
|
, adapterFormat
|
|
|
|
, 0
|
|
|
|
, D3DRTYPE_TEXTURE
|
|
|
|
, s_textureFormat[ii].m_fmt
|
|
|
|
) ) ? BGFX_CAPS_FORMAT_TEXTURE_2D : BGFX_CAPS_FORMAT_TEXTURE_NONE;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2016-02-07 00:42:27 +03:00
|
|
|
support |= SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter
|
|
|
|
, m_deviceType
|
|
|
|
, adapterFormat
|
|
|
|
, D3DUSAGE_QUERY_SRGBREAD
|
|
|
|
, D3DRTYPE_TEXTURE
|
|
|
|
, s_textureFormat[ii].m_fmt
|
|
|
|
) ) ? BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB : BGFX_CAPS_FORMAT_TEXTURE_NONE;
|
|
|
|
|
|
|
|
support |= SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter
|
|
|
|
, m_deviceType
|
|
|
|
, adapterFormat
|
|
|
|
, 0
|
|
|
|
, D3DRTYPE_VOLUMETEXTURE
|
|
|
|
, s_textureFormat[ii].m_fmt
|
|
|
|
) ) ? BGFX_CAPS_FORMAT_TEXTURE_3D : BGFX_CAPS_FORMAT_TEXTURE_NONE;
|
|
|
|
|
|
|
|
support |= SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter
|
|
|
|
, m_deviceType
|
|
|
|
, adapterFormat
|
|
|
|
, D3DUSAGE_QUERY_SRGBREAD
|
|
|
|
, D3DRTYPE_VOLUMETEXTURE
|
|
|
|
, s_textureFormat[ii].m_fmt
|
|
|
|
) ) ? BGFX_CAPS_FORMAT_TEXTURE_3D_SRGB : BGFX_CAPS_FORMAT_TEXTURE_NONE;
|
|
|
|
|
|
|
|
support |= SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter
|
|
|
|
, m_deviceType
|
|
|
|
, adapterFormat
|
|
|
|
, 0
|
|
|
|
, D3DRTYPE_CUBETEXTURE
|
|
|
|
, s_textureFormat[ii].m_fmt
|
|
|
|
) ) ? BGFX_CAPS_FORMAT_TEXTURE_CUBE : BGFX_CAPS_FORMAT_TEXTURE_NONE;
|
|
|
|
|
|
|
|
support |= SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter
|
|
|
|
, m_deviceType
|
|
|
|
, adapterFormat
|
|
|
|
, D3DUSAGE_QUERY_SRGBREAD
|
|
|
|
, D3DRTYPE_CUBETEXTURE
|
|
|
|
, s_textureFormat[ii].m_fmt
|
|
|
|
) ) ? BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB : BGFX_CAPS_FORMAT_TEXTURE_NONE;
|
|
|
|
|
|
|
|
support |= SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter
|
|
|
|
, m_deviceType
|
|
|
|
, adapterFormat
|
|
|
|
, D3DUSAGE_QUERY_VERTEXTEXTURE
|
|
|
|
, D3DRTYPE_TEXTURE
|
|
|
|
, s_textureFormat[ii].m_fmt
|
|
|
|
) ) ? BGFX_CAPS_FORMAT_TEXTURE_VERTEX : BGFX_CAPS_FORMAT_TEXTURE_NONE;
|
|
|
|
|
|
|
|
support |= SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter
|
|
|
|
, m_deviceType
|
|
|
|
, adapterFormat
|
2017-04-04 08:42:27 +03:00
|
|
|
, bimg::isDepth(bimg::TextureFormat::Enum(ii) ) ? D3DUSAGE_DEPTHSTENCIL : D3DUSAGE_RENDERTARGET
|
2016-02-07 00:42:27 +03:00
|
|
|
, D3DRTYPE_TEXTURE
|
|
|
|
, s_textureFormat[ii].m_fmt
|
|
|
|
) ) ? BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER : BGFX_CAPS_FORMAT_TEXTURE_NONE;
|
|
|
|
|
|
|
|
support |= SUCCEEDED(m_d3d9->CheckDeviceMultiSampleType(m_adapter
|
|
|
|
, m_deviceType
|
|
|
|
, s_textureFormat[ii].m_fmt
|
|
|
|
, true
|
|
|
|
, D3DMULTISAMPLE_2_SAMPLES
|
|
|
|
, NULL
|
|
|
|
) ) ? BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA : BGFX_CAPS_FORMAT_TEXTURE_NONE;
|
|
|
|
|
2016-07-24 02:16:43 +03:00
|
|
|
support |= SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter
|
|
|
|
, m_deviceType
|
|
|
|
, adapterFormat
|
2017-04-04 08:42:27 +03:00
|
|
|
, bimg::isDepth(bimg::TextureFormat::Enum(ii) ) ? D3DUSAGE_DEPTHSTENCIL : D3DUSAGE_RENDERTARGET
|
2016-07-24 02:16:43 +03:00
|
|
|
, D3DRTYPE_TEXTURE
|
|
|
|
, s_textureFormat[ii].m_fmt
|
|
|
|
) ) ? BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN : BGFX_CAPS_FORMAT_TEXTURE_NONE;
|
|
|
|
|
2016-02-07 00:42:27 +03:00
|
|
|
g_caps.formats[ii] = support;
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
m_fmtDepth = D3DFMT_D24S8;
|
|
|
|
|
2014-09-28 01:15:56 +04:00
|
|
|
{
|
|
|
|
IDirect3DSwapChain9* swapChain;
|
|
|
|
DX_CHECK(m_device->GetSwapChain(0, &swapChain) );
|
|
|
|
|
|
|
|
// GPA increases swapchain ref count.
|
|
|
|
//
|
|
|
|
// This causes assert in debug. When debugger is present refcount
|
|
|
|
// checks are off.
|
|
|
|
setGraphicsDebuggerPresent(1 != getRefCount(swapChain) );
|
|
|
|
|
|
|
|
DX_RELEASE(swapChain, 0);
|
|
|
|
}
|
|
|
|
|
2014-10-26 04:07:51 +03:00
|
|
|
// Init reserved part of view name.
|
2015-02-22 02:40:51 +03:00
|
|
|
for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_VIEWS; ++ii)
|
2014-10-26 04:07:51 +03:00
|
|
|
{
|
2015-11-16 17:42:56 +03:00
|
|
|
bx::snprintf(s_viewName[ii], BGFX_CONFIG_MAX_VIEW_NAME_RESERVED + 1, "%3d ", ii);
|
|
|
|
mbstowcs(s_viewNameW[ii], s_viewName[ii], BGFX_CONFIG_MAX_VIEW_NAME_RESERVED);
|
2014-10-26 04:07:51 +03:00
|
|
|
}
|
|
|
|
|
2015-10-30 06:41:19 +03:00
|
|
|
if (NULL != m_deviceEx)
|
|
|
|
{
|
|
|
|
int32_t gpuPriority;
|
|
|
|
DX_CHECK(m_deviceEx->GetGPUThreadPriority(&gpuPriority) );
|
|
|
|
BX_TRACE("GPU thread priority: %d", gpuPriority);
|
|
|
|
|
|
|
|
uint32_t maxLatency;
|
|
|
|
DX_CHECK(m_deviceEx->GetMaximumFrameLatency(&maxLatency) );
|
|
|
|
BX_TRACE("GPU max frame latency: %d", maxLatency);
|
|
|
|
}
|
|
|
|
|
2012-08-06 01:51:49 +04:00
|
|
|
postReset();
|
|
|
|
|
|
|
|
m_initialized = true;
|
2015-07-31 04:36:12 +03:00
|
|
|
|
2016-01-14 08:18:59 +03:00
|
|
|
g_internalData.context = m_device;
|
2015-07-31 04:36:12 +03:00
|
|
|
return true;
|
|
|
|
|
|
|
|
error:
|
|
|
|
switch (errorState)
|
|
|
|
{
|
2015-08-20 22:30:59 +03:00
|
|
|
case ErrorState::CreatedDevice:
|
2015-07-31 04:36:12 +03:00
|
|
|
if (NULL != m_d3d9ex)
|
|
|
|
{
|
|
|
|
DX_RELEASE(m_deviceEx, 1);
|
|
|
|
DX_RELEASE(m_device, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DX_RELEASE(m_device, 0);
|
|
|
|
}
|
2018-01-29 08:31:34 +03:00
|
|
|
BX_FALLTHROUGH;
|
2015-07-31 04:36:12 +03:00
|
|
|
|
2015-08-20 22:30:59 +03:00
|
|
|
case ErrorState::CreatedD3D9:
|
2015-07-31 04:36:12 +03:00
|
|
|
if (NULL != m_d3d9ex)
|
|
|
|
{
|
|
|
|
DX_RELEASE(m_d3d9, 1);
|
|
|
|
DX_RELEASE(m_d3d9ex, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DX_RELEASE(m_d3d9, 0);
|
|
|
|
}
|
2018-01-29 08:31:34 +03:00
|
|
|
BX_FALLTHROUGH;
|
2015-07-31 04:36:12 +03:00
|
|
|
|
2015-08-20 22:30:59 +03:00
|
|
|
case ErrorState::LoadedD3D9:
|
2017-10-02 07:18:29 +03:00
|
|
|
m_nvapi.shutdown();
|
2015-07-31 04:36:12 +03:00
|
|
|
bx::dlclose(m_d3d9dll);
|
2018-01-29 08:31:34 +03:00
|
|
|
BX_FALLTHROUGH;
|
2015-07-31 04:36:12 +03:00
|
|
|
|
2015-08-20 22:30:59 +03:00
|
|
|
case ErrorState::Default:
|
2015-07-31 04:36:12 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
|
2014-10-14 08:14:51 +04:00
|
|
|
void shutdown()
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
|
|
|
preReset();
|
|
|
|
|
2013-08-07 08:04:28 +04:00
|
|
|
for (uint32_t ii = 0; ii < BX_COUNTOF(m_indexBuffers); ++ii)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
|
|
|
m_indexBuffers[ii].destroy();
|
|
|
|
}
|
|
|
|
|
2013-08-07 08:04:28 +04:00
|
|
|
for (uint32_t ii = 0; ii < BX_COUNTOF(m_vertexBuffers); ++ii)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
|
|
|
m_vertexBuffers[ii].destroy();
|
|
|
|
}
|
|
|
|
|
2014-03-30 06:42:57 +04:00
|
|
|
for (uint32_t ii = 0; ii < BX_COUNTOF(m_shaders); ++ii)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2014-03-30 06:42:57 +04:00
|
|
|
m_shaders[ii].destroy();
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
|
2013-08-07 08:04:28 +04:00
|
|
|
for (uint32_t ii = 0; ii < BX_COUNTOF(m_textures); ++ii)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
|
|
|
m_textures[ii].destroy();
|
|
|
|
}
|
|
|
|
|
2013-07-27 09:55:13 +04:00
|
|
|
if (NULL != m_d3d9ex)
|
|
|
|
{
|
|
|
|
DX_RELEASE(m_deviceEx, 1);
|
|
|
|
DX_RELEASE(m_device, 0);
|
|
|
|
DX_RELEASE(m_d3d9, 1);
|
|
|
|
DX_RELEASE(m_d3d9ex, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DX_RELEASE(m_device, 0);
|
|
|
|
DX_RELEASE(m_d3d9, 0);
|
|
|
|
}
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2017-10-02 07:18:29 +03:00
|
|
|
m_nvapi.shutdown();
|
2013-07-27 09:55:13 +04:00
|
|
|
bx::dlclose(m_d3d9dll);
|
2012-08-06 01:51:49 +04:00
|
|
|
|
|
|
|
m_initialized = false;
|
|
|
|
}
|
|
|
|
|
2017-07-15 10:17:29 +03:00
|
|
|
RendererType::Enum getRendererType() const override
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
|
|
|
return RendererType::Direct3D9;
|
|
|
|
}
|
|
|
|
|
2017-07-15 10:17:29 +03:00
|
|
|
const char* getRendererName() const override
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
2015-10-29 03:54:50 +03:00
|
|
|
if (NULL != m_d3d9ex)
|
|
|
|
{
|
|
|
|
return BGFX_RENDERER_DIRECT3D9_NAME " Ex";
|
|
|
|
}
|
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
return BGFX_RENDERER_DIRECT3D9_NAME;
|
|
|
|
}
|
|
|
|
|
2018-03-13 04:56:27 +03:00
|
|
|
void createIndexBuffer(IndexBufferHandle _handle, const Memory* _mem, uint16_t _flags) override
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
2015-04-09 05:59:48 +03:00
|
|
|
m_indexBuffers[_handle.idx].create(_mem->size, _mem->data, _flags);
|
2014-05-27 01:09:26 +04:00
|
|
|
}
|
|
|
|
|
2017-07-15 10:17:29 +03:00
|
|
|
void destroyIndexBuffer(IndexBufferHandle _handle) override
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
|
|
|
m_indexBuffers[_handle.idx].destroy();
|
|
|
|
}
|
|
|
|
|
2017-07-15 10:17:29 +03:00
|
|
|
void createVertexDecl(VertexDeclHandle _handle, const VertexDecl& _decl) override
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
2017-05-14 08:21:02 +03:00
|
|
|
VertexDecl& decl = m_vertexDecls[_handle.idx];
|
|
|
|
bx::memCopy(&decl, &_decl, sizeof(VertexDecl) );
|
|
|
|
dump(decl);
|
2014-05-27 01:09:26 +04:00
|
|
|
}
|
|
|
|
|
2017-07-15 10:17:29 +03:00
|
|
|
void destroyVertexDecl(VertexDeclHandle /*_handle*/) override
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-03-13 04:56:27 +03:00
|
|
|
void createVertexBuffer(VertexBufferHandle _handle, const Memory* _mem, VertexDeclHandle _declHandle, uint16_t /*_flags*/) override
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
|
|
|
m_vertexBuffers[_handle.idx].create(_mem->size, _mem->data, _declHandle);
|
|
|
|
}
|
|
|
|
|
2017-07-15 10:17:29 +03:00
|
|
|
void destroyVertexBuffer(VertexBufferHandle _handle) override
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
|
|
|
m_vertexBuffers[_handle.idx].destroy();
|
|
|
|
}
|
|
|
|
|
2017-07-15 10:17:29 +03:00
|
|
|
void createDynamicIndexBuffer(IndexBufferHandle _handle, uint32_t _size, uint16_t _flags) override
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
2015-04-09 05:59:48 +03:00
|
|
|
m_indexBuffers[_handle.idx].create(_size, NULL, _flags);
|
2014-05-27 01:09:26 +04:00
|
|
|
}
|
|
|
|
|
2018-03-13 04:56:27 +03:00
|
|
|
void updateDynamicIndexBuffer(IndexBufferHandle _handle, uint32_t _offset, uint32_t _size, const Memory* _mem) override
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
|
|
|
m_indexBuffers[_handle.idx].update(_offset, bx::uint32_min(_size, _mem->size), _mem->data);
|
|
|
|
}
|
|
|
|
|
2017-07-15 10:17:29 +03:00
|
|
|
void destroyDynamicIndexBuffer(IndexBufferHandle _handle) override
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
|
|
|
m_indexBuffers[_handle.idx].destroy();
|
|
|
|
}
|
|
|
|
|
2017-07-15 10:17:29 +03:00
|
|
|
void createDynamicVertexBuffer(VertexBufferHandle _handle, uint32_t _size, uint16_t /*_flags*/) override
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
|
|
|
VertexDeclHandle decl = BGFX_INVALID_HANDLE;
|
|
|
|
m_vertexBuffers[_handle.idx].create(_size, NULL, decl);
|
|
|
|
}
|
|
|
|
|
2018-03-13 04:56:27 +03:00
|
|
|
void updateDynamicVertexBuffer(VertexBufferHandle _handle, uint32_t _offset, uint32_t _size, const Memory* _mem) override
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
|
|
|
m_vertexBuffers[_handle.idx].update(_offset, bx::uint32_min(_size, _mem->size), _mem->data);
|
|
|
|
}
|
|
|
|
|
2017-07-15 10:17:29 +03:00
|
|
|
void destroyDynamicVertexBuffer(VertexBufferHandle _handle) override
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
|
|
|
m_vertexBuffers[_handle.idx].destroy();
|
|
|
|
}
|
|
|
|
|
2018-03-13 04:56:27 +03:00
|
|
|
void createShader(ShaderHandle _handle, const Memory* _mem) override
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
|
|
|
m_shaders[_handle.idx].create(_mem);
|
|
|
|
}
|
|
|
|
|
2017-07-15 10:17:29 +03:00
|
|
|
void destroyShader(ShaderHandle _handle) override
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
|
|
|
m_shaders[_handle.idx].destroy();
|
|
|
|
}
|
|
|
|
|
2017-07-15 10:17:29 +03:00
|
|
|
void createProgram(ProgramHandle _handle, ShaderHandle _vsh, ShaderHandle _fsh) override
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
2018-03-06 05:15:35 +03:00
|
|
|
m_program[_handle.idx].create(&m_shaders[_vsh.idx], isValid(_fsh) ? &m_shaders[_fsh.idx] : NULL);
|
2014-05-27 01:09:26 +04:00
|
|
|
}
|
|
|
|
|
2017-07-15 10:17:29 +03:00
|
|
|
void destroyProgram(ProgramHandle _handle) override
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
|
|
|
m_program[_handle.idx].destroy();
|
|
|
|
}
|
|
|
|
|
2018-03-13 04:56:27 +03:00
|
|
|
void* createTexture(TextureHandle _handle, const Memory* _mem, uint32_t _flags, uint8_t _skip) override
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
|
|
|
m_textures[_handle.idx].create(_mem, _flags, _skip);
|
2017-12-03 09:12:27 +03:00
|
|
|
return NULL;
|
2014-05-27 01:09:26 +04:00
|
|
|
}
|
|
|
|
|
2017-07-15 10:17:29 +03:00
|
|
|
void updateTextureBegin(TextureHandle _handle, uint8_t _side, uint8_t _mip) override
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
|
|
|
m_updateTexture = &m_textures[_handle.idx];
|
|
|
|
m_updateTexture->updateBegin(_side, _mip);
|
|
|
|
}
|
|
|
|
|
2017-07-15 10:17:29 +03:00
|
|
|
void updateTexture(TextureHandle /*_handle*/, uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem) override
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
|
|
|
m_updateTexture->update(_side, _mip, _rect, _z, _depth, _pitch, _mem);
|
|
|
|
}
|
|
|
|
|
2017-07-15 10:17:29 +03:00
|
|
|
void updateTextureEnd() override
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
|
|
|
m_updateTexture->updateEnd();
|
|
|
|
m_updateTexture = NULL;
|
|
|
|
}
|
|
|
|
|
2017-07-15 10:17:29 +03:00
|
|
|
void readTexture(TextureHandle _handle, void* _data, uint8_t _mip) override
|
2015-10-21 02:32:08 +03:00
|
|
|
{
|
|
|
|
TextureD3D9& texture = m_textures[_handle.idx];
|
|
|
|
|
|
|
|
D3DLOCKED_RECT lockedRect;
|
2016-10-21 18:22:05 +03:00
|
|
|
DX_CHECK(texture.m_texture2d->LockRect(_mip
|
2015-10-21 02:32:08 +03:00
|
|
|
, &lockedRect
|
|
|
|
, NULL
|
|
|
|
, D3DLOCK_NO_DIRTY_UPDATE|D3DLOCK_NOSYSLOCK|D3DLOCK_READONLY
|
|
|
|
) );
|
|
|
|
|
2016-10-24 20:58:24 +03:00
|
|
|
uint32_t srcWidth = bx::uint32_max(1, texture.m_width >>_mip);
|
|
|
|
uint32_t srcHeight = bx::uint32_max(1, texture.m_height>>_mip);
|
2016-10-21 18:22:05 +03:00
|
|
|
uint32_t srcPitch = lockedRect.Pitch;
|
|
|
|
uint8_t* src = (uint8_t*)lockedRect.pBits;
|
2015-10-21 02:32:08 +03:00
|
|
|
|
2017-04-04 08:42:27 +03:00
|
|
|
const uint8_t bpp = bimg::getBitsPerPixel(bimg::TextureFormat::Enum(texture.m_textureFormat) );
|
2015-10-21 02:32:08 +03:00
|
|
|
uint8_t* dst = (uint8_t*)_data;
|
2016-10-21 18:22:05 +03:00
|
|
|
uint32_t dstPitch = srcWidth*bpp/8;
|
2015-10-21 02:32:08 +03:00
|
|
|
|
|
|
|
uint32_t pitch = bx::uint32_min(srcPitch, dstPitch);
|
|
|
|
|
2016-10-21 18:22:05 +03:00
|
|
|
for (uint32_t yy = 0, height = srcHeight; yy < height; ++yy)
|
2015-10-21 02:32:08 +03:00
|
|
|
{
|
2017-02-09 06:55:31 +03:00
|
|
|
bx::memCopy(dst, src, pitch);
|
2015-10-21 02:32:08 +03:00
|
|
|
|
|
|
|
src += srcPitch;
|
|
|
|
dst += dstPitch;
|
|
|
|
}
|
|
|
|
|
2016-10-25 18:59:37 +03:00
|
|
|
DX_CHECK(texture.m_texture2d->UnlockRect(_mip) );
|
2015-10-21 02:32:08 +03:00
|
|
|
}
|
|
|
|
|
2017-07-15 10:17:29 +03:00
|
|
|
void resizeTexture(TextureHandle _handle, uint16_t _width, uint16_t _height, uint8_t _numMips) override
|
2015-04-14 04:39:38 +03:00
|
|
|
{
|
|
|
|
TextureD3D9& texture = m_textures[_handle.idx];
|
2016-03-13 22:13:19 +03:00
|
|
|
|
|
|
|
uint32_t size = sizeof(uint32_t) + sizeof(TextureCreate);
|
|
|
|
const Memory* mem = alloc(size);
|
|
|
|
|
|
|
|
bx::StaticMemoryBlockWriter writer(mem->data, mem->size);
|
|
|
|
uint32_t magic = BGFX_CHUNK_MAGIC_TEX;
|
|
|
|
bx::write(&writer, magic);
|
|
|
|
|
|
|
|
TextureCreate tc;
|
2016-08-20 18:10:20 +03:00
|
|
|
tc.m_width = _width;
|
|
|
|
tc.m_height = _height;
|
|
|
|
tc.m_depth = 0;
|
|
|
|
tc.m_numLayers = 1;
|
|
|
|
tc.m_numMips = _numMips;
|
|
|
|
tc.m_format = TextureFormat::Enum(texture.m_requestedFormat);
|
|
|
|
tc.m_cubeMap = false;
|
|
|
|
tc.m_mem = NULL;
|
2016-03-13 22:13:19 +03:00
|
|
|
bx::write(&writer, tc);
|
|
|
|
|
2016-07-29 07:19:08 +03:00
|
|
|
texture.destroy(true);
|
2016-03-13 22:13:19 +03:00
|
|
|
texture.create(mem, texture.m_flags, 0);
|
|
|
|
|
|
|
|
release(mem);
|
2015-04-14 04:39:38 +03:00
|
|
|
}
|
|
|
|
|
2017-07-15 10:17:29 +03:00
|
|
|
void overrideInternal(TextureHandle _handle, uintptr_t _ptr) override
|
2016-01-18 07:33:39 +03:00
|
|
|
{
|
2016-01-28 01:50:57 +03:00
|
|
|
// Resource ref. counts might be messed up outside of bgfx.
|
|
|
|
// Disabling ref. count check once texture is overridden.
|
|
|
|
setGraphicsDebuggerPresent(true);
|
|
|
|
m_textures[_handle.idx].overrideInternal(_ptr);
|
2016-01-18 07:33:39 +03:00
|
|
|
}
|
|
|
|
|
2017-07-15 10:17:29 +03:00
|
|
|
uintptr_t getInternal(TextureHandle _handle) override
|
2016-01-19 04:29:53 +03:00
|
|
|
{
|
2016-01-28 01:50:57 +03:00
|
|
|
// Resource ref. counts might be messed up outside of bgfx.
|
|
|
|
// Disabling ref. count check once texture is overridden.
|
|
|
|
setGraphicsDebuggerPresent(true);
|
2016-01-19 04:29:53 +03:00
|
|
|
return uintptr_t(m_textures[_handle.idx].m_ptr);
|
|
|
|
}
|
|
|
|
|
2017-07-15 10:17:29 +03:00
|
|
|
void destroyTexture(TextureHandle _handle) override
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
|
|
|
m_textures[_handle.idx].destroy();
|
|
|
|
}
|
|
|
|
|
2017-07-15 10:17:29 +03:00
|
|
|
void createFrameBuffer(FrameBufferHandle _handle, uint8_t _num, const Attachment* _attachment) override
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
2016-02-16 03:55:32 +03:00
|
|
|
m_frameBuffers[_handle.idx].create(_num, _attachment);
|
2014-05-27 01:09:26 +04:00
|
|
|
}
|
|
|
|
|
2017-07-15 10:17:29 +03:00
|
|
|
void createFrameBuffer(FrameBufferHandle _handle, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat) override
|
2014-09-08 04:17:38 +04:00
|
|
|
{
|
|
|
|
uint16_t denseIdx = m_numWindows++;
|
|
|
|
m_windows[denseIdx] = _handle;
|
|
|
|
m_frameBuffers[_handle.idx].create(denseIdx, _nwh, _width, _height, _depthFormat);
|
|
|
|
}
|
|
|
|
|
2017-07-15 10:17:29 +03:00
|
|
|
void destroyFrameBuffer(FrameBufferHandle _handle) override
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
2014-09-08 04:17:38 +04:00
|
|
|
uint16_t denseIdx = m_frameBuffers[_handle.idx].destroy();
|
|
|
|
if (UINT16_MAX != denseIdx)
|
|
|
|
{
|
|
|
|
--m_numWindows;
|
|
|
|
if (m_numWindows > 1)
|
|
|
|
{
|
|
|
|
FrameBufferHandle handle = m_windows[m_numWindows];
|
|
|
|
m_windows[denseIdx] = handle;
|
|
|
|
m_frameBuffers[handle.idx].m_denseIdx = denseIdx;
|
|
|
|
}
|
|
|
|
}
|
2014-05-27 01:09:26 +04:00
|
|
|
}
|
|
|
|
|
2017-07-15 10:17:29 +03:00
|
|
|
void createUniform(UniformHandle _handle, UniformType::Enum _type, uint16_t _num, const char* _name) override
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
|
|
|
if (NULL != m_uniforms[_handle.idx])
|
|
|
|
{
|
|
|
|
BX_FREE(g_allocator, m_uniforms[_handle.idx]);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t size = BX_ALIGN_16(g_uniformTypeSize[_type]*_num);
|
|
|
|
void* data = BX_ALLOC(g_allocator, size);
|
2017-02-09 06:55:31 +03:00
|
|
|
bx::memSet(data, 0, size);
|
2014-05-27 01:09:26 +04:00
|
|
|
m_uniforms[_handle.idx] = data;
|
2018-05-22 02:59:17 +03:00
|
|
|
m_uniformReg.add(_handle, _name);
|
2014-05-27 01:09:26 +04:00
|
|
|
}
|
|
|
|
|
2017-07-15 10:17:29 +03:00
|
|
|
void destroyUniform(UniformHandle _handle) override
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
|
|
|
BX_FREE(g_allocator, m_uniforms[_handle.idx]);
|
|
|
|
m_uniforms[_handle.idx] = NULL;
|
2016-09-09 03:00:16 +03:00
|
|
|
m_uniformReg.remove(_handle);
|
2014-05-27 01:09:26 +04:00
|
|
|
}
|
|
|
|
|
2017-07-15 10:17:29 +03:00
|
|
|
void requestScreenShot(FrameBufferHandle _handle, const char* _filePath) override
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
2017-03-03 09:48:10 +03:00
|
|
|
IDirect3DSwapChain9* swapChain = isValid(_handle)
|
|
|
|
? m_frameBuffers[_handle.idx].m_swapChain
|
|
|
|
: m_swapChain
|
|
|
|
;
|
|
|
|
|
|
|
|
if (NULL == swapChain)
|
|
|
|
{
|
|
|
|
BX_TRACE("Unable to capture screenshot %s.", _filePath);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
D3DPRESENT_PARAMETERS params;
|
|
|
|
DX_CHECK(swapChain->GetPresentParameters(¶ms));
|
2017-03-03 05:02:14 +03:00
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
IDirect3DSurface9* surface;
|
|
|
|
D3DDEVICE_CREATION_PARAMETERS dcp;
|
|
|
|
DX_CHECK(m_device->GetCreationParameters(&dcp) );
|
|
|
|
|
|
|
|
D3DDISPLAYMODE dm;
|
|
|
|
DX_CHECK(m_d3d9->GetAdapterDisplayMode(dcp.AdapterOrdinal, &dm) );
|
|
|
|
|
|
|
|
DX_CHECK(m_device->CreateOffscreenPlainSurface(dm.Width
|
|
|
|
, dm.Height
|
|
|
|
, D3DFMT_A8R8G8B8
|
|
|
|
, D3DPOOL_SCRATCH
|
|
|
|
, &surface
|
|
|
|
, NULL
|
|
|
|
) );
|
|
|
|
|
2017-03-03 09:48:10 +03:00
|
|
|
HWND nwh = params.hDeviceWindow;
|
|
|
|
|
|
|
|
SetWindowPos(nwh, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
|
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
DX_CHECK(m_device->GetFrontBufferData(0, surface) );
|
|
|
|
|
2017-03-03 09:48:10 +03:00
|
|
|
SetWindowPos(nwh, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
|
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
D3DLOCKED_RECT rect;
|
|
|
|
DX_CHECK(surface->LockRect(&rect
|
|
|
|
, NULL
|
|
|
|
, D3DLOCK_NO_DIRTY_UPDATE|D3DLOCK_NOSYSLOCK|D3DLOCK_READONLY
|
|
|
|
) );
|
|
|
|
|
|
|
|
RECT rc;
|
2017-03-03 09:48:10 +03:00
|
|
|
GetClientRect(nwh, &rc);
|
2014-05-27 01:09:26 +04:00
|
|
|
POINT point;
|
|
|
|
point.x = rc.left;
|
|
|
|
point.y = rc.top;
|
2017-03-03 09:48:10 +03:00
|
|
|
ClientToScreen(nwh, &point);
|
2014-05-27 01:09:26 +04:00
|
|
|
uint8_t* data = (uint8_t*)rect.pBits;
|
|
|
|
uint32_t bytesPerPixel = rect.Pitch/dm.Width;
|
|
|
|
|
|
|
|
g_callback->screenShot(_filePath
|
2017-03-03 09:48:10 +03:00
|
|
|
, params.BackBufferWidth
|
|
|
|
, params.BackBufferHeight
|
2014-05-27 01:09:26 +04:00
|
|
|
, rect.Pitch
|
|
|
|
, &data[point.y*rect.Pitch+point.x*bytesPerPixel]
|
2017-03-03 09:48:10 +03:00
|
|
|
, params.BackBufferHeight*rect.Pitch
|
2014-05-27 01:09:26 +04:00
|
|
|
, false
|
|
|
|
);
|
|
|
|
|
|
|
|
DX_CHECK(surface->UnlockRect() );
|
|
|
|
DX_RELEASE(surface, 0);
|
|
|
|
}
|
|
|
|
|
2017-11-24 22:21:51 +03:00
|
|
|
void updateViewName(ViewId _id, const char* _name) override
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
2015-04-02 21:57:53 +03:00
|
|
|
if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) )
|
|
|
|
{
|
|
|
|
mbstowcs(&s_viewNameW[_id][BGFX_CONFIG_MAX_VIEW_NAME_RESERVED]
|
|
|
|
, _name
|
|
|
|
, BX_COUNTOF(s_viewNameW[0])-BGFX_CONFIG_MAX_VIEW_NAME_RESERVED
|
|
|
|
);
|
|
|
|
}
|
2015-11-16 17:42:56 +03:00
|
|
|
|
2017-04-17 07:56:17 +03:00
|
|
|
bx::strCopy(&s_viewName[_id][BGFX_CONFIG_MAX_VIEW_NAME_RESERVED]
|
2015-11-16 17:42:56 +03:00
|
|
|
, BX_COUNTOF(s_viewName[0]) - BGFX_CONFIG_MAX_VIEW_NAME_RESERVED
|
2017-04-17 07:56:17 +03:00
|
|
|
, _name
|
2015-11-16 17:42:56 +03:00
|
|
|
);
|
2014-05-27 01:09:26 +04:00
|
|
|
}
|
|
|
|
|
2017-07-15 10:17:29 +03:00
|
|
|
void updateUniform(uint16_t _loc, const void* _data, uint32_t _size) override
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
2017-02-09 06:55:31 +03:00
|
|
|
bx::memCopy(m_uniforms[_loc], _data, _size);
|
2014-05-27 01:09:26 +04:00
|
|
|
}
|
|
|
|
|
2017-07-15 10:17:29 +03:00
|
|
|
void setMarker(const char* _marker, uint32_t _size) override
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
|
|
|
#if BGFX_CONFIG_DEBUG_PIX
|
|
|
|
uint32_t size = _size*sizeof(wchar_t);
|
|
|
|
wchar_t* name = (wchar_t*)alloca(size);
|
|
|
|
mbstowcs(name, _marker, size-2);
|
2016-08-24 23:16:04 +03:00
|
|
|
PIX_SETMARKER(D3DCOLOR_MARKER, name);
|
2014-05-27 01:09:26 +04:00
|
|
|
#endif // BGFX_CONFIG_DEBUG_PIX
|
|
|
|
BX_UNUSED(_marker, _size);
|
|
|
|
}
|
|
|
|
|
2017-07-15 10:17:29 +03:00
|
|
|
void invalidateOcclusionQuery(OcclusionQueryHandle _handle) override
|
2017-03-04 05:05:36 +03:00
|
|
|
{
|
|
|
|
m_occlusionQuery.invalidate(_handle);
|
|
|
|
}
|
|
|
|
|
2017-08-31 07:46:57 +03:00
|
|
|
virtual void setName(Handle _handle, const char* _name) override
|
|
|
|
{
|
|
|
|
BX_UNUSED(_handle, _name)
|
|
|
|
}
|
|
|
|
|
2017-05-06 08:22:14 +03:00
|
|
|
void submitBlit(BlitState& _bs, uint16_t _view);
|
|
|
|
|
2017-07-15 10:17:29 +03:00
|
|
|
void submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) override;
|
2014-05-27 01:09:26 +04:00
|
|
|
|
2017-07-15 10:17:29 +03:00
|
|
|
void blitSetup(TextVideoMemBlitter& _blitter) override
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
|
|
|
uint32_t width = m_params.BackBufferWidth;
|
|
|
|
uint32_t height = m_params.BackBufferHeight;
|
|
|
|
|
|
|
|
FrameBufferHandle fbh = BGFX_INVALID_HANDLE;
|
2016-11-14 07:59:41 +03:00
|
|
|
setFrameBuffer(fbh, false, false);
|
2014-05-27 01:09:26 +04:00
|
|
|
|
|
|
|
D3DVIEWPORT9 vp;
|
|
|
|
vp.X = 0;
|
|
|
|
vp.Y = 0;
|
|
|
|
vp.Width = width;
|
|
|
|
vp.Height = height;
|
|
|
|
vp.MinZ = 0.0f;
|
|
|
|
vp.MaxZ = 1.0f;
|
|
|
|
|
|
|
|
IDirect3DDevice9* device = m_device;
|
|
|
|
DX_CHECK(device->SetViewport(&vp) );
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_STENCILENABLE, FALSE) );
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_ZENABLE, FALSE) );
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS) );
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE) );
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE) );
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER) );
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED|D3DCOLORWRITEENABLE_GREEN|D3DCOLORWRITEENABLE_BLUE) );
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID) );
|
|
|
|
|
|
|
|
ProgramD3D9& program = m_program[_blitter.m_program.idx];
|
2014-07-21 07:27:13 +04:00
|
|
|
DX_CHECK(device->SetVertexShader(program.m_vsh->m_vertexShader) );
|
|
|
|
DX_CHECK(device->SetPixelShader(program.m_fsh->m_pixelShader) );
|
2014-05-27 01:09:26 +04:00
|
|
|
|
|
|
|
VertexBufferD3D9& vb = m_vertexBuffers[_blitter.m_vb->handle.idx];
|
2017-05-14 08:21:02 +03:00
|
|
|
VertexDecl& vertexDecl = m_vertexDecls[_blitter.m_vb->decl.idx];
|
|
|
|
DX_CHECK(device->SetStreamSource(0, vb.m_ptr, 0, vertexDecl.m_stride) );
|
|
|
|
setInputLayout(vertexDecl, 0);
|
2014-05-27 01:09:26 +04:00
|
|
|
|
|
|
|
IndexBufferD3D9& ib = m_indexBuffers[_blitter.m_ib->handle.idx];
|
|
|
|
DX_CHECK(device->SetIndices(ib.m_ptr) );
|
|
|
|
|
|
|
|
float proj[16];
|
2017-06-13 09:51:07 +03:00
|
|
|
bx::mtxOrtho(proj, 0.0f, (float)width, (float)height, 0.0f, 0.0f, 1000.0f, 0.0f, false);
|
2014-05-27 01:09:26 +04:00
|
|
|
|
|
|
|
PredefinedUniform& predefined = program.m_predefined[0];
|
|
|
|
uint8_t flags = predefined.m_type;
|
2014-12-28 06:00:41 +03:00
|
|
|
setShaderUniform(flags, predefined.m_loc, proj, 4);
|
2014-05-27 01:09:26 +04:00
|
|
|
|
2015-11-02 04:28:23 +03:00
|
|
|
m_textures[_blitter.m_texture.idx].commit(0, BGFX_TEXTURE_INTERNAL_DEFAULT_SAMPLER, NULL);
|
2014-05-27 01:09:26 +04:00
|
|
|
}
|
|
|
|
|
2017-07-15 10:17:29 +03:00
|
|
|
void blitRender(TextVideoMemBlitter& _blitter, uint32_t _numIndices) override
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
2015-01-27 06:09:51 +03:00
|
|
|
const uint32_t numVertices = _numIndices*4/6;
|
|
|
|
if (0 < numVertices)
|
|
|
|
{
|
|
|
|
m_indexBuffers[_blitter.m_ib->handle.idx].update(0, _numIndices * 2, _blitter.m_ib->data, true);
|
|
|
|
m_vertexBuffers[_blitter.m_vb->handle.idx].update(0, numVertices*_blitter.m_decl.m_stride, _blitter.m_vb->data, true);
|
|
|
|
|
|
|
|
DX_CHECK(m_device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST
|
|
|
|
, 0
|
|
|
|
, 0
|
|
|
|
, numVertices
|
|
|
|
, 0
|
|
|
|
, _numIndices / 3
|
|
|
|
) );
|
|
|
|
}
|
2014-05-27 01:09:26 +04:00
|
|
|
}
|
|
|
|
|
2012-08-06 01:51:49 +04:00
|
|
|
void updateMsaa()
|
|
|
|
{
|
2013-08-07 08:04:28 +04:00
|
|
|
for (uint32_t ii = 1, last = 0; ii < BX_COUNTOF(s_checkMsaa); ++ii)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
|
|
|
D3DMULTISAMPLE_TYPE msaa = s_checkMsaa[ii];
|
|
|
|
DWORD quality;
|
|
|
|
|
|
|
|
HRESULT hr = m_d3d9->CheckDeviceMultiSampleType(m_adapter
|
|
|
|
, m_deviceType
|
|
|
|
, m_params.BackBufferFormat
|
|
|
|
, m_params.Windowed
|
|
|
|
, msaa
|
|
|
|
, &quality
|
|
|
|
);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr) )
|
|
|
|
{
|
|
|
|
s_msaa[ii].m_type = msaa;
|
2013-08-04 09:15:13 +04:00
|
|
|
s_msaa[ii].m_quality = bx::uint32_imax(0, quality-1);
|
2012-08-06 01:51:49 +04:00
|
|
|
last = ii;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s_msaa[ii] = s_msaa[last];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateResolution(const Resolution& _resolution)
|
|
|
|
{
|
2018-04-18 01:42:18 +03:00
|
|
|
m_maxAnisotropy = !!(_resolution.reset & BGFX_RESET_MAXANISOTROPY)
|
2015-01-22 07:39:42 +03:00
|
|
|
? m_caps.MaxAnisotropy
|
|
|
|
: 1
|
|
|
|
;
|
2016-05-31 22:50:28 +03:00
|
|
|
const uint32_t maskFlags = ~(0
|
2016-03-09 02:44:42 +03:00
|
|
|
| BGFX_RESET_MAXANISOTROPY
|
|
|
|
| BGFX_RESET_DEPTH_CLAMP
|
|
|
|
| BGFX_RESET_SUSPEND
|
|
|
|
);
|
2015-01-22 07:39:42 +03:00
|
|
|
|
2018-04-18 01:42:18 +03:00
|
|
|
if (m_resolution.width != _resolution.width
|
|
|
|
|| m_resolution.height != _resolution.height
|
|
|
|
|| (m_resolution.reset&maskFlags) != (_resolution.reset&maskFlags) )
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2018-04-18 01:42:18 +03:00
|
|
|
uint32_t flags = _resolution.reset & (~BGFX_RESET_INTERNAL_FORCE);
|
2015-10-22 02:55:50 +03:00
|
|
|
|
2015-10-22 08:04:28 +03:00
|
|
|
m_resolution = _resolution;
|
2018-04-18 01:42:18 +03:00
|
|
|
m_resolution.reset = flags;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2018-04-18 01:42:18 +03:00
|
|
|
m_textVideoMem.resize(false, _resolution.width, _resolution.height);
|
2012-08-06 01:51:49 +04:00
|
|
|
m_textVideoMem.clear();
|
|
|
|
|
|
|
|
D3DDEVICE_CREATION_PARAMETERS dcp;
|
|
|
|
DX_CHECK(m_device->GetCreationParameters(&dcp) );
|
|
|
|
|
|
|
|
D3DDISPLAYMODE dm;
|
|
|
|
DX_CHECK(m_d3d9->GetAdapterDisplayMode(dcp.AdapterOrdinal, &dm) );
|
2014-05-27 01:09:26 +04:00
|
|
|
|
2012-08-06 01:51:49 +04:00
|
|
|
m_params.BackBufferFormat = dm.Format;
|
|
|
|
|
2018-04-18 01:42:18 +03:00
|
|
|
m_params.BackBufferWidth = _resolution.width;
|
|
|
|
m_params.BackBufferHeight = _resolution.height;
|
|
|
|
m_params.FullScreen_RefreshRateInHz = BGFX_RESET_FULLSCREEN == (m_resolution.reset&BGFX_RESET_FULLSCREEN_MASK) ? 60 : 0;
|
|
|
|
m_params.PresentationInterval = !!(m_resolution.reset&BGFX_RESET_VSYNC) ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
|
|
|
updateMsaa();
|
|
|
|
|
2018-04-18 01:42:18 +03:00
|
|
|
Msaa& msaa = s_msaa[(m_resolution.reset&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT];
|
2014-09-08 04:17:38 +04:00
|
|
|
m_params.MultiSampleType = msaa.m_type;
|
2012-08-06 01:51:49 +04:00
|
|
|
m_params.MultiSampleQuality = msaa.m_quality;
|
|
|
|
|
|
|
|
preReset();
|
|
|
|
DX_CHECK(m_device->Reset(&m_params) );
|
|
|
|
postReset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-14 07:59:41 +03:00
|
|
|
void setFrameBuffer(FrameBufferHandle _fbh, bool _msaa = true, bool _needPresent = true)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2014-08-21 02:55:30 +04:00
|
|
|
if (isValid(m_fbh)
|
2016-07-24 02:16:43 +03:00
|
|
|
&& m_fbh.idx != _fbh.idx)
|
2014-08-21 02:55:30 +04:00
|
|
|
{
|
|
|
|
FrameBufferD3D9& frameBuffer = m_frameBuffers[m_fbh.idx];
|
|
|
|
frameBuffer.resolve();
|
|
|
|
}
|
|
|
|
|
2014-02-06 11:07:11 +04:00
|
|
|
if (!isValid(_fbh) )
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2016-11-14 07:59:41 +03:00
|
|
|
m_needPresent |= _needPresent;
|
2012-08-06 01:51:49 +04:00
|
|
|
DX_CHECK(m_device->SetRenderTarget(0, m_backBufferColor) );
|
2016-09-24 10:29:59 +03:00
|
|
|
for (uint32_t ii = 1, num = g_caps.limits.maxFBAttachments; ii < num; ++ii)
|
2014-02-06 11:07:11 +04:00
|
|
|
{
|
|
|
|
DX_CHECK(m_device->SetRenderTarget(ii, NULL) );
|
|
|
|
}
|
2012-08-06 01:51:49 +04:00
|
|
|
DX_CHECK(m_device->SetDepthStencilSurface(m_backBufferDepthStencil) );
|
2015-05-03 06:54:51 +03:00
|
|
|
|
2018-04-18 01:42:18 +03:00
|
|
|
DX_CHECK(m_device->SetRenderState(D3DRS_SRGBWRITEENABLE, 0 != (m_resolution.reset & BGFX_RESET_SRGB_BACKBUFFER) ) );
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-10 01:29:37 +03:00
|
|
|
m_frameBuffers[_fbh.idx].set();
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
|
2014-02-06 11:07:11 +04:00
|
|
|
m_fbh = _fbh;
|
2012-08-06 01:51:49 +04:00
|
|
|
m_rtMsaa = _msaa;
|
|
|
|
}
|
|
|
|
|
2015-04-08 03:58:14 +03:00
|
|
|
void setShaderUniform(uint8_t _flags, uint32_t _regIndex, const void* _val, uint32_t _numRegs)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
|
|
|
if (_flags&BGFX_UNIFORM_FRAGMENTBIT)
|
|
|
|
{
|
2014-12-28 06:00:41 +03:00
|
|
|
DX_CHECK(m_device->SetPixelShaderConstantF(_regIndex, (const float*)_val, _numRegs) );
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-12-28 06:00:41 +03:00
|
|
|
DX_CHECK(m_device->SetVertexShaderConstantF(_regIndex, (const float*)_val, _numRegs) );
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-08 03:58:14 +03:00
|
|
|
void setShaderUniform4f(uint8_t _flags, uint32_t _regIndex, const void* _val, uint32_t _numRegs)
|
2014-12-28 06:00:41 +03:00
|
|
|
{
|
|
|
|
setShaderUniform(_flags, _regIndex, _val, _numRegs);
|
|
|
|
}
|
|
|
|
|
2015-04-08 03:58:14 +03:00
|
|
|
void setShaderUniform4x4f(uint8_t _flags, uint32_t _regIndex, const void* _val, uint32_t _numRegs)
|
2014-12-28 06:00:41 +03:00
|
|
|
{
|
|
|
|
setShaderUniform(_flags, _regIndex, _val, _numRegs);
|
|
|
|
}
|
|
|
|
|
2012-08-06 01:51:49 +04:00
|
|
|
void reset()
|
|
|
|
{
|
|
|
|
preReset();
|
|
|
|
|
|
|
|
HRESULT hr;
|
|
|
|
|
2015-01-11 07:38:47 +03:00
|
|
|
do
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
|
|
|
hr = m_device->Reset(&m_params);
|
|
|
|
} while (FAILED(hr) );
|
|
|
|
|
|
|
|
postReset();
|
|
|
|
}
|
|
|
|
|
2016-11-16 03:57:28 +03:00
|
|
|
void flush()
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2016-11-16 03:57:28 +03:00
|
|
|
m_flushQuery->Issue(D3DISSUE_END);
|
|
|
|
m_flushQuery->GetData(NULL, 0, D3DGETDATA_FLUSH);
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
|
2017-07-15 10:17:29 +03:00
|
|
|
bool isDeviceRemoved() override
|
2017-04-08 05:07:20 +03:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-20 06:22:21 +03:00
|
|
|
void flip() override
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2015-04-21 02:22:40 +03:00
|
|
|
if (NULL != m_swapChain)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2013-07-27 09:55:13 +04:00
|
|
|
if (NULL != m_deviceEx)
|
|
|
|
{
|
|
|
|
DX_CHECK(m_deviceEx->WaitForVBlank(0) );
|
|
|
|
}
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2014-09-08 04:17:38 +04:00
|
|
|
for (uint32_t ii = 0, num = m_numWindows; ii < num; ++ii)
|
|
|
|
{
|
2016-11-14 07:59:41 +03:00
|
|
|
HRESULT hr = S_OK;
|
2014-09-08 04:17:38 +04:00
|
|
|
if (0 == ii)
|
|
|
|
{
|
2016-11-14 07:59:41 +03:00
|
|
|
if (m_needPresent)
|
|
|
|
{
|
|
|
|
hr = m_swapChain->Present(NULL, NULL, (HWND)g_platformData.nwh, NULL, 0);
|
|
|
|
m_needPresent = false;
|
|
|
|
}
|
2016-11-16 03:57:28 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
flush();
|
|
|
|
}
|
2014-09-08 04:17:38 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hr = m_frameBuffers[m_windows[ii].idx].present();
|
|
|
|
}
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2017-04-08 20:46:27 +03:00
|
|
|
if (isLost(hr) )
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2014-09-08 04:17:38 +04:00
|
|
|
do
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2015-01-11 07:38:47 +03:00
|
|
|
do
|
2014-09-08 04:17:38 +04:00
|
|
|
{
|
|
|
|
hr = m_device->TestCooperativeLevel();
|
|
|
|
}
|
|
|
|
while (D3DERR_DEVICENOTRESET != hr);
|
|
|
|
|
|
|
|
reset();
|
2012-08-06 01:51:49 +04:00
|
|
|
hr = m_device->TestCooperativeLevel();
|
|
|
|
}
|
2014-09-08 04:17:38 +04:00
|
|
|
while (FAILED(hr) );
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2014-09-08 04:17:38 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (FAILED(hr) )
|
|
|
|
{
|
|
|
|
BX_TRACE("Present failed with err 0x%08x.", hr);
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
2014-09-08 04:17:38 +04:00
|
|
|
}
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void preReset()
|
|
|
|
{
|
2016-11-14 07:59:41 +03:00
|
|
|
m_needPresent = false;
|
|
|
|
|
2013-07-25 08:59:59 +04:00
|
|
|
invalidateSamplerState();
|
2017-05-14 08:21:02 +03:00
|
|
|
m_inputLayoutCache.invalidate();
|
2013-07-25 08:59:59 +04:00
|
|
|
|
2014-07-31 07:37:54 +04:00
|
|
|
for (uint32_t stage = 0; stage < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++stage)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
|
|
|
DX_CHECK(m_device->SetTexture(stage, NULL) );
|
|
|
|
}
|
|
|
|
|
|
|
|
DX_CHECK(m_device->SetRenderTarget(0, m_backBufferColor) );
|
2016-09-24 10:29:59 +03:00
|
|
|
for (uint32_t ii = 1, num = g_caps.limits.maxFBAttachments; ii < num; ++ii)
|
2014-02-06 11:07:11 +04:00
|
|
|
{
|
|
|
|
DX_CHECK(m_device->SetRenderTarget(ii, NULL) );
|
|
|
|
}
|
2012-08-06 01:51:49 +04:00
|
|
|
DX_CHECK(m_device->SetDepthStencilSurface(m_backBufferDepthStencil) );
|
|
|
|
DX_CHECK(m_device->SetVertexShader(NULL) );
|
|
|
|
DX_CHECK(m_device->SetPixelShader(NULL) );
|
|
|
|
DX_CHECK(m_device->SetStreamSource(0, NULL, 0, 0) );
|
|
|
|
DX_CHECK(m_device->SetIndices(NULL) );
|
|
|
|
|
|
|
|
DX_RELEASE(m_backBufferColor, 0);
|
|
|
|
DX_RELEASE(m_backBufferDepthStencil, 0);
|
2014-09-08 04:17:38 +04:00
|
|
|
DX_RELEASE(m_swapChain, 0);
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2012-12-31 08:52:47 +04:00
|
|
|
capturePreReset();
|
|
|
|
|
2015-05-15 23:14:35 +03:00
|
|
|
DX_RELEASE(m_flushQuery, 0);
|
2015-08-21 23:07:58 +03:00
|
|
|
if (m_timerQuerySupport)
|
|
|
|
{
|
|
|
|
m_gpuTimer.preReset();
|
|
|
|
}
|
2015-05-13 03:03:25 +03:00
|
|
|
|
2015-11-02 04:28:23 +03:00
|
|
|
if (m_occlusionQuerySupport)
|
|
|
|
{
|
|
|
|
m_occlusionQuery.preReset();
|
|
|
|
}
|
|
|
|
|
2013-08-07 08:04:28 +04:00
|
|
|
for (uint32_t ii = 0; ii < BX_COUNTOF(m_indexBuffers); ++ii)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
|
|
|
m_indexBuffers[ii].preReset();
|
|
|
|
}
|
|
|
|
|
2013-08-07 08:04:28 +04:00
|
|
|
for (uint32_t ii = 0; ii < BX_COUNTOF(m_vertexBuffers); ++ii)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
|
|
|
m_vertexBuffers[ii].preReset();
|
|
|
|
}
|
|
|
|
|
2014-02-06 11:07:11 +04:00
|
|
|
for (uint32_t ii = 0; ii < BX_COUNTOF(m_frameBuffers); ++ii)
|
|
|
|
{
|
|
|
|
m_frameBuffers[ii].preReset();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t ii = 0; ii < BX_COUNTOF(m_textures); ++ii)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2014-02-06 11:07:11 +04:00
|
|
|
m_textures[ii].preReset();
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void postReset()
|
|
|
|
{
|
2014-09-08 04:17:38 +04:00
|
|
|
DX_CHECK(m_device->GetSwapChain(0, &m_swapChain) );
|
|
|
|
DX_CHECK(m_swapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &m_backBufferColor) );
|
2012-08-06 01:51:49 +04:00
|
|
|
DX_CHECK(m_device->GetDepthStencilSurface(&m_backBufferDepthStencil) );
|
|
|
|
|
2015-05-15 23:14:35 +03:00
|
|
|
DX_CHECK(m_device->CreateQuery(D3DQUERYTYPE_EVENT, &m_flushQuery) );
|
2015-08-21 23:07:58 +03:00
|
|
|
if (m_timerQuerySupport)
|
|
|
|
{
|
|
|
|
m_gpuTimer.postReset();
|
|
|
|
}
|
2015-05-13 03:03:25 +03:00
|
|
|
|
2015-11-02 04:28:23 +03:00
|
|
|
if (m_occlusionQuerySupport)
|
|
|
|
{
|
|
|
|
m_occlusionQuery.postReset();
|
|
|
|
}
|
|
|
|
|
2012-12-31 08:52:47 +04:00
|
|
|
capturePostReset();
|
|
|
|
|
2013-08-07 08:04:28 +04:00
|
|
|
for (uint32_t ii = 0; ii < BX_COUNTOF(m_indexBuffers); ++ii)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
|
|
|
m_indexBuffers[ii].postReset();
|
|
|
|
}
|
|
|
|
|
2013-08-07 08:04:28 +04:00
|
|
|
for (uint32_t ii = 0; ii < BX_COUNTOF(m_vertexBuffers); ++ii)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
|
|
|
m_vertexBuffers[ii].postReset();
|
|
|
|
}
|
|
|
|
|
2014-02-06 11:07:11 +04:00
|
|
|
for (uint32_t ii = 0; ii < BX_COUNTOF(m_textures); ++ii)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2014-02-06 11:07:11 +04:00
|
|
|
m_textures[ii].postReset();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t ii = 0; ii < BX_COUNTOF(m_frameBuffers); ++ii)
|
|
|
|
{
|
|
|
|
m_frameBuffers[ii].postReset();
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-25 08:59:59 +04:00
|
|
|
void invalidateSamplerState()
|
|
|
|
{
|
2014-07-31 07:37:54 +04:00
|
|
|
for (uint32_t stage = 0; stage < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++stage)
|
2013-07-25 08:59:59 +04:00
|
|
|
{
|
2015-08-11 03:45:18 +03:00
|
|
|
m_samplerFlags[stage] = UINT32_MAX;
|
2013-07-25 08:59:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-17 03:21:28 +03:00
|
|
|
static void setSamplerState(IDirect3DDevice9* _device, DWORD _stage, D3DSAMPLERSTATETYPE _type, DWORD _value)
|
2015-08-11 03:45:18 +03:00
|
|
|
{
|
2015-09-10 23:29:12 +03:00
|
|
|
DX_CHECK(_device->SetSamplerState(_stage, _type, _value) );
|
|
|
|
if (4 > _stage)
|
|
|
|
{
|
|
|
|
DX_CHECK(_device->SetSamplerState(D3DVERTEXTEXTURESAMPLER0 + _stage, _type, _value) );
|
|
|
|
}
|
2015-08-11 03:45:18 +03:00
|
|
|
}
|
|
|
|
|
2015-09-17 03:21:28 +03:00
|
|
|
void setSamplerState(uint8_t _stage, uint32_t _flags, const float _rgba[4])
|
2013-07-25 08:59:59 +04:00
|
|
|
{
|
2015-05-03 06:54:51 +03:00
|
|
|
const uint32_t flags = _flags&( (~BGFX_TEXTURE_RESERVED_MASK) | BGFX_TEXTURE_SAMPLER_BITS_MASK | BGFX_TEXTURE_SRGB);
|
2015-03-02 09:01:30 +03:00
|
|
|
BX_CHECK(_stage < BX_COUNTOF(m_samplerFlags), "");
|
2015-08-11 03:45:18 +03:00
|
|
|
if (m_samplerFlags[_stage] != flags)
|
2013-07-25 08:59:59 +04:00
|
|
|
{
|
2015-08-11 03:45:18 +03:00
|
|
|
m_samplerFlags[_stage] = flags;
|
2013-07-25 08:59:59 +04:00
|
|
|
IDirect3DDevice9* device = m_device;
|
|
|
|
D3DTEXTUREADDRESS tau = s_textureAddress[(_flags&BGFX_TEXTURE_U_MASK)>>BGFX_TEXTURE_U_SHIFT];
|
|
|
|
D3DTEXTUREADDRESS tav = s_textureAddress[(_flags&BGFX_TEXTURE_V_MASK)>>BGFX_TEXTURE_V_SHIFT];
|
|
|
|
D3DTEXTUREADDRESS taw = s_textureAddress[(_flags&BGFX_TEXTURE_W_MASK)>>BGFX_TEXTURE_W_SHIFT];
|
|
|
|
D3DTEXTUREFILTERTYPE minFilter = s_textureFilter[(_flags&BGFX_TEXTURE_MIN_MASK)>>BGFX_TEXTURE_MIN_SHIFT];
|
|
|
|
D3DTEXTUREFILTERTYPE magFilter = s_textureFilter[(_flags&BGFX_TEXTURE_MAG_MASK)>>BGFX_TEXTURE_MAG_SHIFT];
|
|
|
|
D3DTEXTUREFILTERTYPE mipFilter = s_textureFilter[(_flags&BGFX_TEXTURE_MIP_MASK)>>BGFX_TEXTURE_MIP_SHIFT];
|
2015-03-02 09:01:30 +03:00
|
|
|
|
2015-08-11 03:45:18 +03:00
|
|
|
setSamplerState(device, _stage, D3DSAMP_ADDRESSU, tau);
|
|
|
|
setSamplerState(device, _stage, D3DSAMP_ADDRESSV, tav);
|
|
|
|
setSamplerState(device, _stage, D3DSAMP_ADDRESSW, taw);
|
|
|
|
setSamplerState(device, _stage, D3DSAMP_MINFILTER, minFilter);
|
|
|
|
setSamplerState(device, _stage, D3DSAMP_MAGFILTER, magFilter);
|
|
|
|
setSamplerState(device, _stage, D3DSAMP_MIPFILTER, mipFilter);
|
|
|
|
setSamplerState(device, _stage, D3DSAMP_MAXANISOTROPY, m_maxAnisotropy);
|
|
|
|
setSamplerState(device, _stage, D3DSAMP_SRGBTEXTURE, 0 != (flags & BGFX_TEXTURE_SRGB) );
|
2015-09-17 03:21:28 +03:00
|
|
|
if (NULL != _rgba)
|
|
|
|
{
|
2015-09-18 05:55:01 +03:00
|
|
|
if (needBorderColor(_flags) )
|
2015-09-17 03:21:28 +03:00
|
|
|
{
|
|
|
|
DWORD bc = D3DCOLOR_COLORVALUE(_rgba[0], _rgba[1], _rgba[2], _rgba[3]);
|
|
|
|
setSamplerState(device
|
|
|
|
, _stage
|
|
|
|
, D3DSAMP_BORDERCOLOR
|
|
|
|
, bc
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2013-07-25 08:59:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-04 03:00:14 +03:00
|
|
|
bool isVisible(Frame* _render, OcclusionQueryHandle _handle, bool _visible)
|
2015-11-02 04:28:23 +03:00
|
|
|
{
|
2015-11-04 03:00:14 +03:00
|
|
|
m_occlusionQuery.resolve(_render);
|
2015-11-04 06:06:14 +03:00
|
|
|
return _visible == (0 != _render->m_occlusion[_handle.idx]);
|
2015-11-02 04:28:23 +03:00
|
|
|
}
|
|
|
|
|
2012-12-31 08:52:47 +04:00
|
|
|
void capturePreReset()
|
|
|
|
{
|
|
|
|
if (NULL != m_captureSurface)
|
|
|
|
{
|
|
|
|
g_callback->captureEnd();
|
|
|
|
}
|
|
|
|
DX_RELEASE(m_captureSurface, 1);
|
|
|
|
DX_RELEASE(m_captureTexture, 0);
|
|
|
|
DX_RELEASE(m_captureResolve, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void capturePostReset()
|
|
|
|
{
|
2018-04-18 01:42:18 +03:00
|
|
|
if (m_resolution.reset&BGFX_RESET_CAPTURE)
|
2012-12-31 08:52:47 +04:00
|
|
|
{
|
2014-09-08 04:17:38 +04:00
|
|
|
uint32_t width = m_params.BackBufferWidth;
|
2012-12-31 08:52:47 +04:00
|
|
|
uint32_t height = m_params.BackBufferHeight;
|
2014-09-08 04:17:38 +04:00
|
|
|
D3DFORMAT fmt = m_params.BackBufferFormat;
|
2012-12-31 08:52:47 +04:00
|
|
|
|
|
|
|
DX_CHECK(m_device->CreateTexture(width
|
|
|
|
, height
|
|
|
|
, 1
|
|
|
|
, 0
|
|
|
|
, fmt
|
|
|
|
, D3DPOOL_SYSTEMMEM
|
|
|
|
, &m_captureTexture
|
|
|
|
, NULL
|
|
|
|
) );
|
|
|
|
|
|
|
|
DX_CHECK(m_captureTexture->GetSurfaceLevel(0
|
|
|
|
, &m_captureSurface
|
|
|
|
) );
|
|
|
|
|
|
|
|
if (m_params.MultiSampleType != D3DMULTISAMPLE_NONE)
|
|
|
|
{
|
|
|
|
DX_CHECK(m_device->CreateRenderTarget(width
|
|
|
|
, height
|
|
|
|
, fmt
|
|
|
|
, D3DMULTISAMPLE_NONE
|
|
|
|
, 0
|
|
|
|
, false
|
|
|
|
, &m_captureResolve
|
|
|
|
, NULL
|
|
|
|
) );
|
|
|
|
}
|
|
|
|
|
|
|
|
g_callback->captureBegin(width, height, width*4, TextureFormat::BGRA8, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void capture()
|
|
|
|
{
|
|
|
|
if (NULL != m_captureSurface)
|
|
|
|
{
|
|
|
|
IDirect3DSurface9* resolve = m_backBufferColor;
|
|
|
|
|
|
|
|
if (NULL != m_captureResolve)
|
|
|
|
{
|
|
|
|
resolve = m_captureResolve;
|
|
|
|
DX_CHECK(m_device->StretchRect(m_backBufferColor
|
|
|
|
, 0
|
|
|
|
, m_captureResolve
|
|
|
|
, NULL
|
|
|
|
, D3DTEXF_NONE
|
|
|
|
) );
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT hr = m_device->GetRenderTargetData(resolve, m_captureSurface);
|
|
|
|
if (SUCCEEDED(hr) )
|
|
|
|
{
|
|
|
|
D3DLOCKED_RECT rect;
|
|
|
|
DX_CHECK(m_captureSurface->LockRect(&rect
|
|
|
|
, NULL
|
|
|
|
, D3DLOCK_NO_DIRTY_UPDATE|D3DLOCK_NOSYSLOCK|D3DLOCK_READONLY
|
|
|
|
) );
|
|
|
|
|
|
|
|
g_callback->captureFrame(rect.pBits, m_params.BackBufferHeight*rect.Pitch);
|
|
|
|
|
|
|
|
DX_CHECK(m_captureSurface->UnlockRect() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-15 01:53:33 +03:00
|
|
|
void commit(UniformBuffer& _uniformBuffer)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2015-09-15 01:53:33 +03:00
|
|
|
_uniformBuffer.reset();
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
IDirect3DDevice9* device = m_device;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2014-06-09 07:57:39 +04:00
|
|
|
for (;;)
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
2015-09-15 01:53:33 +03:00
|
|
|
uint32_t opcode = _uniformBuffer.read();
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
if (UniformType::End == opcode)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
UniformType::Enum type;
|
|
|
|
uint16_t loc;
|
|
|
|
uint16_t num;
|
|
|
|
uint16_t copy;
|
2015-09-15 01:53:33 +03:00
|
|
|
UniformBuffer::decodeOpcode(opcode, type, loc, num, copy);
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
const char* data;
|
|
|
|
if (copy)
|
|
|
|
{
|
2015-09-15 01:53:33 +03:00
|
|
|
data = _uniformBuffer.read(g_uniformTypeSize[type]*num);
|
2014-05-27 01:09:26 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
UniformHandle handle;
|
2017-02-09 06:55:31 +03:00
|
|
|
bx::memCopy(&handle, _uniformBuffer.read(sizeof(UniformHandle) ), sizeof(UniformHandle) );
|
2014-05-27 01:09:26 +04:00
|
|
|
data = (const char*)m_uniforms[handle.idx];
|
|
|
|
}
|
2012-12-31 08:52:47 +04:00
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
#define CASE_IMPLEMENT_UNIFORM(_uniform, _dxsuffix, _type) \
|
|
|
|
case UniformType::_uniform: \
|
|
|
|
{ \
|
|
|
|
_type* value = (_type*)data; \
|
|
|
|
DX_CHECK(device->SetVertexShaderConstant##_dxsuffix(loc, value, num) ); \
|
|
|
|
} \
|
|
|
|
break; \
|
|
|
|
\
|
|
|
|
case UniformType::_uniform|BGFX_UNIFORM_FRAGMENTBIT: \
|
|
|
|
{ \
|
|
|
|
_type* value = (_type*)data; \
|
|
|
|
DX_CHECK(device->SetPixelShaderConstant##_dxsuffix(loc, value, num) ); \
|
|
|
|
} \
|
|
|
|
break
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
switch ( (int32_t)type)
|
|
|
|
{
|
2015-05-29 01:27:00 +03:00
|
|
|
case UniformType::Mat3:
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
|
|
|
float* value = (float*)data;
|
|
|
|
for (uint32_t ii = 0, count = num/3; ii < count; ++ii, loc += 3, value += 9)
|
|
|
|
{
|
|
|
|
Matrix4 mtx;
|
|
|
|
mtx.un.val[ 0] = value[0];
|
|
|
|
mtx.un.val[ 1] = value[1];
|
|
|
|
mtx.un.val[ 2] = value[2];
|
|
|
|
mtx.un.val[ 3] = 0.0f;
|
|
|
|
mtx.un.val[ 4] = value[3];
|
|
|
|
mtx.un.val[ 5] = value[4];
|
|
|
|
mtx.un.val[ 6] = value[5];
|
|
|
|
mtx.un.val[ 7] = 0.0f;
|
|
|
|
mtx.un.val[ 8] = value[6];
|
|
|
|
mtx.un.val[ 9] = value[7];
|
|
|
|
mtx.un.val[10] = value[8];
|
|
|
|
mtx.un.val[11] = 0.0f;
|
|
|
|
DX_CHECK(device->SetVertexShaderConstantF(loc, &mtx.un.val[0], 3) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-05-29 01:27:00 +03:00
|
|
|
case UniformType::Mat3|BGFX_UNIFORM_FRAGMENTBIT:
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
|
|
|
float* value = (float*)data;
|
|
|
|
for (uint32_t ii = 0, count = num/3; ii < count; ++ii, loc += 3, value += 9)
|
|
|
|
{
|
|
|
|
Matrix4 mtx;
|
|
|
|
mtx.un.val[ 0] = value[0];
|
|
|
|
mtx.un.val[ 1] = value[1];
|
|
|
|
mtx.un.val[ 2] = value[2];
|
|
|
|
mtx.un.val[ 3] = 0.0f;
|
|
|
|
mtx.un.val[ 4] = value[3];
|
|
|
|
mtx.un.val[ 5] = value[4];
|
|
|
|
mtx.un.val[ 6] = value[5];
|
|
|
|
mtx.un.val[ 7] = 0.0f;
|
|
|
|
mtx.un.val[ 8] = value[6];
|
|
|
|
mtx.un.val[ 9] = value[7];
|
|
|
|
mtx.un.val[10] = value[8];
|
|
|
|
mtx.un.val[11] = 0.0f;
|
|
|
|
DX_CHECK(device->SetPixelShaderConstantF(loc, &mtx.un.val[0], 3) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-05-29 01:27:00 +03:00
|
|
|
CASE_IMPLEMENT_UNIFORM(Int1, I, int);
|
|
|
|
CASE_IMPLEMENT_UNIFORM(Vec4, F, float);
|
|
|
|
CASE_IMPLEMENT_UNIFORM(Mat4, F, float);
|
2014-05-27 01:09:26 +04:00
|
|
|
|
|
|
|
case UniformType::End:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2015-09-15 01:53:33 +03:00
|
|
|
BX_TRACE("%4d: INVALID 0x%08x, t %d, l %d, n %d, c %d", _uniformBuffer.getPos(), opcode, type, loc, num, copy);
|
2014-05-27 01:09:26 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#undef CASE_IMPLEMENT_UNIFORM
|
2014-09-01 22:24:51 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void clearQuad(ClearQuad& _clearQuad, const Rect& _rect, const Clear& _clear, const float _palette[][4])
|
|
|
|
{
|
|
|
|
IDirect3DDevice9* device = m_device;
|
|
|
|
|
|
|
|
uint32_t numMrt = 1;
|
|
|
|
FrameBufferHandle fbh = m_fbh;
|
|
|
|
if (isValid(fbh) )
|
|
|
|
{
|
|
|
|
const FrameBufferD3D9& fb = m_frameBuffers[fbh.idx];
|
|
|
|
numMrt = bx::uint32_max(1, fb.m_num);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (1 == numMrt)
|
|
|
|
{
|
|
|
|
D3DCOLOR color = 0;
|
|
|
|
DWORD flags = 0;
|
|
|
|
|
2015-01-11 08:39:45 +03:00
|
|
|
if (BGFX_CLEAR_COLOR & _clear.m_flags)
|
2014-09-01 22:24:51 +04:00
|
|
|
{
|
2015-01-12 05:02:34 +03:00
|
|
|
if (BGFX_CLEAR_COLOR_USE_PALETTE & _clear.m_flags)
|
2014-09-01 22:24:51 +04:00
|
|
|
{
|
2015-09-17 03:21:28 +03:00
|
|
|
uint8_t index = (uint8_t)bx::uint32_min(BGFX_CONFIG_MAX_COLOR_PALETTE-1, _clear.m_index[0]);
|
2014-09-01 22:24:51 +04:00
|
|
|
const float* rgba = _palette[index];
|
|
|
|
const float rr = rgba[0];
|
|
|
|
const float gg = rgba[1];
|
|
|
|
const float bb = rgba[2];
|
|
|
|
const float aa = rgba[3];
|
|
|
|
color = D3DCOLOR_COLORVALUE(rr, gg, bb, aa);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-05-03 02:40:13 +03:00
|
|
|
color = D3DCOLOR_RGBA(_clear.m_index[0], _clear.m_index[1], _clear.m_index[2], _clear.m_index[3]);
|
2014-09-01 22:24:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
flags |= D3DCLEAR_TARGET;
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_COLORWRITEENABLE
|
|
|
|
, D3DCOLORWRITEENABLE_RED
|
|
|
|
| D3DCOLORWRITEENABLE_GREEN
|
|
|
|
| D3DCOLORWRITEENABLE_BLUE
|
|
|
|
| D3DCOLORWRITEENABLE_ALPHA
|
|
|
|
) );
|
|
|
|
}
|
|
|
|
|
2015-01-11 08:39:45 +03:00
|
|
|
if (BGFX_CLEAR_DEPTH & _clear.m_flags)
|
2014-09-01 22:24:51 +04:00
|
|
|
{
|
|
|
|
flags |= D3DCLEAR_ZBUFFER;
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_ZWRITEENABLE, TRUE) );
|
|
|
|
}
|
|
|
|
|
2015-01-11 08:39:45 +03:00
|
|
|
if (BGFX_CLEAR_STENCIL & _clear.m_flags)
|
2014-09-01 22:24:51 +04:00
|
|
|
{
|
|
|
|
flags |= D3DCLEAR_STENCIL;
|
|
|
|
}
|
2014-05-27 01:09:26 +04:00
|
|
|
|
2014-09-01 22:24:51 +04:00
|
|
|
if (0 != flags)
|
|
|
|
{
|
|
|
|
RECT rc;
|
|
|
|
rc.left = _rect.m_x;
|
|
|
|
rc.top = _rect.m_y;
|
|
|
|
rc.right = _rect.m_x + _rect.m_width;
|
|
|
|
rc.bottom = _rect.m_y + _rect.m_height;
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_SCISSORTESTENABLE, TRUE) );
|
|
|
|
DX_CHECK(device->SetScissorRect(&rc) );
|
|
|
|
DX_CHECK(device->Clear(0, NULL, flags, color, _clear.m_depth, _clear.m_stencil) );
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE) );
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE) );
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE) );
|
|
|
|
|
2015-05-21 03:02:19 +03:00
|
|
|
if (BGFX_CLEAR_COLOR & _clear.m_flags)
|
2014-09-01 22:24:51 +04:00
|
|
|
{
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_COLORWRITEENABLE
|
|
|
|
, D3DCOLORWRITEENABLE_RED
|
|
|
|
| D3DCOLORWRITEENABLE_GREEN
|
|
|
|
| D3DCOLORWRITEENABLE_BLUE
|
|
|
|
| D3DCOLORWRITEENABLE_ALPHA
|
|
|
|
) );
|
2015-05-21 03:02:19 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_COLORWRITEENABLE, 0) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BGFX_CLEAR_DEPTH & _clear.m_flags)
|
|
|
|
{
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_ZWRITEENABLE, TRUE) );
|
2014-09-01 22:24:51 +04:00
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_ZENABLE, TRUE) );
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_ZWRITEENABLE, FALSE) );
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_ZENABLE, FALSE) );
|
|
|
|
}
|
|
|
|
|
2015-01-11 08:39:45 +03:00
|
|
|
if (BGFX_CLEAR_STENCIL & _clear.m_flags)
|
2014-09-01 22:24:51 +04:00
|
|
|
{
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_STENCILENABLE, TRUE) );
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_TWOSIDEDSTENCILMODE, TRUE) );
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_STENCILREF, _clear.m_stencil) );
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_STENCILMASK, 0xff) );
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS) );
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_REPLACE) );
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_REPLACE) );
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_REPLACE) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_STENCILENABLE, FALSE) );
|
|
|
|
}
|
|
|
|
|
|
|
|
VertexBufferD3D9& vb = m_vertexBuffers[_clearQuad.m_vb->handle.idx];
|
2017-05-14 08:21:02 +03:00
|
|
|
VertexDecl& vertexDecl = m_vertexDecls[_clearQuad.m_vb->decl.idx];
|
2014-09-01 22:24:51 +04:00
|
|
|
uint32_t stride = _clearQuad.m_decl.m_stride;
|
|
|
|
|
|
|
|
{
|
|
|
|
struct Vertex
|
|
|
|
{
|
|
|
|
float m_x;
|
|
|
|
float m_y;
|
|
|
|
float m_z;
|
|
|
|
};
|
|
|
|
|
|
|
|
Vertex* vertex = (Vertex*)_clearQuad.m_vb->data;
|
|
|
|
BX_CHECK(stride == sizeof(Vertex), "Stride/Vertex mismatch (stride %d, sizeof(Vertex) %d)", stride, sizeof(Vertex) );
|
|
|
|
|
|
|
|
const float depth = _clear.m_depth;
|
|
|
|
|
|
|
|
vertex->m_x = -1.0f;
|
|
|
|
vertex->m_y = -1.0f;
|
|
|
|
vertex->m_z = depth;
|
|
|
|
vertex++;
|
|
|
|
vertex->m_x = 1.0f;
|
|
|
|
vertex->m_y = -1.0f;
|
|
|
|
vertex->m_z = depth;
|
|
|
|
vertex++;
|
|
|
|
vertex->m_x = -1.0f;
|
|
|
|
vertex->m_y = 1.0f;
|
|
|
|
vertex->m_z = depth;
|
|
|
|
vertex++;
|
|
|
|
vertex->m_x = 1.0f;
|
|
|
|
vertex->m_y = 1.0f;
|
|
|
|
vertex->m_z = depth;
|
|
|
|
}
|
|
|
|
|
|
|
|
vb.update(0, 4*stride, _clearQuad.m_vb->data);
|
|
|
|
|
|
|
|
ProgramD3D9& program = m_program[_clearQuad.m_program[numMrt-1].idx];
|
|
|
|
device->SetVertexShader(program.m_vsh->m_vertexShader);
|
|
|
|
device->SetPixelShader(program.m_fsh->m_pixelShader);
|
|
|
|
|
2016-01-06 05:32:24 +03:00
|
|
|
float mrtClear[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS][4];
|
|
|
|
|
2015-01-12 05:02:34 +03:00
|
|
|
if (BGFX_CLEAR_COLOR_USE_PALETTE & _clear.m_flags)
|
2014-09-01 22:24:51 +04:00
|
|
|
{
|
|
|
|
for (uint32_t ii = 0; ii < numMrt; ++ii)
|
|
|
|
{
|
2016-01-06 05:32:24 +03:00
|
|
|
uint8_t index = (uint8_t)bx::uint32_min(BGFX_CONFIG_MAX_COLOR_PALETTE - 1, _clear.m_index[ii]);
|
2017-02-09 06:55:31 +03:00
|
|
|
bx::memCopy(mrtClear[ii], _palette[index], 16);
|
2014-09-01 22:24:51 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float rgba[4] =
|
|
|
|
{
|
2016-01-06 05:32:24 +03:00
|
|
|
_clear.m_index[0] * 1.0f / 255.0f,
|
|
|
|
_clear.m_index[1] * 1.0f / 255.0f,
|
|
|
|
_clear.m_index[2] * 1.0f / 255.0f,
|
|
|
|
_clear.m_index[3] * 1.0f / 255.0f,
|
2014-09-01 22:24:51 +04:00
|
|
|
};
|
|
|
|
|
2016-01-06 05:32:24 +03:00
|
|
|
for (uint32_t ii = 0; ii < numMrt; ++ii)
|
|
|
|
{
|
2017-02-09 06:55:31 +03:00
|
|
|
bx::memCopy(mrtClear[ii], rgba, 16);
|
2016-01-06 05:32:24 +03:00
|
|
|
}
|
2014-09-01 22:24:51 +04:00
|
|
|
}
|
|
|
|
|
2016-01-06 05:32:24 +03:00
|
|
|
DX_CHECK(device->SetPixelShaderConstantF(0, mrtClear[0], numMrt));
|
|
|
|
|
2014-09-01 22:24:51 +04:00
|
|
|
DX_CHECK(device->SetStreamSource(0, vb.m_ptr, 0, stride) );
|
|
|
|
DX_CHECK(device->SetStreamSourceFreq(0, 1) );
|
|
|
|
DX_CHECK(device->SetStreamSource(1, NULL, 0, 0) );
|
2017-05-14 08:21:02 +03:00
|
|
|
setInputLayout(vertexDecl, 0);
|
2014-09-01 22:24:51 +04:00
|
|
|
DX_CHECK(device->SetIndices(NULL) );
|
|
|
|
DX_CHECK(device->DrawPrimitive(D3DPT_TRIANGLESTRIP
|
|
|
|
, 0
|
|
|
|
, 2
|
|
|
|
) );
|
2014-06-09 07:57:39 +04:00
|
|
|
}
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
|
2017-05-14 08:21:02 +03:00
|
|
|
void setInputLayout(uint8_t _numStreams, const VertexDecl** _vertexDecls, uint16_t _numInstanceData)
|
|
|
|
{
|
|
|
|
bx::HashMurmur2A murmur;
|
|
|
|
murmur.begin();
|
|
|
|
murmur.add(_numInstanceData);
|
|
|
|
for (uint8_t stream = 0; stream < _numStreams; ++stream)
|
|
|
|
{
|
|
|
|
murmur.add(_vertexDecls[stream]->m_hash);
|
|
|
|
}
|
|
|
|
uint64_t layoutHash = murmur.end();
|
|
|
|
|
|
|
|
IDirect3DVertexDeclaration9* layout = m_inputLayoutCache.find(layoutHash);
|
|
|
|
if (NULL == layout)
|
|
|
|
{
|
|
|
|
D3DVERTEXELEMENT9 vertexElements[Attrib::Count+1+BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT];
|
|
|
|
D3DVERTEXELEMENT9* elem = vertexElements;
|
|
|
|
|
|
|
|
for (uint8_t stream = 0; stream < _numStreams; ++stream)
|
|
|
|
{
|
|
|
|
elem = fillVertexDecl(stream, elem, *_vertexDecls[stream]);
|
|
|
|
}
|
|
|
|
|
|
|
|
const D3DVERTEXELEMENT9 inst = { _numStreams, 0, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 };
|
|
|
|
|
|
|
|
for (uint8_t ii = 0; ii < _numInstanceData; ++ii)
|
|
|
|
{
|
|
|
|
bx::memCopy(elem, &inst, sizeof(D3DVERTEXELEMENT9) );
|
|
|
|
elem->UsageIndex = uint8_t(7-ii); // TEXCOORD7 = i_data0, TEXCOORD6 = i_data1, etc.
|
|
|
|
elem->Offset = ii*16;
|
|
|
|
++elem;
|
|
|
|
}
|
|
|
|
|
|
|
|
bx::memCopy(elem, &s_attrib[Attrib::Count], sizeof(D3DVERTEXELEMENT9) );
|
|
|
|
|
|
|
|
DX_CHECK(m_device->CreateVertexDeclaration(vertexElements, &layout) );
|
|
|
|
|
|
|
|
m_inputLayoutCache.add(layoutHash, layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
DX_CHECK(m_device->SetVertexDeclaration(layout) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void setInputLayout(const VertexDecl& _vertexDecl, uint16_t _numInstanceData)
|
|
|
|
{
|
|
|
|
const VertexDecl* decls[1] = { &_vertexDecl };
|
|
|
|
setInputLayout(BX_COUNTOF(decls), decls, _numInstanceData);
|
|
|
|
}
|
|
|
|
|
2012-08-06 01:51:49 +04:00
|
|
|
D3DCAPS9 m_caps;
|
|
|
|
|
2013-07-27 09:55:13 +04:00
|
|
|
IDirect3D9Ex* m_d3d9ex;
|
|
|
|
IDirect3DDevice9Ex* m_deviceEx;
|
|
|
|
|
2015-11-02 04:28:23 +03:00
|
|
|
IDirect3D9* m_d3d9;
|
|
|
|
IDirect3DDevice9* m_device;
|
|
|
|
IDirect3DQuery9* m_flushQuery;
|
|
|
|
TimerQueryD3D9 m_gpuTimer;
|
|
|
|
OcclusionQueryD3D9 m_occlusionQuery;
|
2013-07-27 09:55:13 +04:00
|
|
|
D3DPOOL m_pool;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2014-09-08 04:17:38 +04:00
|
|
|
IDirect3DSwapChain9* m_swapChain;
|
2016-11-14 07:59:41 +03:00
|
|
|
|
|
|
|
bool m_needPresent;
|
2014-09-08 04:17:38 +04:00
|
|
|
uint16_t m_numWindows;
|
|
|
|
FrameBufferHandle m_windows[BGFX_CONFIG_MAX_FRAME_BUFFERS];
|
|
|
|
|
2012-08-06 01:51:49 +04:00
|
|
|
IDirect3DSurface9* m_backBufferColor;
|
|
|
|
IDirect3DSurface9* m_backBufferDepthStencil;
|
2012-12-31 08:52:47 +04:00
|
|
|
|
|
|
|
IDirect3DTexture9* m_captureTexture;
|
|
|
|
IDirect3DSurface9* m_captureSurface;
|
|
|
|
IDirect3DSurface9* m_captureResolve;
|
|
|
|
|
2012-08-06 01:51:49 +04:00
|
|
|
IDirect3DVertexDeclaration9* m_instanceDataDecls[BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT];
|
|
|
|
|
2013-07-27 09:55:13 +04:00
|
|
|
void* m_d3d9dll;
|
2017-10-02 07:18:29 +03:00
|
|
|
NvApi m_nvapi;
|
2012-08-06 01:51:49 +04:00
|
|
|
uint32_t m_adapter;
|
|
|
|
D3DDEVTYPE m_deviceType;
|
|
|
|
D3DPRESENT_PARAMETERS m_params;
|
2015-01-22 07:39:42 +03:00
|
|
|
uint32_t m_maxAnisotropy;
|
2013-04-28 03:55:34 +04:00
|
|
|
D3DADAPTER_IDENTIFIER9 m_identifier;
|
2014-05-27 01:09:26 +04:00
|
|
|
Resolution m_resolution;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
|
|
|
bool m_initialized;
|
|
|
|
bool m_amd;
|
|
|
|
bool m_nvidia;
|
2016-03-17 01:09:15 +03:00
|
|
|
bool m_atocSupport;
|
2015-08-21 23:07:58 +03:00
|
|
|
bool m_instancingSupport;
|
2015-11-02 04:28:23 +03:00
|
|
|
bool m_occlusionQuerySupport;
|
2016-03-17 01:09:15 +03:00
|
|
|
bool m_timerQuerySupport;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
|
|
|
D3DFORMAT m_fmtDepth;
|
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
IndexBufferD3D9 m_indexBuffers[BGFX_CONFIG_MAX_INDEX_BUFFERS];
|
|
|
|
VertexBufferD3D9 m_vertexBuffers[BGFX_CONFIG_MAX_VERTEX_BUFFERS];
|
|
|
|
ShaderD3D9 m_shaders[BGFX_CONFIG_MAX_SHADERS];
|
|
|
|
ProgramD3D9 m_program[BGFX_CONFIG_MAX_PROGRAMS];
|
|
|
|
TextureD3D9 m_textures[BGFX_CONFIG_MAX_TEXTURES];
|
2017-05-14 08:21:02 +03:00
|
|
|
VertexDecl m_vertexDecls[BGFX_CONFIG_MAX_VERTEX_DECLS];
|
2014-05-27 01:09:26 +04:00
|
|
|
FrameBufferD3D9 m_frameBuffers[BGFX_CONFIG_MAX_FRAME_BUFFERS];
|
2012-08-06 01:51:49 +04:00
|
|
|
UniformRegistry m_uniformReg;
|
|
|
|
void* m_uniforms[BGFX_CONFIG_MAX_UNIFORMS];
|
|
|
|
|
2015-08-11 03:45:18 +03:00
|
|
|
uint32_t m_samplerFlags[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS];
|
2013-07-25 08:59:59 +04:00
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
TextureD3D9* m_updateTexture;
|
2013-03-03 09:35:09 +04:00
|
|
|
uint8_t* m_updateTextureBits;
|
|
|
|
uint32_t m_updateTexturePitch;
|
|
|
|
uint8_t m_updateTextureSide;
|
|
|
|
uint8_t m_updateTextureMip;
|
|
|
|
|
2017-05-14 08:21:02 +03:00
|
|
|
StateCacheT<IDirect3DVertexDeclaration9> m_inputLayoutCache;
|
|
|
|
|
2012-08-06 01:51:49 +04:00
|
|
|
TextVideoMem m_textVideoMem;
|
2014-02-06 11:07:11 +04:00
|
|
|
|
|
|
|
FrameBufferHandle m_fbh;
|
2012-08-06 01:51:49 +04:00
|
|
|
bool m_rtMsaa;
|
|
|
|
};
|
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
static RendererContextD3D9* s_renderD3D9;
|
|
|
|
|
2017-12-08 08:52:52 +03:00
|
|
|
RendererContextI* rendererCreate(const Init& _init)
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
|
|
|
s_renderD3D9 = BX_NEW(g_allocator, RendererContextD3D9);
|
2017-12-08 08:52:52 +03:00
|
|
|
if (!s_renderD3D9->init(_init) )
|
2015-07-31 04:36:12 +03:00
|
|
|
{
|
|
|
|
BX_DELETE(g_allocator, s_renderD3D9);
|
|
|
|
s_renderD3D9 = NULL;
|
|
|
|
}
|
2014-05-27 01:09:26 +04:00
|
|
|
return s_renderD3D9;
|
|
|
|
}
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2015-03-22 08:11:59 +03:00
|
|
|
void rendererDestroy()
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
2014-10-14 08:14:51 +04:00
|
|
|
s_renderD3D9->shutdown();
|
2014-05-27 01:09:26 +04:00
|
|
|
BX_DELETE(g_allocator, s_renderD3D9);
|
|
|
|
s_renderD3D9 = NULL;
|
|
|
|
}
|
|
|
|
|
2015-05-14 21:37:32 +03:00
|
|
|
void IndexBufferD3D9::create(uint32_t _size, void* _data, uint16_t _flags)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2015-04-09 05:59:48 +03:00
|
|
|
m_size = _size;
|
|
|
|
m_flags = _flags;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
|
|
|
uint32_t usage = D3DUSAGE_WRITEONLY;
|
2015-04-09 05:59:48 +03:00
|
|
|
D3DPOOL pool = s_renderD3D9->m_pool;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2017-09-18 07:01:20 +03:00
|
|
|
if (NULL == _data)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
|
|
|
usage |= D3DUSAGE_DYNAMIC;
|
|
|
|
pool = D3DPOOL_DEFAULT;
|
2017-09-18 07:01:20 +03:00
|
|
|
m_dynamic = (uint8_t*)BX_ALLOC(g_allocator, _size);
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
|
2015-04-09 05:59:48 +03:00
|
|
|
const D3DFORMAT format = 0 == (_flags & BGFX_BUFFER_INDEX32)
|
|
|
|
? D3DFMT_INDEX16
|
|
|
|
: D3DFMT_INDEX32
|
|
|
|
;
|
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
DX_CHECK(s_renderD3D9->m_device->CreateIndexBuffer(m_size
|
2012-08-06 01:51:49 +04:00
|
|
|
, usage
|
2015-04-09 05:59:48 +03:00
|
|
|
, format
|
2012-08-06 01:51:49 +04:00
|
|
|
, pool
|
|
|
|
, &m_ptr
|
|
|
|
, NULL
|
|
|
|
) );
|
|
|
|
|
|
|
|
if (NULL != _data)
|
|
|
|
{
|
|
|
|
update(0, _size, _data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
void IndexBufferD3D9::preReset()
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2017-09-18 07:01:20 +03:00
|
|
|
if (NULL != m_dynamic)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
|
|
|
DX_RELEASE(m_ptr, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
void IndexBufferD3D9::postReset()
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2017-09-18 07:01:20 +03:00
|
|
|
if (NULL != m_dynamic)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2015-04-09 05:59:48 +03:00
|
|
|
const D3DFORMAT format = 0 == (m_flags & BGFX_BUFFER_INDEX32)
|
|
|
|
? D3DFMT_INDEX16
|
|
|
|
: D3DFMT_INDEX32
|
|
|
|
;
|
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
DX_CHECK(s_renderD3D9->m_device->CreateIndexBuffer(m_size
|
2012-08-06 01:51:49 +04:00
|
|
|
, D3DUSAGE_WRITEONLY|D3DUSAGE_DYNAMIC
|
2015-04-09 05:59:48 +03:00
|
|
|
, format
|
2012-08-06 01:51:49 +04:00
|
|
|
, D3DPOOL_DEFAULT
|
|
|
|
, &m_ptr
|
|
|
|
, NULL
|
|
|
|
) );
|
2017-09-18 07:01:20 +03:00
|
|
|
|
|
|
|
update(0, m_size, m_dynamic);
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
void VertexBufferD3D9::create(uint32_t _size, void* _data, VertexDeclHandle _declHandle)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
|
|
|
m_size = _size;
|
|
|
|
m_decl = _declHandle;
|
|
|
|
|
|
|
|
uint32_t usage = D3DUSAGE_WRITEONLY;
|
2014-05-27 01:09:26 +04:00
|
|
|
D3DPOOL pool = s_renderD3D9->m_pool;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2017-09-18 07:01:20 +03:00
|
|
|
if (NULL == _data)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
|
|
|
usage |= D3DUSAGE_DYNAMIC;
|
|
|
|
pool = D3DPOOL_DEFAULT;
|
2017-09-18 07:01:20 +03:00
|
|
|
m_dynamic = (uint8_t*)BX_ALLOC(g_allocator, _size);
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
DX_CHECK(s_renderD3D9->m_device->CreateVertexBuffer(m_size
|
2017-09-18 07:01:20 +03:00
|
|
|
, usage
|
|
|
|
, 0
|
|
|
|
, pool
|
|
|
|
, &m_ptr
|
|
|
|
, NULL
|
|
|
|
) );
|
2012-08-06 01:51:49 +04:00
|
|
|
|
|
|
|
if (NULL != _data)
|
|
|
|
{
|
|
|
|
update(0, _size, _data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
void VertexBufferD3D9::preReset()
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2017-09-18 07:01:20 +03:00
|
|
|
if (NULL != m_dynamic)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
|
|
|
DX_RELEASE(m_ptr, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
void VertexBufferD3D9::postReset()
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2017-09-18 07:01:20 +03:00
|
|
|
if (NULL != m_dynamic)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2014-05-27 01:09:26 +04:00
|
|
|
DX_CHECK(s_renderD3D9->m_device->CreateVertexBuffer(m_size
|
2017-09-18 07:01:20 +03:00
|
|
|
, D3DUSAGE_WRITEONLY|D3DUSAGE_DYNAMIC
|
|
|
|
, 0
|
|
|
|
, D3DPOOL_DEFAULT
|
|
|
|
, &m_ptr
|
|
|
|
, NULL
|
|
|
|
) );
|
|
|
|
|
|
|
|
update(0, m_size, m_dynamic);
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
void ShaderD3D9::create(const Memory* _mem)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2012-11-26 06:24:50 +04:00
|
|
|
bx::MemoryReader reader(_mem->data, _mem->size);
|
|
|
|
|
|
|
|
uint32_t magic;
|
|
|
|
bx::read(&reader, magic);
|
|
|
|
|
2014-03-30 06:42:57 +04:00
|
|
|
switch (magic)
|
|
|
|
{
|
|
|
|
case BGFX_CHUNK_MAGIC_FSH:
|
|
|
|
case BGFX_CHUNK_MAGIC_VSH:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
BGFX_FATAL(false, Fatal::InvalidShader, "Unknown shader format %x.", magic);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool fragment = BGFX_CHUNK_MAGIC_FSH == magic;
|
|
|
|
|
2012-11-26 06:24:50 +04:00
|
|
|
uint32_t iohash;
|
|
|
|
bx::read(&reader, iohash);
|
2012-08-06 01:51:49 +04:00
|
|
|
|
|
|
|
uint16_t count;
|
2012-11-26 06:24:50 +04:00
|
|
|
bx::read(&reader, count);
|
2012-08-06 01:51:49 +04:00
|
|
|
|
|
|
|
m_numPredefined = 0;
|
|
|
|
|
|
|
|
BX_TRACE("Shader consts %d", count);
|
|
|
|
|
2014-03-30 06:42:57 +04:00
|
|
|
uint8_t fragmentBit = fragment ? BGFX_UNIFORM_FRAGMENTBIT : 0;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2012-11-26 06:24:50 +04:00
|
|
|
if (0 < count)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2012-11-26 06:24:50 +04:00
|
|
|
for (uint32_t ii = 0; ii < count; ++ii)
|
|
|
|
{
|
2016-09-03 05:49:01 +03:00
|
|
|
uint8_t nameSize = 0;
|
2012-11-26 06:24:50 +04:00
|
|
|
bx::read(&reader, nameSize);
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2016-09-03 05:49:01 +03:00
|
|
|
char name[256] = {};
|
2012-11-26 06:24:50 +04:00
|
|
|
bx::read(&reader, &name, nameSize);
|
|
|
|
name[nameSize] = '\0';
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2016-09-03 05:49:01 +03:00
|
|
|
uint8_t type = 0;
|
2012-11-26 06:24:50 +04:00
|
|
|
bx::read(&reader, type);
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2016-09-03 05:49:01 +03:00
|
|
|
uint8_t num = 0;
|
2012-11-26 06:24:50 +04:00
|
|
|
bx::read(&reader, num);
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2016-09-03 05:49:01 +03:00
|
|
|
uint16_t regIndex = 0;
|
2012-11-26 06:24:50 +04:00
|
|
|
bx::read(&reader, regIndex);
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2016-09-03 05:49:01 +03:00
|
|
|
uint16_t regCount = 0;
|
2012-11-26 06:24:50 +04:00
|
|
|
bx::read(&reader, regCount);
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2012-11-26 06:24:50 +04:00
|
|
|
const char* kind = "invalid";
|
|
|
|
|
|
|
|
PredefinedUniform::Enum predefined = nameToPredefinedUniformEnum(name);
|
|
|
|
if (PredefinedUniform::Count != predefined)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2012-11-26 06:24:50 +04:00
|
|
|
kind = "predefined";
|
2015-04-08 03:58:14 +03:00
|
|
|
m_predefined[m_numPredefined].m_loc = regIndex;
|
2012-11-26 06:24:50 +04:00
|
|
|
m_predefined[m_numPredefined].m_count = regCount;
|
2015-04-08 03:58:14 +03:00
|
|
|
m_predefined[m_numPredefined].m_type = uint8_t(predefined|fragmentBit);
|
2012-11-26 06:24:50 +04:00
|
|
|
m_numPredefined++;
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
2015-09-02 02:44:11 +03:00
|
|
|
else if (0 == (BGFX_UNIFORM_SAMPLERBIT & type) )
|
2012-11-26 06:24:50 +04:00
|
|
|
{
|
2016-11-02 10:12:40 +03:00
|
|
|
const UniformRegInfo* info = s_renderD3D9->m_uniformReg.find(name);
|
2016-09-09 03:00:16 +03:00
|
|
|
BX_WARN(NULL != info, "User defined uniform '%s' is not found, it won't be set.", name);
|
2015-09-26 07:51:30 +03:00
|
|
|
|
2012-11-26 06:24:50 +04:00
|
|
|
if (NULL != info)
|
|
|
|
{
|
2014-10-09 06:36:59 +04:00
|
|
|
if (NULL == m_constantBuffer)
|
|
|
|
{
|
2015-09-15 01:53:33 +03:00
|
|
|
m_constantBuffer = UniformBuffer::create(1024);
|
2014-10-09 06:36:59 +04:00
|
|
|
}
|
|
|
|
|
2012-11-26 06:24:50 +04:00
|
|
|
kind = "user";
|
2014-04-16 06:10:56 +04:00
|
|
|
m_constantBuffer->writeUniformHandle( (UniformType::Enum)(type|fragmentBit), regIndex, info->m_handle, regCount);
|
2012-11-26 06:24:50 +04:00
|
|
|
}
|
|
|
|
}
|
2015-09-05 07:20:55 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
kind = "sampler";
|
|
|
|
}
|
2012-11-26 06:24:50 +04:00
|
|
|
|
2015-09-02 02:44:11 +03:00
|
|
|
BX_TRACE("\t%s: %s (%s), num %2d, r.index %3d, r.count %2d"
|
2012-11-26 06:24:50 +04:00
|
|
|
, kind
|
|
|
|
, name
|
2015-09-02 02:44:11 +03:00
|
|
|
, getUniformTypeName(UniformType::Enum(type&~BGFX_UNIFORM_MASK) )
|
2012-11-26 06:24:50 +04:00
|
|
|
, num
|
|
|
|
, regIndex
|
|
|
|
, regCount
|
|
|
|
);
|
2013-05-18 07:03:45 +04:00
|
|
|
BX_UNUSED(kind);
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
|
2014-10-09 06:36:59 +04:00
|
|
|
if (NULL != m_constantBuffer)
|
|
|
|
{
|
|
|
|
m_constantBuffer->finish();
|
|
|
|
}
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
|
2017-06-21 06:34:41 +03:00
|
|
|
uint32_t shaderSize;
|
2012-11-26 06:24:50 +04:00
|
|
|
bx::read(&reader, shaderSize);
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2012-11-26 06:24:50 +04:00
|
|
|
const DWORD* code = (const DWORD*)reader.getDataPtr();
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2014-03-30 06:42:57 +04:00
|
|
|
if (fragment)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2014-07-21 07:27:13 +04:00
|
|
|
m_type = 1;
|
|
|
|
DX_CHECK(s_renderD3D9->m_device->CreatePixelShader(code, &m_pixelShader) );
|
|
|
|
BGFX_FATAL(NULL != m_pixelShader, bgfx::Fatal::InvalidShader, "Failed to create fragment shader.");
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-21 07:27:13 +04:00
|
|
|
m_type = 0;
|
|
|
|
DX_CHECK(s_renderD3D9->m_device->CreateVertexShader(code, &m_vertexShader) );
|
|
|
|
BGFX_FATAL(NULL != m_vertexShader, bgfx::Fatal::InvalidShader, "Failed to create vertex shader.");
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
void TextureD3D9::createTexture(uint32_t _width, uint32_t _height, uint8_t _numMips)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2015-10-23 07:30:55 +03:00
|
|
|
m_type = Texture2D;
|
2017-04-04 08:42:27 +03:00
|
|
|
const bimg::TextureFormat::Enum fmt = (bimg::TextureFormat::Enum)m_textureFormat;
|
2014-02-06 11:07:11 +04:00
|
|
|
|
|
|
|
DWORD usage = 0;
|
2015-10-23 07:30:55 +03:00
|
|
|
D3DPOOL pool = D3DPOOL_DEFAULT;
|
2014-02-06 11:07:11 +04:00
|
|
|
|
|
|
|
const bool renderTarget = 0 != (m_flags&BGFX_TEXTURE_RT_MASK);
|
2015-10-16 02:38:59 +03:00
|
|
|
const bool blit = 0 != (m_flags&BGFX_TEXTURE_BLIT_DST);
|
2015-10-23 07:30:55 +03:00
|
|
|
const bool readBack = 0 != (m_flags&BGFX_TEXTURE_READ_BACK);
|
2017-04-04 08:42:27 +03:00
|
|
|
if (bimg::isDepth(fmt) )
|
2014-02-06 11:07:11 +04:00
|
|
|
{
|
|
|
|
usage = D3DUSAGE_DEPTHSTENCIL;
|
2015-10-23 07:30:55 +03:00
|
|
|
}
|
|
|
|
else if (readBack)
|
|
|
|
{
|
|
|
|
usage = 0;
|
|
|
|
pool = D3DPOOL_SYSTEMMEM;
|
2014-02-06 11:07:11 +04:00
|
|
|
}
|
2015-10-16 02:38:59 +03:00
|
|
|
else if (renderTarget || blit)
|
2014-02-06 11:07:11 +04:00
|
|
|
{
|
2016-07-23 03:42:55 +03:00
|
|
|
usage = 0
|
|
|
|
| D3DUSAGE_RENDERTARGET
|
|
|
|
| (1 < _numMips ? D3DUSAGE_AUTOGENMIPMAP : 0)
|
|
|
|
;
|
2014-02-06 11:07:11 +04:00
|
|
|
}
|
|
|
|
|
2015-10-23 07:30:55 +03:00
|
|
|
IDirect3DDevice9* device = s_renderD3D9->m_device;
|
|
|
|
|
2014-02-06 11:07:11 +04:00
|
|
|
if (renderTarget)
|
|
|
|
{
|
|
|
|
uint32_t msaaQuality = ( (m_flags&BGFX_TEXTURE_RT_MSAA_MASK)>>BGFX_TEXTURE_RT_MSAA_SHIFT);
|
|
|
|
msaaQuality = bx::uint32_satsub(msaaQuality, 1);
|
|
|
|
|
2016-01-13 04:11:16 +03:00
|
|
|
bool writeOnly = 0 != (m_flags&BGFX_TEXTURE_RT_WRITE_ONLY);
|
2014-02-06 11:07:11 +04:00
|
|
|
|
|
|
|
if (0 != msaaQuality
|
2016-01-13 04:11:16 +03:00
|
|
|
|| writeOnly)
|
2014-02-06 11:07:11 +04:00
|
|
|
{
|
|
|
|
const Msaa& msaa = s_msaa[msaaQuality];
|
|
|
|
|
2017-04-04 08:42:27 +03:00
|
|
|
if (bimg::isDepth(fmt) )
|
2014-02-06 11:07:11 +04:00
|
|
|
{
|
2015-10-23 07:30:55 +03:00
|
|
|
DX_CHECK(device->CreateDepthStencilSurface(
|
2014-02-06 11:07:11 +04:00
|
|
|
m_width
|
|
|
|
, m_height
|
|
|
|
, s_textureFormat[m_textureFormat].m_fmt
|
|
|
|
, msaa.m_type
|
|
|
|
, msaa.m_quality
|
|
|
|
, FALSE
|
|
|
|
, &m_surface
|
|
|
|
, NULL
|
|
|
|
) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-10-23 07:30:55 +03:00
|
|
|
DX_CHECK(device->CreateRenderTarget(
|
2014-02-06 11:07:11 +04:00
|
|
|
m_width
|
|
|
|
, m_height
|
|
|
|
, s_textureFormat[m_textureFormat].m_fmt
|
|
|
|
, msaa.m_type
|
|
|
|
, msaa.m_quality
|
|
|
|
, FALSE
|
|
|
|
, &m_surface
|
|
|
|
, NULL
|
|
|
|
) );
|
|
|
|
}
|
|
|
|
|
2016-01-13 04:11:16 +03:00
|
|
|
if (writeOnly)
|
2014-02-06 11:07:11 +04:00
|
|
|
{
|
|
|
|
// This is render buffer, there is no sampling, no need
|
|
|
|
// to create texture.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2015-10-23 07:30:55 +03:00
|
|
|
DX_CHECK(device->CreateTexture(_width
|
2012-08-06 01:51:49 +04:00
|
|
|
, _height
|
|
|
|
, _numMips
|
2014-02-06 11:07:11 +04:00
|
|
|
, usage
|
|
|
|
, s_textureFormat[fmt].m_fmt
|
|
|
|
, pool
|
2012-08-13 08:02:11 +04:00
|
|
|
, &m_texture2d
|
2012-08-06 01:51:49 +04:00
|
|
|
, NULL
|
|
|
|
) );
|
|
|
|
|
2015-10-23 07:30:55 +03:00
|
|
|
if (!renderTarget
|
|
|
|
&& !readBack)
|
|
|
|
{
|
|
|
|
if (NULL == m_staging)
|
|
|
|
{
|
|
|
|
DX_CHECK(device->CreateTexture(_width
|
|
|
|
, _height
|
|
|
|
, _numMips
|
|
|
|
, 0
|
|
|
|
, s_textureFormat[fmt].m_fmt
|
|
|
|
, D3DPOOL_SYSTEMMEM
|
|
|
|
, &m_staging2d
|
|
|
|
, NULL
|
|
|
|
) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-10-23 22:57:04 +03:00
|
|
|
DX_CHECK(m_staging2d->AddDirtyRect(NULL));
|
|
|
|
DX_CHECK(device->UpdateTexture(m_staging2d, m_texture2d));
|
2015-10-23 07:30:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-06 11:07:11 +04:00
|
|
|
BGFX_FATAL(NULL != m_texture2d, Fatal::UnableToCreateTexture, "Failed to create texture (size: %dx%d, mips: %d, fmt: %d)."
|
2012-08-06 01:51:49 +04:00
|
|
|
, _width
|
|
|
|
, _height
|
|
|
|
, _numMips
|
2017-04-04 08:42:27 +03:00
|
|
|
, bimg::getName(fmt)
|
2012-08-06 01:51:49 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-10-23 22:57:04 +03:00
|
|
|
void TextureD3D9::createVolumeTexture(uint32_t _width, uint32_t _height, uint32_t _depth, uint8_t _numMips)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
|
|
|
m_type = Texture3D;
|
2014-02-06 11:07:11 +04:00
|
|
|
const TextureFormat::Enum fmt = (TextureFormat::Enum)m_textureFormat;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2015-10-23 07:30:55 +03:00
|
|
|
IDirect3DDevice9* device = s_renderD3D9->m_device;
|
|
|
|
DX_CHECK(device->CreateVolumeTexture(_width
|
2012-08-06 01:51:49 +04:00
|
|
|
, _height
|
|
|
|
, _depth
|
|
|
|
, _numMips
|
|
|
|
, 0
|
2014-02-06 11:07:11 +04:00
|
|
|
, s_textureFormat[fmt].m_fmt
|
2015-10-23 07:30:55 +03:00
|
|
|
, D3DPOOL_DEFAULT
|
2012-08-13 08:02:11 +04:00
|
|
|
, &m_texture3d
|
2012-08-06 01:51:49 +04:00
|
|
|
, NULL
|
|
|
|
) );
|
|
|
|
|
2015-10-23 07:30:55 +03:00
|
|
|
if (NULL == m_staging)
|
|
|
|
{
|
|
|
|
DX_CHECK(device->CreateVolumeTexture(_width
|
|
|
|
, _height
|
|
|
|
, _depth
|
|
|
|
, _numMips
|
|
|
|
, 0
|
|
|
|
, s_textureFormat[fmt].m_fmt
|
|
|
|
, D3DPOOL_SYSTEMMEM
|
|
|
|
, &m_staging3d
|
|
|
|
, NULL
|
|
|
|
) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-10-23 22:57:04 +03:00
|
|
|
DX_CHECK(m_staging3d->AddDirtyBox(NULL) );
|
2015-10-23 07:30:55 +03:00
|
|
|
DX_CHECK(device->UpdateTexture(m_staging3d, m_texture3d) );
|
|
|
|
}
|
|
|
|
|
2014-02-06 11:07:11 +04:00
|
|
|
BGFX_FATAL(NULL != m_texture3d, Fatal::UnableToCreateTexture, "Failed to create volume texture (size: %dx%dx%d, mips: %d, fmt: %s)."
|
2012-08-06 01:51:49 +04:00
|
|
|
, _width
|
|
|
|
, _height
|
|
|
|
, _depth
|
|
|
|
, _numMips
|
2014-02-06 11:07:11 +04:00
|
|
|
, getName(fmt)
|
2012-08-06 01:51:49 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-10-23 22:57:04 +03:00
|
|
|
void TextureD3D9::createCubeTexture(uint32_t _width, uint8_t _numMips)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
|
|
|
m_type = TextureCube;
|
2017-04-04 08:42:27 +03:00
|
|
|
const bimg::TextureFormat::Enum fmt = (bimg::TextureFormat::Enum)m_textureFormat;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2015-10-19 07:27:49 +03:00
|
|
|
DWORD usage = 0;
|
|
|
|
|
|
|
|
const bool renderTarget = 0 != (m_flags&BGFX_TEXTURE_RT_MASK);
|
|
|
|
const bool blit = 0 != (m_flags&BGFX_TEXTURE_BLIT_DST);
|
2017-04-04 08:42:27 +03:00
|
|
|
if (bimg::isDepth(fmt) )
|
2015-10-19 07:27:49 +03:00
|
|
|
{
|
|
|
|
usage = D3DUSAGE_DEPTHSTENCIL;
|
|
|
|
}
|
|
|
|
else if (renderTarget || blit)
|
|
|
|
{
|
|
|
|
usage = D3DUSAGE_RENDERTARGET;
|
|
|
|
}
|
|
|
|
|
2015-10-23 07:30:55 +03:00
|
|
|
IDirect3DDevice9* device = s_renderD3D9->m_device;
|
2015-10-23 22:57:04 +03:00
|
|
|
DX_CHECK(device->CreateCubeTexture(_width
|
2012-08-06 01:51:49 +04:00
|
|
|
, _numMips
|
2015-10-19 07:27:49 +03:00
|
|
|
, usage
|
2014-02-06 11:07:11 +04:00
|
|
|
, s_textureFormat[fmt].m_fmt
|
2015-10-23 07:30:55 +03:00
|
|
|
, D3DPOOL_DEFAULT
|
2012-08-13 08:02:11 +04:00
|
|
|
, &m_textureCube
|
2012-08-06 01:51:49 +04:00
|
|
|
, NULL
|
|
|
|
) );
|
|
|
|
|
2015-10-23 07:30:55 +03:00
|
|
|
if (!renderTarget)
|
|
|
|
{
|
|
|
|
if (NULL == m_staging)
|
|
|
|
{
|
2015-10-23 22:57:04 +03:00
|
|
|
DX_CHECK(device->CreateCubeTexture(_width
|
2015-10-23 07:30:55 +03:00
|
|
|
, _numMips
|
|
|
|
, 0
|
|
|
|
, s_textureFormat[fmt].m_fmt
|
|
|
|
, D3DPOOL_SYSTEMMEM
|
|
|
|
, &m_stagingCube
|
|
|
|
, NULL
|
|
|
|
) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-10-23 22:57:04 +03:00
|
|
|
for (uint8_t ii = 0; ii < 6; ++ii)
|
2015-10-23 07:30:55 +03:00
|
|
|
{
|
2015-10-23 22:57:04 +03:00
|
|
|
DX_CHECK(m_stagingCube->AddDirtyRect(D3DCUBEMAP_FACES(ii), NULL) );
|
2015-10-23 07:30:55 +03:00
|
|
|
}
|
2015-10-23 22:57:04 +03:00
|
|
|
DX_CHECK(device->UpdateTexture(m_stagingCube, m_textureCube) );
|
2015-10-23 07:30:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-06 11:07:11 +04:00
|
|
|
BGFX_FATAL(NULL != m_textureCube, Fatal::UnableToCreateTexture, "Failed to create cube texture (edge: %d, mips: %d, fmt: %s)."
|
2015-10-23 22:57:04 +03:00
|
|
|
, _width
|
2012-08-06 01:51:49 +04:00
|
|
|
, _numMips
|
2014-02-06 11:07:11 +04:00
|
|
|
, getName(fmt)
|
2012-08-06 01:51:49 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
uint8_t* TextureD3D9::lock(uint8_t _side, uint8_t _lod, uint32_t& _pitch, uint32_t& _slicePitch, const Rect* _rect)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
|
|
|
switch (m_type)
|
|
|
|
{
|
|
|
|
case Texture2D:
|
|
|
|
{
|
2012-08-13 08:02:11 +04:00
|
|
|
D3DLOCKED_RECT lockedRect;
|
|
|
|
|
|
|
|
if (NULL != _rect)
|
|
|
|
{
|
|
|
|
RECT rect;
|
2015-03-30 08:40:35 +03:00
|
|
|
rect.left = _rect->m_x;
|
|
|
|
rect.top = _rect->m_y;
|
|
|
|
rect.right = rect.left + _rect->m_width;
|
|
|
|
rect.bottom = rect.top + _rect->m_height;
|
2015-10-23 07:30:55 +03:00
|
|
|
DX_CHECK(m_staging2d->LockRect(_lod, &lockedRect, &rect, 0) );
|
2015-10-29 21:34:55 +03:00
|
|
|
DX_CHECK(m_staging2d->AddDirtyRect(&rect) );
|
2012-08-13 08:02:11 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-10-23 07:30:55 +03:00
|
|
|
DX_CHECK(m_staging2d->LockRect(_lod, &lockedRect, NULL, 0) );
|
2015-10-29 21:34:55 +03:00
|
|
|
DX_CHECK(m_staging2d->AddDirtyRect(NULL) );
|
2012-08-13 08:02:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
_pitch = lockedRect.Pitch;
|
2012-08-06 01:51:49 +04:00
|
|
|
_slicePitch = 0;
|
2012-08-13 08:02:11 +04:00
|
|
|
return (uint8_t*)lockedRect.pBits;
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
case Texture3D:
|
|
|
|
{
|
|
|
|
D3DLOCKED_BOX box;
|
2015-10-23 07:30:55 +03:00
|
|
|
DX_CHECK(m_staging3d->LockBox(_lod, &box, NULL, 0) );
|
2015-10-29 21:34:55 +03:00
|
|
|
DX_CHECK(m_staging3d->AddDirtyBox(NULL) );
|
2015-10-23 07:30:55 +03:00
|
|
|
_pitch = box.RowPitch;
|
2012-08-06 01:51:49 +04:00
|
|
|
_slicePitch = box.SlicePitch;
|
|
|
|
return (uint8_t*)box.pBits;
|
|
|
|
}
|
|
|
|
|
|
|
|
case TextureCube:
|
|
|
|
{
|
2013-01-07 05:53:45 +04:00
|
|
|
D3DLOCKED_RECT lockedRect;
|
|
|
|
|
|
|
|
if (NULL != _rect)
|
|
|
|
{
|
|
|
|
RECT rect;
|
2015-10-23 07:30:55 +03:00
|
|
|
rect.left = _rect->m_x;
|
|
|
|
rect.top = _rect->m_y;
|
|
|
|
rect.right = rect.left + _rect->m_width;
|
2013-01-07 05:53:45 +04:00
|
|
|
rect.bottom = rect.top + _rect->m_height;
|
2015-10-23 07:30:55 +03:00
|
|
|
DX_CHECK(m_stagingCube->LockRect(D3DCUBEMAP_FACES(_side), _lod, &lockedRect, &rect, 0) );
|
2015-10-29 21:34:55 +03:00
|
|
|
DX_CHECK(m_textureCube->AddDirtyRect(D3DCUBEMAP_FACES(_side), &rect) );
|
2013-01-07 05:53:45 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-10-23 07:30:55 +03:00
|
|
|
DX_CHECK(m_stagingCube->LockRect(D3DCUBEMAP_FACES(_side), _lod, &lockedRect, NULL, 0) );
|
2015-10-29 21:34:55 +03:00
|
|
|
DX_CHECK(m_textureCube->AddDirtyRect(D3DCUBEMAP_FACES(_side), NULL) );
|
2013-01-07 05:53:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
_pitch = lockedRect.Pitch;
|
2012-08-06 01:51:49 +04:00
|
|
|
_slicePitch = 0;
|
2013-01-07 05:53:45 +04:00
|
|
|
return (uint8_t*)lockedRect.pBits;
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BX_CHECK(false, "You should not be here.");
|
2015-10-23 07:30:55 +03:00
|
|
|
_pitch = 0;
|
2013-12-24 08:57:58 +04:00
|
|
|
_slicePitch = 0;
|
2012-08-06 01:51:49 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
void TextureD3D9::unlock(uint8_t _side, uint8_t _lod)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2015-10-23 22:57:04 +03:00
|
|
|
IDirect3DDevice9* device = s_renderD3D9->m_device;
|
|
|
|
|
2012-08-06 01:51:49 +04:00
|
|
|
switch (m_type)
|
|
|
|
{
|
|
|
|
case Texture2D:
|
|
|
|
{
|
2015-10-23 07:30:55 +03:00
|
|
|
DX_CHECK(m_staging2d->UnlockRect(_lod) );
|
2015-10-23 22:57:04 +03:00
|
|
|
DX_CHECK(device->UpdateTexture(m_staging2d, m_texture2d) );
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
case Texture3D:
|
|
|
|
{
|
2015-10-23 07:30:55 +03:00
|
|
|
DX_CHECK(m_staging3d->UnlockBox(_lod) );
|
2015-10-23 22:57:04 +03:00
|
|
|
DX_CHECK(device->UpdateTexture(m_staging3d, m_texture3d) );
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
case TextureCube:
|
|
|
|
{
|
2015-10-23 07:30:55 +03:00
|
|
|
DX_CHECK(m_stagingCube->UnlockRect(D3DCUBEMAP_FACES(_side), _lod) );
|
2015-10-23 22:57:04 +03:00
|
|
|
DX_CHECK(device->UpdateTexture(m_stagingCube, m_textureCube) );
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
BX_CHECK(false, "You should not be here.");
|
|
|
|
}
|
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
void TextureD3D9::dirty(uint8_t _side, const Rect& _rect, uint16_t _z, uint16_t _depth)
|
2013-03-03 09:35:09 +04:00
|
|
|
{
|
|
|
|
switch (m_type)
|
|
|
|
{
|
|
|
|
case Texture2D:
|
|
|
|
{
|
|
|
|
RECT rect;
|
2015-10-23 07:30:55 +03:00
|
|
|
rect.left = _rect.m_x;
|
|
|
|
rect.top = _rect.m_y;
|
|
|
|
rect.right = rect.left + _rect.m_width;
|
2013-03-03 09:35:09 +04:00
|
|
|
rect.bottom = rect.top + _rect.m_height;
|
|
|
|
DX_CHECK(m_texture2d->AddDirtyRect(&rect) );
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
case Texture3D:
|
|
|
|
{
|
2013-03-03 11:20:28 +04:00
|
|
|
D3DBOX box;
|
2015-10-23 07:30:55 +03:00
|
|
|
box.Left = _rect.m_x;
|
|
|
|
box.Top = _rect.m_y;
|
|
|
|
box.Right = box.Left + _rect.m_width;
|
2013-03-03 11:20:28 +04:00
|
|
|
box.Bottom = box.Top + _rect.m_height;
|
2015-10-23 07:30:55 +03:00
|
|
|
box.Front = _z;
|
|
|
|
box.Back = box.Front + _depth;
|
2013-03-03 11:20:28 +04:00
|
|
|
DX_CHECK(m_texture3d->AddDirtyBox(&box) );
|
2013-03-03 09:35:09 +04:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
case TextureCube:
|
|
|
|
{
|
|
|
|
RECT rect;
|
2015-10-23 07:30:55 +03:00
|
|
|
rect.left = _rect.m_x;
|
|
|
|
rect.top = _rect.m_y;
|
|
|
|
rect.right = rect.left + _rect.m_width;
|
2013-03-03 09:35:09 +04:00
|
|
|
rect.bottom = rect.top + _rect.m_height;
|
|
|
|
DX_CHECK(m_textureCube->AddDirtyRect(D3DCUBEMAP_FACES(_side), &rect) );
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
BX_CHECK(false, "You should not be here.");
|
|
|
|
}
|
|
|
|
|
2015-10-20 01:09:56 +03:00
|
|
|
IDirect3DSurface9* TextureD3D9::getSurface(uint8_t _side, uint8_t _mip) const
|
|
|
|
{
|
|
|
|
IDirect3DSurface9* surface = NULL;
|
|
|
|
|
|
|
|
switch (m_type)
|
|
|
|
{
|
|
|
|
case Texture2D:
|
|
|
|
DX_CHECK(m_texture2d->GetSurfaceLevel(_mip, &surface) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Texture3D:
|
|
|
|
BX_CHECK(false, "");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TextureCube:
|
|
|
|
DX_CHECK(m_textureCube->GetCubeMapSurface(D3DCUBEMAP_FACES(_side), _mip, &surface) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
void TextureD3D9::create(const Memory* _mem, uint32_t _flags, uint8_t _skip)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2017-04-04 08:42:27 +03:00
|
|
|
bimg::ImageContainer imageContainer;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2017-04-04 08:42:27 +03:00
|
|
|
if (bimg::imageParse(imageContainer, _mem->data, _mem->size) )
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2014-02-20 10:34:53 +04:00
|
|
|
uint8_t numMips = imageContainer.m_numMips;
|
2015-04-08 03:58:14 +03:00
|
|
|
const uint8_t startLod = uint8_t(bx::uint32_min(_skip, numMips-1) );
|
2014-02-20 10:34:53 +04:00
|
|
|
numMips -= startLod;
|
2017-04-04 08:42:27 +03:00
|
|
|
const bimg::ImageBlockInfo& blockInfo = bimg::getBlockInfo(bimg::TextureFormat::Enum(imageContainer.m_format) );
|
2014-03-02 07:27:34 +04:00
|
|
|
const uint32_t textureWidth = bx::uint32_max(blockInfo.blockWidth, imageContainer.m_width >>startLod);
|
|
|
|
const uint32_t textureHeight = bx::uint32_max(blockInfo.blockHeight, imageContainer.m_height>>startLod);
|
2014-02-20 10:34:53 +04:00
|
|
|
|
2015-10-19 07:27:49 +03:00
|
|
|
m_flags = _flags;
|
|
|
|
m_width = textureWidth;
|
|
|
|
m_height = textureHeight;
|
|
|
|
m_depth = imageContainer.m_depth;
|
|
|
|
m_numMips = numMips;
|
2016-02-23 04:32:20 +03:00
|
|
|
m_requestedFormat = uint8_t(imageContainer.m_format);
|
|
|
|
m_textureFormat = uint8_t(getViableTextureFormat(imageContainer) );
|
|
|
|
const bool convert = m_textureFormat != m_requestedFormat;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2017-04-04 08:42:27 +03:00
|
|
|
uint8_t bpp = bimg::getBitsPerPixel(bimg::TextureFormat::Enum(m_textureFormat) );
|
2013-01-21 00:47:29 +04:00
|
|
|
|
2013-09-03 03:22:53 +04:00
|
|
|
if (imageContainer.m_cubeMap)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2014-02-20 10:34:53 +04:00
|
|
|
createCubeTexture(textureWidth, numMips);
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
2013-09-03 03:22:53 +04:00
|
|
|
else if (imageContainer.m_depth > 1)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2014-02-20 10:34:53 +04:00
|
|
|
createVolumeTexture(textureWidth, textureHeight, imageContainer.m_depth, numMips);
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-20 10:34:53 +04:00
|
|
|
createTexture(textureWidth, textureHeight, numMips);
|
2014-02-06 11:07:11 +04:00
|
|
|
}
|
|
|
|
|
2014-04-20 02:02:43 +04:00
|
|
|
BX_TRACE("Texture %3d: %s (requested: %s), %dx%d%s%s."
|
2014-05-27 01:09:26 +04:00
|
|
|
, this - s_renderD3D9->m_textures
|
2014-04-20 02:02:43 +04:00
|
|
|
, getName( (TextureFormat::Enum)m_textureFormat)
|
|
|
|
, getName( (TextureFormat::Enum)m_requestedFormat)
|
|
|
|
, textureWidth
|
|
|
|
, textureHeight
|
|
|
|
, imageContainer.m_cubeMap ? "x6" : ""
|
|
|
|
, 0 != (m_flags&BGFX_TEXTURE_RT_MASK) ? " (render target)" : ""
|
|
|
|
);
|
|
|
|
|
2016-01-13 04:11:16 +03:00
|
|
|
if (0 != (_flags&BGFX_TEXTURE_RT_WRITE_ONLY) )
|
2014-02-06 11:07:11 +04:00
|
|
|
{
|
|
|
|
return;
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
|
2013-09-09 08:03:03 +04:00
|
|
|
// For BC4 and B5 in DX9 LockRect returns wrong number of
|
|
|
|
// bytes. If actual mip size is used it causes memory corruption.
|
|
|
|
// http://www.aras-p.info/texts/D3D9GPUHacks.html#3dc
|
|
|
|
const bool useMipSize = true
|
2017-04-04 08:42:27 +03:00
|
|
|
&& imageContainer.m_format != bimg::TextureFormat::BC4
|
|
|
|
&& imageContainer.m_format != bimg::TextureFormat::BC5
|
2013-09-09 08:03:03 +04:00
|
|
|
;
|
|
|
|
|
|
|
|
for (uint8_t side = 0, numSides = imageContainer.m_cubeMap ? 6 : 1; side < numSides; ++side)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2014-02-20 10:34:53 +04:00
|
|
|
uint32_t width = textureWidth;
|
|
|
|
uint32_t height = textureHeight;
|
2013-09-09 08:03:03 +04:00
|
|
|
uint32_t depth = imageContainer.m_depth;
|
|
|
|
uint32_t mipWidth = imageContainer.m_width;
|
|
|
|
uint32_t mipHeight = imageContainer.m_height;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2015-04-08 03:58:14 +03:00
|
|
|
for (uint8_t lod = 0, num = numMips; lod < num; ++lod)
|
2013-09-09 08:03:03 +04:00
|
|
|
{
|
|
|
|
width = bx::uint32_max(1, width);
|
|
|
|
height = bx::uint32_max(1, height);
|
|
|
|
depth = bx::uint32_max(1, depth);
|
2014-03-02 08:08:50 +04:00
|
|
|
mipWidth = bx::uint32_max(blockInfo.blockWidth, mipWidth);
|
|
|
|
mipHeight = bx::uint32_max(blockInfo.blockHeight, mipHeight);
|
2013-09-09 08:03:03 +04:00
|
|
|
uint32_t mipSize = width*height*depth*bpp/8;
|
|
|
|
|
2017-04-04 08:42:27 +03:00
|
|
|
bimg::ImageMip mip;
|
|
|
|
if (bimg::imageGetRawData(imageContainer, side, lod+startLod, _mem->data, _mem->size, mip) )
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2013-09-09 08:03:03 +04:00
|
|
|
uint32_t pitch;
|
|
|
|
uint32_t slicePitch;
|
|
|
|
uint8_t* bits = lock(side, lod, pitch, slicePitch);
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2013-09-09 08:03:03 +04:00
|
|
|
if (convert)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2013-09-09 08:03:03 +04:00
|
|
|
if (width != mipWidth
|
|
|
|
|| height != mipHeight)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2013-09-09 08:03:03 +04:00
|
|
|
uint32_t srcpitch = mipWidth*bpp/8;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2013-09-17 08:40:30 +04:00
|
|
|
uint8_t* temp = (uint8_t*)BX_ALLOC(g_allocator, srcpitch*mipHeight);
|
2018-05-25 04:03:31 +03:00
|
|
|
bimg::imageDecodeToBgra8(
|
|
|
|
g_allocator
|
|
|
|
, temp
|
|
|
|
, mip.m_data
|
|
|
|
, mip.m_width
|
|
|
|
, mip.m_height
|
|
|
|
, srcpitch
|
|
|
|
, mip.m_format
|
|
|
|
);
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2016-02-07 01:31:14 +03:00
|
|
|
bx::memCopy(bits, temp, pitch, height, srcpitch, pitch);
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2013-09-17 08:40:30 +04:00
|
|
|
BX_FREE(g_allocator, temp);
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-05-25 04:03:31 +03:00
|
|
|
bimg::imageDecodeToBgra8(g_allocator, bits, mip.m_data, mip.m_width, mip.m_height, pitch, mip.m_format);
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
}
|
2013-09-09 08:03:03 +04:00
|
|
|
else
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2013-09-09 08:03:03 +04:00
|
|
|
uint32_t size = useMipSize ? mip.m_size : mipSize;
|
2016-02-24 05:50:33 +03:00
|
|
|
switch (m_textureFormat)
|
|
|
|
{
|
|
|
|
case TextureFormat::RGB5A1:
|
2017-04-04 08:42:27 +03:00
|
|
|
bimg::imageConvert(bits, 16, bx::packBgr5a1, mip.m_data, bx::unpackRgb5a1, size);
|
2016-02-24 05:50:33 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TextureFormat::RGBA4:
|
2017-04-04 08:42:27 +03:00
|
|
|
bimg::imageConvert(bits, 16, bx::packBgra4, mip.m_data, bx::unpackRgba4, size);
|
2016-02-24 05:50:33 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2017-02-09 06:55:31 +03:00
|
|
|
bx::memCopy(bits, mip.m_data, size);
|
2016-02-24 05:50:33 +03:00
|
|
|
break;
|
|
|
|
}
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
2013-02-15 09:42:44 +04:00
|
|
|
|
2013-09-09 08:03:03 +04:00
|
|
|
unlock(side, lod);
|
2012-08-13 08:02:11 +04:00
|
|
|
}
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2013-09-09 08:03:03 +04:00
|
|
|
width >>= 1;
|
|
|
|
height >>= 1;
|
|
|
|
depth >>= 1;
|
|
|
|
mipWidth >>= 1;
|
|
|
|
mipHeight >>= 1;
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
void TextureD3D9::updateBegin(uint8_t _side, uint8_t _mip)
|
2012-08-13 08:02:11 +04:00
|
|
|
{
|
|
|
|
uint32_t slicePitch;
|
2014-05-27 01:09:26 +04:00
|
|
|
s_renderD3D9->m_updateTextureSide = _side;
|
2015-09-17 03:21:28 +03:00
|
|
|
s_renderD3D9->m_updateTextureMip = _mip;
|
2014-05-27 01:09:26 +04:00
|
|
|
s_renderD3D9->m_updateTextureBits = lock(_side, _mip, s_renderD3D9->m_updateTexturePitch, slicePitch);
|
2013-03-03 09:35:09 +04:00
|
|
|
}
|
2012-08-13 08:02:11 +04:00
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
void TextureD3D9::update(uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem)
|
2013-03-03 09:35:09 +04:00
|
|
|
{
|
2017-04-04 08:42:27 +03:00
|
|
|
const uint32_t bpp = bimg::getBitsPerPixel(bimg::TextureFormat::Enum(m_textureFormat) );
|
2013-11-08 10:59:17 +04:00
|
|
|
const uint32_t rectpitch = _rect.m_width*bpp/8;
|
|
|
|
const uint32_t srcpitch = UINT16_MAX == _pitch ? rectpitch : _pitch;
|
2014-05-27 01:09:26 +04:00
|
|
|
const uint32_t dstpitch = s_renderD3D9->m_updateTexturePitch;
|
|
|
|
uint8_t* bits = s_renderD3D9->m_updateTextureBits + _rect.m_y*dstpitch + _rect.m_x*bpp/8;
|
2013-03-03 09:35:09 +04:00
|
|
|
|
2013-09-09 08:03:03 +04:00
|
|
|
const bool convert = m_textureFormat != m_requestedFormat;
|
2015-01-11 07:38:47 +03:00
|
|
|
|
2013-09-09 08:03:03 +04:00
|
|
|
uint8_t* data = _mem->data;
|
|
|
|
uint8_t* temp = NULL;
|
|
|
|
|
|
|
|
if (convert)
|
|
|
|
{
|
2015-03-30 08:40:35 +03:00
|
|
|
temp = (uint8_t*)BX_ALLOC(g_allocator, rectpitch*_rect.m_height);
|
2018-05-25 04:03:31 +03:00
|
|
|
bimg::imageDecodeToBgra8(g_allocator, temp, data, _rect.m_width, _rect.m_height, srcpitch, bimg::TextureFormat::Enum(m_requestedFormat) );
|
2013-09-09 08:03:03 +04:00
|
|
|
data = temp;
|
|
|
|
}
|
|
|
|
|
2013-03-03 09:35:09 +04:00
|
|
|
{
|
2013-12-08 10:01:55 +04:00
|
|
|
uint8_t* src = data;
|
|
|
|
uint8_t* dst = bits;
|
2013-03-03 09:35:09 +04:00
|
|
|
for (uint32_t yy = 0, height = _rect.m_height; yy < height; ++yy)
|
|
|
|
{
|
2016-02-24 05:50:33 +03:00
|
|
|
switch (m_textureFormat)
|
|
|
|
{
|
|
|
|
case TextureFormat::RGB5A1:
|
2017-04-04 08:42:27 +03:00
|
|
|
bimg::imageConvert(dst, 16, bx::packBgr5a1, src, bx::unpackRgb5a1, rectpitch);
|
2016-02-24 05:50:33 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TextureFormat::RGBA4:
|
2017-04-04 08:42:27 +03:00
|
|
|
bimg::imageConvert(dst, 16, bx::packBgra4, src, bx::unpackRgba4, rectpitch);
|
2016-02-24 05:50:33 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2017-02-09 06:55:31 +03:00
|
|
|
bx::memCopy(dst, src, rectpitch);
|
2016-02-24 05:50:33 +03:00
|
|
|
break;
|
|
|
|
}
|
2013-12-08 10:01:55 +04:00
|
|
|
src += srcpitch;
|
|
|
|
dst += dstpitch;
|
2013-03-03 09:35:09 +04:00
|
|
|
}
|
2012-08-13 08:02:11 +04:00
|
|
|
}
|
|
|
|
|
2013-09-09 08:03:03 +04:00
|
|
|
if (NULL != temp)
|
|
|
|
{
|
2013-09-17 08:40:30 +04:00
|
|
|
BX_FREE(g_allocator, temp);
|
2013-09-09 08:03:03 +04:00
|
|
|
}
|
|
|
|
|
2013-03-03 11:20:28 +04:00
|
|
|
if (0 == _mip)
|
|
|
|
{
|
|
|
|
dirty(_side, _rect, _z, _depth);
|
|
|
|
}
|
2013-03-03 09:35:09 +04:00
|
|
|
}
|
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
void TextureD3D9::updateEnd()
|
2013-03-03 09:35:09 +04:00
|
|
|
{
|
2014-05-27 01:09:26 +04:00
|
|
|
unlock(s_renderD3D9->m_updateTextureSide, s_renderD3D9->m_updateTextureMip);
|
2012-08-13 08:02:11 +04:00
|
|
|
}
|
|
|
|
|
2015-09-17 03:21:28 +03:00
|
|
|
void TextureD3D9::commit(uint8_t _stage, uint32_t _flags, const float _palette[][4])
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2015-11-02 04:28:23 +03:00
|
|
|
uint32_t flags = 0 == (BGFX_TEXTURE_INTERNAL_DEFAULT_SAMPLER & _flags)
|
2015-09-17 03:21:28 +03:00
|
|
|
? _flags
|
|
|
|
: m_flags
|
|
|
|
;
|
|
|
|
uint32_t index = (flags & BGFX_TEXTURE_BORDER_COLOR_MASK) >> BGFX_TEXTURE_BORDER_COLOR_SHIFT;
|
|
|
|
s_renderD3D9->setSamplerState(_stage, flags, _palette[index]);
|
|
|
|
|
2015-08-11 03:45:18 +03:00
|
|
|
IDirect3DDevice9* device = s_renderD3D9->m_device;
|
2015-09-10 23:29:12 +03:00
|
|
|
DX_CHECK(device->SetTexture(_stage, m_ptr) );
|
|
|
|
if (4 > _stage)
|
|
|
|
{
|
|
|
|
DX_CHECK(device->SetTexture(D3DVERTEXTEXTURESAMPLER0 + _stage, m_ptr) );
|
|
|
|
}
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
void TextureD3D9::resolve() const
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2014-02-06 11:07:11 +04:00
|
|
|
if (NULL != m_surface
|
2016-07-23 03:42:55 +03:00
|
|
|
&& NULL != m_ptr)
|
2014-02-06 11:07:11 +04:00
|
|
|
{
|
2015-10-20 01:09:56 +03:00
|
|
|
IDirect3DSurface9* surface = getSurface();
|
2014-05-27 01:09:26 +04:00
|
|
|
DX_CHECK(s_renderD3D9->m_device->StretchRect(m_surface
|
2014-02-06 11:07:11 +04:00
|
|
|
, NULL
|
|
|
|
, surface
|
|
|
|
, NULL
|
|
|
|
, D3DTEXF_LINEAR
|
|
|
|
) );
|
|
|
|
DX_RELEASE(surface, 1);
|
2016-07-23 03:42:55 +03:00
|
|
|
|
|
|
|
if (1 < m_numMips)
|
|
|
|
{
|
|
|
|
m_ptr->GenerateMipSubLevels();
|
|
|
|
}
|
2014-02-06 11:07:11 +04:00
|
|
|
}
|
|
|
|
}
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
void TextureD3D9::preReset()
|
2014-02-06 11:07:11 +04:00
|
|
|
{
|
|
|
|
TextureFormat::Enum fmt = (TextureFormat::Enum)m_textureFormat;
|
2015-10-23 07:30:55 +03:00
|
|
|
if (TextureFormat::Unknown != fmt)
|
2014-02-06 11:07:11 +04:00
|
|
|
{
|
|
|
|
DX_RELEASE(m_ptr, 0);
|
|
|
|
DX_RELEASE(m_surface, 0);
|
|
|
|
}
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
void TextureD3D9::postReset()
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2014-02-06 11:07:11 +04:00
|
|
|
TextureFormat::Enum fmt = (TextureFormat::Enum)m_textureFormat;
|
2015-10-23 07:30:55 +03:00
|
|
|
if (TextureFormat::Unknown != fmt)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2015-10-23 07:30:55 +03:00
|
|
|
switch (m_type)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case Texture2D:
|
|
|
|
createTexture(m_width, m_height, m_numMips);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Texture3D:
|
|
|
|
createVolumeTexture(m_width, m_height, m_depth, m_numMips);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TextureCube:
|
|
|
|
createCubeTexture(m_width, m_numMips);
|
|
|
|
break;
|
|
|
|
}
|
2014-02-06 11:07:11 +04:00
|
|
|
}
|
|
|
|
}
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2016-02-16 03:55:32 +03:00
|
|
|
void FrameBufferD3D9::create(uint8_t _num, const Attachment* _attachment)
|
2014-02-06 11:07:11 +04:00
|
|
|
{
|
2016-02-19 03:52:58 +03:00
|
|
|
for (uint32_t ii = 0; ii < BX_COUNTOF(m_surface); ++ii)
|
2014-02-06 11:07:11 +04:00
|
|
|
{
|
2016-02-19 03:52:58 +03:00
|
|
|
m_surface[ii] = NULL;
|
2014-02-06 11:07:11 +04:00
|
|
|
}
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2017-01-27 02:34:11 +03:00
|
|
|
m_denseIdx = UINT16_MAX;
|
2016-02-19 03:52:58 +03:00
|
|
|
m_dsIdx = UINT8_MAX;
|
|
|
|
m_num = 0;
|
|
|
|
m_numTh = _num;
|
2014-02-06 11:07:11 +04:00
|
|
|
m_needResolve = false;
|
2017-02-09 06:55:31 +03:00
|
|
|
bx::memCopy(m_attachment, _attachment, _num*sizeof(Attachment) );
|
2016-02-19 00:11:52 +03:00
|
|
|
|
2014-02-06 11:07:11 +04:00
|
|
|
for (uint32_t ii = 0; ii < _num; ++ii)
|
|
|
|
{
|
2016-02-19 00:11:52 +03:00
|
|
|
TextureHandle handle = m_attachment[ii].handle;
|
2014-02-06 11:07:11 +04:00
|
|
|
if (isValid(handle) )
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2014-05-27 01:09:26 +04:00
|
|
|
const TextureD3D9& texture = s_renderD3D9->m_textures[handle.idx];
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2016-02-19 03:52:58 +03:00
|
|
|
if (NULL != texture.m_surface)
|
|
|
|
{
|
|
|
|
m_surface[ii] = texture.m_surface;
|
|
|
|
m_surface[ii]->AddRef();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_surface[ii] = texture.getSurface(uint8_t(m_attachment[ii].layer), uint8_t(m_attachment[ii].mip) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 == m_num)
|
|
|
|
{
|
|
|
|
m_width = texture.m_width;
|
|
|
|
m_height = texture.m_height;
|
|
|
|
}
|
|
|
|
|
2017-04-04 08:42:27 +03:00
|
|
|
if (bimg::isDepth(bimg::TextureFormat::Enum(texture.m_textureFormat) ) )
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2016-02-19 03:52:58 +03:00
|
|
|
m_dsIdx = uint8_t(ii);
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
2014-02-06 11:07:11 +04:00
|
|
|
else
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2016-02-19 03:52:58 +03:00
|
|
|
++m_num;
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
|
2016-02-19 00:11:52 +03:00
|
|
|
m_needResolve |= true
|
|
|
|
&& (NULL != texture.m_surface)
|
|
|
|
&& (NULL != texture.m_texture2d)
|
|
|
|
;
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
}
|
2014-02-22 20:48:30 +04:00
|
|
|
|
|
|
|
if (0 == m_num)
|
|
|
|
{
|
|
|
|
createNullColorRT();
|
|
|
|
}
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
|
2014-09-08 04:17:38 +04:00
|
|
|
void FrameBufferD3D9::create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2014-09-23 06:34:10 +04:00
|
|
|
BX_UNUSED(_depthFormat);
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2014-09-08 04:17:38 +04:00
|
|
|
m_hwnd = (HWND)_nwh;
|
2014-09-23 06:34:10 +04:00
|
|
|
|
2015-08-07 01:37:13 +03:00
|
|
|
m_width = bx::uint32_max(_width, 16);
|
|
|
|
m_height = bx::uint32_max(_height, 16);
|
|
|
|
|
2014-09-23 06:34:10 +04:00
|
|
|
D3DPRESENT_PARAMETERS params;
|
2017-02-09 06:55:31 +03:00
|
|
|
bx::memCopy(¶ms, &s_renderD3D9->m_params, sizeof(D3DPRESENT_PARAMETERS) );
|
2015-08-07 01:37:13 +03:00
|
|
|
params.BackBufferWidth = m_width;
|
|
|
|
params.BackBufferHeight = m_height;
|
2014-09-23 06:34:10 +04:00
|
|
|
|
|
|
|
DX_CHECK(s_renderD3D9->m_device->CreateAdditionalSwapChain(¶ms, &m_swapChain) );
|
2016-02-19 03:52:58 +03:00
|
|
|
DX_CHECK(m_swapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &m_surface[0]) );
|
2014-09-23 10:00:42 +04:00
|
|
|
|
|
|
|
DX_CHECK(s_renderD3D9->m_device->CreateDepthStencilSurface(
|
|
|
|
params.BackBufferWidth
|
|
|
|
, params.BackBufferHeight
|
|
|
|
, params.AutoDepthStencilFormat
|
|
|
|
, params.MultiSampleType
|
|
|
|
, params.MultiSampleQuality
|
|
|
|
, FALSE
|
2016-02-19 03:52:58 +03:00
|
|
|
, &m_surface[1]
|
2014-09-23 10:00:42 +04:00
|
|
|
, NULL
|
|
|
|
) );
|
|
|
|
|
2016-02-19 03:52:58 +03:00
|
|
|
m_dsIdx = 1;
|
2014-09-08 04:17:38 +04:00
|
|
|
m_denseIdx = _denseIdx;
|
|
|
|
m_num = 1;
|
|
|
|
m_needResolve = false;
|
2016-11-10 01:29:37 +03:00
|
|
|
m_needPresent = false;
|
2014-09-08 04:17:38 +04:00
|
|
|
}
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2014-09-08 04:17:38 +04:00
|
|
|
uint16_t FrameBufferD3D9::destroy()
|
|
|
|
{
|
|
|
|
if (NULL != m_hwnd)
|
2014-02-06 11:07:11 +04:00
|
|
|
{
|
2016-02-19 03:52:58 +03:00
|
|
|
DX_RELEASE(m_surface[0], 0);
|
|
|
|
DX_RELEASE(m_surface[1], 0);
|
|
|
|
DX_RELEASE(m_swapChain, 0);
|
2014-09-08 04:17:38 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-02-19 03:52:58 +03:00
|
|
|
uint32_t num = m_numTh;
|
|
|
|
num += uint32_t(0 < m_numTh && 0 == m_num);
|
2014-09-08 04:17:38 +04:00
|
|
|
|
2016-02-19 03:52:58 +03:00
|
|
|
for (uint32_t ii = 0; ii < num; ++ii)
|
|
|
|
{
|
|
|
|
IDirect3DSurface9* ptr = m_surface[ii];
|
2014-02-22 20:48:30 +04:00
|
|
|
if (NULL != ptr)
|
|
|
|
{
|
|
|
|
ptr->Release();
|
2016-02-19 03:52:58 +03:00
|
|
|
m_surface[ii] = NULL;
|
2014-02-22 20:48:30 +04:00
|
|
|
}
|
|
|
|
}
|
2014-02-06 11:07:11 +04:00
|
|
|
}
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2016-02-19 03:52:58 +03:00
|
|
|
m_hwnd = NULL;
|
|
|
|
m_num = 0;
|
|
|
|
m_numTh = 0;
|
2016-11-10 01:29:37 +03:00
|
|
|
m_needPresent = false;
|
2014-09-08 04:17:38 +04:00
|
|
|
|
|
|
|
uint16_t denseIdx = m_denseIdx;
|
|
|
|
m_denseIdx = UINT16_MAX;
|
|
|
|
|
|
|
|
return denseIdx;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT FrameBufferD3D9::present()
|
|
|
|
{
|
2016-11-10 01:29:37 +03:00
|
|
|
if (m_needPresent)
|
|
|
|
{
|
|
|
|
HRESULT hr = m_swapChain->Present(NULL, NULL, m_hwnd, NULL, 0);
|
|
|
|
m_needPresent = false;
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2014-02-06 11:07:11 +04:00
|
|
|
}
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
void FrameBufferD3D9::resolve() const
|
2014-02-06 11:07:11 +04:00
|
|
|
{
|
|
|
|
if (m_needResolve)
|
|
|
|
{
|
2016-02-19 03:52:58 +03:00
|
|
|
for (uint32_t ii = 0, num = m_numTh; ii < num; ++ii)
|
2014-02-06 11:07:11 +04:00
|
|
|
{
|
2016-02-19 03:52:58 +03:00
|
|
|
const TextureD3D9& texture = s_renderD3D9->m_textures[m_attachment[ii].handle.idx];
|
2014-02-06 11:07:11 +04:00
|
|
|
texture.resolve();
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
void FrameBufferD3D9::preReset()
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2014-09-08 04:17:38 +04:00
|
|
|
if (NULL != m_hwnd)
|
2014-02-06 11:07:11 +04:00
|
|
|
{
|
2016-02-19 03:52:58 +03:00
|
|
|
DX_RELEASE(m_surface[0], 0);
|
|
|
|
DX_RELEASE(m_surface[1], 0);
|
2015-08-07 01:37:13 +03:00
|
|
|
DX_RELEASE(m_swapChain, 0);
|
2014-02-06 11:07:11 +04:00
|
|
|
}
|
2014-09-08 04:17:38 +04:00
|
|
|
else
|
2014-02-06 11:07:11 +04:00
|
|
|
{
|
2016-02-19 03:52:58 +03:00
|
|
|
uint32_t num = m_numTh;
|
|
|
|
num += uint32_t(0 < m_numTh && 0 == m_num);
|
2014-02-22 20:48:30 +04:00
|
|
|
|
2016-02-19 03:52:58 +03:00
|
|
|
for (uint32_t ii = 0; ii < num; ++ii)
|
2014-09-08 04:17:38 +04:00
|
|
|
{
|
2016-02-19 03:52:58 +03:00
|
|
|
m_surface[ii]->Release();
|
|
|
|
m_surface[ii] = NULL;
|
2014-09-08 04:17:38 +04:00
|
|
|
}
|
2014-02-06 11:07:11 +04:00
|
|
|
}
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
void FrameBufferD3D9::postReset()
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2014-09-08 04:17:38 +04:00
|
|
|
if (NULL != m_hwnd)
|
2014-02-06 11:07:11 +04:00
|
|
|
{
|
2015-08-07 01:37:13 +03:00
|
|
|
D3DPRESENT_PARAMETERS params;
|
2017-02-09 06:55:31 +03:00
|
|
|
bx::memCopy(¶ms, &s_renderD3D9->m_params, sizeof(D3DPRESENT_PARAMETERS) );
|
2015-08-07 01:37:13 +03:00
|
|
|
params.BackBufferWidth = m_width;
|
|
|
|
params.BackBufferHeight = m_height;
|
|
|
|
|
|
|
|
DX_CHECK(s_renderD3D9->m_device->CreateAdditionalSwapChain(¶ms, &m_swapChain) );
|
2016-02-19 03:52:58 +03:00
|
|
|
DX_CHECK(m_swapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &m_surface[0]) );
|
2015-08-07 01:37:13 +03:00
|
|
|
DX_CHECK(s_renderD3D9->m_device->CreateDepthStencilSurface(params.BackBufferWidth
|
|
|
|
, params.BackBufferHeight
|
|
|
|
, params.AutoDepthStencilFormat
|
|
|
|
, params.MultiSampleType
|
|
|
|
, params.MultiSampleQuality
|
|
|
|
, FALSE
|
2016-02-19 03:52:58 +03:00
|
|
|
, &m_surface[1]
|
2015-08-07 01:37:13 +03:00
|
|
|
, NULL
|
|
|
|
) );
|
2014-02-06 11:07:11 +04:00
|
|
|
}
|
2016-02-19 03:52:58 +03:00
|
|
|
else if (0 < m_numTh)
|
2014-02-06 11:07:11 +04:00
|
|
|
{
|
2016-02-19 03:52:58 +03:00
|
|
|
for (uint32_t ii = 0, num = m_numTh; ii < num; ++ii)
|
2014-02-06 11:07:11 +04:00
|
|
|
{
|
2016-02-19 03:52:58 +03:00
|
|
|
TextureHandle th = m_attachment[ii].handle;
|
2014-09-08 04:17:38 +04:00
|
|
|
|
|
|
|
if (isValid(th) )
|
|
|
|
{
|
|
|
|
TextureD3D9& texture = s_renderD3D9->m_textures[th.idx];
|
|
|
|
if (NULL != texture.m_surface)
|
|
|
|
{
|
2016-02-19 03:52:58 +03:00
|
|
|
m_surface[ii] = texture.m_surface;
|
|
|
|
m_surface[ii]->AddRef();
|
2014-09-08 04:17:38 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-02-19 03:52:58 +03:00
|
|
|
m_surface[ii] = texture.getSurface(uint8_t(m_attachment[ii].layer), uint8_t(m_attachment[ii].mip) );
|
2014-09-08 04:17:38 +04:00
|
|
|
}
|
|
|
|
}
|
2014-02-06 11:07:11 +04:00
|
|
|
}
|
2014-02-22 20:48:30 +04:00
|
|
|
|
2016-02-19 03:52:58 +03:00
|
|
|
if (0 == m_num)
|
2014-02-22 20:48:30 +04:00
|
|
|
{
|
2016-02-19 03:52:58 +03:00
|
|
|
createNullColorRT();
|
2014-02-22 20:48:30 +04:00
|
|
|
}
|
2014-02-06 11:07:11 +04:00
|
|
|
}
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
void FrameBufferD3D9::createNullColorRT()
|
2014-02-22 20:48:30 +04:00
|
|
|
{
|
2016-02-19 03:52:58 +03:00
|
|
|
DX_CHECK(s_renderD3D9->m_device->CreateRenderTarget(
|
|
|
|
m_width
|
|
|
|
, m_height
|
2014-02-22 20:48:30 +04:00
|
|
|
, D3DFMT_NULL
|
|
|
|
, D3DMULTISAMPLE_NONE
|
|
|
|
, 0
|
|
|
|
, false
|
2016-02-19 03:52:58 +03:00
|
|
|
, &m_surface[1]
|
2014-02-22 20:48:30 +04:00
|
|
|
, NULL
|
|
|
|
) );
|
|
|
|
}
|
|
|
|
|
2016-11-10 01:29:37 +03:00
|
|
|
void FrameBufferD3D9::set()
|
|
|
|
{
|
|
|
|
m_needPresent = UINT16_MAX != m_denseIdx;
|
|
|
|
|
|
|
|
// If frame buffer has only depth attachment D3DFMT_NULL
|
|
|
|
// render target is created.
|
|
|
|
const uint32_t fbnum = bx::uint32_max(2, m_numTh);
|
|
|
|
const uint8_t dsIdx = m_dsIdx;
|
|
|
|
|
|
|
|
IDirect3DDevice9* device = s_renderD3D9->m_device;
|
|
|
|
|
|
|
|
DX_CHECK(device->SetDepthStencilSurface(UINT8_MAX == dsIdx
|
|
|
|
? s_renderD3D9->m_backBufferDepthStencil
|
|
|
|
: m_surface[dsIdx]
|
|
|
|
) );
|
|
|
|
|
|
|
|
uint32_t rtIdx = 0;
|
|
|
|
for (uint32_t ii = 0; ii < fbnum; ++ii)
|
|
|
|
{
|
|
|
|
IDirect3DSurface9* surface = m_surface[ii];
|
|
|
|
if (ii != dsIdx)
|
|
|
|
{
|
|
|
|
DX_CHECK(device->SetRenderTarget(rtIdx, surface) );
|
|
|
|
++rtIdx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t ii = rtIdx, num = g_caps.limits.maxFBAttachments; ii < num; ++ii)
|
|
|
|
{
|
|
|
|
DX_CHECK(device->SetRenderTarget(ii, NULL) );
|
|
|
|
}
|
|
|
|
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_SRGBWRITEENABLE, FALSE) );
|
|
|
|
}
|
|
|
|
|
2015-05-14 21:37:32 +03:00
|
|
|
void TimerQueryD3D9::postReset()
|
2015-05-13 03:03:25 +03:00
|
|
|
{
|
|
|
|
IDirect3DDevice9* device = s_renderD3D9->m_device;
|
|
|
|
|
2017-08-28 06:34:00 +03:00
|
|
|
for (uint32_t ii = 0; ii < BX_COUNTOF(m_query); ++ii)
|
2015-05-13 03:03:25 +03:00
|
|
|
{
|
2017-08-28 06:34:00 +03:00
|
|
|
Query& frame = m_query[ii];
|
2015-05-13 03:03:25 +03:00
|
|
|
DX_CHECK(device->CreateQuery(D3DQUERYTYPE_TIMESTAMPDISJOINT, &frame.m_disjoint) );
|
2015-11-10 04:56:12 +03:00
|
|
|
DX_CHECK(device->CreateQuery(D3DQUERYTYPE_TIMESTAMP, &frame.m_begin) );
|
2015-05-13 03:03:25 +03:00
|
|
|
DX_CHECK(device->CreateQuery(D3DQUERYTYPE_TIMESTAMP, &frame.m_end) );
|
|
|
|
DX_CHECK(device->CreateQuery(D3DQUERYTYPE_TIMESTAMPFREQ, &frame.m_freq) );
|
|
|
|
}
|
|
|
|
|
2017-08-28 06:34:00 +03:00
|
|
|
for (uint32_t ii = 0; ii < BX_COUNTOF(m_result); ++ii)
|
|
|
|
{
|
|
|
|
Result& result = m_result[ii];
|
|
|
|
result.reset();
|
|
|
|
}
|
|
|
|
|
2015-05-14 21:37:32 +03:00
|
|
|
m_control.reset();
|
2015-05-13 03:03:25 +03:00
|
|
|
}
|
|
|
|
|
2015-05-14 21:37:32 +03:00
|
|
|
void TimerQueryD3D9::preReset()
|
2015-05-13 03:03:25 +03:00
|
|
|
{
|
2017-08-28 06:34:00 +03:00
|
|
|
for (uint32_t ii = 0; ii < BX_COUNTOF(m_query); ++ii)
|
2015-05-13 03:03:25 +03:00
|
|
|
{
|
2017-08-28 06:34:00 +03:00
|
|
|
Query& frame = m_query[ii];
|
2015-05-13 03:03:25 +03:00
|
|
|
DX_RELEASE(frame.m_disjoint, 0);
|
2015-11-10 04:56:12 +03:00
|
|
|
DX_RELEASE(frame.m_begin, 0);
|
2015-05-13 03:03:25 +03:00
|
|
|
DX_RELEASE(frame.m_end, 0);
|
|
|
|
DX_RELEASE(frame.m_freq, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-28 06:34:00 +03:00
|
|
|
uint32_t TimerQueryD3D9::begin(uint32_t _resultIdx)
|
2015-05-13 03:03:25 +03:00
|
|
|
{
|
|
|
|
while (0 == m_control.reserve(1) )
|
|
|
|
{
|
2017-08-28 06:34:00 +03:00
|
|
|
update();
|
2015-05-13 03:03:25 +03:00
|
|
|
}
|
|
|
|
|
2017-08-28 06:34:00 +03:00
|
|
|
Result& result = m_result[_resultIdx];
|
|
|
|
++result.m_pending;
|
|
|
|
|
|
|
|
const uint32_t idx = m_control.m_current;
|
|
|
|
Query& query = m_query[idx];
|
|
|
|
query.m_resultIdx = _resultIdx;
|
|
|
|
query.m_ready = false;
|
|
|
|
|
|
|
|
query.m_disjoint->Issue(D3DISSUE_BEGIN);
|
|
|
|
query.m_begin->Issue(D3DISSUE_END);
|
|
|
|
|
|
|
|
m_control.commit(1);
|
|
|
|
|
|
|
|
return idx;
|
2015-05-13 03:03:25 +03:00
|
|
|
}
|
|
|
|
|
2017-08-28 06:34:00 +03:00
|
|
|
void TimerQueryD3D9::end(uint32_t _idx)
|
2015-05-13 03:03:25 +03:00
|
|
|
{
|
2017-08-28 06:34:00 +03:00
|
|
|
Query& query = m_query[_idx];
|
|
|
|
query.m_ready = true;
|
|
|
|
|
|
|
|
query.m_disjoint->Issue(D3DISSUE_END);
|
|
|
|
query.m_freq->Issue(D3DISSUE_END);
|
|
|
|
query.m_end->Issue(D3DISSUE_END);
|
|
|
|
|
|
|
|
while (update() )
|
|
|
|
{
|
|
|
|
}
|
2015-05-13 03:03:25 +03:00
|
|
|
}
|
|
|
|
|
2017-08-28 06:34:00 +03:00
|
|
|
bool TimerQueryD3D9::update()
|
2015-05-13 03:03:25 +03:00
|
|
|
{
|
2015-05-16 02:49:53 +03:00
|
|
|
if (0 != m_control.available() )
|
2015-05-13 03:03:25 +03:00
|
|
|
{
|
2017-08-28 06:34:00 +03:00
|
|
|
Query& query = m_query[m_control.m_read];
|
|
|
|
|
|
|
|
if (!query.m_ready)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2015-05-16 02:49:53 +03:00
|
|
|
|
2015-10-29 06:04:59 +03:00
|
|
|
uint64_t timeEnd;
|
2017-08-28 06:34:00 +03:00
|
|
|
const bool flush = BX_COUNTOF(m_query)-1 == m_control.available();
|
|
|
|
HRESULT hr = query.m_end->GetData(&timeEnd, sizeof(timeEnd), flush ? D3DGETDATA_FLUSH : 0);
|
2016-11-16 03:57:28 +03:00
|
|
|
if (S_OK == hr
|
|
|
|
|| isLost(hr) )
|
2015-05-16 02:49:53 +03:00
|
|
|
{
|
|
|
|
m_control.consume(1);
|
2015-05-13 03:03:25 +03:00
|
|
|
|
2015-11-10 04:56:12 +03:00
|
|
|
uint64_t timeBegin;
|
2017-08-28 06:34:00 +03:00
|
|
|
DX_CHECK(query.m_begin->GetData(&timeBegin, sizeof(timeBegin), 0) );
|
2015-05-13 03:03:25 +03:00
|
|
|
|
2015-10-29 06:04:59 +03:00
|
|
|
uint64_t freq;
|
2017-08-28 06:34:00 +03:00
|
|
|
DX_CHECK(query.m_freq->GetData(&freq, sizeof(freq), 0) );
|
2015-05-13 03:03:25 +03:00
|
|
|
|
2017-08-28 06:34:00 +03:00
|
|
|
Result& result = m_result[query.m_resultIdx];
|
|
|
|
--result.m_pending;
|
|
|
|
|
|
|
|
result.m_frequency = freq;
|
|
|
|
result.m_begin = timeBegin;
|
|
|
|
result.m_end = timeEnd;
|
2015-05-13 03:03:25 +03:00
|
|
|
|
2015-05-16 02:49:53 +03:00
|
|
|
return true;
|
|
|
|
}
|
2015-05-13 03:03:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-11-02 04:28:23 +03:00
|
|
|
void OcclusionQueryD3D9::postReset()
|
|
|
|
{
|
|
|
|
IDirect3DDevice9* device = s_renderD3D9->m_device;
|
|
|
|
|
|
|
|
for (uint32_t ii = 0; ii < BX_COUNTOF(m_query); ++ii)
|
|
|
|
{
|
|
|
|
Query& query = m_query[ii];
|
|
|
|
DX_CHECK(device->CreateQuery(D3DQUERYTYPE_OCCLUSION, &query.m_ptr) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OcclusionQueryD3D9::preReset()
|
|
|
|
{
|
|
|
|
for (uint32_t ii = 0; ii < BX_COUNTOF(m_query); ++ii)
|
|
|
|
{
|
|
|
|
Query& query = m_query[ii];
|
|
|
|
DX_RELEASE(query.m_ptr, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-04 03:00:14 +03:00
|
|
|
void OcclusionQueryD3D9::begin(Frame* _render, OcclusionQueryHandle _handle)
|
2015-11-02 04:28:23 +03:00
|
|
|
{
|
|
|
|
while (0 == m_control.reserve(1) )
|
|
|
|
{
|
2015-11-04 03:00:14 +03:00
|
|
|
resolve(_render, true);
|
2015-11-02 04:28:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Query& query = m_query[m_control.m_current];
|
|
|
|
query.m_ptr->Issue(D3DISSUE_BEGIN);
|
|
|
|
query.m_handle = _handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OcclusionQueryD3D9::end()
|
|
|
|
{
|
|
|
|
Query& query = m_query[m_control.m_current];
|
|
|
|
query.m_ptr->Issue(D3DISSUE_END);
|
|
|
|
m_control.commit(1);
|
|
|
|
}
|
|
|
|
|
2015-11-04 03:00:14 +03:00
|
|
|
void OcclusionQueryD3D9::resolve(Frame* _render, bool)
|
2015-11-02 04:28:23 +03:00
|
|
|
{
|
|
|
|
while (0 != m_control.available() )
|
|
|
|
{
|
|
|
|
Query& query = m_query[m_control.m_read];
|
|
|
|
|
2017-03-04 05:05:36 +03:00
|
|
|
if (isValid(query.m_handle) )
|
2015-11-02 04:28:23 +03:00
|
|
|
{
|
2017-03-04 05:05:36 +03:00
|
|
|
uint32_t result;
|
|
|
|
HRESULT hr = query.m_ptr->GetData(&result, sizeof(result), 0);
|
|
|
|
if (S_FALSE == hr)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-03-07 04:23:22 +03:00
|
|
|
_render->m_occlusion[query.m_handle.idx] = int32_t(result);
|
2015-11-02 04:28:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
m_control.consume(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-04 05:05:36 +03:00
|
|
|
void OcclusionQueryD3D9::invalidate(OcclusionQueryHandle _handle)
|
|
|
|
{
|
|
|
|
const uint32_t size = m_control.m_size;
|
|
|
|
|
|
|
|
for (uint32_t ii = 0, num = m_control.available(); ii < num; ++ii)
|
|
|
|
{
|
|
|
|
Query& query = m_query[(m_control.m_read + ii) % size];
|
|
|
|
if (query.m_handle.idx == _handle.idx)
|
|
|
|
{
|
2017-06-10 07:57:08 +03:00
|
|
|
query.m_handle.idx = bgfx::kInvalidHandle;
|
2017-03-04 05:05:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-06 08:22:14 +03:00
|
|
|
void RendererContextD3D9::submitBlit(BlitState& _bs, uint16_t _view)
|
|
|
|
{
|
|
|
|
while (_bs.hasItem(_view) )
|
|
|
|
{
|
|
|
|
const BlitItem& blit = _bs.advance();
|
|
|
|
|
|
|
|
const TextureD3D9& src = m_textures[blit.m_src.idx];
|
|
|
|
const TextureD3D9& dst = m_textures[blit.m_dst.idx];
|
|
|
|
|
|
|
|
uint32_t srcWidth = bx::uint32_min(src.m_width, blit.m_srcX + blit.m_width) - blit.m_srcX;
|
|
|
|
uint32_t srcHeight = bx::uint32_min(src.m_height, blit.m_srcY + blit.m_height) - blit.m_srcY;
|
|
|
|
uint32_t dstWidth = bx::uint32_min(dst.m_width, blit.m_dstX + blit.m_width) - blit.m_dstX;
|
|
|
|
uint32_t dstHeight = bx::uint32_min(dst.m_height, blit.m_dstY + blit.m_height) - blit.m_dstY;
|
|
|
|
uint32_t width = bx::uint32_min(srcWidth, dstWidth);
|
|
|
|
uint32_t height = bx::uint32_min(srcHeight, dstHeight);
|
|
|
|
|
|
|
|
RECT srcRect = { LONG(blit.m_srcX), LONG(blit.m_srcY), LONG(blit.m_srcX + width), LONG(blit.m_srcY + height) };
|
|
|
|
RECT dstRect = { LONG(blit.m_dstX), LONG(blit.m_dstY), LONG(blit.m_dstX + width), LONG(blit.m_dstY + height) };
|
|
|
|
|
|
|
|
IDirect3DSurface9* srcSurface = src.getSurface(uint8_t(blit.m_srcZ), blit.m_srcMip);
|
|
|
|
IDirect3DSurface9* dstSurface = dst.getSurface(uint8_t(blit.m_dstZ), blit.m_dstMip);
|
|
|
|
|
|
|
|
// UpdateSurface (pool src: SYSTEMMEM, dst: DEFAULT)
|
|
|
|
// s/d T RTT RT
|
|
|
|
// T y y y
|
|
|
|
// RTT - - -
|
|
|
|
// RT - - -
|
|
|
|
//
|
|
|
|
// StretchRect (pool src and dst must be DEFAULT)
|
|
|
|
// s/d T RTT RT
|
|
|
|
// T - y y
|
|
|
|
// RTT - y y
|
|
|
|
// RT - y y
|
|
|
|
//
|
|
|
|
// GetRenderTargetData (dst must be SYSTEMMEM)
|
|
|
|
|
|
|
|
bool depth = bimg::isDepth(bimg::TextureFormat::Enum(src.m_textureFormat) );
|
|
|
|
HRESULT hr = m_device->StretchRect(srcSurface
|
|
|
|
, depth ? NULL : &srcRect
|
|
|
|
, dstSurface
|
|
|
|
, depth ? NULL : &dstRect
|
|
|
|
, D3DTEXF_NONE
|
|
|
|
);
|
|
|
|
if (FAILED(hr) )
|
|
|
|
{
|
|
|
|
hr = m_device->GetRenderTargetData(srcSurface, dstSurface);
|
|
|
|
BX_WARN(SUCCEEDED(hr), "StretchRect and GetRenderTargetData failed %x.", hr);
|
|
|
|
}
|
|
|
|
|
|
|
|
srcSurface->Release();
|
|
|
|
dstSurface->Release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-01 22:24:51 +04:00
|
|
|
void RendererContextD3D9::submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2014-05-27 01:09:26 +04:00
|
|
|
IDirect3DDevice9* device = m_device;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2016-08-24 23:16:04 +03:00
|
|
|
PIX_BEGINEVENT(D3DCOLOR_FRAME, L"rendererSubmit");
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
updateResolution(_render->m_resolution);
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2017-09-22 07:34:02 +03:00
|
|
|
int64_t timeBegin = bx::getHPCounter();
|
2013-01-02 01:19:10 +04:00
|
|
|
int64_t captureElapsed = 0;
|
|
|
|
|
2017-08-28 06:34:00 +03:00
|
|
|
uint32_t frameQueryIdx = UINT32_MAX;
|
|
|
|
|
2012-08-06 01:51:49 +04:00
|
|
|
device->BeginScene();
|
2015-08-21 23:07:58 +03:00
|
|
|
if (m_timerQuerySupport)
|
|
|
|
{
|
2017-08-28 06:34:00 +03:00
|
|
|
frameQueryIdx = m_gpuTimer.begin(BGFX_CONFIG_MAX_VIEWS);
|
2015-08-21 23:07:58 +03:00
|
|
|
}
|
2015-05-13 03:03:25 +03:00
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
if (0 < _render->m_iboffset)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2014-05-27 01:09:26 +04:00
|
|
|
TransientIndexBuffer* ib = _render->m_transientIb;
|
|
|
|
m_indexBuffers[ib->handle.idx].update(0, _render->m_iboffset, ib->data, true);
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
if (0 < _render->m_vboffset)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2014-05-27 01:09:26 +04:00
|
|
|
TransientVertexBuffer* vb = _render->m_transientVb;
|
|
|
|
m_vertexBuffers[vb->handle.idx].update(0, _render->m_vboffset, vb->data, true);
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
_render->sort();
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2014-07-21 07:27:13 +04:00
|
|
|
RenderDraw currentState;
|
|
|
|
currentState.clear();
|
2015-11-02 04:28:23 +03:00
|
|
|
currentState.m_stateFlags = BGFX_STATE_NONE;
|
|
|
|
currentState.m_stencil = packStencil(BGFX_STENCIL_NONE, BGFX_STENCIL_NONE);
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2017-04-07 06:32:48 +03:00
|
|
|
RenderBind currentBind;
|
|
|
|
currentBind.clear();
|
|
|
|
|
2014-12-28 06:00:41 +03:00
|
|
|
ViewState viewState(_render, false);
|
2014-05-11 07:51:44 +04:00
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_FILLMODE, _render->m_debug&BGFX_DEBUG_WIREFRAME ? D3DFILL_WIREFRAME : D3DFILL_SOLID) );
|
2017-06-10 07:57:08 +03:00
|
|
|
uint16_t programIdx = kInvalidHandle;
|
2012-08-06 01:51:49 +04:00
|
|
|
SortKey key;
|
2015-08-29 06:34:14 +03:00
|
|
|
uint16_t view = UINT16_MAX;
|
2015-12-31 04:46:05 +03:00
|
|
|
FrameBufferHandle fbh = { BGFX_CONFIG_MAX_FRAME_BUFFERS };
|
2013-03-30 09:58:50 +04:00
|
|
|
uint32_t blendFactor = 0;
|
2014-04-27 10:48:41 +04:00
|
|
|
|
2017-05-06 08:22:14 +03:00
|
|
|
BlitState bs(_render);
|
2015-10-16 02:38:59 +03:00
|
|
|
|
2015-03-30 08:40:35 +03:00
|
|
|
uint8_t primIndex;
|
|
|
|
{
|
|
|
|
const uint64_t pt = _render->m_debug&BGFX_DEBUG_WIREFRAME ? BGFX_STATE_PT_LINES : 0;
|
|
|
|
primIndex = uint8_t(pt>>BGFX_STATE_PT_SHIFT);
|
|
|
|
}
|
2014-04-27 10:48:41 +04:00
|
|
|
PrimInfo prim = s_primInfo[primIndex];
|
|
|
|
|
2013-08-02 09:55:26 +04:00
|
|
|
bool viewHasScissor = false;
|
|
|
|
Rect viewScissorRect;
|
2013-08-05 03:56:07 +04:00
|
|
|
viewScissorRect.clear();
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2014-04-27 10:48:41 +04:00
|
|
|
uint32_t statsNumPrimsSubmitted[BX_COUNTOF(s_primInfo)] = {};
|
|
|
|
uint32_t statsNumPrimsRendered[BX_COUNTOF(s_primInfo)] = {};
|
|
|
|
uint32_t statsNumInstances[BX_COUNTOF(s_primInfo)] = {};
|
2012-08-06 01:51:49 +04:00
|
|
|
uint32_t statsNumIndices = 0;
|
2015-03-27 08:43:50 +03:00
|
|
|
uint32_t statsKeyType[2] = {};
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
invalidateSamplerState();
|
2013-07-25 08:59:59 +04:00
|
|
|
|
2017-08-28 06:34:00 +03:00
|
|
|
Profiler<TimerQueryD3D9> profiler(
|
|
|
|
_render
|
|
|
|
, m_gpuTimer
|
|
|
|
, s_viewName
|
|
|
|
, m_timerQuerySupport
|
|
|
|
);
|
|
|
|
|
2015-11-02 06:12:42 +03:00
|
|
|
if (m_occlusionQuerySupport)
|
|
|
|
{
|
2015-11-04 03:00:14 +03:00
|
|
|
m_occlusionQuery.resolve(_render);
|
2015-11-02 06:12:42 +03:00
|
|
|
}
|
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
if (0 == (_render->m_debug&BGFX_DEBUG_IFH) )
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2017-10-08 04:17:16 +03:00
|
|
|
for (uint32_t item = 0, numItems = _render->m_numRenderItems; item < numItems; ++item)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2016-11-21 01:29:37 +03:00
|
|
|
const uint64_t encodedKey = _render->m_sortKeys[item];
|
|
|
|
const bool isCompute = key.decode(encodedKey, _render->m_viewRemap);
|
2015-03-27 08:43:50 +03:00
|
|
|
statsKeyType[isCompute]++;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2014-07-21 07:27:13 +04:00
|
|
|
if (isCompute)
|
|
|
|
{
|
|
|
|
BX_CHECK(false, "Compute is not supported on DirectX 9.");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-04-07 06:32:48 +03:00
|
|
|
const uint32_t itemIdx = _render->m_sortValues[item];
|
|
|
|
const RenderDraw& draw = _render->m_renderItem[itemIdx].draw;
|
|
|
|
const RenderBind& renderBind = _render->m_renderItemBind[itemIdx];
|
2014-07-21 07:27:13 +04:00
|
|
|
|
2015-11-02 04:28:23 +03:00
|
|
|
const bool hasOcclusionQuery = 0 != (draw.m_stateFlags & BGFX_STATE_INTERNAL_OCCLUSION_QUERY);
|
|
|
|
{
|
2018-03-27 02:21:27 +03:00
|
|
|
const bool occluded = true
|
|
|
|
&& isValid(draw.m_occlusionQuery)
|
|
|
|
&& !hasOcclusionQuery
|
|
|
|
&& !isVisible(_render, draw.m_occlusionQuery, 0 != (draw.m_submitFlags&BGFX_SUBMIT_INTERNAL_OCCLUSION_VISIBLE) )
|
|
|
|
;
|
|
|
|
|
|
|
|
if (occluded
|
|
|
|
|| _render->m_frameCache.isZeroArea(viewScissorRect, draw.m_scissor) )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2015-11-02 04:28:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const uint64_t newFlags = draw.m_stateFlags;
|
|
|
|
uint64_t changedFlags = currentState.m_stateFlags ^ draw.m_stateFlags;
|
|
|
|
currentState.m_stateFlags = newFlags;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2014-07-21 07:27:13 +04:00
|
|
|
const uint64_t newStencil = draw.m_stencil;
|
|
|
|
uint64_t changedStencil = currentState.m_stencil ^ draw.m_stencil;
|
2012-11-11 07:59:23 +04:00
|
|
|
currentState.m_stencil = newStencil;
|
|
|
|
|
2012-08-06 01:51:49 +04:00
|
|
|
if (key.m_view != view)
|
|
|
|
{
|
|
|
|
currentState.clear();
|
2014-07-21 07:27:13 +04:00
|
|
|
currentState.m_scissor = !draw.m_scissor;
|
2012-08-06 01:51:49 +04:00
|
|
|
changedFlags = BGFX_STATE_MASK;
|
2012-11-11 07:59:23 +04:00
|
|
|
changedStencil = packStencil(BGFX_STENCIL_MASK, BGFX_STENCIL_MASK);
|
2015-11-02 04:28:23 +03:00
|
|
|
currentState.m_stateFlags = newFlags;
|
|
|
|
currentState.m_stencil = newStencil;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
|
|
|
view = key.m_view;
|
2017-06-10 07:57:08 +03:00
|
|
|
programIdx = kInvalidHandle;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2017-10-30 18:39:25 +03:00
|
|
|
if (_render->m_view[view].m_fbh.idx != fbh.idx)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2017-10-30 18:39:25 +03:00
|
|
|
fbh = _render->m_view[view].m_fbh;
|
2014-05-27 01:09:26 +04:00
|
|
|
setFrameBuffer(fbh);
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
|
2017-08-28 06:34:00 +03:00
|
|
|
PIX_ENDEVENT();
|
|
|
|
if (item > 0)
|
|
|
|
{
|
|
|
|
profiler.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
profiler.begin(view);
|
|
|
|
PIX_BEGINEVENT(D3DCOLOR_VIEW, s_viewNameW[view]);
|
|
|
|
|
2017-10-30 18:39:25 +03:00
|
|
|
viewState.m_rect = _render->m_view[view].m_rect;
|
|
|
|
const Rect& scissorRect = _render->m_view[view].m_scissor;
|
2014-12-28 06:00:41 +03:00
|
|
|
viewHasScissor = !scissorRect.isZero();
|
|
|
|
viewScissorRect = viewHasScissor ? scissorRect : viewState.m_rect;
|
2013-08-02 09:55:26 +04:00
|
|
|
|
2012-08-06 01:51:49 +04:00
|
|
|
D3DVIEWPORT9 vp;
|
2014-12-28 06:00:41 +03:00
|
|
|
vp.X = viewState.m_rect.m_x;
|
|
|
|
vp.Y = viewState.m_rect.m_y;
|
|
|
|
vp.Width = viewState.m_rect.m_width;
|
|
|
|
vp.Height = viewState.m_rect.m_height;
|
2012-08-06 01:51:49 +04:00
|
|
|
vp.MinZ = 0.0f;
|
|
|
|
vp.MaxZ = 1.0f;
|
|
|
|
DX_CHECK(device->SetViewport(&vp) );
|
|
|
|
|
2017-10-30 18:39:25 +03:00
|
|
|
Clear& clear = _render->m_view[view].m_clear;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2015-01-12 05:02:34 +03:00
|
|
|
if (BGFX_CLEAR_NONE != (clear.m_flags & BGFX_CLEAR_MASK) )
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2015-09-17 03:21:28 +03:00
|
|
|
clearQuad(_clearQuad, viewState.m_rect, clear, _render->m_colorPalette);
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
|
2013-07-28 02:27:54 +04:00
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_STENCILENABLE, FALSE) );
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_ZENABLE, TRUE) );
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESS) );
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE) );
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE) );
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER) );
|
2015-10-16 02:38:59 +03:00
|
|
|
|
2017-05-06 08:22:14 +03:00
|
|
|
submitBlit(bs, view);
|
2013-07-28 02:27:54 +04:00
|
|
|
}
|
|
|
|
|
2014-07-21 07:27:13 +04:00
|
|
|
uint16_t scissor = draw.m_scissor;
|
2013-07-28 02:27:54 +04:00
|
|
|
if (currentState.m_scissor != scissor)
|
|
|
|
{
|
|
|
|
currentState.m_scissor = scissor;
|
|
|
|
|
|
|
|
if (UINT16_MAX == scissor)
|
2013-07-15 01:32:09 +04:00
|
|
|
{
|
2013-08-02 09:55:26 +04:00
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_SCISSORTESTENABLE, viewHasScissor) );
|
|
|
|
if (viewHasScissor)
|
2013-07-28 02:27:54 +04:00
|
|
|
{
|
|
|
|
RECT rc;
|
2014-12-28 06:00:41 +03:00
|
|
|
rc.left = viewScissorRect.m_x;
|
|
|
|
rc.top = viewScissorRect.m_y;
|
|
|
|
rc.right = viewScissorRect.m_x + viewScissorRect.m_width;
|
2013-08-02 09:55:26 +04:00
|
|
|
rc.bottom = viewScissorRect.m_y + viewScissorRect.m_height;
|
2013-07-28 02:27:54 +04:00
|
|
|
DX_CHECK(device->SetScissorRect(&rc) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-08-02 09:55:26 +04:00
|
|
|
Rect scissorRect;
|
2017-10-09 06:57:56 +03:00
|
|
|
scissorRect.setIntersect(viewScissorRect, _render->m_frameCache.m_rectCache.m_cache[scissor]);
|
2017-01-12 07:38:38 +03:00
|
|
|
|
2013-07-28 02:27:54 +04:00
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_SCISSORTESTENABLE, true) );
|
2013-07-15 01:32:09 +04:00
|
|
|
RECT rc;
|
2014-12-28 06:00:41 +03:00
|
|
|
rc.left = scissorRect.m_x;
|
|
|
|
rc.top = scissorRect.m_y;
|
|
|
|
rc.right = scissorRect.m_x + scissorRect.m_width;
|
2013-07-15 01:32:09 +04:00
|
|
|
rc.bottom = scissorRect.m_y + scissorRect.m_height;
|
|
|
|
DX_CHECK(device->SetScissorRect(&rc) );
|
|
|
|
}
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
|
2012-11-11 07:59:23 +04:00
|
|
|
if (0 != changedStencil)
|
|
|
|
{
|
|
|
|
bool enable = 0 != newStencil;
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_STENCILENABLE, enable) );
|
2015-01-11 07:38:47 +03:00
|
|
|
|
2012-11-11 07:59:23 +04:00
|
|
|
if (0 != newStencil)
|
|
|
|
{
|
|
|
|
uint32_t fstencil = unpackStencil(0, newStencil);
|
|
|
|
uint32_t bstencil = unpackStencil(1, newStencil);
|
2015-04-08 03:58:14 +03:00
|
|
|
uint8_t frontAndBack = bstencil != BGFX_STENCIL_NONE && bstencil != fstencil;
|
2012-11-11 07:59:23 +04:00
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_TWOSIDEDSTENCILMODE, 0 != frontAndBack) );
|
|
|
|
|
|
|
|
uint32_t fchanged = unpackStencil(0, changedStencil);
|
|
|
|
if ( (BGFX_STENCIL_FUNC_REF_MASK|BGFX_STENCIL_FUNC_RMASK_MASK) & fchanged)
|
|
|
|
{
|
|
|
|
uint32_t ref = (fstencil&BGFX_STENCIL_FUNC_REF_MASK)>>BGFX_STENCIL_FUNC_REF_SHIFT;
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_STENCILREF, ref) );
|
|
|
|
|
|
|
|
uint32_t rmask = (fstencil&BGFX_STENCIL_FUNC_RMASK_MASK)>>BGFX_STENCIL_FUNC_RMASK_SHIFT;
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_STENCILMASK, rmask) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// uint32_t bchanged = unpackStencil(1, changedStencil);
|
|
|
|
// if (BGFX_STENCIL_FUNC_RMASK_MASK & bchanged)
|
|
|
|
// {
|
|
|
|
// uint32_t wmask = (bstencil&BGFX_STENCIL_FUNC_RMASK_MASK)>>BGFX_STENCIL_FUNC_RMASK_SHIFT;
|
|
|
|
// DX_CHECK(device->SetRenderState(D3DRS_STENCILWRITEMASK, wmask) );
|
|
|
|
// }
|
|
|
|
|
2015-04-08 03:58:14 +03:00
|
|
|
for (uint8_t ii = 0, num = frontAndBack+1; ii < num; ++ii)
|
2012-11-11 07:59:23 +04:00
|
|
|
{
|
|
|
|
uint32_t stencil = unpackStencil(ii, newStencil);
|
|
|
|
uint32_t changed = unpackStencil(ii, changedStencil);
|
|
|
|
|
|
|
|
if ( (BGFX_STENCIL_TEST_MASK|BGFX_STENCIL_FUNC_REF_MASK|BGFX_STENCIL_FUNC_RMASK_MASK) & changed)
|
|
|
|
{
|
|
|
|
uint32_t func = (stencil&BGFX_STENCIL_TEST_MASK)>>BGFX_STENCIL_TEST_SHIFT;
|
2014-02-22 20:48:30 +04:00
|
|
|
DX_CHECK(device->SetRenderState(s_stencilFuncRs[ii], s_cmpFunc[func]) );
|
2012-11-11 07:59:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( (BGFX_STENCIL_OP_FAIL_S_MASK|BGFX_STENCIL_OP_FAIL_Z_MASK|BGFX_STENCIL_OP_PASS_Z_MASK) & changed)
|
|
|
|
{
|
|
|
|
uint32_t sfail = (stencil&BGFX_STENCIL_OP_FAIL_S_MASK)>>BGFX_STENCIL_OP_FAIL_S_SHIFT;
|
|
|
|
DX_CHECK(device->SetRenderState(s_stencilFailRs[ii], s_stencilOp[sfail]) );
|
|
|
|
|
|
|
|
uint32_t zfail = (stencil&BGFX_STENCIL_OP_FAIL_Z_MASK)>>BGFX_STENCIL_OP_FAIL_Z_SHIFT;
|
|
|
|
DX_CHECK(device->SetRenderState(s_stencilZFailRs[ii], s_stencilOp[zfail]) );
|
|
|
|
|
|
|
|
uint32_t zpass = (stencil&BGFX_STENCIL_OP_PASS_Z_MASK)>>BGFX_STENCIL_OP_PASS_Z_SHIFT;
|
|
|
|
DX_CHECK(device->SetRenderState(s_stencilZPassRs[ii], s_stencilOp[zpass]) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-18 09:11:45 +04:00
|
|
|
if ( (0
|
|
|
|
| BGFX_STATE_CULL_MASK
|
2018-02-13 23:35:23 +03:00
|
|
|
| BGFX_STATE_WRITE_Z
|
2013-06-18 09:11:45 +04:00
|
|
|
| BGFX_STATE_DEPTH_TEST_MASK
|
2018-02-13 23:35:23 +03:00
|
|
|
| BGFX_STATE_WRITE_RGB
|
|
|
|
| BGFX_STATE_WRITE_A
|
2013-06-18 09:11:45 +04:00
|
|
|
| BGFX_STATE_BLEND_MASK
|
|
|
|
| BGFX_STATE_BLEND_EQUATION_MASK
|
|
|
|
| BGFX_STATE_ALPHA_REF_MASK
|
|
|
|
| BGFX_STATE_PT_MASK
|
|
|
|
| BGFX_STATE_POINT_SIZE_MASK
|
|
|
|
| BGFX_STATE_MSAA
|
|
|
|
) & changedFlags)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
|
|
|
if (BGFX_STATE_CULL_MASK & changedFlags)
|
|
|
|
{
|
|
|
|
uint32_t cull = (newFlags&BGFX_STATE_CULL_MASK)>>BGFX_STATE_CULL_SHIFT;
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_CULLMODE, s_cullMode[cull]) );
|
|
|
|
}
|
|
|
|
|
2018-02-13 23:35:23 +03:00
|
|
|
if (BGFX_STATE_WRITE_Z & changedFlags)
|
2015-01-11 07:38:47 +03:00
|
|
|
{
|
2018-02-13 23:35:23 +03:00
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_ZWRITEENABLE, !!(BGFX_STATE_WRITE_Z & newFlags) ) );
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (BGFX_STATE_DEPTH_TEST_MASK & changedFlags)
|
|
|
|
{
|
|
|
|
uint32_t func = (newFlags&BGFX_STATE_DEPTH_TEST_MASK)>>BGFX_STATE_DEPTH_TEST_SHIFT;
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_ZENABLE, 0 != func) );
|
|
|
|
|
|
|
|
if (0 != func)
|
|
|
|
{
|
2014-02-22 20:48:30 +04:00
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_ZFUNC, s_cmpFunc[func]) );
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-09 09:54:08 +04:00
|
|
|
if (BGFX_STATE_ALPHA_REF_MASK & changedFlags)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
|
|
|
uint32_t ref = (newFlags&BGFX_STATE_ALPHA_REF_MASK)>>BGFX_STATE_ALPHA_REF_SHIFT;
|
2014-12-28 06:00:41 +03:00
|
|
|
viewState.m_alphaRef = ref/255.0f;
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( (BGFX_STATE_PT_POINTS|BGFX_STATE_POINT_SIZE_MASK) & changedFlags)
|
|
|
|
{
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_POINTSIZE, castfu( (float)( (newFlags&BGFX_STATE_POINT_SIZE_MASK)>>BGFX_STATE_POINT_SIZE_SHIFT) ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BGFX_STATE_MSAA & changedFlags)
|
|
|
|
{
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, (newFlags&BGFX_STATE_MSAA) == BGFX_STATE_MSAA) );
|
|
|
|
}
|
|
|
|
|
2016-03-17 01:09:15 +03:00
|
|
|
if (BGFX_STATE_LINEAA & changedFlags)
|
|
|
|
{
|
|
|
|
DX_CHECK(m_device->SetRenderState(D3DRS_ANTIALIASEDLINEENABLE, !!(newFlags&BGFX_STATE_LINEAA) ) );
|
|
|
|
}
|
|
|
|
|
2018-02-13 23:35:23 +03:00
|
|
|
if ( (BGFX_STATE_WRITE_A|BGFX_STATE_WRITE_RGB) & changedFlags)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2018-02-13 23:35:23 +03:00
|
|
|
uint32_t writeEnable = 0;
|
|
|
|
writeEnable |= (newFlags&BGFX_STATE_WRITE_R) ? D3DCOLORWRITEENABLE_RED : 0;
|
|
|
|
writeEnable |= (newFlags&BGFX_STATE_WRITE_G) ? D3DCOLORWRITEENABLE_GREEN : 0;
|
|
|
|
writeEnable |= (newFlags&BGFX_STATE_WRITE_B) ? D3DCOLORWRITEENABLE_BLUE : 0;
|
|
|
|
writeEnable |= (newFlags&BGFX_STATE_WRITE_A) ? D3DCOLORWRITEENABLE_ALPHA : 0;
|
2012-08-06 01:51:49 +04:00
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_COLORWRITEENABLE, writeEnable) );
|
|
|
|
}
|
|
|
|
|
2016-03-17 01:09:15 +03:00
|
|
|
if ( ( (0
|
|
|
|
| BGFX_STATE_BLEND_MASK
|
|
|
|
| BGFX_STATE_BLEND_EQUATION_MASK
|
|
|
|
| BGFX_STATE_BLEND_ALPHA_TO_COVERAGE
|
|
|
|
) & changedFlags)
|
2014-07-21 07:27:13 +04:00
|
|
|
|| blendFactor != draw.m_rgba)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2014-03-26 10:07:51 +04:00
|
|
|
bool enabled = !!(BGFX_STATE_BLEND_MASK & newFlags);
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_ALPHABLENDENABLE, enabled) );
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2016-03-17 01:09:15 +03:00
|
|
|
if (m_atocSupport
|
|
|
|
&& BGFX_STATE_BLEND_ALPHA_TO_COVERAGE & changedFlags)
|
|
|
|
{
|
|
|
|
DX_CHECK(m_device->SetRenderState(D3DRS_ADAPTIVETESS_Y
|
|
|
|
, !!(newFlags&BGFX_STATE_BLEND_ALPHA_TO_COVERAGE)
|
|
|
|
? D3DFMT_ATOC
|
|
|
|
: 0
|
|
|
|
) );
|
|
|
|
}
|
|
|
|
|
2014-03-26 10:07:51 +04:00
|
|
|
if (enabled)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2014-03-26 10:07:51 +04:00
|
|
|
const uint32_t blend = uint32_t( (newFlags&BGFX_STATE_BLEND_MASK)>>BGFX_STATE_BLEND_SHIFT);
|
|
|
|
const uint32_t equation = uint32_t( (newFlags&BGFX_STATE_BLEND_EQUATION_MASK)>>BGFX_STATE_BLEND_EQUATION_SHIFT);
|
|
|
|
|
|
|
|
const uint32_t srcRGB = (blend )&0xf;
|
|
|
|
const uint32_t dstRGB = (blend>> 4)&0xf;
|
|
|
|
const uint32_t srcA = (blend>> 8)&0xf;
|
|
|
|
const uint32_t dstA = (blend>>12)&0xf;
|
|
|
|
|
|
|
|
const uint32_t equRGB = (equation )&0x7;
|
|
|
|
const uint32_t equA = (equation>>3)&0x7;
|
|
|
|
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_SRCBLEND, s_blendFactor[srcRGB].m_src) );
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_DESTBLEND, s_blendFactor[dstRGB].m_dst) );
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_BLENDOP, s_blendEquation[equRGB]) );
|
|
|
|
|
|
|
|
const bool separate = srcRGB != srcA || dstRGB != dstA || equRGB != equA;
|
|
|
|
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, separate) );
|
|
|
|
if (separate)
|
|
|
|
{
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_SRCBLENDALPHA, s_blendFactor[srcA].m_src) );
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_DESTBLENDALPHA, s_blendFactor[dstA].m_dst) );
|
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_BLENDOPALPHA, s_blendEquation[equA]) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (s_blendFactor[srcRGB].m_factor || s_blendFactor[dstRGB].m_factor)
|
2014-07-21 07:27:13 +04:00
|
|
|
&& blendFactor != draw.m_rgba)
|
2013-03-30 09:58:50 +04:00
|
|
|
{
|
2014-07-21 07:27:13 +04:00
|
|
|
const uint32_t rgba = draw.m_rgba;
|
2018-05-03 02:40:13 +03:00
|
|
|
D3DCOLOR color = D3DCOLOR_RGBA(
|
2018-03-11 00:16:45 +03:00
|
|
|
rgba>>24
|
|
|
|
, (rgba>>16)&0xff
|
|
|
|
, (rgba>> 8)&0xff
|
|
|
|
, (rgba )&0xff
|
|
|
|
);
|
2013-03-30 20:44:13 +04:00
|
|
|
DX_CHECK(device->SetRenderState(D3DRS_BLENDFACTOR, color) );
|
2013-03-30 09:58:50 +04:00
|
|
|
}
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
2014-03-26 10:07:51 +04:00
|
|
|
|
2014-07-21 07:27:13 +04:00
|
|
|
blendFactor = draw.m_rgba;
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
const uint64_t pt = _render->m_debug&BGFX_DEBUG_WIREFRAME ? BGFX_STATE_PT_LINES : newFlags&BGFX_STATE_PT_MASK;
|
2014-04-27 10:48:41 +04:00
|
|
|
primIndex = uint8_t(pt>>BGFX_STATE_PT_SHIFT);
|
|
|
|
prim = s_primInfo[primIndex];
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
|
2012-09-17 04:36:08 +04:00
|
|
|
bool programChanged = false;
|
2017-10-10 07:08:03 +03:00
|
|
|
bool constantsChanged = draw.m_uniformBegin < draw.m_uniformEnd;
|
2017-11-02 08:34:11 +03:00
|
|
|
rendererUpdateUniforms(this, _render->m_uniformBuffer[draw.m_uniformIdx], draw.m_uniformBegin, draw.m_uniformEnd);
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2012-09-17 04:36:08 +04:00
|
|
|
if (key.m_program != programIdx)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2012-09-17 04:36:08 +04:00
|
|
|
programIdx = key.m_program;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2017-06-10 07:57:08 +03:00
|
|
|
if (kInvalidHandle == programIdx)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
|
|
|
device->SetVertexShader(NULL);
|
|
|
|
device->SetPixelShader(NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-27 01:09:26 +04:00
|
|
|
ProgramD3D9& program = m_program[programIdx];
|
2014-07-21 07:27:13 +04:00
|
|
|
device->SetVertexShader(program.m_vsh->m_vertexShader);
|
2018-03-06 05:15:35 +03:00
|
|
|
device->SetPixelShader(NULL == program.m_fsh
|
|
|
|
? NULL
|
|
|
|
: program.m_fsh->m_pixelShader
|
|
|
|
);
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
|
2015-01-11 07:38:47 +03:00
|
|
|
programChanged =
|
2012-08-06 01:51:49 +04:00
|
|
|
constantsChanged = true;
|
|
|
|
}
|
|
|
|
|
2017-06-10 07:57:08 +03:00
|
|
|
if (kInvalidHandle != programIdx)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2014-05-27 01:09:26 +04:00
|
|
|
ProgramD3D9& program = m_program[programIdx];
|
2012-08-06 01:51:49 +04:00
|
|
|
|
|
|
|
if (constantsChanged)
|
|
|
|
{
|
2015-09-15 01:53:33 +03:00
|
|
|
UniformBuffer* vcb = program.m_vsh->m_constantBuffer;
|
2014-05-27 01:09:26 +04:00
|
|
|
if (NULL != vcb)
|
|
|
|
{
|
|
|
|
commit(*vcb);
|
|
|
|
}
|
|
|
|
|
2018-03-06 05:15:35 +03:00
|
|
|
if (NULL != program.m_fsh)
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
2018-03-06 05:15:35 +03:00
|
|
|
UniformBuffer* fcb = program.m_fsh->m_constantBuffer;
|
|
|
|
if (NULL != fcb)
|
|
|
|
{
|
|
|
|
commit(*fcb);
|
|
|
|
}
|
2014-05-27 01:09:26 +04:00
|
|
|
}
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
|
2014-12-28 06:00:41 +03:00
|
|
|
viewState.setPredefined<4>(this, view, 0, program, _render, draw);
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2015-04-08 03:58:14 +03:00
|
|
|
for (uint8_t stage = 0; stage < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++stage)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2017-04-07 06:32:48 +03:00
|
|
|
const Binding& bind = renderBind.m_bind[stage];
|
|
|
|
Binding& current = currentBind.m_bind[stage];
|
2017-04-07 04:59:30 +03:00
|
|
|
|
2015-08-29 06:34:14 +03:00
|
|
|
if (current.m_idx != bind.m_idx
|
2015-11-02 04:28:23 +03:00
|
|
|
|| current.m_un.m_draw.m_textureFlags != bind.m_un.m_draw.m_textureFlags
|
2012-09-17 04:36:08 +04:00
|
|
|
|| programChanged)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2017-06-10 07:57:08 +03:00
|
|
|
if (kInvalidHandle != bind.m_idx)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2015-11-02 04:28:23 +03:00
|
|
|
m_textures[bind.m_idx].commit(stage, bind.m_un.m_draw.m_textureFlags, _render->m_colorPalette);
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DX_CHECK(device->SetTexture(stage, NULL) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-29 06:34:14 +03:00
|
|
|
current = bind;
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-14 08:21:02 +03:00
|
|
|
bool vertexStreamChanged = hasVertexStreamChanged(currentState, draw);
|
|
|
|
|
2013-07-26 10:13:48 +04:00
|
|
|
if (programChanged
|
2017-05-14 08:21:02 +03:00
|
|
|
|| vertexStreamChanged)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2017-05-14 08:21:02 +03:00
|
|
|
currentState.m_streamMask = draw.m_streamMask;
|
2014-07-21 07:27:13 +04:00
|
|
|
currentState.m_instanceDataBuffer.idx = draw.m_instanceDataBuffer.idx;
|
2016-09-13 05:38:29 +03:00
|
|
|
currentState.m_instanceDataOffset = draw.m_instanceDataOffset;
|
|
|
|
currentState.m_instanceDataStride = draw.m_instanceDataStride;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2017-05-14 08:21:02 +03:00
|
|
|
const VertexDecl* decls[BGFX_CONFIG_MAX_VERTEX_STREAMS];
|
|
|
|
|
|
|
|
const bool instanced = true
|
|
|
|
&& isValid(draw.m_instanceDataBuffer)
|
|
|
|
&& m_instancingSupport
|
|
|
|
;
|
|
|
|
|
|
|
|
const uint32_t freq = instanced
|
|
|
|
? D3DSTREAMSOURCE_INDEXEDDATA|draw.m_numInstances
|
|
|
|
: 1
|
|
|
|
;
|
|
|
|
|
|
|
|
uint32_t numVertices = draw.m_numVertices;
|
|
|
|
uint8_t numStreams = 0;
|
|
|
|
for (uint32_t idx = 0, streamMask = draw.m_streamMask, ntz = bx::uint32_cnttz(streamMask)
|
|
|
|
; 0 != streamMask
|
|
|
|
; streamMask >>= 1, idx += 1, ntz = bx::uint32_cnttz(streamMask), ++numStreams
|
|
|
|
)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2017-05-14 08:21:02 +03:00
|
|
|
streamMask >>= ntz;
|
|
|
|
idx += ntz;
|
|
|
|
|
|
|
|
currentState.m_stream[idx].m_decl = draw.m_stream[idx].m_decl;
|
|
|
|
currentState.m_stream[idx].m_handle = draw.m_stream[idx].m_handle;
|
|
|
|
currentState.m_stream[idx].m_startVertex = draw.m_stream[idx].m_startVertex;
|
|
|
|
|
|
|
|
const uint16_t handle = draw.m_stream[idx].m_handle.idx;
|
2014-05-27 01:09:26 +04:00
|
|
|
const VertexBufferD3D9& vb = m_vertexBuffers[handle];
|
2017-05-14 08:21:02 +03:00
|
|
|
const uint16_t decl = !isValid(vb.m_decl) ? draw.m_stream[idx].m_decl.idx : vb.m_decl.idx;
|
|
|
|
const VertexDecl& vertexDecl = m_vertexDecls[decl];
|
|
|
|
const uint32_t stride = vertexDecl.m_stride;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2017-05-14 08:21:02 +03:00
|
|
|
decls[numStreams] = &vertexDecl;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2017-05-14 08:21:02 +03:00
|
|
|
numVertices = bx::uint32_min(UINT32_MAX == draw.m_numVertices
|
|
|
|
? vb.m_size/stride
|
|
|
|
: draw.m_numVertices
|
|
|
|
, numVertices
|
|
|
|
);
|
|
|
|
|
|
|
|
DX_CHECK(device->SetStreamSourceFreq(0, freq) );
|
|
|
|
DX_CHECK(device->SetStreamSource(numStreams, vb.m_ptr, 0, stride) );
|
|
|
|
}
|
|
|
|
|
|
|
|
currentState.m_numVertices = numVertices;
|
|
|
|
|
|
|
|
if (0 < numStreams)
|
|
|
|
{
|
|
|
|
if (instanced)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2014-07-21 07:27:13 +04:00
|
|
|
const VertexBufferD3D9& inst = m_vertexBuffers[draw.m_instanceDataBuffer.idx];
|
2017-05-14 08:21:02 +03:00
|
|
|
DX_CHECK(device->SetStreamSourceFreq(numStreams, UINT(D3DSTREAMSOURCE_INSTANCEDATA|1) ) );
|
|
|
|
DX_CHECK(device->SetStreamSource(numStreams, inst.m_ptr, draw.m_instanceDataOffset, draw.m_instanceDataStride) );
|
|
|
|
setInputLayout(numStreams, decls, draw.m_instanceDataStride/16);
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-05-14 08:21:02 +03:00
|
|
|
DX_CHECK(device->SetStreamSource(numStreams, NULL, 0, 0) );
|
|
|
|
setInputLayout(numStreams, decls, 0);
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DX_CHECK(device->SetStreamSource(0, NULL, 0, 0) );
|
|
|
|
DX_CHECK(device->SetStreamSource(1, NULL, 0, 0) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-21 07:27:13 +04:00
|
|
|
if (currentState.m_indexBuffer.idx != draw.m_indexBuffer.idx)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2014-07-21 07:27:13 +04:00
|
|
|
currentState.m_indexBuffer = draw.m_indexBuffer;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2014-07-21 07:27:13 +04:00
|
|
|
uint16_t handle = draw.m_indexBuffer.idx;
|
2017-06-10 07:57:08 +03:00
|
|
|
if (kInvalidHandle != handle)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2014-05-27 01:09:26 +04:00
|
|
|
const IndexBufferD3D9& ib = m_indexBuffers[handle];
|
2012-08-06 01:51:49 +04:00
|
|
|
DX_CHECK(device->SetIndices(ib.m_ptr) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DX_CHECK(device->SetIndices(NULL) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-16 06:54:00 +03:00
|
|
|
if (0 != currentState.m_streamMask)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2017-05-14 08:21:02 +03:00
|
|
|
uint32_t numVertices = draw.m_numVertices;
|
2015-09-10 23:29:12 +03:00
|
|
|
uint32_t numIndices = 0;
|
2012-08-06 01:51:49 +04:00
|
|
|
uint32_t numPrimsSubmitted = 0;
|
2015-09-10 23:29:12 +03:00
|
|
|
uint32_t numInstances = 0;
|
|
|
|
uint32_t numPrimsRendered = 0;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2015-11-02 04:28:23 +03:00
|
|
|
if (hasOcclusionQuery)
|
|
|
|
{
|
2015-11-04 03:00:14 +03:00
|
|
|
m_occlusionQuery.begin(_render, draw.m_occlusionQuery);
|
2015-11-02 04:28:23 +03:00
|
|
|
}
|
|
|
|
|
2014-07-21 07:27:13 +04:00
|
|
|
if (isValid(draw.m_indexBuffer) )
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2014-07-21 07:27:13 +04:00
|
|
|
if (UINT32_MAX == draw.m_numIndices)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2015-04-09 05:59:48 +03:00
|
|
|
const IndexBufferD3D9& ib = m_indexBuffers[draw.m_indexBuffer.idx];
|
|
|
|
const uint32_t indexSize = 0 == (ib.m_flags & BGFX_BUFFER_INDEX32) ? 2 : 4;
|
2015-04-09 09:25:17 +03:00
|
|
|
numIndices = ib.m_size/indexSize;
|
2014-04-27 10:48:41 +04:00
|
|
|
numPrimsSubmitted = numIndices/prim.m_div - prim.m_sub;
|
2015-04-09 09:25:17 +03:00
|
|
|
numInstances = draw.m_numInstances;
|
|
|
|
numPrimsRendered = numPrimsSubmitted*draw.m_numInstances;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2014-04-27 10:48:41 +04:00
|
|
|
DX_CHECK(device->DrawIndexedPrimitive(prim.m_type
|
2016-09-13 05:38:29 +03:00
|
|
|
, draw.m_stream[0].m_startVertex
|
2012-08-06 01:51:49 +04:00
|
|
|
, 0
|
|
|
|
, numVertices
|
|
|
|
, 0
|
|
|
|
, numPrimsSubmitted
|
|
|
|
) );
|
|
|
|
}
|
2014-07-21 07:27:13 +04:00
|
|
|
else if (prim.m_min <= draw.m_numIndices)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2015-09-10 23:29:12 +03:00
|
|
|
numIndices = draw.m_numIndices;
|
2014-04-27 10:48:41 +04:00
|
|
|
numPrimsSubmitted = numIndices/prim.m_div - prim.m_sub;
|
2015-09-10 23:29:12 +03:00
|
|
|
numInstances = draw.m_numInstances;
|
|
|
|
numPrimsRendered = numPrimsSubmitted*draw.m_numInstances;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2014-04-27 10:48:41 +04:00
|
|
|
DX_CHECK(device->DrawIndexedPrimitive(prim.m_type
|
2016-09-13 05:38:29 +03:00
|
|
|
, draw.m_stream[0].m_startVertex
|
2012-08-06 01:51:49 +04:00
|
|
|
, 0
|
|
|
|
, numVertices
|
2014-07-21 07:27:13 +04:00
|
|
|
, draw.m_startIndex
|
2012-08-06 01:51:49 +04:00
|
|
|
, numPrimsSubmitted
|
|
|
|
) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-04-27 10:48:41 +04:00
|
|
|
numPrimsSubmitted = numVertices/prim.m_div - prim.m_sub;
|
2015-09-10 23:29:12 +03:00
|
|
|
numInstances = draw.m_numInstances;
|
|
|
|
numPrimsRendered = numPrimsSubmitted*draw.m_numInstances;
|
2013-01-22 09:49:42 +04:00
|
|
|
|
2014-04-27 10:48:41 +04:00
|
|
|
DX_CHECK(device->DrawPrimitive(prim.m_type
|
2016-09-13 05:38:29 +03:00
|
|
|
, draw.m_stream[0].m_startVertex
|
2012-08-06 01:51:49 +04:00
|
|
|
, numPrimsSubmitted
|
|
|
|
) );
|
|
|
|
}
|
|
|
|
|
2015-11-02 04:28:23 +03:00
|
|
|
if (hasOcclusionQuery)
|
|
|
|
{
|
|
|
|
m_occlusionQuery.end();
|
|
|
|
}
|
|
|
|
|
2014-04-27 10:48:41 +04:00
|
|
|
statsNumPrimsSubmitted[primIndex] += numPrimsSubmitted;
|
|
|
|
statsNumPrimsRendered[primIndex] += numPrimsRendered;
|
|
|
|
statsNumInstances[primIndex] += numInstances;
|
2012-08-06 01:51:49 +04:00
|
|
|
statsNumIndices += numIndices;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-06 08:22:14 +03:00
|
|
|
submitBlit(bs, BGFX_CONFIG_MAX_VIEWS);
|
|
|
|
|
2017-10-08 04:17:16 +03:00
|
|
|
if (0 < _render->m_numRenderItems)
|
2013-01-02 01:19:10 +04:00
|
|
|
{
|
2018-04-18 01:42:18 +03:00
|
|
|
if (0 != (m_resolution.reset & BGFX_RESET_FLUSH_AFTER_RENDER) )
|
2015-05-15 23:14:35 +03:00
|
|
|
{
|
2016-11-16 03:57:28 +03:00
|
|
|
flush();
|
2015-05-15 23:14:35 +03:00
|
|
|
}
|
|
|
|
|
2013-01-02 01:19:10 +04:00
|
|
|
captureElapsed = -bx::getHPCounter();
|
2014-05-27 01:09:26 +04:00
|
|
|
capture();
|
2013-01-02 01:19:10 +04:00
|
|
|
captureElapsed += bx::getHPCounter();
|
2015-11-16 17:42:56 +03:00
|
|
|
|
2017-08-28 06:34:00 +03:00
|
|
|
profiler.end();
|
2013-01-02 01:19:10 +04:00
|
|
|
}
|
2012-08-06 01:51:49 +04:00
|
|
|
}
|
|
|
|
|
2014-10-26 05:16:24 +03:00
|
|
|
PIX_ENDEVENT();
|
|
|
|
|
2017-09-22 07:34:02 +03:00
|
|
|
int64_t timeEnd = bx::getHPCounter();
|
|
|
|
int64_t frameTime = timeEnd - timeBegin;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
|
|
|
static int64_t min = frameTime;
|
|
|
|
static int64_t max = frameTime;
|
|
|
|
min = min > frameTime ? frameTime : min;
|
|
|
|
max = max < frameTime ? frameTime : max;
|
|
|
|
|
2015-07-23 04:05:11 +03:00
|
|
|
static uint32_t maxGpuLatency = 0;
|
|
|
|
static double maxGpuElapsed = 0.0f;
|
|
|
|
double elapsedGpuMs = 0.0;
|
|
|
|
|
2017-08-28 06:34:00 +03:00
|
|
|
if (UINT32_MAX != frameQueryIdx)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2017-08-28 06:34:00 +03:00
|
|
|
m_gpuTimer.end(frameQueryIdx);
|
2015-08-21 23:07:58 +03:00
|
|
|
|
2017-08-28 06:34:00 +03:00
|
|
|
const TimerQueryD3D9::Result& result = m_gpuTimer.m_result[BGFX_CONFIG_MAX_VIEWS];
|
|
|
|
double toGpuMs = 1000.0 / double(result.m_frequency);
|
|
|
|
elapsedGpuMs = (result.m_end - result.m_begin) * toGpuMs;
|
|
|
|
maxGpuElapsed = elapsedGpuMs > maxGpuElapsed ? elapsedGpuMs : maxGpuElapsed;
|
2016-06-14 02:45:29 +03:00
|
|
|
|
2017-08-28 06:34:00 +03:00
|
|
|
maxGpuLatency = bx::uint32_imax(maxGpuLatency, result.m_pending-1);
|
2015-07-23 04:05:11 +03:00
|
|
|
}
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2015-07-23 04:05:11 +03:00
|
|
|
const int64_t timerFreq = bx::getHPFrequency();
|
2015-05-13 03:03:25 +03:00
|
|
|
|
2017-09-22 07:34:02 +03:00
|
|
|
Stats& perfStats = _render->m_perfStats;
|
|
|
|
perfStats.cpuTimeBegin = timeBegin;
|
|
|
|
perfStats.cpuTimeEnd = timeEnd;
|
2016-12-20 04:18:07 +03:00
|
|
|
perfStats.cpuTimerFreq = timerFreq;
|
2017-08-28 06:34:00 +03:00
|
|
|
const TimerQueryD3D9::Result& result = m_gpuTimer.m_result[BGFX_CONFIG_MAX_VIEWS];
|
|
|
|
perfStats.gpuTimeBegin = result.m_begin;
|
|
|
|
perfStats.gpuTimeEnd = result.m_end;
|
|
|
|
perfStats.gpuTimerFreq = result.m_frequency;
|
2016-12-20 04:18:07 +03:00
|
|
|
perfStats.numDraw = statsKeyType[0];
|
|
|
|
perfStats.numCompute = statsKeyType[1];
|
|
|
|
perfStats.maxGpuLatency = maxGpuLatency;
|
2018-05-18 03:24:10 +03:00
|
|
|
bx::memCopy(perfStats.numPrims, statsNumPrimsRendered, sizeof(perfStats.numPrims) );
|
2017-10-02 07:18:29 +03:00
|
|
|
m_nvapi.getMemoryInfo(perfStats.gpuMemoryUsed, perfStats.gpuMemoryMax);
|
2015-05-13 03:03:25 +03:00
|
|
|
|
2015-07-23 04:05:11 +03:00
|
|
|
if (_render->m_debug & (BGFX_DEBUG_IFH|BGFX_DEBUG_STATS) )
|
|
|
|
{
|
2016-08-24 23:16:04 +03:00
|
|
|
PIX_BEGINEVENT(D3DCOLOR_FRAME, L"debugstats");
|
2015-05-13 03:03:25 +03:00
|
|
|
|
2017-01-11 04:14:50 +03:00
|
|
|
m_needPresent = true;
|
2014-05-27 01:09:26 +04:00
|
|
|
TextVideoMem& tvm = m_textVideoMem;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2017-09-22 07:34:02 +03:00
|
|
|
static int64_t next = timeEnd;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2017-09-22 07:34:02 +03:00
|
|
|
if (timeEnd >= next)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2017-09-22 07:34:02 +03:00
|
|
|
next = timeEnd + timerFreq;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2015-07-23 04:05:11 +03:00
|
|
|
double freq = double(timerFreq);
|
2012-08-06 01:51:49 +04:00
|
|
|
double toMs = 1000.0/freq;
|
|
|
|
|
|
|
|
tvm.clear();
|
2013-04-28 03:55:34 +04:00
|
|
|
uint16_t pos = 0;
|
2018-01-27 03:40:34 +03:00
|
|
|
tvm.printf(0, pos++, BGFX_CONFIG_DEBUG ? 0x8c : 0x8f
|
|
|
|
, " %s / " BX_COMPILER_NAME " / " BX_CPU_NAME " / " BX_ARCH_NAME " / " BX_PLATFORM_NAME " "
|
2014-05-27 01:09:26 +04:00
|
|
|
, getRendererName()
|
|
|
|
);
|
2013-04-28 03:55:34 +04:00
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
const D3DADAPTER_IDENTIFIER9& identifier = m_identifier;
|
2018-03-06 05:15:35 +03:00
|
|
|
tvm.printf(0, pos++, 0x8f, " Device: %s (%s)", identifier.Description, identifier.Driver);
|
2013-04-28 03:55:34 +04:00
|
|
|
|
2015-09-10 03:26:55 +03:00
|
|
|
char processMemoryUsed[16];
|
|
|
|
bx::prettify(processMemoryUsed, BX_COUNTOF(processMemoryUsed), bx::getProcessMemoryUsed() );
|
2018-03-06 05:15:35 +03:00
|
|
|
tvm.printf(0, pos++, 0x8f, " Memory: %s (process) ", processMemoryUsed);
|
2015-09-10 03:26:55 +03:00
|
|
|
|
2013-04-28 03:55:34 +04:00
|
|
|
pos = 10;
|
2018-01-27 03:40:34 +03:00
|
|
|
tvm.printf(10, pos++, 0x8b, " Frame: %7.3f, % 7.3f \x1f, % 7.3f \x1e [ms] / % 6.2f FPS "
|
2012-08-06 01:51:49 +04:00
|
|
|
, double(frameTime)*toMs
|
|
|
|
, double(min)*toMs
|
|
|
|
, double(max)*toMs
|
|
|
|
, freq/frameTime
|
2014-02-06 11:07:11 +04:00
|
|
|
);
|
|
|
|
|
2018-04-18 01:42:18 +03:00
|
|
|
const uint32_t msaa = (m_resolution.reset&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT;
|
2018-01-27 03:40:34 +03:00
|
|
|
tvm.printf(10, pos++, 0x8b, " Reset flags: [%c] vsync, [%c] MSAAx%d, [%c] MaxAnisotropy "
|
2018-04-18 01:42:18 +03:00
|
|
|
, !!(m_resolution.reset&BGFX_RESET_VSYNC) ? '\xfe' : ' '
|
2014-02-06 11:07:11 +04:00
|
|
|
, 0 != msaa ? '\xfe' : ' '
|
|
|
|
, 1<<msaa
|
2018-04-18 01:42:18 +03:00
|
|
|
, !!(m_resolution.reset&BGFX_RESET_MAXANISOTROPY) ? '\xfe' : ' '
|
2012-08-06 01:51:49 +04:00
|
|
|
);
|
2012-12-31 08:52:47 +04:00
|
|
|
|
2017-09-22 07:34:02 +03:00
|
|
|
double elapsedCpuMs = double(frameTime)*toMs;
|
2018-01-27 03:40:34 +03:00
|
|
|
tvm.printf(10, pos++, 0x8b, " Submitted: %5d (draw %5d, compute %4d) / CPU %7.4f [ms] %c GPU %7.4f [ms] (latency %d)"
|
2017-10-08 04:17:16 +03:00
|
|
|
, _render->m_numRenderItems
|
2015-03-27 08:43:50 +03:00
|
|
|
, statsKeyType[0]
|
|
|
|
, statsKeyType[1]
|
2012-08-06 01:51:49 +04:00
|
|
|
, elapsedCpuMs
|
2015-05-13 03:03:25 +03:00
|
|
|
, elapsedCpuMs > maxGpuElapsed ? '>' : '<'
|
|
|
|
, maxGpuElapsed
|
|
|
|
, maxGpuLatency
|
2012-08-06 01:51:49 +04:00
|
|
|
);
|
2015-05-13 03:03:25 +03:00
|
|
|
maxGpuLatency = 0;
|
|
|
|
maxGpuElapsed = 0.0;
|
|
|
|
|
2018-05-18 03:24:10 +03:00
|
|
|
for (uint32_t ii = 0; ii < Topology::Count; ++ii)
|
2014-04-27 10:48:41 +04:00
|
|
|
{
|
2018-01-27 03:40:34 +03:00
|
|
|
tvm.printf(10, pos++, 0x8b, " %10s: %7d (#inst: %5d), submitted: %7d"
|
2018-05-18 03:24:10 +03:00
|
|
|
, getName(Topology::Enum(ii) )
|
2014-04-27 10:48:41 +04:00
|
|
|
, statsNumPrimsRendered[ii]
|
|
|
|
, statsNumInstances[ii]
|
|
|
|
, statsNumPrimsSubmitted[ii]
|
|
|
|
);
|
|
|
|
}
|
2012-12-31 08:52:47 +04:00
|
|
|
|
2018-01-27 03:40:34 +03:00
|
|
|
tvm.printf(10, pos++, 0x8b, " Indices: %7d ", statsNumIndices);
|
|
|
|
// tvm.printf(10, pos++, 0x8b, " Uniform size: %7d, Max: %7d ", _render->m_uniformEnd, _render->m_uniformMax);
|
|
|
|
tvm.printf(10, pos++, 0x8b, " DVB size: %7d ", _render->m_vboffset);
|
|
|
|
tvm.printf(10, pos++, 0x8b, " DIB size: %7d ", _render->m_iboffset);
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2015-12-04 01:39:26 +03:00
|
|
|
pos++;
|
2018-01-27 03:40:34 +03:00
|
|
|
tvm.printf(10, pos++, 0x8b, " Occlusion queries: %3d ", m_occlusionQuery.m_control.available() );
|
2017-05-14 08:21:02 +03:00
|
|
|
|
|
|
|
pos++;
|
2018-01-27 03:40:34 +03:00
|
|
|
tvm.printf(10, pos++, 0x8b, " State cache: ");
|
|
|
|
tvm.printf(10, pos++, 0x8b, " Input ");
|
|
|
|
tvm.printf(10, pos++, 0x8b, " %6d "
|
2017-05-14 08:21:02 +03:00
|
|
|
, m_inputLayoutCache.getCount()
|
|
|
|
);
|
|
|
|
pos++;
|
|
|
|
|
2014-04-27 10:48:41 +04:00
|
|
|
double captureMs = double(captureElapsed)*toMs;
|
2018-01-27 03:40:34 +03:00
|
|
|
tvm.printf(10, pos++, 0x8b, " Capture: %7.4f [ms]", captureMs);
|
2014-04-27 10:48:41 +04:00
|
|
|
|
2018-01-27 03:40:34 +03:00
|
|
|
uint8_t attr[2] = { 0x8c, 0x8a };
|
2014-05-27 01:09:26 +04:00
|
|
|
uint8_t attrIndex = _render->m_waitSubmit < _render->m_waitRender;
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2015-08-16 20:30:29 +03:00
|
|
|
tvm.printf(10, pos++, attr[attrIndex&1], " Submit wait: %7.4f [ms]", _render->m_waitSubmit*toMs);
|
|
|
|
tvm.printf(10, pos++, attr[(attrIndex+1)&1], " Render wait: %7.4f [ms]", _render->m_waitRender*toMs);
|
2012-08-06 01:51:49 +04:00
|
|
|
|
|
|
|
min = frameTime;
|
|
|
|
max = frameTime;
|
|
|
|
}
|
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
blit(this, _textVideoMemBlitter, tvm);
|
2012-08-06 01:51:49 +04:00
|
|
|
|
|
|
|
PIX_ENDEVENT();
|
|
|
|
}
|
2014-05-27 01:09:26 +04:00
|
|
|
else if (_render->m_debug & BGFX_DEBUG_TEXT)
|
2012-08-06 01:51:49 +04:00
|
|
|
{
|
2016-08-24 23:16:04 +03:00
|
|
|
PIX_BEGINEVENT(D3DCOLOR_FRAME, L"debugtext");
|
2012-08-06 01:51:49 +04:00
|
|
|
|
2014-05-27 01:09:26 +04:00
|
|
|
blit(this, _textVideoMemBlitter, _render->m_textVideoMem);
|
2012-08-06 01:51:49 +04:00
|
|
|
|
|
|
|
PIX_ENDEVENT();
|
|
|
|
}
|
|
|
|
|
|
|
|
device->EndScene();
|
|
|
|
}
|
2015-03-22 08:11:59 +03:00
|
|
|
} /* namespace d3d9 */ } // namespace bgfx
|
2014-05-27 01:09:26 +04:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2015-03-22 08:11:59 +03:00
|
|
|
namespace bgfx { namespace d3d9
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
2017-12-08 08:52:52 +03:00
|
|
|
RendererContextI* rendererCreate(const Init& _init)
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
2017-12-08 08:52:52 +03:00
|
|
|
BX_UNUSED(_init);
|
2014-05-27 01:09:26 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-03-22 08:11:59 +03:00
|
|
|
void rendererDestroy()
|
2014-05-27 01:09:26 +04:00
|
|
|
{
|
|
|
|
}
|
2015-03-22 08:11:59 +03:00
|
|
|
} /* namespace d3d9 */ } // namespace bgfx
|
2012-08-06 01:51:49 +04:00
|
|
|
|
|
|
|
#endif // BGFX_CONFIG_RENDERER_DIRECT3D9
|