diff --git a/src/bgfx_p.h b/src/bgfx_p.h index 48972f694..2f67d83c4 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -2746,8 +2746,12 @@ namespace bgfx if (!isValid(declHandle) ) { - VertexDeclHandle temp = { m_vertexDeclHandle.alloc() }; - declHandle = temp; + declHandle.idx = m_vertexDeclHandle.alloc(); + if (!isValid(declHandle) ) + { + return declHandle; + } + CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateVertexDecl); cmdbuf.write(declHandle); cmdbuf.write(_decl); @@ -2762,10 +2766,16 @@ namespace bgfx VertexBufferHandle handle = { m_vertexBufferHandle.alloc() }; - BX_WARN(isValid(handle), "Failed to allocate vertex buffer handle."); if (isValid(handle) ) { VertexDeclHandle declHandle = findVertexDecl(_decl); + if (!isValid(declHandle) ) + { + BX_TRACE("WARNING: Failed to allocate vertex decl handle (BGFX_CONFIG_MAX_VERTEX_DECLS, max: %d).", BGFX_CONFIG_MAX_VERTEX_DECLS); + m_vertexBufferHandle.free(handle.idx); + return BGFX_INVALID_HANDLE; + } + m_declRef.add(handle, declHandle, _decl.m_hash); m_vertexBuffers[handle.idx].m_stride = _decl.m_stride; @@ -2775,13 +2785,14 @@ namespace bgfx cmdbuf.write(_mem); cmdbuf.write(declHandle); cmdbuf.write(_flags); - } - else - { - release(_mem); + + return handle; } - return handle; + BX_TRACE("WARNING: Failed to allocate vertex buffer handle (BGFX_CONFIG_MAX_VERTEX_BUFFERS, max: %d).", BGFX_CONFIG_MAX_VERTEX_BUFFERS); + release(_mem); + + return BGFX_INVALID_HANDLE; } BGFX_API_FUNC(void destroyVertexBuffer(VertexBufferHandle _handle) ) @@ -3017,6 +3028,7 @@ namespace bgfx VertexBufferHandle vertexBufferHandle = { m_vertexBufferHandle.alloc() }; if (!isValid(vertexBufferHandle) ) { + BX_TRACE("WARNING: Failed to allocate vertex buffer handle (BGFX_CONFIG_MAX_VERTEX_BUFFERS, max: %d).", BGFX_CONFIG_MAX_VERTEX_BUFFERS); return handle; } @@ -3037,8 +3049,19 @@ namespace bgfx } VertexDeclHandle declHandle = findVertexDecl(_decl); + if (!isValid(declHandle) ) + { + BX_TRACE("WARNING: Failed to allocate vertex decl handle (BGFX_CONFIG_MAX_VERTEX_DECLS, max: %d).", BGFX_CONFIG_MAX_VERTEX_DECLS); + return handle; + } handle.idx = m_dynamicVertexBufferHandle.alloc(); + if (!isValid(handle) ) + { + BX_TRACE("WARNING: Failed to allocate dynamic vertex buffer handle (BGFX_CONFIG_MAX_DYNAMIC_VERTEX_BUFFERS, max: %d).", BGFX_CONFIG_MAX_DYNAMIC_VERTEX_BUFFERS); + return handle; + } + DynamicVertexBuffer& dvb = m_dynamicVertexBuffers[handle.idx]; dvb.m_handle.idx = uint16_t(ptr>>32); dvb.m_offset = uint32_t(ptr); diff --git a/src/renderer_d3d.h b/src/renderer_d3d.h index 3b0f48a0c..a654ab073 100644 --- a/src/renderer_d3d.h +++ b/src/renderer_d3d.h @@ -71,10 +71,10 @@ namespace bgfx #define DX_RELEASE(_ptr, _expected) _DX_RELEASE(_ptr, _expected, BX_CHECK) #define DX_RELEASE_WARNONLY(_ptr, _expected) _DX_RELEASE(_ptr, _expected, BX_WARN) - typedef int (WINAPI* PFN_D3DPERF_BEGIN_EVENT)(DWORD _color, LPCWSTR _wszName); + typedef int (WINAPI* PFN_D3DPERF_BEGIN_EVENT)(DWORD _color, LPCWSTR _name); typedef int (WINAPI* PFN_D3DPERF_END_EVENT)(); - typedef void (WINAPI* PFN_D3DPERF_SET_MARKER)(DWORD _color, LPCWSTR _wszName); - typedef void (WINAPI* PFN_D3DPERF_SET_REGION)(DWORD _color, LPCWSTR _wszName); + typedef void (WINAPI* PFN_D3DPERF_SET_MARKER)(DWORD _color, LPCWSTR _name); + typedef void (WINAPI* PFN_D3DPERF_SET_REGION)(DWORD _color, LPCWSTR _name); typedef BOOL (WINAPI* PFN_D3DPERF_QUERY_REPEAT_FRAME)(); typedef void (WINAPI* PFN_D3DPERF_SET_OPTIONS)(DWORD _options); typedef DWORD (WINAPI* PFN_D3DPERF_GET_STATUS)(); diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index 524f0c3f1..16a3db33f 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -399,19 +399,20 @@ namespace bgfx { namespace d3d11 BX_PRAGMA_DIAGNOSTIC_IGNORED_CLANG("-Wunused-const-variable"); BX_PRAGMA_DIAGNOSTIC_IGNORED_CLANG("-Wunneeded-internal-declaration"); - static const GUID WKPDID_D3DDebugObjectName = { 0x429b8c22, 0x9188, 0x4b0c, { 0x87, 0x42, 0xac, 0xb0, 0xbf, 0x85, 0xc2, 0x00 } }; - static const GUID IID_ID3D11Texture2D = { 0x6f15aaf2, 0xd208, 0x4e89, { 0x9a, 0xb4, 0x48, 0x95, 0x35, 0xd3, 0x4f, 0x9c } }; - static const GUID IID_IDXGIFactory = { 0x7b7166ec, 0x21c7, 0x44ae, { 0xb2, 0x1a, 0xc9, 0xae, 0x32, 0x1a, 0xe3, 0x69 } }; - static const GUID IID_IDXGIDevice0 = { 0x54ec77fa, 0x1377, 0x44e6, { 0x8c, 0x32, 0x88, 0xfd, 0x5f, 0x44, 0xc8, 0x4c } }; - static const GUID IID_IDXGIDevice1 = { 0x77db970f, 0x6276, 0x48ba, { 0xba, 0x28, 0x07, 0x01, 0x43, 0xb4, 0x39, 0x2c } }; - static const GUID IID_IDXGIDevice2 = { 0x05008617, 0xfbfd, 0x4051, { 0xa7, 0x90, 0x14, 0x48, 0x84, 0xb4, 0xf6, 0xa9 } }; - static const GUID IID_IDXGIDevice3 = { 0x6007896c, 0x3244, 0x4afd, { 0xbf, 0x18, 0xa6, 0xd3, 0xbe, 0xda, 0x50, 0x23 } }; - static const GUID IID_ID3D11Device1 = { 0xa04bfb29, 0x08ef, 0x43d6, { 0xa4, 0x9c, 0xa9, 0xbd, 0xbd, 0xcb, 0xe6, 0x86 } }; - static const GUID IID_ID3D11Device2 = { 0x9d06dffa, 0xd1e5, 0x4d07, { 0x83, 0xa8, 0x1b, 0xb1, 0x23, 0xf2, 0xf8, 0x41 } }; - static const GUID IID_ID3D11Device3 = { 0xa05c8c37, 0xd2c6, 0x4732, { 0xb3, 0xa0, 0x9c, 0xe0, 0xb0, 0xdc, 0x9a, 0xe6 } }; - static const GUID IID_IDXGIAdapter = { 0x2411e7e1, 0x12ac, 0x4ccf, { 0xbd, 0x14, 0x97, 0x98, 0xe8, 0x53, 0x4d, 0xc0 } }; - static const GUID IID_ID3D11InfoQueue = { 0x6543dbb6, 0x1b48, 0x42f5, { 0xab, 0x82, 0xe9, 0x7e, 0xc7, 0x43, 0x26, 0xf6 } }; - static const GUID IID_IDXGIDeviceRenderDoc = { 0xa7aa6116, 0x9c8d, 0x4bba, { 0x90, 0x83, 0xb4, 0xd8, 0x16, 0xb7, 0x1b, 0x78 } }; + static const GUID WKPDID_D3DDebugObjectName = { 0x429b8c22, 0x9188, 0x4b0c, { 0x87, 0x42, 0xac, 0xb0, 0xbf, 0x85, 0xc2, 0x00 } }; + static const GUID IID_ID3D11Texture2D = { 0x6f15aaf2, 0xd208, 0x4e89, { 0x9a, 0xb4, 0x48, 0x95, 0x35, 0xd3, 0x4f, 0x9c } }; + static const GUID IID_IDXGIFactory = { 0x7b7166ec, 0x21c7, 0x44ae, { 0xb2, 0x1a, 0xc9, 0xae, 0x32, 0x1a, 0xe3, 0x69 } }; + static const GUID IID_IDXGIDevice0 = { 0x54ec77fa, 0x1377, 0x44e6, { 0x8c, 0x32, 0x88, 0xfd, 0x5f, 0x44, 0xc8, 0x4c } }; + static const GUID IID_IDXGIDevice1 = { 0x77db970f, 0x6276, 0x48ba, { 0xba, 0x28, 0x07, 0x01, 0x43, 0xb4, 0x39, 0x2c } }; + static const GUID IID_IDXGIDevice2 = { 0x05008617, 0xfbfd, 0x4051, { 0xa7, 0x90, 0x14, 0x48, 0x84, 0xb4, 0xf6, 0xa9 } }; + static const GUID IID_IDXGIDevice3 = { 0x6007896c, 0x3244, 0x4afd, { 0xbf, 0x18, 0xa6, 0xd3, 0xbe, 0xda, 0x50, 0x23 } }; + static const GUID IID_ID3D11Device1 = { 0xa04bfb29, 0x08ef, 0x43d6, { 0xa4, 0x9c, 0xa9, 0xbd, 0xbd, 0xcb, 0xe6, 0x86 } }; + static const GUID IID_ID3D11Device2 = { 0x9d06dffa, 0xd1e5, 0x4d07, { 0x83, 0xa8, 0x1b, 0xb1, 0x23, 0xf2, 0xf8, 0x41 } }; + static const GUID IID_ID3D11Device3 = { 0xa05c8c37, 0xd2c6, 0x4732, { 0xb3, 0xa0, 0x9c, 0xe0, 0xb0, 0xdc, 0x9a, 0xe6 } }; + static const GUID IID_IDXGIAdapter = { 0x2411e7e1, 0x12ac, 0x4ccf, { 0xbd, 0x14, 0x97, 0x98, 0xe8, 0x53, 0x4d, 0xc0 } }; + static const GUID IID_ID3D11InfoQueue = { 0x6543dbb6, 0x1b48, 0x42f5, { 0xab, 0x82, 0xe9, 0x7e, 0xc7, 0x43, 0x26, 0xf6 } }; + static const GUID IID_IDXGIDeviceRenderDoc = { 0xa7aa6116, 0x9c8d, 0x4bba, { 0x90, 0x83, 0xb4, 0xd8, 0x16, 0xb7, 0x1b, 0x78 } }; + static const GUID IID_ID3DUserDefinedAnnotation = { 0xb2daad8b, 0x03d4, 0x4dbf, { 0x95, 0xeb, 0x32, 0xab, 0x4b, 0x63, 0xd0, 0xab } }; enum D3D11_FORMAT_SUPPORT2 { @@ -639,6 +640,10 @@ namespace bgfx { namespace d3d11 static PFN_GET_DEBUG_INTERFACE1 DXGIGetDebugInterface1; #endif // USE_D3D11_DYNAMIC_LIB + int WINAPI d3d11Annotation_BeginEvent(DWORD _color, LPCWSTR _name); + int WINAPI d3d11Annotation_EndEvent(); + void WINAPI d3d11Annotation_SetMarker(DWORD _color, LPCWSTR _name); + #if BGFX_CONFIG_USE_OVR class VRImplOVRD3D11 : public VRImplOVR { @@ -1272,6 +1277,20 @@ BX_PRAGMA_DIAGNOSTIC_POP(); m_numWindows = 1; +#if USE_D3D11_DYNAMIC_LIB + if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) + { + hr = m_deviceCtx->QueryInterface(IID_ID3DUserDefinedAnnotation, (void**)&m_annotation); + + if (SUCCEEDED(hr) ) + { + D3DPERF_BeginEvent = d3d11Annotation_BeginEvent; + D3DPERF_EndEvent = d3d11Annotation_EndEvent; + D3DPERF_SetMarker = d3d11Annotation_SetMarker; + } + } +#endif // USE_D3D11_DYNAMIC_LIB + if (BX_ENABLED(BGFX_CONFIG_DEBUG) ) { hr = m_device->QueryInterface(IID_ID3D11InfoQueue, (void**)&m_infoQueue); @@ -3685,11 +3704,13 @@ BX_PRAGMA_DIAGNOSTIC_POP(); uint16_t m_numWindows; FrameBufferHandle m_windows[BGFX_CONFIG_MAX_FRAME_BUFFERS]; - ID3D11Device* m_device; - ID3D11DeviceContext* m_deviceCtx; - ID3D11InfoQueue* m_infoQueue; - TimerQueryD3D11 m_gpuTimer; - OcclusionQueryD3D11 m_occlusionQuery; + ID3D11Device* m_device; + ID3D11DeviceContext* m_deviceCtx; + ID3DUserDefinedAnnotation* m_annotation; + ID3D11InfoQueue* m_infoQueue; + + TimerQueryD3D11 m_gpuTimer; + OcclusionQueryD3D11 m_occlusionQuery; uint32_t m_deviceInterfaceVersion; @@ -3803,6 +3824,23 @@ BX_PRAGMA_DIAGNOSTIC_POP(); agsDriverExtensions_MultiDrawIndexedInstancedIndirect(s_renderD3D11->m_ags, _numDrawIndirect, _ptr, _offset, _stride); } + int WINAPI d3d11Annotation_BeginEvent(DWORD _color, LPCWSTR _name) + { + BX_UNUSED(_color); + return s_renderD3D11->m_annotation->BeginEvent(_name); + } + + int WINAPI d3d11Annotation_EndEvent() + { + return s_renderD3D11->m_annotation->EndEvent(); + } + + void WINAPI d3d11Annotation_SetMarker(DWORD _color, LPCWSTR _name) + { + BX_UNUSED(_color); + s_renderD3D11->m_annotation->SetMarker(_name); + } + #if BGFX_CONFIG_USE_OVR VRImplOVRD3D11::VRImplOVRD3D11()