diff --git a/examples/15-shadowmaps-simple/shadowmaps_simple.cpp b/examples/15-shadowmaps-simple/shadowmaps_simple.cpp index 13d86afb..513a37f2 100644 --- a/examples/15-shadowmaps-simple/shadowmaps_simple.cpp +++ b/examples/15-shadowmaps-simple/shadowmaps_simple.cpp @@ -311,7 +311,6 @@ int _main_(int /*_argc*/, char** /*_argv*/) // Floor. bx::mtxMul(lightMtx, mtxFloor, mtxShadow); - bgfx::setUniform(u_lightMtx, lightMtx); uint32_t cached = bgfx::setTransform(mtxFloor); for (uint32_t pass = 0; pass < 2; ++pass) { diff --git a/examples/23-vectordisplay/vectordisplay.cpp b/examples/23-vectordisplay/vectordisplay.cpp index 46179aeb..42855023 100644 --- a/examples/23-vectordisplay/vectordisplay.cpp +++ b/examples/23-vectordisplay/vectordisplay.cpp @@ -210,8 +210,6 @@ void VectorDisplay::endFrame() if (m_brightness > 0) { - bgfx::setUniform(u_params, params); - bgfx::setTexture(0, s_texColor, m_sceneFrameBuffer); int npasses = (int)(m_brightness * 4); @@ -264,6 +262,8 @@ void VectorDisplay::endFrame() } } + bgfx::discard(); + //now do last pass, combination of blur and normal buffer to screen bgfx::setViewTransform(viewCounter, NULL, proj); bgfx::setViewRect(viewCounter, 0, 0, m_screenWidth, m_screenHeight); diff --git a/examples/common/nanovg/nanovg_bgfx.cpp b/examples/common/nanovg/nanovg_bgfx.cpp index 8a7d83f4..263c1b31 100644 --- a/examples/common/nanovg/nanovg_bgfx.cpp +++ b/examples/common/nanovg/nanovg_bgfx.cpp @@ -667,7 +667,6 @@ namespace ); bgfx::setVertexBuffer(&gl->tvb, paths[i].strokeOffset, paths[i].strokeCount); bgfx::setTexture(0, gl->s_tex, gl->th); - bgfx::setTexture(0, gl->s_tex, gl->th); bgfx::submit(gl->viewid, gl->prog); } } diff --git a/src/bgfx.cpp b/src/bgfx.cpp index a5aa5e67..cab1790b 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -1313,6 +1313,19 @@ namespace bgfx ); } + const char* Context::getName(UniformHandle _handle) const + { + for (UniformHashMap::const_iterator it = m_uniformHashMap.begin(), itEnd = m_uniformHashMap.end(); it != itEnd; ++it) + { + if (it->second.idx == _handle.idx) + { + return it->first.c_str(); + } + } + + return NULL; + } + bool Context::renderFrame() { if (m_rendererInitialized diff --git a/src/bgfx_p.h b/src/bgfx_p.h index 26de034b..a25d1b83 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -2950,7 +2950,7 @@ namespace bgfx , _handle.idx , _width , _height - , getName(TextureFormat::Enum(textureRef.m_format) ) + , bgfx::getName(TextureFormat::Enum(textureRef.m_format) ) ); CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::ResizeTexture); @@ -3359,6 +3359,15 @@ namespace bgfx BGFX_CHECK_HANDLE("setUniform", m_uniformHandle, _handle); UniformRef& uniform = m_uniformRef[_handle.idx]; BX_CHECK(uniform.m_num >= _num, "Truncated uniform update. %d (max: %d)", _num, uniform.m_num); + if (BX_ENABLED(BGFX_CONFIG_DEBUG_UNIFORM) ) + { + BX_CHECK(m_uniformSet.end() == m_uniformSet.find(_handle.idx) + , "Uniform %d (%s) was already set for this draw call." + , _handle.idx + , getName(_handle) + ); + m_uniformSet.insert(_handle.idx); + } m_submit->writeUniform(uniform.m_type, _handle, _value, bx::uint16_min(uniform.m_num, _num) ); } @@ -3446,6 +3455,10 @@ namespace bgfx BGFX_API_FUNC(uint32_t submit(uint8_t _id, ProgramHandle _handle, int32_t _depth) ) { BGFX_CHECK_HANDLE_INVALID_OK("submit", m_programHandle, _handle); + if (BX_ENABLED(BGFX_CONFIG_DEBUG_UNIFORM) ) + { + m_uniformSet.clear(); + } return m_submit->submit(_id, _handle, _depth); } @@ -3453,6 +3466,10 @@ namespace bgfx { BGFX_CHECK_HANDLE_INVALID_OK("submit", m_programHandle, _handle); BGFX_CHECK_HANDLE("submit", m_vertexBufferHandle, _indirectHandle); + if (BX_ENABLED(BGFX_CONFIG_DEBUG_UNIFORM) ) + { + m_uniformSet.clear(); + } return m_submit->submit(_id, _handle, _indirectHandle, _start, _num, _depth); } @@ -3515,16 +3532,28 @@ namespace bgfx BGFX_API_FUNC(uint32_t dispatch(uint8_t _id, ProgramHandle _handle, uint16_t _numX, uint16_t _numY, uint16_t _numZ, uint8_t _flags) ) { + if (BX_ENABLED(BGFX_CONFIG_DEBUG_UNIFORM) ) + { + m_uniformSet.clear(); + } return m_submit->dispatch(_id, _handle, _numX, _numY, _numZ, _flags); } BGFX_API_FUNC(uint32_t dispatch(uint8_t _id, ProgramHandle _handle, IndirectBufferHandle _indirectHandle, uint16_t _start, uint16_t _num, uint8_t _flags) ) { + if (BX_ENABLED(BGFX_CONFIG_DEBUG_UNIFORM) ) + { + m_uniformSet.clear(); + } return m_submit->dispatch(_id, _handle, _indirectHandle, _start, _num, _flags); } BGFX_API_FUNC(void discard() ) { + if (BX_ENABLED(BGFX_CONFIG_DEBUG_UNIFORM) ) + { + m_uniformSet.clear(); + } m_submit->discard(); } @@ -3535,6 +3564,7 @@ namespace bgfx void freeAllHandles(Frame* _frame); void frameNoRenderWait(); void swap(); + const char* getName(UniformHandle _handle) const; // render thread bool renderFrame(); @@ -3676,6 +3706,8 @@ namespace bgfx typedef stl::unordered_map UniformHashMap; UniformHashMap m_uniformHashMap; + typedef stl::unordered_set UniformSet; + UniformSet m_uniformSet; UniformRef m_uniformRef[BGFX_CONFIG_MAX_UNIFORMS]; ShaderRef m_shaderRef[BGFX_CONFIG_MAX_SHADERS]; diff --git a/src/config.h b/src/config.h index 199fc144..550f9a3a 100644 --- a/src/config.h +++ b/src/config.h @@ -164,6 +164,11 @@ # define BGFX_CONFIG_DEBUG_MTL BGFX_CONFIG_DEBUG #endif // BGFX_CONFIG_DEBUG_MTL +/// +#ifndef BGFX_CONFIG_DEBUG_UNIFORM +# define BGFX_CONFIG_DEBUG_UNIFORM BGFX_CONFIG_DEBUG +#endif // BGFX_CONFIG_DEBUG_UNIFORM + #ifndef BGFX_CONFIG_MULTITHREADED # define BGFX_CONFIG_MULTITHREADED ( (!BGFX_CONFIG_RENDERER_NULL)&&(0 \ || BX_PLATFORM_ANDROID \