mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-28 10:35:43 -05:00
Added uniform buffer dynamic resizing.
This commit is contained in:
parent
cba8c5d430
commit
5690e1cde8
14 changed files with 140 additions and 127 deletions
1
3rdparty/ocornut-imgui/imgui.cpp
vendored
1
3rdparty/ocornut-imgui/imgui.cpp
vendored
|
@ -2214,6 +2214,7 @@ static void AddDrawListToRenderList(ImVector<ImDrawList*>& out_render_list, ImDr
|
|||
// If this assert triggers because you are drawing lots of stuff manually, A) workaround by calling BeginChild()/EndChild() to put your draw commands in multiple draw lists, B) #define ImDrawIdx to a 'unsigned int' in imconfig.h and render accordingly.
|
||||
const unsigned long long int max_vtx_idx = (unsigned long long int)1L << (sizeof(ImDrawIdx)*8);
|
||||
IM_ASSERT((unsigned long long int)draw_list->_VtxCurrentIdx <= max_vtx_idx);
|
||||
(void)max_vtx_idx;
|
||||
|
||||
GImGui->IO.MetricsRenderVertices += draw_list->VtxBuffer.Size;
|
||||
GImGui->IO.MetricsRenderIndices += draw_list->IdxBuffer.Size;
|
||||
|
|
34
src/bgfx.cpp
34
src/bgfx.cpp
|
@ -765,7 +765,7 @@ namespace bgfx
|
|||
return m_num;
|
||||
}
|
||||
|
||||
m_constEnd = m_constantBuffer->getPos();
|
||||
m_uniformEnd = m_uniformBuffer->getPos();
|
||||
|
||||
m_key.m_program = invalidHandle == _handle.idx
|
||||
? 0
|
||||
|
@ -782,14 +782,14 @@ namespace bgfx
|
|||
m_sortValues[m_num] = m_numRenderItems;
|
||||
++m_num;
|
||||
|
||||
m_draw.m_constBegin = m_constBegin;
|
||||
m_draw.m_constEnd = m_constEnd;
|
||||
m_draw.m_constBegin = m_uniformBegin;
|
||||
m_draw.m_constEnd = m_uniformEnd;
|
||||
m_draw.m_flags |= m_flags;
|
||||
m_renderItem[m_numRenderItems].draw = m_draw;
|
||||
++m_numRenderItems;
|
||||
|
||||
m_draw.clear();
|
||||
m_constBegin = m_constEnd;
|
||||
m_uniformBegin = m_uniformEnd;
|
||||
m_flags = BGFX_STATE_NONE;
|
||||
|
||||
return m_num;
|
||||
|
@ -809,7 +809,7 @@ namespace bgfx
|
|||
return m_num;
|
||||
}
|
||||
|
||||
m_constEnd = m_constantBuffer->getPos();
|
||||
m_uniformEnd = m_uniformBuffer->getPos();
|
||||
|
||||
m_compute.m_matrix = m_draw.m_matrix;
|
||||
m_compute.m_num = m_draw.m_num;
|
||||
|
@ -829,13 +829,13 @@ namespace bgfx
|
|||
m_sortValues[m_num] = m_numRenderItems;
|
||||
++m_num;
|
||||
|
||||
m_compute.m_constBegin = m_constBegin;
|
||||
m_compute.m_constEnd = m_constEnd;
|
||||
m_compute.m_constBegin = m_uniformBegin;
|
||||
m_compute.m_constEnd = m_uniformEnd;
|
||||
m_renderItem[m_numRenderItems].compute = m_compute;
|
||||
++m_numRenderItems;
|
||||
|
||||
m_compute.clear();
|
||||
m_constBegin = m_constEnd;
|
||||
m_uniformBegin = m_uniformEnd;
|
||||
|
||||
return m_num;
|
||||
}
|
||||
|
@ -887,21 +887,21 @@ namespace bgfx
|
|||
1,
|
||||
};
|
||||
|
||||
void ConstantBuffer::writeUniform(UniformType::Enum _type, uint16_t _loc, const void* _value, uint16_t _num)
|
||||
void UniformBuffer::writeUniform(UniformType::Enum _type, uint16_t _loc, const void* _value, uint16_t _num)
|
||||
{
|
||||
uint32_t opcode = encodeOpcode(_type, _loc, _num, true);
|
||||
write(opcode);
|
||||
write(_value, g_uniformTypeSize[_type]*_num);
|
||||
}
|
||||
|
||||
void ConstantBuffer::writeUniformHandle(UniformType::Enum _type, uint16_t _loc, UniformHandle _handle, uint16_t _num)
|
||||
void UniformBuffer::writeUniformHandle(UniformType::Enum _type, uint16_t _loc, UniformHandle _handle, uint16_t _num)
|
||||
{
|
||||
uint32_t opcode = encodeOpcode(_type, _loc, _num, false);
|
||||
write(opcode);
|
||||
write(&_handle, sizeof(UniformHandle) );
|
||||
}
|
||||
|
||||
void ConstantBuffer::writeMarker(const char* _marker)
|
||||
void UniformBuffer::writeMarker(const char* _marker)
|
||||
{
|
||||
uint16_t num = (uint16_t)strlen(_marker)+1;
|
||||
uint32_t opcode = encodeOpcode(bgfx::UniformType::Count, 0, num, true);
|
||||
|
@ -1342,12 +1342,12 @@ namespace bgfx
|
|||
return m_exit;
|
||||
}
|
||||
|
||||
void rendererUpdateUniforms(RendererContextI* _renderCtx, ConstantBuffer* _constantBuffer, uint32_t _begin, uint32_t _end)
|
||||
void rendererUpdateUniforms(RendererContextI* _renderCtx, UniformBuffer* _uniformBuffer, uint32_t _begin, uint32_t _end)
|
||||
{
|
||||
_constantBuffer->reset(_begin);
|
||||
while (_constantBuffer->getPos() < _end)
|
||||
_uniformBuffer->reset(_begin);
|
||||
while (_uniformBuffer->getPos() < _end)
|
||||
{
|
||||
uint32_t opcode = _constantBuffer->read();
|
||||
uint32_t opcode = _uniformBuffer->read();
|
||||
|
||||
if (UniformType::End == opcode)
|
||||
{
|
||||
|
@ -1358,10 +1358,10 @@ namespace bgfx
|
|||
uint16_t loc;
|
||||
uint16_t num;
|
||||
uint16_t copy;
|
||||
ConstantBuffer::decodeOpcode(opcode, type, loc, num, copy);
|
||||
UniformBuffer::decodeOpcode(opcode, type, loc, num, copy);
|
||||
|
||||
uint32_t size = g_uniformTypeSize[type]*num;
|
||||
const char* data = _constantBuffer->read(size);
|
||||
const char* data = _uniformBuffer->read(size);
|
||||
if (UniformType::Count > type)
|
||||
{
|
||||
if (copy)
|
||||
|
|
63
src/bgfx_p.h
63
src/bgfx_p.h
|
@ -861,20 +861,31 @@ namespace bgfx
|
|||
#define BGFX_UNIFORM_SAMPLERBIT UINT8_C(0x20)
|
||||
#define BGFX_UNIFORM_MASK (BGFX_UNIFORM_FRAGMENTBIT|BGFX_UNIFORM_SAMPLERBIT)
|
||||
|
||||
class ConstantBuffer
|
||||
class UniformBuffer
|
||||
{
|
||||
public:
|
||||
static ConstantBuffer* create(uint32_t _size)
|
||||
static UniformBuffer* create(uint32_t _size = 1<<20)
|
||||
{
|
||||
uint32_t size = BX_ALIGN_16(bx::uint32_max(_size, sizeof(ConstantBuffer) ) );
|
||||
void* data = BX_ALLOC(g_allocator, size);
|
||||
return ::new(data) ConstantBuffer(_size);
|
||||
uint32_t size = BX_ALIGN_16(bx::uint32_max(_size, sizeof(UniformBuffer) ) );
|
||||
void* data = BX_ALLOC(g_allocator, size);
|
||||
return ::new(data) UniformBuffer(_size);
|
||||
}
|
||||
|
||||
static void destroy(ConstantBuffer* _constantBuffer)
|
||||
static void destroy(UniformBuffer* _uniformBuffer)
|
||||
{
|
||||
_constantBuffer->~ConstantBuffer();
|
||||
BX_FREE(g_allocator, _constantBuffer);
|
||||
_uniformBuffer->~UniformBuffer();
|
||||
BX_FREE(g_allocator, _uniformBuffer);
|
||||
}
|
||||
|
||||
static void update(UniformBuffer*& _uniformBuffer, uint32_t _treshold = 64<<10, uint32_t _grow = 1<<20)
|
||||
{
|
||||
if (_treshold >= _uniformBuffer->m_size - _uniformBuffer->m_pos)
|
||||
{
|
||||
uint32_t size = BX_ALIGN_16(bx::uint32_max(_uniformBuffer->m_size + _grow, sizeof(UniformBuffer) ) );
|
||||
void* data = BX_REALLOC(g_allocator, _uniformBuffer, size);
|
||||
_uniformBuffer = reinterpret_cast<UniformBuffer*>(data);
|
||||
_uniformBuffer->m_size = size;
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t encodeOpcode(UniformType::Enum _type, uint16_t _loc, uint16_t _num, uint16_t _copy)
|
||||
|
@ -956,14 +967,14 @@ namespace bgfx
|
|||
void writeMarker(const char* _marker);
|
||||
|
||||
private:
|
||||
ConstantBuffer(uint32_t _size)
|
||||
UniformBuffer(uint32_t _size)
|
||||
: m_size(_size-sizeof(m_buffer) )
|
||||
, m_pos(0)
|
||||
{
|
||||
finish();
|
||||
}
|
||||
|
||||
~ConstantBuffer()
|
||||
~UniformBuffer()
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -1208,9 +1219,10 @@ namespace bgfx
|
|||
BX_ALIGN_DECL_CACHE_LINE(struct) Frame
|
||||
{
|
||||
Frame()
|
||||
: m_hmdInitialized(false)
|
||||
: m_uniformMax(0)
|
||||
, m_waitSubmit(0)
|
||||
, m_waitRender(0)
|
||||
, m_hmdInitialized(false)
|
||||
{
|
||||
SortKey term;
|
||||
term.reset();
|
||||
|
@ -1225,7 +1237,7 @@ namespace bgfx
|
|||
|
||||
void create()
|
||||
{
|
||||
m_constantBuffer = ConstantBuffer::create(BGFX_CONFIG_MAX_CONSTANT_BUFFER_SIZE);
|
||||
m_uniformBuffer = UniformBuffer::create();
|
||||
reset();
|
||||
start();
|
||||
m_textVideoMem = BX_NEW(g_allocator, TextVideoMem);
|
||||
|
@ -1233,7 +1245,7 @@ namespace bgfx
|
|||
|
||||
void destroy()
|
||||
{
|
||||
ConstantBuffer::destroy(m_constantBuffer);
|
||||
UniformBuffer::destroy(m_uniformBuffer);
|
||||
BX_DELETE(g_allocator, m_textVideoMem);
|
||||
}
|
||||
|
||||
|
@ -1247,8 +1259,8 @@ namespace bgfx
|
|||
void start()
|
||||
{
|
||||
m_flags = BGFX_STATE_NONE;
|
||||
m_constBegin = 0;
|
||||
m_constEnd = 0;
|
||||
m_uniformBegin = 0;
|
||||
m_uniformEnd = 0;
|
||||
m_draw.clear();
|
||||
m_compute.clear();
|
||||
m_matrixCache.reset();
|
||||
|
@ -1261,7 +1273,7 @@ namespace bgfx
|
|||
m_vboffset = 0;
|
||||
m_cmdPre.start();
|
||||
m_cmdPost.start();
|
||||
m_constantBuffer->reset();
|
||||
m_uniformBuffer->reset();
|
||||
m_discard = false;
|
||||
}
|
||||
|
||||
|
@ -1270,7 +1282,8 @@ namespace bgfx
|
|||
m_cmdPre.finish();
|
||||
m_cmdPost.finish();
|
||||
|
||||
m_constantBuffer->finish();
|
||||
m_uniformMax = bx::uint32_max(m_uniformMax, m_uniformBuffer->getPos() );
|
||||
m_uniformBuffer->finish();
|
||||
|
||||
if (0 < m_numDropped)
|
||||
{
|
||||
|
@ -1284,7 +1297,7 @@ namespace bgfx
|
|||
|
||||
void setMarker(const char* _name)
|
||||
{
|
||||
m_constantBuffer->writeMarker(_name);
|
||||
m_uniformBuffer->writeMarker(_name);
|
||||
}
|
||||
|
||||
void setState(uint64_t _state, uint32_t _rgba)
|
||||
|
@ -1520,7 +1533,8 @@ namespace bgfx
|
|||
|
||||
void writeUniform(UniformType::Enum _type, UniformHandle _handle, const void* _value, uint16_t _num)
|
||||
{
|
||||
m_constantBuffer->writeUniform(_type, _handle.idx, _value, _num);
|
||||
UniformBuffer::update(m_uniformBuffer);
|
||||
m_uniformBuffer->writeUniform(_type, _handle.idx, _value, _num);
|
||||
}
|
||||
|
||||
void free(IndexBufferHandle _handle)
|
||||
|
@ -1601,10 +1615,11 @@ namespace bgfx
|
|||
RenderDraw m_draw;
|
||||
RenderCompute m_compute;
|
||||
uint64_t m_flags;
|
||||
uint32_t m_constBegin;
|
||||
uint32_t m_constEnd;
|
||||
uint32_t m_uniformBegin;
|
||||
uint32_t m_uniformEnd;
|
||||
uint32_t m_uniformMax;
|
||||
|
||||
ConstantBuffer* m_constantBuffer;
|
||||
UniformBuffer* m_uniformBuffer;
|
||||
|
||||
RenderItemCount m_num;
|
||||
RenderItemCount m_numRenderItems;
|
||||
|
@ -1645,11 +1660,11 @@ namespace bgfx
|
|||
TextVideoMem* m_textVideoMem;
|
||||
HMD m_hmd;
|
||||
Stats m_perfStats;
|
||||
bool m_hmdInitialized;
|
||||
|
||||
int64_t m_waitSubmit;
|
||||
int64_t m_waitRender;
|
||||
|
||||
bool m_hmdInitialized;
|
||||
bool m_discard;
|
||||
};
|
||||
|
||||
|
@ -1887,7 +1902,7 @@ namespace bgfx
|
|||
{
|
||||
}
|
||||
|
||||
void rendererUpdateUniforms(RendererContextI* _renderCtx, ConstantBuffer* _constantBuffer, uint32_t _begin, uint32_t _end);
|
||||
void rendererUpdateUniforms(RendererContextI* _renderCtx, UniformBuffer* _uniformBuffer, uint32_t _begin, uint32_t _end);
|
||||
|
||||
#if BGFX_CONFIG_DEBUG
|
||||
# define BGFX_API_FUNC(_func) BX_NO_INLINE _func
|
||||
|
|
|
@ -258,7 +258,7 @@
|
|||
|
||||
#ifndef BGFX_CONFIG_MAX_UNIFORMS
|
||||
# define BGFX_CONFIG_MAX_UNIFORMS 512
|
||||
#endif // BGFX_CONFIG_MAX_CONSTANTS
|
||||
#endif // BGFX_CONFIG_MAX_UNIFORMS
|
||||
|
||||
#ifndef BGFX_CONFIG_MAX_COMMAND_BUFFER_SIZE
|
||||
# define BGFX_CONFIG_MAX_COMMAND_BUFFER_SIZE (64<<10)
|
||||
|
@ -272,10 +272,6 @@
|
|||
# define BGFX_CONFIG_TRANSIENT_INDEX_BUFFER_SIZE (2<<20)
|
||||
#endif // BGFX_CONFIG_TRANSIENT_INDEX_BUFFER_SIZE
|
||||
|
||||
#ifndef BGFX_CONFIG_MAX_CONSTANT_BUFFER_SIZE
|
||||
# define BGFX_CONFIG_MAX_CONSTANT_BUFFER_SIZE (1<<20)
|
||||
#endif // BGFX_CONFIG_MAX_CONSTANT_BUFFER_SIZE
|
||||
|
||||
#ifndef BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT
|
||||
# define BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT 5
|
||||
#endif // BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT
|
||||
|
|
|
@ -2885,13 +2885,13 @@ BX_PRAGMA_DIAGNOSTIC_POP();
|
|||
}
|
||||
}
|
||||
|
||||
void commit(ConstantBuffer& _constantBuffer)
|
||||
void commit(UniformBuffer& _uniformBuffer)
|
||||
{
|
||||
_constantBuffer.reset();
|
||||
_uniformBuffer.reset();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
uint32_t opcode = _constantBuffer.read();
|
||||
uint32_t opcode = _uniformBuffer.read();
|
||||
|
||||
if (UniformType::End == opcode)
|
||||
{
|
||||
|
@ -2902,17 +2902,17 @@ BX_PRAGMA_DIAGNOSTIC_POP();
|
|||
uint16_t loc;
|
||||
uint16_t num;
|
||||
uint16_t copy;
|
||||
ConstantBuffer::decodeOpcode(opcode, type, loc, num, copy);
|
||||
UniformBuffer::decodeOpcode(opcode, type, loc, num, copy);
|
||||
|
||||
const char* data;
|
||||
if (copy)
|
||||
{
|
||||
data = _constantBuffer.read(g_uniformTypeSize[type]*num);
|
||||
data = _uniformBuffer.read(g_uniformTypeSize[type]*num);
|
||||
}
|
||||
else
|
||||
{
|
||||
UniformHandle handle;
|
||||
memcpy(&handle, _constantBuffer.read(sizeof(UniformHandle) ), sizeof(UniformHandle) );
|
||||
memcpy(&handle, _uniformBuffer.read(sizeof(UniformHandle) ), sizeof(UniformHandle) );
|
||||
data = (const char*)m_uniforms[handle.idx];
|
||||
}
|
||||
|
||||
|
@ -2958,7 +2958,7 @@ BX_PRAGMA_DIAGNOSTIC_POP();
|
|||
break;
|
||||
|
||||
default:
|
||||
BX_TRACE("%4d: INVALID 0x%08x, t %d, l %d, n %d, c %d", _constantBuffer.getPos(), opcode, type, loc, num, copy);
|
||||
BX_TRACE("%4d: INVALID 0x%08x, t %d, l %d, n %d, c %d", _uniformBuffer.getPos(), opcode, type, loc, num, copy);
|
||||
break;
|
||||
}
|
||||
#undef CASE_IMPLEMENT_UNIFORM
|
||||
|
@ -3571,7 +3571,7 @@ BX_PRAGMA_DIAGNOSTIC_POP();
|
|||
{
|
||||
if (NULL == m_constantBuffer)
|
||||
{
|
||||
m_constantBuffer = ConstantBuffer::create(1024);
|
||||
m_constantBuffer = UniformBuffer::create(1024);
|
||||
}
|
||||
|
||||
kind = "user";
|
||||
|
@ -4490,7 +4490,7 @@ BX_PRAGMA_DIAGNOSTIC_POP();
|
|||
|
||||
bool programChanged = false;
|
||||
bool constantsChanged = compute.m_constBegin < compute.m_constEnd;
|
||||
rendererUpdateUniforms(this, _render->m_constantBuffer, compute.m_constBegin, compute.m_constEnd);
|
||||
rendererUpdateUniforms(this, _render->m_uniformBuffer, compute.m_constBegin, compute.m_constEnd);
|
||||
|
||||
if (key.m_program != programIdx)
|
||||
{
|
||||
|
@ -4512,7 +4512,7 @@ BX_PRAGMA_DIAGNOSTIC_POP();
|
|||
|
||||
if (constantsChanged)
|
||||
{
|
||||
ConstantBuffer* vcb = program.m_vsh->m_constantBuffer;
|
||||
UniformBuffer* vcb = program.m_vsh->m_constantBuffer;
|
||||
if (NULL != vcb)
|
||||
{
|
||||
commit(*vcb);
|
||||
|
@ -4739,7 +4739,7 @@ BX_PRAGMA_DIAGNOSTIC_POP();
|
|||
|
||||
bool programChanged = false;
|
||||
bool constantsChanged = draw.m_constBegin < draw.m_constEnd;
|
||||
rendererUpdateUniforms(this, _render->m_constantBuffer, draw.m_constBegin, draw.m_constEnd);
|
||||
rendererUpdateUniforms(this, _render->m_uniformBuffer, draw.m_constBegin, draw.m_constEnd);
|
||||
|
||||
if (key.m_program != programIdx)
|
||||
{
|
||||
|
@ -4784,13 +4784,13 @@ BX_PRAGMA_DIAGNOSTIC_POP();
|
|||
|
||||
if (constantsChanged)
|
||||
{
|
||||
ConstantBuffer* vcb = program.m_vsh->m_constantBuffer;
|
||||
UniformBuffer* vcb = program.m_vsh->m_constantBuffer;
|
||||
if (NULL != vcb)
|
||||
{
|
||||
commit(*vcb);
|
||||
}
|
||||
|
||||
ConstantBuffer* fcb = program.m_fsh->m_constantBuffer;
|
||||
UniformBuffer* fcb = program.m_fsh->m_constantBuffer;
|
||||
if (NULL != fcb)
|
||||
{
|
||||
commit(*fcb);
|
||||
|
@ -5193,7 +5193,7 @@ BX_PRAGMA_DIAGNOSTIC_POP();
|
|||
}
|
||||
|
||||
tvm.printf(10, pos++, 0x8e, " Indices: %7d ", statsNumIndices);
|
||||
tvm.printf(10, pos++, 0x8e, " Uniform size: %7d ", _render->m_constEnd);
|
||||
tvm.printf(10, pos++, 0x8e, " Uniform size: %7d, Max: %7d ", _render->m_uniformEnd, _render->m_uniformMax);
|
||||
tvm.printf(10, pos++, 0x8e, " DVB size: %7d ", _render->m_vboffset);
|
||||
tvm.printf(10, pos++, 0x8e, " DIB size: %7d ", _render->m_iboffset);
|
||||
|
||||
|
|
|
@ -124,7 +124,7 @@ namespace bgfx { namespace d3d11
|
|||
{
|
||||
if (NULL != m_constantBuffer)
|
||||
{
|
||||
ConstantBuffer::destroy(m_constantBuffer);
|
||||
UniformBuffer::destroy(m_constantBuffer);
|
||||
m_constantBuffer = NULL;
|
||||
}
|
||||
|
||||
|
@ -154,7 +154,7 @@ namespace bgfx { namespace d3d11
|
|||
};
|
||||
const Memory* m_code;
|
||||
ID3D11Buffer* m_buffer;
|
||||
ConstantBuffer* m_constantBuffer;
|
||||
UniformBuffer* m_constantBuffer;
|
||||
|
||||
PredefinedUniform m_predefined[PredefinedUniform::Count];
|
||||
uint16_t m_attrMask[Attrib::Count];
|
||||
|
|
|
@ -2282,13 +2282,13 @@ data.NumQualityLevels = 0;
|
|||
return sampler;
|
||||
}
|
||||
|
||||
void commit(ConstantBuffer& _constantBuffer)
|
||||
void commit(UniformBuffer& _uniformBuffer)
|
||||
{
|
||||
_constantBuffer.reset();
|
||||
_uniformBuffer.reset();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
uint32_t opcode = _constantBuffer.read();
|
||||
uint32_t opcode = _uniformBuffer.read();
|
||||
|
||||
if (UniformType::End == opcode)
|
||||
{
|
||||
|
@ -2299,17 +2299,17 @@ data.NumQualityLevels = 0;
|
|||
uint16_t loc;
|
||||
uint16_t num;
|
||||
uint16_t copy;
|
||||
ConstantBuffer::decodeOpcode(opcode, type, loc, num, copy);
|
||||
UniformBuffer::decodeOpcode(opcode, type, loc, num, copy);
|
||||
|
||||
const char* data;
|
||||
if (copy)
|
||||
{
|
||||
data = _constantBuffer.read(g_uniformTypeSize[type]*num);
|
||||
data = _uniformBuffer.read(g_uniformTypeSize[type]*num);
|
||||
}
|
||||
else
|
||||
{
|
||||
UniformHandle handle;
|
||||
memcpy(&handle, _constantBuffer.read(sizeof(UniformHandle) ), sizeof(UniformHandle) );
|
||||
memcpy(&handle, _uniformBuffer.read(sizeof(UniformHandle) ), sizeof(UniformHandle) );
|
||||
data = (const char*)m_uniforms[handle.idx];
|
||||
}
|
||||
|
||||
|
@ -2355,7 +2355,7 @@ data.NumQualityLevels = 0;
|
|||
break;
|
||||
|
||||
default:
|
||||
BX_TRACE("%4d: INVALID 0x%08x, t %d, l %d, n %d, c %d", _constantBuffer.getPos(), opcode, type, loc, num, copy);
|
||||
BX_TRACE("%4d: INVALID 0x%08x, t %d, l %d, n %d, c %d", _uniformBuffer.getPos(), opcode, type, loc, num, copy);
|
||||
break;
|
||||
}
|
||||
#undef CASE_IMPLEMENT_UNIFORM
|
||||
|
@ -3533,7 +3533,7 @@ data.NumQualityLevels = 0;
|
|||
{
|
||||
if (NULL == m_constantBuffer)
|
||||
{
|
||||
m_constantBuffer = ConstantBuffer::create(1024);
|
||||
m_constantBuffer = UniformBuffer::create(1024);
|
||||
}
|
||||
|
||||
kind = "user";
|
||||
|
@ -4473,12 +4473,12 @@ data.NumQualityLevels = 0;
|
|||
if (compute.m_constBegin < compute.m_constEnd
|
||||
|| currentProgramIdx != key.m_program)
|
||||
{
|
||||
rendererUpdateUniforms(this, _render->m_constantBuffer, compute.m_constBegin, compute.m_constEnd);
|
||||
rendererUpdateUniforms(this, _render->m_uniformBuffer, compute.m_constBegin, compute.m_constEnd);
|
||||
|
||||
currentProgramIdx = key.m_program;
|
||||
ProgramD3D12& program = m_program[currentProgramIdx];
|
||||
|
||||
ConstantBuffer* vcb = program.m_vsh->m_constantBuffer;
|
||||
UniformBuffer* vcb = program.m_vsh->m_constantBuffer;
|
||||
if (NULL != vcb)
|
||||
{
|
||||
commit(*vcb);
|
||||
|
@ -4569,7 +4569,7 @@ data.NumQualityLevels = 0;
|
|||
primIndex = uint8_t(pt>>BGFX_STATE_PT_SHIFT);
|
||||
}
|
||||
|
||||
rendererUpdateUniforms(this, _render->m_constantBuffer, draw.m_constBegin, draw.m_constEnd);
|
||||
rendererUpdateUniforms(this, _render->m_uniformBuffer, draw.m_constBegin, draw.m_constEnd);
|
||||
|
||||
if (isValid(draw.m_vertexBuffer) )
|
||||
{
|
||||
|
@ -4740,13 +4740,13 @@ data.NumQualityLevels = 0;
|
|||
currentProgramIdx = key.m_program;
|
||||
ProgramD3D12& program = m_program[currentProgramIdx];
|
||||
|
||||
ConstantBuffer* vcb = program.m_vsh->m_constantBuffer;
|
||||
UniformBuffer* vcb = program.m_vsh->m_constantBuffer;
|
||||
if (NULL != vcb)
|
||||
{
|
||||
commit(*vcb);
|
||||
}
|
||||
|
||||
ConstantBuffer* fcb = program.m_fsh->m_constantBuffer;
|
||||
UniformBuffer* fcb = program.m_fsh->m_constantBuffer;
|
||||
if (NULL != fcb)
|
||||
{
|
||||
commit(*fcb);
|
||||
|
@ -4925,7 +4925,7 @@ data.NumQualityLevels = 0;
|
|||
// }
|
||||
|
||||
tvm.printf(10, pos++, 0x8e, " Indices: %7d ", statsNumIndices);
|
||||
tvm.printf(10, pos++, 0x8e, " Uniform size: %7d ", _render->m_constEnd);
|
||||
tvm.printf(10, pos++, 0x8e, " Uniform size: %7d, Max: %7d ", _render->m_uniformEnd, _render->m_uniformMax);
|
||||
tvm.printf(10, pos++, 0x8e, " DVB size: %7d ", _render->m_vboffset);
|
||||
tvm.printf(10, pos++, 0x8e, " DIB size: %7d ", _render->m_iboffset);
|
||||
|
||||
|
|
|
@ -179,7 +179,7 @@ namespace bgfx { namespace d3d12
|
|||
{
|
||||
if (NULL != m_constantBuffer)
|
||||
{
|
||||
ConstantBuffer::destroy(m_constantBuffer);
|
||||
UniformBuffer::destroy(m_constantBuffer);
|
||||
m_constantBuffer = NULL;
|
||||
}
|
||||
|
||||
|
@ -194,7 +194,7 @@ namespace bgfx { namespace d3d12
|
|||
}
|
||||
|
||||
const Memory* m_code;
|
||||
ConstantBuffer* m_constantBuffer;
|
||||
UniformBuffer* m_constantBuffer;
|
||||
|
||||
PredefinedUniform m_predefined[PredefinedUniform::Count];
|
||||
uint16_t m_attrMask[Attrib::Count];
|
||||
|
|
|
@ -1539,15 +1539,15 @@ namespace bgfx { namespace d3d9
|
|||
}
|
||||
}
|
||||
|
||||
void commit(ConstantBuffer& _constantBuffer)
|
||||
void commit(UniformBuffer& _uniformBuffer)
|
||||
{
|
||||
_constantBuffer.reset();
|
||||
_uniformBuffer.reset();
|
||||
|
||||
IDirect3DDevice9* device = m_device;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
uint32_t opcode = _constantBuffer.read();
|
||||
uint32_t opcode = _uniformBuffer.read();
|
||||
|
||||
if (UniformType::End == opcode)
|
||||
{
|
||||
|
@ -1558,17 +1558,17 @@ namespace bgfx { namespace d3d9
|
|||
uint16_t loc;
|
||||
uint16_t num;
|
||||
uint16_t copy;
|
||||
ConstantBuffer::decodeOpcode(opcode, type, loc, num, copy);
|
||||
UniformBuffer::decodeOpcode(opcode, type, loc, num, copy);
|
||||
|
||||
const char* data;
|
||||
if (copy)
|
||||
{
|
||||
data = _constantBuffer.read(g_uniformTypeSize[type]*num);
|
||||
data = _uniformBuffer.read(g_uniformTypeSize[type]*num);
|
||||
}
|
||||
else
|
||||
{
|
||||
UniformHandle handle;
|
||||
memcpy(&handle, _constantBuffer.read(sizeof(UniformHandle) ), sizeof(UniformHandle) );
|
||||
memcpy(&handle, _uniformBuffer.read(sizeof(UniformHandle) ), sizeof(UniformHandle) );
|
||||
data = (const char*)m_uniforms[handle.idx];
|
||||
}
|
||||
|
||||
|
@ -1643,7 +1643,7 @@ namespace bgfx { namespace d3d9
|
|||
break;
|
||||
|
||||
default:
|
||||
BX_TRACE("%4d: INVALID 0x%08x, t %d, l %d, n %d, c %d", _constantBuffer.getPos(), opcode, type, loc, num, copy);
|
||||
BX_TRACE("%4d: INVALID 0x%08x, t %d, l %d, n %d, c %d", _uniformBuffer.getPos(), opcode, type, loc, num, copy);
|
||||
break;
|
||||
}
|
||||
#undef CASE_IMPLEMENT_UNIFORM
|
||||
|
@ -2227,7 +2227,7 @@ namespace bgfx { namespace d3d9
|
|||
{
|
||||
if (NULL == m_constantBuffer)
|
||||
{
|
||||
m_constantBuffer = ConstantBuffer::create(1024);
|
||||
m_constantBuffer = UniformBuffer::create(1024);
|
||||
}
|
||||
|
||||
kind = "user";
|
||||
|
@ -3481,7 +3481,7 @@ namespace bgfx { namespace d3d9
|
|||
|
||||
bool programChanged = false;
|
||||
bool constantsChanged = draw.m_constBegin < draw.m_constEnd;
|
||||
rendererUpdateUniforms(this, _render->m_constantBuffer, draw.m_constBegin, draw.m_constEnd);
|
||||
rendererUpdateUniforms(this, _render->m_uniformBuffer, draw.m_constBegin, draw.m_constEnd);
|
||||
|
||||
if (key.m_program != programIdx)
|
||||
{
|
||||
|
@ -3509,13 +3509,13 @@ namespace bgfx { namespace d3d9
|
|||
|
||||
if (constantsChanged)
|
||||
{
|
||||
ConstantBuffer* vcb = program.m_vsh->m_constantBuffer;
|
||||
UniformBuffer* vcb = program.m_vsh->m_constantBuffer;
|
||||
if (NULL != vcb)
|
||||
{
|
||||
commit(*vcb);
|
||||
}
|
||||
|
||||
ConstantBuffer* fcb = program.m_fsh->m_constantBuffer;
|
||||
UniformBuffer* fcb = program.m_fsh->m_constantBuffer;
|
||||
if (NULL != fcb)
|
||||
{
|
||||
commit(*fcb);
|
||||
|
@ -3801,7 +3801,7 @@ namespace bgfx { namespace d3d9
|
|||
}
|
||||
|
||||
tvm.printf(10, pos++, 0x8e, " Indices: %7d ", statsNumIndices);
|
||||
tvm.printf(10, pos++, 0x8e, " Uniform size: %7d ", _render->m_constEnd);
|
||||
tvm.printf(10, pos++, 0x8e, " Uniform size: %7d, Max: %7d ", _render->m_uniformEnd, _render->m_uniformMax);
|
||||
tvm.printf(10, pos++, 0x8e, " DVB size: %7d ", _render->m_vboffset);
|
||||
tvm.printf(10, pos++, 0x8e, " DIB size: %7d ", _render->m_iboffset);
|
||||
|
||||
|
|
|
@ -245,7 +245,7 @@ namespace bgfx { namespace d3d9
|
|||
{
|
||||
if (NULL != m_constantBuffer)
|
||||
{
|
||||
ConstantBuffer::destroy(m_constantBuffer);
|
||||
UniformBuffer::destroy(m_constantBuffer);
|
||||
m_constantBuffer = NULL;
|
||||
}
|
||||
m_numPredefined = 0;
|
||||
|
@ -263,7 +263,7 @@ namespace bgfx { namespace d3d9
|
|||
IDirect3DVertexShader9* m_vertexShader;
|
||||
IDirect3DPixelShader9* m_pixelShader;
|
||||
};
|
||||
ConstantBuffer* m_constantBuffer;
|
||||
UniformBuffer* m_constantBuffer;
|
||||
PredefinedUniform m_predefined[PredefinedUniform::Count];
|
||||
uint8_t m_numPredefined;
|
||||
uint8_t m_type;
|
||||
|
|
|
@ -2773,13 +2773,13 @@ namespace bgfx { namespace gl
|
|||
}
|
||||
}
|
||||
|
||||
void commit(ConstantBuffer& _constantBuffer)
|
||||
void commit(UniformBuffer& _uniformBuffer)
|
||||
{
|
||||
_constantBuffer.reset();
|
||||
_uniformBuffer.reset();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
uint32_t opcode = _constantBuffer.read();
|
||||
uint32_t opcode = _uniformBuffer.read();
|
||||
|
||||
if (UniformType::End == opcode)
|
||||
{
|
||||
|
@ -2790,21 +2790,21 @@ namespace bgfx { namespace gl
|
|||
uint16_t ignore;
|
||||
uint16_t num;
|
||||
uint16_t copy;
|
||||
ConstantBuffer::decodeOpcode(opcode, type, ignore, num, copy);
|
||||
UniformBuffer::decodeOpcode(opcode, type, ignore, num, copy);
|
||||
|
||||
const char* data;
|
||||
if (copy)
|
||||
{
|
||||
data = _constantBuffer.read(g_uniformTypeSize[type]*num);
|
||||
data = _uniformBuffer.read(g_uniformTypeSize[type]*num);
|
||||
}
|
||||
else
|
||||
{
|
||||
UniformHandle handle;
|
||||
memcpy(&handle, _constantBuffer.read(sizeof(UniformHandle) ), sizeof(UniformHandle) );
|
||||
memcpy(&handle, _uniformBuffer.read(sizeof(UniformHandle) ), sizeof(UniformHandle) );
|
||||
data = (const char*)m_uniforms[handle.idx];
|
||||
}
|
||||
|
||||
uint32_t loc = _constantBuffer.read();
|
||||
uint32_t loc = _uniformBuffer.read();
|
||||
|
||||
#define CASE_IMPLEMENT_UNIFORM(_uniform, _glsuffix, _dxsuffix, _type) \
|
||||
case UniformType::_uniform: \
|
||||
|
@ -2841,7 +2841,7 @@ namespace bgfx { namespace gl
|
|||
break;
|
||||
|
||||
default:
|
||||
BX_TRACE("%4d: INVALID 0x%08x, t %d, l %d, n %d, c %d", _constantBuffer.getPos(), opcode, type, loc, num, copy);
|
||||
BX_TRACE("%4d: INVALID 0x%08x, t %d, l %d, n %d, c %d", _uniformBuffer.getPos(), opcode, type, loc, num, copy);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -3302,7 +3302,7 @@ namespace bgfx { namespace gl
|
|||
{
|
||||
if (NULL != m_constantBuffer)
|
||||
{
|
||||
ConstantBuffer::destroy(m_constantBuffer);
|
||||
UniformBuffer::destroy(m_constantBuffer);
|
||||
m_constantBuffer = NULL;
|
||||
}
|
||||
m_numPredefined = 0;
|
||||
|
@ -3487,7 +3487,7 @@ namespace bgfx { namespace gl
|
|||
{
|
||||
if (NULL == m_constantBuffer)
|
||||
{
|
||||
m_constantBuffer = ConstantBuffer::create(1024);
|
||||
m_constantBuffer = UniformBuffer::create(1024);
|
||||
}
|
||||
|
||||
UniformType::Enum type = convertGlType(gltype);
|
||||
|
@ -5264,7 +5264,7 @@ namespace bgfx { namespace gl
|
|||
if (0 != barrier)
|
||||
{
|
||||
bool constantsChanged = compute.m_constBegin < compute.m_constEnd;
|
||||
rendererUpdateUniforms(this, _render->m_constantBuffer, compute.m_constBegin, compute.m_constEnd);
|
||||
rendererUpdateUniforms(this, _render->m_uniformBuffer, compute.m_constBegin, compute.m_constEnd);
|
||||
|
||||
if (constantsChanged
|
||||
&& NULL != program.m_constantBuffer)
|
||||
|
@ -5620,7 +5620,7 @@ namespace bgfx { namespace gl
|
|||
bool programChanged = false;
|
||||
bool constantsChanged = draw.m_constBegin < draw.m_constEnd;
|
||||
bool bindAttribs = false;
|
||||
rendererUpdateUniforms(this, _render->m_constantBuffer, draw.m_constBegin, draw.m_constEnd);
|
||||
rendererUpdateUniforms(this, _render->m_uniformBuffer, draw.m_constBegin, draw.m_constEnd);
|
||||
|
||||
if (key.m_program != programIdx)
|
||||
{
|
||||
|
@ -6083,7 +6083,7 @@ namespace bgfx { namespace gl
|
|||
}
|
||||
|
||||
tvm.printf(10, pos++, 0x8e, " Indices: %7d ", statsNumIndices);
|
||||
tvm.printf(10, pos++, 0x8e, " Uniform size: %7d ", _render->m_constEnd);
|
||||
tvm.printf(10, pos++, 0x8e, " Uniform size: %7d, Max: %7d ", _render->m_uniformEnd, _render->m_uniformMax);
|
||||
tvm.printf(10, pos++, 0x8e, " DVB size: %7d ", _render->m_vboffset);
|
||||
tvm.printf(10, pos++, 0x8e, " DIB size: %7d ", _render->m_iboffset);
|
||||
|
||||
|
|
|
@ -807,7 +807,7 @@ typedef uint64_t GLuint64;
|
|||
|
||||
namespace bgfx
|
||||
{
|
||||
class ConstantBuffer;
|
||||
class UniformBuffer;
|
||||
} // namespace bgfx
|
||||
|
||||
namespace bgfx { namespace gl
|
||||
|
@ -1174,7 +1174,7 @@ namespace bgfx { namespace gl
|
|||
GLint m_sampler[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS];
|
||||
uint8_t m_numSamplers;
|
||||
|
||||
ConstantBuffer* m_constantBuffer;
|
||||
UniformBuffer* m_constantBuffer;
|
||||
PredefinedUniform m_predefined[PredefinedUniform::Count];
|
||||
uint8_t m_numPredefined;
|
||||
VaoCacheRef m_vcref;
|
||||
|
|
|
@ -395,8 +395,8 @@ namespace bgfx { namespace mtl
|
|||
uint32_t m_vshConstantBufferAlignmentMask;
|
||||
uint32_t m_fshConstantBufferSize;
|
||||
uint32_t m_fshConstantBufferAlignmentMask;
|
||||
ConstantBuffer* m_fshConstantBuffer;
|
||||
ConstantBuffer* m_vshConstantBuffer;
|
||||
UniformBuffer* m_fshConstantBuffer;
|
||||
UniformBuffer* m_vshConstantBuffer;
|
||||
PredefinedUniform m_predefined[PredefinedUniform::Count*2];
|
||||
uint8_t m_numPredefined;
|
||||
};
|
||||
|
|
|
@ -932,13 +932,13 @@ namespace bgfx { namespace mtl
|
|||
setShaderUniform(_flags, _loc, _val, _numRegs);
|
||||
}
|
||||
|
||||
void commit(ConstantBuffer& _constantBuffer)
|
||||
void commit(UniformBuffer& _uniformBuffer)
|
||||
{
|
||||
_constantBuffer.reset();
|
||||
_uniformBuffer.reset();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
uint32_t opcode = _constantBuffer.read();
|
||||
uint32_t opcode = _uniformBuffer.read();
|
||||
|
||||
if (UniformType::End == opcode)
|
||||
{
|
||||
|
@ -949,17 +949,17 @@ namespace bgfx { namespace mtl
|
|||
uint16_t loc;
|
||||
uint16_t num;
|
||||
uint16_t copy;
|
||||
ConstantBuffer::decodeOpcode(opcode, type, loc, num, copy);
|
||||
UniformBuffer::decodeOpcode(opcode, type, loc, num, copy);
|
||||
|
||||
const char* data;
|
||||
if (copy)
|
||||
{
|
||||
data = _constantBuffer.read(g_uniformTypeSize[type]*num);
|
||||
data = _uniformBuffer.read(g_uniformTypeSize[type]*num);
|
||||
}
|
||||
else
|
||||
{
|
||||
UniformHandle handle;
|
||||
memcpy(&handle, _constantBuffer.read(sizeof(UniformHandle) ), sizeof(UniformHandle) );
|
||||
memcpy(&handle, _uniformBuffer.read(sizeof(UniformHandle) ), sizeof(UniformHandle) );
|
||||
data = (const char*)m_uniforms[handle.idx];
|
||||
}
|
||||
|
||||
|
@ -1005,7 +1005,7 @@ namespace bgfx { namespace mtl
|
|||
break;
|
||||
|
||||
default:
|
||||
BX_TRACE("%4d: INVALID 0x%08x, t %d, l %d, n %d, c %d", _constantBuffer.getPos(), opcode, type, loc, num, copy);
|
||||
BX_TRACE("%4d: INVALID 0x%08x, t %d, l %d, n %d, c %d", _uniformBuffer.getPos(), opcode, type, loc, num, copy);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1376,13 +1376,13 @@ namespace bgfx { namespace mtl
|
|||
|
||||
if (NULL != m_vshConstantBuffer)
|
||||
{
|
||||
ConstantBuffer::destroy(m_vshConstantBuffer);
|
||||
UniformBuffer::destroy(m_vshConstantBuffer);
|
||||
m_vshConstantBuffer = NULL;
|
||||
}
|
||||
|
||||
if (NULL != m_fshConstantBuffer)
|
||||
{
|
||||
ConstantBuffer::destroy(m_fshConstantBuffer);
|
||||
UniformBuffer::destroy(m_fshConstantBuffer);
|
||||
m_fshConstantBuffer = NULL;
|
||||
}
|
||||
|
||||
|
@ -1606,7 +1606,7 @@ namespace bgfx { namespace mtl
|
|||
{
|
||||
for( int type =0; type<2; ++type)
|
||||
{
|
||||
ConstantBuffer*& constantBuffer = (type==0?m_vshConstantBuffer : m_fshConstantBuffer);
|
||||
UniformBuffer*& constantBuffer = (type==0?m_vshConstantBuffer : m_fshConstantBuffer);
|
||||
uint8_t fragmentBit = (1 == type ? BGFX_UNIFORM_FRAGMENTBIT : 0);
|
||||
|
||||
for( MTLArgument* arg in (type==0?reflection.vertexArguments:reflection.fragmentArguments))
|
||||
|
@ -1676,7 +1676,7 @@ namespace bgfx { namespace mtl
|
|||
{
|
||||
if (NULL == constantBuffer)
|
||||
{
|
||||
constantBuffer = ConstantBuffer::create(1024);
|
||||
constantBuffer = UniformBuffer::create(1024);
|
||||
}
|
||||
|
||||
UniformType::Enum type = convertMtlType(dataType);
|
||||
|
@ -2385,8 +2385,8 @@ namespace bgfx { namespace mtl
|
|||
}
|
||||
|
||||
bool programChanged = false;
|
||||
bool constantsChanged = draw.m_constBegin < draw.m_constEnd;
|
||||
rendererUpdateUniforms(this, _render->m_constantBuffer, draw.m_constBegin, draw.m_constEnd);
|
||||
bool constantsChanged = draw.m_uniformBegin < draw.m_uniformEnd;
|
||||
rendererUpdateUniforms(this, _render->m_uniformBuffer, draw.m_uniformBegin, draw.m_uniformEnd);
|
||||
|
||||
if (key.m_program != programIdx ||
|
||||
(BGFX_STATE_BLEND_MASK|BGFX_STATE_BLEND_EQUATION_MASK|BGFX_STATE_ALPHA_WRITE|BGFX_STATE_RGB_WRITE|BGFX_STATE_BLEND_INDEPENDENT|BGFX_STATE_MSAA) & changedFlags ||
|
||||
|
@ -2453,13 +2453,13 @@ namespace bgfx { namespace mtl
|
|||
|
||||
if (constantsChanged)
|
||||
{
|
||||
ConstantBuffer* vcb = program.m_vshConstantBuffer;
|
||||
UniformBuffer* vcb = program.m_vshConstantBuffer;
|
||||
if (NULL != vcb)
|
||||
{
|
||||
commit(*vcb);
|
||||
}
|
||||
|
||||
ConstantBuffer* fcb = program.m_fshConstantBuffer;
|
||||
UniformBuffer* fcb = program.m_fshConstantBuffer;
|
||||
if (NULL != fcb)
|
||||
{
|
||||
commit(*fcb);
|
||||
|
@ -2709,9 +2709,10 @@ namespace bgfx { namespace mtl
|
|||
);
|
||||
}
|
||||
|
||||
tvm.printf(10, pos++, 0x8e, " Indices: %7d", statsNumIndices);
|
||||
tvm.printf(10, pos++, 0x8e, " DVB size: %7d", _render->m_vboffset);
|
||||
tvm.printf(10, pos++, 0x8e, " DIB size: %7d", _render->m_iboffset);
|
||||
tvm.printf(10, pos++, 0x8e, " Indices: %7d ", statsNumIndices);
|
||||
tvm.printf(10, pos++, 0x8e, " Uniform size: %7d, Max: %7d ", _render->m_uniformEnd, _render->m_uniformMax);
|
||||
tvm.printf(10, pos++, 0x8e, " DVB size: %7d ", _render->m_vboffset);
|
||||
tvm.printf(10, pos++, 0x8e, " DIB size: %7d ", _render->m_iboffset);
|
||||
|
||||
double captureMs = double(captureElapsed)*toMs;
|
||||
tvm.printf(10, pos++, 0x8e, " Capture: %3.4f [ms]", captureMs);
|
||||
|
|
Loading…
Reference in a new issue