Added checks for redundant uniform sets.

This commit is contained in:
Branimir Karadžić 2015-09-25 20:54:40 -07:00
parent 9e71d6bf70
commit 0fba3c137e
6 changed files with 53 additions and 5 deletions

View file

@ -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)
{

View file

@ -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);

View file

@ -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);
}
}

View file

@ -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

View file

@ -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<stl::string, UniformHandle> UniformHashMap;
UniformHashMap m_uniformHashMap;
typedef stl::unordered_set<uint16_t> UniformSet;
UniformSet m_uniformSet;
UniformRef m_uniformRef[BGFX_CONFIG_MAX_UNIFORMS];
ShaderRef m_shaderRef[BGFX_CONFIG_MAX_SHADERS];

View file

@ -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 \