Moved bindings outside of render item.

This commit is contained in:
Branimir Karadžić 2017-04-06 20:32:48 -07:00
parent 5ffdd2de23
commit 81f9162d58
7 changed files with 79 additions and 43 deletions

View File

@ -910,11 +910,13 @@ namespace bgfx
}
m_renderItem[m_numRenderItems].draw = m_draw;
m_renderItemBind[m_numRenderItems] = m_bind;
++m_numRenderItems;
if (!_preserveState)
{
m_draw.clear();
m_bind.clear();
m_uniformBegin = m_uniformEnd;
m_stateFlags = BGFX_STATE_NONE;
}
@ -959,9 +961,11 @@ namespace bgfx
m_compute.m_constBegin = m_uniformBegin;
m_compute.m_constEnd = m_uniformEnd;
m_renderItem[m_numRenderItems].compute = m_compute;
m_renderItemBind[m_numRenderItems] = m_bind;
++m_numRenderItems;
m_compute.clear();
m_bind.clear();
m_uniformBegin = m_uniformEnd;
return m_num;

View File

@ -1237,6 +1237,22 @@ namespace bgfx
VertexDeclHandle m_decl;
};
struct RenderBind
{
void clear()
{
for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++ii)
{
Binding& bind = m_bind[ii];
bind.m_idx = invalidHandle;
bind.m_type = 0;
bind.m_un.m_draw.m_textureFlags = 0;
}
};
Binding m_bind[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS];
};
struct RenderDraw
{
void clear()
@ -1264,14 +1280,6 @@ namespace bgfx
m_instanceDataBuffer.idx = invalidHandle;
m_indirectBuffer.idx = invalidHandle;
m_occlusionQuery.idx = invalidHandle;
for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++ii)
{
Binding& bind = m_bind[ii];
bind.m_idx = invalidHandle;
bind.m_type = 0;
bind.m_un.m_draw.m_textureFlags = 0;
}
}
bool setStreamBit(uint8_t _stream, VertexBufferHandle _handle)
@ -1283,7 +1291,6 @@ namespace bgfx
return 0 != tmp;
}
Binding m_bind[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS];
Stream m_stream[BGFX_CONFIG_MAX_VERTEX_STREAMS];
uint64_t m_stateFlags;
uint64_t m_stencil;
@ -1326,14 +1333,8 @@ namespace bgfx
m_indirectBuffer.idx = invalidHandle;
m_startIndirect = 0;
m_numIndirect = UINT16_MAX;
for (uint32_t ii = 0; ii < BGFX_MAX_COMPUTE_BINDINGS; ++ii)
{
m_bind[ii].m_idx = invalidHandle;
}
}
Binding m_bind[BGFX_MAX_COMPUTE_BINDINGS];
uint32_t m_constBegin;
uint32_t m_constEnd;
uint32_t m_matrix;
@ -1461,6 +1462,7 @@ namespace bgfx
m_uniformEnd = 0;
m_draw.clear();
m_compute.clear();
m_bind.clear();
m_matrixCache.reset();
m_rectCache.reset();
m_key.reset();
@ -1642,7 +1644,7 @@ namespace bgfx
void setTexture(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint32_t _flags)
{
Binding& bind = m_draw.m_bind[_stage];
Binding& bind = m_bind.m_bind[_stage];
bind.m_idx = _handle.idx;
bind.m_type = uint8_t(Binding::Texture);
bind.m_un.m_draw.m_textureFlags = (_flags&BGFX_TEXTURE_INTERNAL_DEFAULT_SAMPLER)
@ -1659,7 +1661,7 @@ namespace bgfx
void setBuffer(uint8_t _stage, IndexBufferHandle _handle, Access::Enum _access)
{
Binding& bind = m_compute.m_bind[_stage];
Binding& bind = m_bind.m_bind[_stage];
bind.m_idx = _handle.idx;
bind.m_type = uint8_t(Binding::IndexBuffer);
bind.m_un.m_compute.m_format = 0;
@ -1669,7 +1671,7 @@ namespace bgfx
void setBuffer(uint8_t _stage, VertexBufferHandle _handle, Access::Enum _access)
{
Binding& bind = m_compute.m_bind[_stage];
Binding& bind = m_bind.m_bind[_stage];
bind.m_idx = _handle.idx;
bind.m_type = uint8_t(Binding::VertexBuffer);
bind.m_un.m_compute.m_format = 0;
@ -1679,7 +1681,7 @@ namespace bgfx
void setImage(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint8_t _mip, Access::Enum _access, TextureFormat::Enum _format)
{
Binding& bind = m_compute.m_bind[_stage];
Binding& bind = m_bind.m_bind[_stage];
bind.m_idx = _handle.idx;
bind.m_type = uint8_t(Binding::Image);
bind.m_un.m_compute.m_format = uint8_t(_format);
@ -1838,8 +1840,12 @@ namespace bgfx
uint64_t m_sortKeys[BGFX_CONFIG_MAX_DRAW_CALLS+1];
RenderItemCount m_sortValues[BGFX_CONFIG_MAX_DRAW_CALLS+1];
RenderItem m_renderItem[BGFX_CONFIG_MAX_DRAW_CALLS+1];
RenderDraw m_draw;
RenderBind m_renderItemBind[BGFX_CONFIG_MAX_DRAW_CALLS + 1];
RenderDraw m_draw;
RenderCompute m_compute;
RenderBind m_bind;
uint32_t m_numVertices[BGFX_CONFIG_MAX_VERTEX_STREAMS];
uint32_t m_blitKeys[BGFX_CONFIG_MAX_BLIT_ITEMS+1];
BlitItem m_blitItem[BGFX_CONFIG_MAX_BLIT_ITEMS+1];

View File

@ -5315,6 +5315,9 @@ BX_PRAGMA_DIAGNOSTIC_POP();
currentState.m_stateFlags = BGFX_STATE_NONE;
currentState.m_stencil = packStencil(BGFX_STENCIL_NONE, BGFX_STENCIL_NONE);
RenderBind currentBind;
currentBind.clear();
_render->m_hmdInitialized = m_ovr.isInitialized();
const bool hmdEnabled = m_ovr.isEnabled();
@ -5378,7 +5381,9 @@ BX_PRAGMA_DIAGNOSTIC_POP();
|| item == numItems
;
const RenderItem& renderItem = _render->m_renderItem[_render->m_sortValues[item] ];
const uint32_t itemIdx = _render->m_sortValues[item];
const RenderItem& renderItem = _render->m_renderItem[itemIdx];
const RenderBind& renderBind = _render->m_renderItemBind[itemIdx];
++item;
if (viewChanged)
@ -5639,7 +5644,7 @@ BX_PRAGMA_DIAGNOSTIC_POP();
for (uint32_t ii = 0; ii < BGFX_MAX_COMPUTE_BINDINGS; ++ii)
{
const Binding& bind = compute.m_bind[ii];
const Binding& bind = renderBind.m_bind[ii];
if (invalidHandle != bind.m_idx)
{
switch (bind.m_type)
@ -5764,6 +5769,8 @@ BX_PRAGMA_DIAGNOSTIC_POP();
currentState.m_stateFlags = newFlags;
currentState.m_stencil = newStencil;
currentBind.clear();
setBlendState(newFlags);
setDepthStencilState(newFlags, packStencil(BGFX_STENCIL_DEFAULT, BGFX_STENCIL_DEFAULT) );
@ -5935,8 +5942,8 @@ BX_PRAGMA_DIAGNOSTIC_POP();
uint32_t changes = 0;
for (uint8_t stage = 0; stage < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++stage)
{
const Binding& bind = draw.m_bind[stage];
Binding& current = currentState.m_bind[stage];
const Binding& bind = renderBind.m_bind[stage];
Binding& current = currentBind.m_bind[stage];
if (current.m_idx != bind.m_idx
|| current.m_type != bind.m_type
|| current.m_un.m_draw.m_textureFlags != bind.m_un.m_draw.m_textureFlags

View File

@ -4805,6 +4805,9 @@ data.NumQualityLevels = 0;
currentState.m_stateFlags = BGFX_STATE_NONE;
currentState.m_stencil = packStencil(BGFX_STENCIL_NONE, BGFX_STENCIL_NONE);
RenderBind currentBind;
currentBind.clear();
_render->m_hmdInitialized = false;
const bool hmdEnabled = false;
@ -4890,7 +4893,9 @@ data.NumQualityLevels = 0;
|| item == numItems
;
const RenderItem& renderItem = _render->m_renderItem[_render->m_sortValues[item] ];
const uint32_t itemIdx = _render->m_sortValues[item];
const RenderItem& renderItem = _render->m_renderItem[itemIdx];
const RenderBind& renderBind = _render->m_renderItemBind[itemIdx];
++item;
if (viewChanged)
@ -5043,7 +5048,7 @@ data.NumQualityLevels = 0;
currentBindHash = 0;
}
uint32_t bindHash = bx::hashMurmur2A(compute.m_bind, sizeof(compute.m_bind) );
uint32_t bindHash = bx::hashMurmur2A(renderBind.m_bind, sizeof(renderBind.m_bind) );
if (currentBindHash != bindHash)
{
currentBindHash = bindHash;
@ -5056,7 +5061,7 @@ data.NumQualityLevels = 0;
for (uint32_t ii = 0; ii < BGFX_MAX_COMPUTE_BINDINGS; ++ii)
{
const Binding& bind = compute.m_bind[ii];
const Binding& bind = renderBind.m_bind[ii];
if (invalidHandle != bind.m_idx)
{
switch (bind.m_type)
@ -5243,6 +5248,8 @@ data.NumQualityLevels = 0;
currentState.m_stateFlags = newFlags;
currentState.m_stencil = newStencil;
currentBind.clear();
const uint64_t pt = newFlags&BGFX_STATE_PT_MASK;
primIndex = uint8_t(pt>>BGFX_STATE_PT_SHIFT);
}
@ -5271,7 +5278,7 @@ data.NumQualityLevels = 0;
);
uint16_t scissor = draw.m_scissor;
uint32_t bindHash = bx::hashMurmur2A(draw.m_bind, sizeof(draw.m_bind) );
uint32_t bindHash = bx::hashMurmur2A(renderBind.m_bind, sizeof(renderBind.m_bind) );
if (currentBindHash != bindHash
|| 0 != changedStencil
|| (hasFactor && blendFactor != draw.m_rgba)
@ -5297,7 +5304,7 @@ data.NumQualityLevels = 0;
srvHandle[0].ptr = 0;
for (uint32_t stage = 0; stage < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++stage)
{
const Binding& bind = draw.m_bind[stage];
const Binding& bind = renderBind.m_bind[stage];
if (invalidHandle != bind.m_idx)
{
switch (bind.m_type)

View File

@ -3640,6 +3640,9 @@ namespace bgfx { namespace d3d9
currentState.m_stateFlags = BGFX_STATE_NONE;
currentState.m_stencil = packStencil(BGFX_STENCIL_NONE, BGFX_STENCIL_NONE);
RenderBind currentBind;
currentBind.clear();
ViewState viewState(_render, false);
DX_CHECK(device->SetRenderState(D3DRS_FILLMODE, _render->m_debug&BGFX_DEBUG_WIREFRAME ? D3DFILL_WIREFRAME : D3DFILL_SOLID) );
@ -3692,7 +3695,9 @@ namespace bgfx { namespace d3d9
continue;
}
const RenderDraw& draw = _render->m_renderItem[_render->m_sortValues[item] ].draw;
const uint32_t itemIdx = _render->m_sortValues[item];
const RenderDraw& draw = _render->m_renderItem[itemIdx].draw;
const RenderBind& renderBind = _render->m_renderItemBind[itemIdx];
const bool hasOcclusionQuery = 0 != (draw.m_stateFlags & BGFX_STATE_INTERNAL_OCCLUSION_QUERY);
if (isValid(draw.m_occlusionQuery)
@ -4092,10 +4097,8 @@ namespace bgfx { namespace d3d9
{
for (uint8_t stage = 0; stage < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++stage)
{
const Binding& bind = draw.m_bind[stage];
Binding& current = currentState.m_bind[stage];
BX_CHECK(Binding::Texture == current.m_type
, "Buffer binding is not supported on DirectX 9.");
const Binding& bind = renderBind.m_bind[stage];
Binding& current = currentBind.m_bind[stage];
if (current.m_idx != bind.m_idx
|| current.m_un.m_draw.m_textureFlags != bind.m_un.m_draw.m_textureFlags

View File

@ -6244,6 +6244,9 @@ namespace bgfx { namespace gl
currentState.m_stateFlags = BGFX_STATE_NONE;
currentState.m_stencil = packStencil(BGFX_STENCIL_NONE, BGFX_STENCIL_NONE);
RenderBind currentBind;
currentBind.clear();
_render->m_hmdInitialized = m_ovr.isInitialized();
const bool hmdEnabled = m_ovr.isEnabled();
@ -6324,7 +6327,9 @@ namespace bgfx { namespace gl
|| item == numItems
;
const RenderItem& renderItem = _render->m_renderItem[_render->m_sortValues[item] ];
const uint32_t itemIdx = _render->m_sortValues[item];
const RenderItem& renderItem = _render->m_renderItem[itemIdx];
const RenderBind& renderBind = _render->m_renderItemBind[itemIdx];
++item;
if (viewChanged)
@ -6499,7 +6504,7 @@ namespace bgfx { namespace gl
GLbitfield barrier = 0;
for (uint32_t ii = 0; ii < BGFX_MAX_COMPUTE_BINDINGS; ++ii)
{
const Binding& bind = compute.m_bind[ii];
const Binding& bind = renderBind.m_bind[ii];
if (invalidHandle != bind.m_idx)
{
switch (bind.m_type)
@ -6630,6 +6635,8 @@ namespace bgfx { namespace gl
changedStencil = packStencil(BGFX_STENCIL_MASK, BGFX_STENCIL_MASK);
currentState.m_stateFlags = newFlags;
currentState.m_stencil = newStencil;
currentBind.clear();
}
uint16_t scissor = draw.m_scissor;
@ -6985,8 +6992,8 @@ namespace bgfx { namespace gl
{
for (uint32_t stage = 0; stage < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++stage)
{
const Binding& bind = draw.m_bind[stage];
Binding& current = currentState.m_bind[stage];
const Binding& bind = renderBind.m_bind[stage];
Binding& current = currentBind.m_bind[stage];
if (current.m_idx != bind.m_idx
|| current.m_type != bind.m_type
|| current.m_un.m_draw.m_textureFlags != bind.m_un.m_draw.m_textureFlags

View File

@ -3745,7 +3745,9 @@ VK_DESTROY
|| item == numItems
;
const RenderItem& renderItem = _render->m_renderItem[_render->m_sortValues[item] ];
const uint32_t itemIdx = _render->m_sortValues[item];
const RenderItem& renderItem = _render->m_renderItem[itemIdx];
const RenderBind& renderBind = _render->m_renderItemBind[itemIdx];
++item;
if (viewChanged)
@ -3912,7 +3914,7 @@ BX_UNUSED(currentSamplerStateIdx);
currentBindHash = 0;
}
// uint32_t bindHash = bx::hashMurmur2A(compute.m_bind, sizeof(compute.m_bind) );
// uint32_t bindHash = bx::hashMurmur2A(renderBind.m_bind, sizeof(renderBind.m_bind) );
// if (currentBindHash != bindHash)
// {
// currentBindHash = bindHash;
@ -3925,7 +3927,7 @@ BX_UNUSED(currentSamplerStateIdx);
//
// for (uint32_t ii = 0; ii < BGFX_MAX_COMPUTE_BINDINGS; ++ii)
// {
// const Binding& bind = compute.m_bind[ii];
// const Binding& bind = renderBind.m_bind[ii];
// if (invalidHandle != bind.m_idx)
// {
// switch (bind.m_type)
@ -4138,7 +4140,7 @@ BX_UNUSED(currentSamplerStateIdx);
);
uint16_t scissor = draw.m_scissor;
uint32_t bindHash = bx::hashMurmur2A(draw.m_bind, sizeof(draw.m_bind) );
uint32_t bindHash = bx::hashMurmur2A(renderBind.m_bind, sizeof(renderBind.m_bind) );
if (currentBindHash != bindHash
|| 0 != changedStencil
|| (hasFactor && blendFactor != draw.m_rgba)
@ -4164,7 +4166,7 @@ BX_UNUSED(currentSamplerStateIdx);
// srvHandle[0].ptr = 0;
// for (uint32_t stage = 0; stage < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++stage)
// {
// const Binding& bind = draw.m_bind[stage];
// const Binding& bind = renderBind.m_bind[stage];
// if (invalidHandle != bind.m_idx)
// {
// TextureD3D12& texture = m_textures[bind.m_idx];