From 47f100d70fd183a01f676c0921714aa8c8d95829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Wed, 10 Dec 2014 21:09:13 -0800 Subject: [PATCH] Fixed compute buffer. --- src/bgfx_p.h | 39 +++++++++++++++++---------------------- src/renderer_d3d11.cpp | 32 ++++++++++++++++---------------- src/renderer_d3d9.cpp | 2 +- 3 files changed, 34 insertions(+), 39 deletions(-) diff --git a/src/bgfx_p.h b/src/bgfx_p.h index 8ff6e371c..430b7421a 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -2051,23 +2051,18 @@ namespace bgfx uint64_t ptr = 0; if (0 != (_flags & BGFX_BUFFER_COMPUTE_WRITE) ) { - ptr = m_gpuDvbAllocator.alloc(size); - if (ptr == NonLocalAllocator::invalidBlock) + VertexBufferHandle vertexBufferHandle = { m_vertexBufferHandle.alloc() }; + if (!isValid(vertexBufferHandle) ) { - VertexBufferHandle vertexBufferHandle = { m_vertexBufferHandle.alloc() }; - if (!isValid(vertexBufferHandle) ) - { - return handle; - } - - CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateDynamicVertexBuffer); - cmdbuf.write(vertexBufferHandle); - cmdbuf.write(BGFX_CONFIG_DYNAMIC_VERTEX_BUFFER_SIZE); - cmdbuf.write(_flags); - - m_gpuDvbAllocator.add(uint64_t(vertexBufferHandle.idx)<<32, BGFX_CONFIG_DYNAMIC_VERTEX_BUFFER_SIZE); - ptr = m_gpuDvbAllocator.alloc(size); + return handle; } + + CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateDynamicVertexBuffer); + cmdbuf.write(vertexBufferHandle); + cmdbuf.write(size); + cmdbuf.write(_flags); + + ptr = uint64_t(vertexBufferHandle.idx)<<32; } else { @@ -2096,13 +2091,14 @@ namespace bgfx handle.idx = m_dynamicVertexBufferHandle.alloc(); DynamicVertexBuffer& dvb = m_dynamicVertexBuffers[handle.idx]; - dvb.m_handle.idx = uint16_t(ptr>>32); - dvb.m_offset = uint32_t(ptr); - dvb.m_size = size; + dvb.m_handle.idx = uint16_t(ptr>>32); + dvb.m_offset = uint32_t(ptr); + dvb.m_size = size; dvb.m_startVertex = dvb.m_offset/_decl.m_stride; dvb.m_numVertices = dvb.m_size/_decl.m_stride; - dvb.m_decl = declHandle; - dvb.m_flags = _flags; + dvb.m_stride = _decl.m_stride; + dvb.m_decl = declHandle; + dvb.m_flags = _flags; m_declRef.add(dvb.m_handle, declHandle, _decl.m_hash); return handle; @@ -2149,7 +2145,7 @@ namespace bgfx if (0 != (dvb.m_flags & BGFX_BUFFER_COMPUTE_WRITE) ) { - m_gpuDvbAllocator.free(uint64_t(dvb.m_handle.idx)<<32 | dvb.m_offset); + destroyVertexBuffer(dvb.m_handle); } else { @@ -3131,7 +3127,6 @@ namespace bgfx NonLocalAllocator m_dynamicIndexBufferAllocator; bx::HandleAllocT m_dynamicIndexBufferHandle; NonLocalAllocator m_cpuDvbAllocator; - NonLocalAllocator m_gpuDvbAllocator; bx::HandleAllocT m_dynamicVertexBufferHandle; bx::HandleAllocT m_indexBufferHandle; diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index 88df6541b..ce429fd8b 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -1303,14 +1303,14 @@ RENDERDOC_IMPORT { m_deviceCtx->CSSetShader(NULL, NULL, 0); - ID3D11UnorderedAccessView* uav[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS] = {}; - m_deviceCtx->CSSetUnorderedAccessViews(0, BGFX_CONFIG_MAX_TEXTURE_SAMPLERS, uav, NULL); + ID3D11UnorderedAccessView* uav[BGFX_MAX_COMPUTE_BINDINGS] = {}; + m_deviceCtx->CSSetUnorderedAccessViews(0, BX_COUNTOF(uav), uav, NULL); - ID3D11ShaderResourceView* srv[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS] = {}; - m_deviceCtx->CSSetShaderResources(0, BGFX_CONFIG_MAX_TEXTURE_SAMPLERS, srv); + ID3D11ShaderResourceView* srv[BGFX_MAX_COMPUTE_BINDINGS] = {}; + m_deviceCtx->CSSetShaderResources(0, BX_COUNTOF(srv), srv); - ID3D11SamplerState* samplers[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS] = {}; - m_deviceCtx->CSSetSamplers(0, BGFX_CONFIG_MAX_TEXTURE_SAMPLERS, samplers); + ID3D11SamplerState* samplers[BGFX_MAX_COMPUTE_BINDINGS] = {}; + m_deviceCtx->CSSetSamplers(0, BX_COUNTOF(samplers), samplers); } void updateMsaa() @@ -1344,10 +1344,10 @@ RENDERDOC_IMPORT || getBufferHeight() != _resolution.m_height || m_flags != flags) { - bool resize = (m_flags&BGFX_RESET_MSAA_MASK) == (flags&BGFX_RESET_MSAA_MASK); -#if BX_PLATFORM_WINRT - resize = false; // can't use ResizeBuffers on Windows Phone -#endif + bool resize = true + && !BX_ENABLED(BX_PLATFORM_WINRT) // can't use ResizeBuffers on Windows Phone + && (m_flags&BGFX_RESET_MSAA_MASK) == (flags&BGFX_RESET_MSAA_MASK) + ; m_flags = flags; m_textVideoMem.resize(false, _resolution.m_width, _resolution.m_height); @@ -1390,7 +1390,7 @@ RENDERDOC_IMPORT , &m_scd , &m_swapChain ); -#endif +#endif // BX_PLATFORM_WINRT BGFX_FATAL(SUCCEEDED(hr), bgfx::Fatal::UnableToInitialize, "Failed to create swap chain."); } @@ -3346,7 +3346,7 @@ RENDERDOC_IMPORT BX_UNUSED(programChanged); ID3D11UnorderedAccessView* uav[BGFX_MAX_COMPUTE_BINDINGS] = {}; ID3D11ShaderResourceView* srv[BGFX_MAX_COMPUTE_BINDINGS] = {}; - ID3D11SamplerState* sampler[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS] = {}; + ID3D11SamplerState* sampler[BGFX_MAX_COMPUTE_BINDINGS] = {}; for (uint32_t ii = 0; ii < BGFX_MAX_COMPUTE_BINDINGS; ++ii) { @@ -3387,9 +3387,9 @@ RENDERDOC_IMPORT } } - deviceCtx->CSSetUnorderedAccessViews(0, BGFX_MAX_COMPUTE_BINDINGS, uav, NULL); - deviceCtx->CSSetShaderResources(0, BGFX_MAX_COMPUTE_BINDINGS, srv); - deviceCtx->CSSetSamplers(0, BGFX_MAX_COMPUTE_BINDINGS, sampler); + deviceCtx->CSSetUnorderedAccessViews(0, BX_COUNTOF(uav), uav, NULL); + deviceCtx->CSSetShaderResources(0, BX_COUNTOF(srv), srv); + deviceCtx->CSSetSamplers(0, BX_COUNTOF(sampler), sampler); deviceCtx->Dispatch(compute.m_numX, compute.m_numY, compute.m_numZ); @@ -3957,7 +3957,7 @@ RENDERDOC_IMPORT ); for (uint32_t ii = 0; ii < BX_COUNTOF(s_primName); ++ii) { - tvm.printf(10, pos++, 0x8e, " %8s: %7d (#inst: %5d), submitted: %7d" + tvm.printf(10, pos++, 0x8e, " %9s: %7d (#inst: %5d), submitted: %7d" , s_primName[ii] , statsNumPrimsRendered[ii] , statsNumInstances[ii] diff --git a/src/renderer_d3d9.cpp b/src/renderer_d3d9.cpp index b42ca2f1b..d78becf7d 100644 --- a/src/renderer_d3d9.cpp +++ b/src/renderer_d3d9.cpp @@ -3505,7 +3505,7 @@ namespace bgfx ); for (uint32_t ii = 0; ii < BX_COUNTOF(s_primName); ++ii) { - tvm.printf(10, pos++, 0x8e, " %8s: %7d (#inst: %5d), submitted: %7d" + tvm.printf(10, pos++, 0x8e, " %9s: %7d (#inst: %5d), submitted: %7d" , s_primName[ii] , statsNumPrimsRendered[ii] , statsNumInstances[ii]