diff --git a/bindings/c3/bgfx.c3 b/bindings/c3/bgfx.c3 index e9e602685..abea6cfb1 100644 --- a/bindings/c3/bgfx.c3 +++ b/bindings/c3/bgfx.c3 @@ -1831,10 +1831,12 @@ struct InitLimits // `Stats::numDrawCallsPeak` to size it. uint numDrawCalls; // Number of frames the draw-call peak (high-water mark) is observed - // before unused storage is released. Set to 0 to keep whatever has - // been allocated for the lifetime of the context. With - // `BGFX_CONFIG_DYNAMIC_FRAME_STORAGE` disabled nothing per frame is - // resized at all, and this only releases unused uniform buffer space. + // before unused storage is released. Also used for resource command + // buffers and uniform buffers. Set to 0 to keep whatever has been + // allocated for the lifetime of the context. With + // `BGFX_CONFIG_DYNAMIC_FRAME_STORAGE` disabled draw/blit/rect storage + // is not resized; unused uniform and resource command buffer space + // is still released. uint numDrawCallPeakFrames; // Minimum resource command buffer size. uint minResourceCbSize; diff --git a/bindings/d/package.d b/bindings/d/package.d index 90b2ee393..de3618313 100644 --- a/bindings/d/package.d +++ b/bindings/d/package.d @@ -1295,10 +1295,12 @@ extern(C++, "bgfx") struct Init{ /** Number of frames the draw-call peak (high-water mark) is observed - before unused storage is released. Set to 0 to keep whatever has - been allocated for the lifetime of the context. With - `BGFX_CONFIG_DYNAMIC_FRAME_STORAGE` disabled nothing per frame is - resized at all, and this only releases unused uniform buffer space. + before unused storage is released. Also used for resource command + buffers and uniform buffers. Set to 0 to keep whatever has been + allocated for the lifetime of the context. With + `BGFX_CONFIG_DYNAMIC_FRAME_STORAGE` disabled draw/blit/rect storage + is not resized; unused uniform and resource command buffer space + is still released. */ uint numDrawCallPeakFrames; uint minResourceCBSize; ///Minimum resource command buffer size. diff --git a/bindings/py/bgfx.pyi b/bindings/py/bgfx.pyi index 750b6b851..10ebfee6e 100644 --- a/bindings/py/bgfx.pyi +++ b/bindings/py/bgfx.pyi @@ -1371,10 +1371,12 @@ class InitLimits(ctypes.Structure): # `Stats::numDrawCallsPeak` to size it. numDrawCalls: int # Number of frames the draw-call peak (high-water mark) is observed - # before unused storage is released. Set to 0 to keep whatever has - # been allocated for the lifetime of the context. With - # `BGFX_CONFIG_DYNAMIC_FRAME_STORAGE` disabled nothing per frame is - # resized at all, and this only releases unused uniform buffer space. + # before unused storage is released. Also used for resource command + # buffers and uniform buffers. Set to 0 to keep whatever has been + # allocated for the lifetime of the context. With + # `BGFX_CONFIG_DYNAMIC_FRAME_STORAGE` disabled draw/blit/rect storage + # is not resized; unused uniform and resource command buffer space + # is still released. numDrawCallPeakFrames: int # Minimum resource command buffer size. minResourceCbSize: int diff --git a/docs/internals.rst b/docs/internals.rst index 79af5047d..c3ac59b25 100644 --- a/docs/internals.rst +++ b/docs/internals.rst @@ -226,7 +226,7 @@ Buffer sizes ``BGFX_CONFIG_MAX_TRANSIENT_INDEX_BUFFER_SIZE`` - Maximum transient index buffer size. There is no growth; all transient indices must fit into this buffer. Default is 2 MB. -``BGFX_CONFIG_MIN_RESOURCE_COMMAND_BUFFER_SIZE`` - Minimum initial size of the resource command buffer (pre/post render commands for resource creation and updates). Default is 64 KB. The buffer grows as needed. +``BGFX_CONFIG_MIN_RESOURCE_COMMAND_BUFFER_SIZE`` - Minimum initial size of the resource command buffer (pre/post render commands for resource creation and updates). Default is 64 KB. The buffer grows as needed. After ``Init::Limits::numDrawCallPeakFrames`` (default 60) of observing the high-water mark it shrinks toward that peak, but not below this minimum. Set ``numDrawCallPeakFrames`` to 0 to keep the largest size for the lifetime of the context. ``BGFX_CONFIG_MIN_UNIFORM_BUFFER_SIZE`` - Minimum initial size in bytes of the per-encoder uniform buffer. Default is 128 KB. This buffer will resize on demand. Must be larger than ``BGFX_CONFIG_UNIFORM_BUFFER_RESIZE_THRESHOLD_SIZE``, otherwise the buffer resizes on first use. @@ -284,8 +284,6 @@ Debugging and profiling Miscellaneous ^^^^^^^^^^^^^ -``BGFX_CONFIG_USE_TINYSTL`` - Enable use of tinystl instead of std containers for internal data structures. Default is 1. Reduces binary size and avoids std library dependency. - ``BGFX_CONFIG_MIP_LOD_BIAS`` - Global MIP level-of-detail bias applied to all texture sampling. Default is 0. Positive values select coarser MIP levels, negative values select finer MIP levels. ``BGFX_CONFIG_DRAW_INDIRECT_STRIDE`` - Stride in bytes of each draw indirect command. Fixed at 32 bytes. Not configurable. diff --git a/include/bgfx/bgfx.h b/include/bgfx/bgfx.h index b5b4ded36..8e077197a 100644 --- a/include/bgfx/bgfx.h +++ b/include/bgfx/bgfx.h @@ -754,10 +754,12 @@ namespace bgfx /// back; submissions past it are dropped. See /// `Stats::numDrawCallsPeak` to size it. uint32_t numDrawCallPeakFrames; //!< Number of frames the draw-call peak (high-water mark) is observed - /// before unused storage is released. Set to 0 to keep whatever has - /// been allocated for the lifetime of the context. With - /// `BGFX_CONFIG_DYNAMIC_FRAME_STORAGE` disabled nothing per frame is - /// resized at all, and this only releases unused uniform buffer space. + /// before unused storage is released. Also used for resource command + /// buffers and uniform buffers. Set to 0 to keep whatever has been + /// allocated for the lifetime of the context. With + /// `BGFX_CONFIG_DYNAMIC_FRAME_STORAGE` disabled draw/blit/rect storage + /// is not resized; unused uniform and resource command buffer space + /// is still released. uint32_t minResourceCbSize; //!< Minimum resource command buffer size. uint32_t maxTransientVbSize; //!< Maximum transient vertex buffer size. uint32_t maxTransientIbSize; //!< Maximum transient index buffer size. diff --git a/include/bgfx/c99/bgfx.h b/include/bgfx/c99/bgfx.h index 84ad10d08..7b0348c15 100644 --- a/include/bgfx/c99/bgfx.h +++ b/include/bgfx/c99/bgfx.h @@ -847,10 +847,12 @@ typedef struct bgfx_init_limits_s /** * Number of frames the draw-call peak (high-water mark) is observed - * before unused storage is released. Set to 0 to keep whatever has - * been allocated for the lifetime of the context. With - * `BGFX_CONFIG_DYNAMIC_FRAME_STORAGE` disabled nothing per frame is - * resized at all, and this only releases unused uniform buffer space. + * before unused storage is released. Also used for resource command + * buffers and uniform buffers. Set to 0 to keep whatever has been + * allocated for the lifetime of the context. With + * `BGFX_CONFIG_DYNAMIC_FRAME_STORAGE` disabled draw/blit/rect storage + * is not resized; unused uniform and resource command buffer space + * is still released. */ uint32_t numDrawCallPeakFrames; uint32_t minResourceCbSize; /** Minimum resource command buffer size. */ diff --git a/scripts/bgfx.idl b/scripts/bgfx.idl index bb68e7090..7183a0145 100644 --- a/scripts/bgfx.idl +++ b/scripts/bgfx.idl @@ -923,10 +923,12 @@ struct.Limits { ctor, namespace = "Init" } --- back; submissions past it are dropped. See --- `Stats::numDrawCallsPeak` to size it. .numDrawCallPeakFrames "uint32_t" --- Number of frames the draw-call peak (high-water mark) is observed - --- before unused storage is released. Set to 0 to keep whatever has - --- been allocated for the lifetime of the context. With - --- `BGFX_CONFIG_DYNAMIC_FRAME_STORAGE` disabled nothing per frame is - --- resized at all, and this only releases unused uniform buffer space. + --- before unused storage is released. Also used for resource command + --- buffers and uniform buffers. Set to 0 to keep whatever has been + --- allocated for the lifetime of the context. With + --- `BGFX_CONFIG_DYNAMIC_FRAME_STORAGE` disabled draw/blit/rect storage + --- is not resized; unused uniform and resource command buffer space + --- is still released. .minResourceCbSize "uint32_t" --- Minimum resource command buffer size. .maxTransientVbSize "uint32_t" --- Maximum transient vertex buffer size. .maxTransientIbSize "uint32_t" --- Maximum transient index buffer size. diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 2bb1b2aa7..f0355ba68 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -55,7 +55,6 @@ namespace bgfx , _msg " Use bgfx::getCaps to check " #_caps " backend renderer capabilities." \ ); -#if BGFX_CONFIG_USE_TINYSTL void* TinyStlAllocator::static_allocate(size_t _bytes) { return bx::alloc(g_allocator, _bytes); @@ -68,7 +67,6 @@ namespace bgfx bx::free(g_allocator, _ptr); } } -#endif // BGFX_CONFIG_USE_TINYSTL struct Superluminal { @@ -569,8 +567,10 @@ namespace bgfx va_end(argList); } +#if BGFX_CONFIG_DEBUG_TEXT #include "vs_debugfont.bin.h" #include "fs_debugfont.bin.h" +#endif // BGFX_CONFIG_DEBUG_TEXT #include "vs_clear.bin.h" #include "fs_clear0.bin.h" #include "fs_clear1.bin.h" @@ -599,8 +599,10 @@ namespace bgfx static const EmbeddedShader s_embeddedShaders[] = { +#if BGFX_CONFIG_DEBUG_TEXT BGFX_EMBEDDED_SHADER(vs_debugfont), BGFX_EMBEDDED_SHADER(fs_debugfont), +#endif // BGFX_CONFIG_DEBUG_TEXT BGFX_EMBEDDED_SHADER(vs_clear), BGFX_EMBEDDED_SHADER(fs_clear0), BGFX_EMBEDDED_SHADER(fs_clear1), @@ -691,6 +693,7 @@ namespace bgfx } } +#if BGFX_CONFIG_DEBUG_TEXT #include "charset.h" void charsetFillTexture(const uint8_t* _charset, uint8_t* _rgba, uint32_t _height, uint32_t _pitch, uint32_t _bpp) @@ -710,6 +713,7 @@ namespace bgfx } } } +#endif // BGFX_CONFIG_DEBUG_TEXT static uint8_t parseAttrTo(char*& _ptr, char _to, uint8_t _default) { @@ -787,6 +791,7 @@ namespace bgfx } } +#if BGFX_CONFIG_DEBUG_TEXT static constexpr uint32_t kNumCharsPerBatch = 1024; static constexpr uint32_t kNumBatchVertices = kNumCharsPerBatch*4; static constexpr uint32_t kNumBatchIndices = kNumCharsPerBatch*6; @@ -990,6 +995,19 @@ namespace bgfx _renderCtx->dbgTextRenderEnd(_blitter); } +#else + void TextVideoMemBlitter::init(uint8_t /*_scale*/) + { + } + + void TextVideoMemBlitter::shutdown() + { + } + + void dbgTextSubmit(RendererContextI* /*_renderCtx*/, TextVideoMemBlitter& /*_blitter*/, const TextVideoMem& /*_mem*/) + { + } +#endif // BGFX_CONFIG_DEBUG_TEXT void ClearQuad::init() { @@ -1838,7 +1856,7 @@ namespace bgfx BGFX_PROFILER_SCOPE("bgfx/DedupBind", kColorSubmit); Context::BindHashMap& bindHashMap = s_ctx->m_renderBindHashMap; - bindHashMap.clear(); + bindHashMap.reset(); RenderItemCount* remap = s_ctx->m_tempValues; @@ -2959,11 +2977,14 @@ namespace bgfx bx::memSet(m_seq, 0, sizeof(m_seq) ); - m_submit->m_textVideoMem->resize( - m_render->m_textVideoMem->m_small - , m_init.resolution.width - , m_init.resolution.height - ); + if (BX_ENABLED(BGFX_CONFIG_DEBUG_TEXT) ) + { + m_submit->m_textVideoMem->resize( + m_render->m_textVideoMem->m_small + , m_init.resolution.width + , m_init.resolution.height + ); + } const int64_t now = bx::getHPCounter(); m_submit->m_perfStats.cpuTimeFrame = now - m_frameTimeLast; diff --git a/src/bgfx_p.h b/src/bgfx_p.h index 0c00d731b..5edb00156 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -154,7 +154,6 @@ namespace bgfx | BGFX_CLEAR_COLOR_USE_PALETTE \ ) -#if BGFX_CONFIG_USE_TINYSTL namespace bgfx { struct TinyStlAllocator @@ -163,11 +162,11 @@ namespace bgfx static void static_deallocate(void* _ptr, size_t /*_bytes*/); }; } // namespace bgfx -# define TINYSTL_ALLOCATOR bgfx::TinyStlAllocator -# include -# include -# include -# include +#define TINYSTL_ALLOCATOR bgfx::TinyStlAllocator +#include +#include +#include +#include namespace tinystl { @@ -202,14 +201,6 @@ namespace tinystl } // namespace tinystl namespace stl = tinystl; -#else -# include -# include -# include -# include -# include -namespace stl = std; -#endif // BGFX_CONFIG_USE_TINYSTL #if BX_PLATFORM_ANDROID # include @@ -852,7 +843,10 @@ namespace bgfx inline void dbgTextSubmit(RendererContextI* _renderCtx, TextVideoMemBlitter& _blitter, const TextVideoMem* _mem) { - dbgTextSubmit(_renderCtx, _blitter, *_mem); + if (NULL != _mem) + { + dbgTextSubmit(_renderCtx, _blitter, *_mem); + } } template @@ -1073,6 +1067,7 @@ namespace bgfx , m_pos(0) , m_size(0) , m_minCapacity(0) + , m_peak(0) { resize(); finish(); @@ -1222,13 +1217,20 @@ namespace bgfx uint8_t cmd = End; write(cmd); m_size = m_pos; + m_peak = bx::max(m_peak, m_pos); m_pos = 0; + } - if (m_size < m_minCapacity - && m_capacity != m_minCapacity) + void shrink() + { + const uint32_t keep = bx::alignUp(bx::max(m_peak, m_minCapacity), 1024); + + if (keep < m_capacity) { - resize(); + resize(keep); } + + m_peak = 0; } uint8_t* m_buffer; @@ -1236,6 +1238,7 @@ namespace bgfx uint32_t m_size; uint32_t m_capacity; uint32_t m_minCapacity; + uint32_t m_peak; }; // @@ -3226,6 +3229,8 @@ namespace bgfx m_renderBind.shrink(keep); m_blitItem.shrink(m_peakBlit + 1 + kBlitBlock); m_frameCache.m_rectCache.shrink(m_peakRect + 1 + kRectBlock); + m_cmdPre.shrink(); + m_cmdPost.shrink(); for (uint32_t ii = 0, num = g_caps.limits.maxEncoders; ii < num; ++ii) { @@ -3260,7 +3265,11 @@ namespace bgfx reset(); start(0); - m_textVideoMem = BX_NEW(g_allocator, TextVideoMem); + m_textVideoMem = NULL; + if (BX_ENABLED(BGFX_CONFIG_DEBUG_TEXT) ) + { + m_textVideoMem = BX_NEW(g_allocator, TextVideoMem); + } } void destroy() @@ -3605,7 +3614,7 @@ namespace bgfx m_numSubmitted = 0; m_numDropped = 0; - m_bindHashMap.clear(); + m_bindHashMap.reset(); m_bindLlastIdx = 0; m_bindEmptyIdx = UINT32_MAX; m_bindDirty = true; @@ -4926,27 +4935,36 @@ namespace bgfx { BGFX_MUTEX_SCOPE(m_resourceApiLock); - const uint8_t debugTextScale = m_init.resolution.debugTextScale; - m_submit->m_textVideoMem->resize( - _small - , (uint16_t)m_init.resolution.width / debugTextScale - , (uint16_t)m_init.resolution.height / debugTextScale - ); - m_submit->m_textVideoMem->clear(_attr); + if (BX_ENABLED(BGFX_CONFIG_DEBUG_TEXT) ) + { + const uint8_t debugTextScale = m_init.resolution.debugTextScale; + m_submit->m_textVideoMem->resize( + _small + , (uint16_t)m_init.resolution.width / debugTextScale + , (uint16_t)m_init.resolution.height / debugTextScale + ); + m_submit->m_textVideoMem->clear(_attr); + } } BGFX_API_FUNC(void dbgTextPrintfVargs(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, va_list _argList) ) { BGFX_MUTEX_SCOPE(m_resourceApiLock); - m_submit->m_textVideoMem->printfVargs(_x, _y, _attr, _format, _argList); + if (BX_ENABLED(BGFX_CONFIG_DEBUG_TEXT) ) + { + m_submit->m_textVideoMem->printfVargs(_x, _y, _attr, _format, _argList); + } } BGFX_API_FUNC(void dbgTextImage(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const void* _data, uint16_t _pitch) ) { BGFX_MUTEX_SCOPE(m_resourceApiLock); - m_submit->m_textVideoMem->image(_x, _y, _width, _height, _data, _pitch); + if (BX_ENABLED(BGFX_CONFIG_DEBUG_TEXT) ) + { + m_submit->m_textVideoMem->image(_x, _y, _width, _height, _data, _pitch); + } } BGFX_API_FUNC(const Stats* getPerfStats() ) @@ -4957,9 +4975,14 @@ namespace bgfx const Resolution& resolution = m_submit->m_resolution; stats.width = uint16_t(resolution.width); stats.height = uint16_t(resolution.height); - const TextVideoMem* tvm = m_submit->m_textVideoMem; - stats.textWidth = tvm->m_width; - stats.textHeight = tvm->m_height; + stats.textWidth = 0; + stats.textHeight = 0; + if (BX_ENABLED(BGFX_CONFIG_DEBUG_TEXT) ) + { + const TextVideoMem* tvm = m_submit->m_textVideoMem; + stats.textWidth = tvm->m_width; + stats.textHeight = tvm->m_height; + } stats.encoderStats = m_encoderStats; stats.numDynamicIndexBuffers = m_dynamicIndexBufferHandle.getNumHandles(); diff --git a/src/config.h b/src/config.h index 959d7da87..815fb2139 100644 --- a/src/config.h +++ b/src/config.h @@ -193,7 +193,7 @@ # define BGFX_CONFIG_GL_USE_WGL 0 #endif // BGFX_CONFIG_GL_USE_WGL -// Enable hardware video decoder. +/// Enable hardware video decoder. #ifndef BGFX_CONFIG_VIDEO # define BGFX_CONFIG_VIDEO 1 #endif // BGFX_CONFIG_VIDEO @@ -247,12 +247,10 @@ # define BGFX_CONFIG_RENDERER_VULKAN_ROBUST_BUFFER_ACCESS 0 #endif // BGFX_CONFIG_RENDERER_VULKAN_ROBUST_BUFFER_ACCESS -/// Enable use of tinystl instead of std containers for internal data -/// structures. Default is 1 (enabled). Reduces binary size and avoids -/// std library dependency. -#ifndef BGFX_CONFIG_USE_TINYSTL -# define BGFX_CONFIG_USE_TINYSTL 1 -#endif // BGFX_CONFIG_USE_TINYSTL +/// Enable debug text. +#ifndef BGFX_CONFIG_DEBUG_TEXT +# define BGFX_CONFIG_DEBUG_TEXT 1 +#endif // BGFX_CONFIG_DEBUG_TEXT /// Debug text maximum scale factor. #ifndef BGFX_CONFIG_DEBUG_TEXT_MAX_SCALE @@ -478,7 +476,10 @@ static_assert(BGFX_CONFIG_MAX_VERTEX_STREAMS < 32, "Must be less than 32!"); /// Minimum initial size in bytes of the resource command buffer (pre/post /// render commands for resource creation and updates). Default is 64 KB. -/// The buffer grows as needed. +/// The buffer grows as needed. After `Init::Limits::numDrawCallPeakFrames` +/// of observing the high-water mark it shrinks toward that peak, but not +/// below this minimum. Set `numDrawCallPeakFrames` to 0 to keep the largest +/// size for the lifetime of the context. #ifndef BGFX_CONFIG_MIN_RESOURCE_COMMAND_BUFFER_SIZE # define BGFX_CONFIG_MIN_RESOURCE_COMMAND_BUFFER_SIZE (64<<10) #endif // BGFX_CONFIG_MIN_RESOURCE_COMMAND_BUFFER_SIZE diff --git a/src/renderer_d3d12.cpp b/src/renderer_d3d12.cpp index 17666e5dc..55e046832 100644 --- a/src/renderer_d3d12.cpp +++ b/src/renderer_d3d12.cpp @@ -2010,14 +2010,7 @@ namespace bgfx { namespace d3d12 postReset(); m_batch.create(4<<10); -#if !BX_PLATFORM_LINUX - // ExecuteIndirect is a net loss on following GPU vendors: - m_batch.setIndirectMode(true - && BGFX_PCI_ID_NVIDIA != m_dxgi.m_adapterDesc.VendorId - && BGFX_PCI_ID_INTEL != m_dxgi.m_adapterDesc.VendorId - && BGFX_PCI_ID_MICROSOFT != m_dxgi.m_adapterDesc.VendorId - ); -#endif // !BX_PLATFORM_LINUX + m_batch.setIndirectMode(false /* ExecuteIndirect is a net loss on all GPU vendors... */); m_gpuTimer.init(); m_occlusionQuery.init(); diff --git a/src/renderer_gnm.cpp b/src/renderer_gnm.cpp index 62892c245..6d8a44974 100644 --- a/src/renderer_gnm.cpp +++ b/src/renderer_gnm.cpp @@ -15,8 +15,10 @@ namespace bgfx const uint8_t* BX_CONCATENATE(_name, _pssl) = &BX_CONCATENATE(_name, _int_pssl)[0]; \ const uint32_t BX_CONCATENATE(_name, _pssl_size) = 1 +#if BGFX_CONFIG_DEBUG_TEXT BGFX_DECLARE_EMBEDDED_SHADER(vs_debugfont); BGFX_DECLARE_EMBEDDED_SHADER(fs_debugfont); +#endif // BGFX_CONFIG_DEBUG_TEXT BGFX_DECLARE_EMBEDDED_SHADER(vs_clear); BGFX_DECLARE_EMBEDDED_SHADER(fs_clear0); BGFX_DECLARE_EMBEDDED_SHADER(fs_clear1); diff --git a/src/renderer_nvn.cpp b/src/renderer_nvn.cpp index 6cdeea29e..5a3c68985 100644 --- a/src/renderer_nvn.cpp +++ b/src/renderer_nvn.cpp @@ -15,8 +15,10 @@ namespace bgfx const uint8_t* BX_CONCATENATE(_name, _nvn) = &BX_CONCATENATE(_name, _int_nvn)[0]; \ const uint32_t BX_CONCATENATE(_name, _nvn_size) = 1 +#if BGFX_CONFIG_DEBUG_TEXT BGFX_DECLARE_EMBEDDED_SHADER(vs_debugfont); BGFX_DECLARE_EMBEDDED_SHADER(fs_debugfont); +#endif // BGFX_CONFIG_DEBUG_TEXT BGFX_DECLARE_EMBEDDED_SHADER(vs_clear); BGFX_DECLARE_EMBEDDED_SHADER(fs_clear0); BGFX_DECLARE_EMBEDDED_SHADER(fs_clear1); diff --git a/src/renderer_vk.cpp b/src/renderer_vk.cpp index edaa354b5..165a102d2 100644 --- a/src/renderer_vk.cpp +++ b/src/renderer_vk.cpp @@ -5949,15 +5949,14 @@ VK_DESTROY const void* code = reader.getDataPtr(); bx::skip(&reader, shaderSize+1); - m_code = alloc(shaderSize); - bx::memCopy(m_code->data, code, shaderSize); + const Memory* shaderCode = copy(code, shaderSize); VkShaderModuleCreateInfo smci; smci.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; smci.pNext = NULL; smci.flags = 0; - smci.codeSize = m_code->size; - smci.pCode = (const uint32_t*)m_code->data; + smci.codeSize = shaderCode->size; + smci.pCode = (const uint32_t*)shaderCode->data; BX_TRACE("%x", bx::hash(code, shaderSize) ); VK_CHECK(vkCreateShaderModule( @@ -5967,6 +5966,8 @@ VK_DESTROY , &m_module ) ); + release(shaderCode); + bx::memSet(m_attrMask, 0, sizeof(m_attrMask) ); bx::memSet(m_attrRemap, 0, sizeof(m_attrRemap) ); @@ -5990,7 +5991,7 @@ VK_DESTROY murmur.begin(); murmur.add(hashIn); murmur.add(hashOut); - murmur.add(m_code->data, m_code->size); + murmur.add(code, shaderSize); murmur.add(m_numAttrs); murmur.add(m_attrMask, m_numAttrs); murmur.add(m_attrRemap, m_numAttrs); @@ -6070,13 +6071,7 @@ VK_DESTROY } m_numPredefined = 0; - - if (NULL != m_code) - { - release(m_code); - m_code = NULL; - m_hash = 0; - } + m_hash = 0; if (VK_NULL_HANDLE != m_module) { @@ -6086,7 +6081,7 @@ VK_DESTROY void ProgramVK::create(const ShaderVK* _vsh, const ShaderVK* _fsh) { - BX_ASSERT(NULL != _vsh->m_code, "Vertex shader doesn't exist."); + BX_ASSERT(VK_NULL_HANDLE != _vsh->m_module, "Vertex shader doesn't exist."); m_vsh = _vsh; bx::memCopy( &m_predefined[0] @@ -6097,7 +6092,7 @@ VK_DESTROY if (NULL != _fsh) { - BX_ASSERT(NULL != _fsh->m_code, "Fragment shader doesn't exist."); + BX_ASSERT(VK_NULL_HANDLE != _fsh->m_module, "Fragment shader doesn't exist."); m_fsh = _fsh; bx::memCopy( &m_predefined[m_numPredefined] diff --git a/src/renderer_vk.h b/src/renderer_vk.h index 0e4a925eb..77ff0e8e7 100644 --- a/src/renderer_vk.h +++ b/src/renderer_vk.h @@ -535,8 +535,7 @@ VK_DESTROY_FUNC(DescriptorSet); struct ShaderVK { ShaderVK() - : m_code(NULL) - , m_module(VK_NULL_HANDLE) + : m_module(VK_NULL_HANDLE) , m_constantBuffer(NULL) , m_hash(0) , m_numUniforms(0) @@ -550,7 +549,6 @@ VK_DESTROY_FUNC(DescriptorSet); void create(const Memory* _mem); void destroy(); - const Memory* m_code; VkShaderModule m_module; UniformBuffer* m_constantBuffer; diff --git a/src/renderer_webgpu.cpp b/src/renderer_webgpu.cpp index 762a54845..695556569 100644 --- a/src/renderer_webgpu.cpp +++ b/src/renderer_webgpu.cpp @@ -4264,6 +4264,12 @@ WGPU_IMPORT bx::read(&reader, m_size, &err); bx::read(&reader, m_blockSize, &err); + + if (bx::strFind(bx::StringView( (const char*)m_code->data, m_code->size), "rgba8unorm").isEmpty() ) + { + release(m_code); + m_code = NULL; + } } void ShaderWGPU::destroy() @@ -4289,7 +4295,8 @@ WGPU_IMPORT WGPUShaderModule ShaderWGPU::getModule(bool _bgra8Storage) const { - if (!_bgra8Storage) + if (!_bgra8Storage + || NULL == m_code) { return m_module; }