mirror of https://github.com/bkaradzic/bgfx
Removed alignment macros, and added functions instead.
This commit is contained in:
parent
a169bffb1e
commit
36ec2a462d
|
@ -4107,7 +4107,7 @@ namespace bgfx
|
||||||
void allocInstanceDataBuffer(InstanceDataBuffer* _idb, uint32_t _num, uint16_t _stride)
|
void allocInstanceDataBuffer(InstanceDataBuffer* _idb, uint32_t _num, uint16_t _stride)
|
||||||
{
|
{
|
||||||
BGFX_CHECK_CAPS(BGFX_CAPS_INSTANCING, "Instancing is not supported!");
|
BGFX_CHECK_CAPS(BGFX_CAPS_INSTANCING, "Instancing is not supported!");
|
||||||
BX_CHECK(_stride == BX_ALIGN_16(_stride), "Stride must be multiple of 16.");
|
BX_CHECK(bx::isAligned(_stride, 16), "Stride must be multiple of 16.");
|
||||||
BX_CHECK(0 < _num, "Requesting 0 instanced data vertices.");
|
BX_CHECK(0 < _num, "Requesting 0 instanced data vertices.");
|
||||||
s_ctx->allocInstanceDataBuffer(_idb, _num, _stride);
|
s_ctx->allocInstanceDataBuffer(_idb, _num, _stride);
|
||||||
BX_CHECK(_num == _idb->size / _stride
|
BX_CHECK(_num == _idb->size / _stride
|
||||||
|
|
24
src/bgfx_p.h
24
src/bgfx_p.h
|
@ -1335,7 +1335,7 @@ constexpr uint64_t kSortKeyComputeProgramMask = uint64_t(BGFX_CONFIG_MAX_PROGRA
|
||||||
{
|
{
|
||||||
const uint32_t structSize = sizeof(UniformBuffer)-sizeof(UniformBuffer::m_buffer);
|
const uint32_t structSize = sizeof(UniformBuffer)-sizeof(UniformBuffer::m_buffer);
|
||||||
|
|
||||||
uint32_t size = BX_ALIGN_16(_size);
|
uint32_t size = bx::alignUp(_size, 16);
|
||||||
void* data = BX_ALLOC(g_allocator, size+structSize);
|
void* data = BX_ALLOC(g_allocator, size+structSize);
|
||||||
return BX_PLACEMENT_NEW(data, UniformBuffer)(size);
|
return BX_PLACEMENT_NEW(data, UniformBuffer)(size);
|
||||||
}
|
}
|
||||||
|
@ -1352,7 +1352,7 @@ constexpr uint64_t kSortKeyComputeProgramMask = uint64_t(BGFX_CONFIG_MAX_PROGRA
|
||||||
if (_treshold >= uniformBuffer->m_size - uniformBuffer->m_pos)
|
if (_treshold >= uniformBuffer->m_size - uniformBuffer->m_pos)
|
||||||
{
|
{
|
||||||
const uint32_t structSize = sizeof(UniformBuffer)-sizeof(UniformBuffer::m_buffer);
|
const uint32_t structSize = sizeof(UniformBuffer)-sizeof(UniformBuffer::m_buffer);
|
||||||
uint32_t size = BX_ALIGN_16(uniformBuffer->m_size + _grow);
|
uint32_t size = bx::alignUp(uniformBuffer->m_size + _grow, 16);
|
||||||
void* data = BX_REALLOC(g_allocator, uniformBuffer, size+structSize);
|
void* data = BX_REALLOC(g_allocator, uniformBuffer, size+structSize);
|
||||||
uniformBuffer = reinterpret_cast<UniformBuffer*>(data);
|
uniformBuffer = reinterpret_cast<UniformBuffer*>(data);
|
||||||
uniformBuffer->m_size = size;
|
uniformBuffer->m_size = size;
|
||||||
|
@ -3219,7 +3219,7 @@ constexpr uint64_t kSortKeyComputeProgramMask = uint64_t(BGFX_CONFIG_MAX_PROGRA
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint32_t indexSize = 0 == (_flags & BGFX_BUFFER_INDEX32) ? 2 : 4;
|
const uint32_t indexSize = 0 == (_flags & BGFX_BUFFER_INDEX32) ? 2 : 4;
|
||||||
uint32_t size = BX_ALIGN_16(_num*indexSize);
|
const uint32_t size = bx::alignUp(_num*indexSize, 16);
|
||||||
|
|
||||||
uint64_t ptr = 0;
|
uint64_t ptr = 0;
|
||||||
if (0 != (_flags & BGFX_BUFFER_COMPUTE_READ_WRITE) )
|
if (0 != (_flags & BGFX_BUFFER_COMPUTE_READ_WRITE) )
|
||||||
|
@ -3583,9 +3583,12 @@ constexpr uint64_t kSortKeyComputeProgramMask = uint64_t(BGFX_CONFIG_MAX_PROGRA
|
||||||
uint16_t flags = BGFX_BUFFER_NONE;
|
uint16_t flags = BGFX_BUFFER_NONE;
|
||||||
cmdbuf.write(flags);
|
cmdbuf.write(flags);
|
||||||
|
|
||||||
const uint32_t size = BX_ALIGN_16(sizeof(TransientIndexBuffer) ) + BX_ALIGN_16(_size);
|
const uint32_t size = 0
|
||||||
|
+ bx::alignUp(sizeof(TransientIndexBuffer), 16)
|
||||||
|
+ bx::alignUp(_size, 16)
|
||||||
|
;
|
||||||
tib = (TransientIndexBuffer*)BX_ALIGNED_ALLOC(g_allocator, size, 16);
|
tib = (TransientIndexBuffer*)BX_ALIGNED_ALLOC(g_allocator, size, 16);
|
||||||
tib->data = (uint8_t *)tib + BX_ALIGN_16(sizeof(TransientIndexBuffer) );
|
tib->data = (uint8_t *)tib + bx::alignUp(sizeof(TransientIndexBuffer), 16);
|
||||||
tib->size = _size;
|
tib->size = _size;
|
||||||
tib->handle = handle;
|
tib->handle = handle;
|
||||||
|
|
||||||
|
@ -3644,9 +3647,12 @@ constexpr uint64_t kSortKeyComputeProgramMask = uint64_t(BGFX_CONFIG_MAX_PROGRA
|
||||||
uint16_t flags = BGFX_BUFFER_NONE;
|
uint16_t flags = BGFX_BUFFER_NONE;
|
||||||
cmdbuf.write(flags);
|
cmdbuf.write(flags);
|
||||||
|
|
||||||
const uint32_t size = BX_ALIGN_16(sizeof(TransientVertexBuffer) ) + BX_ALIGN_16(_size);
|
const uint32_t size = 0
|
||||||
|
+ bx::alignUp(sizeof(TransientVertexBuffer), 16)
|
||||||
|
+ bx::alignUp(_size, 16)
|
||||||
|
;
|
||||||
tvb = (TransientVertexBuffer*)BX_ALIGNED_ALLOC(g_allocator, size, 16);
|
tvb = (TransientVertexBuffer*)BX_ALIGNED_ALLOC(g_allocator, size, 16);
|
||||||
tvb->data = (uint8_t *)tvb + BX_ALIGN_16(sizeof(TransientVertexBuffer) );
|
tvb->data = (uint8_t *)tvb + bx::alignUp(sizeof(TransientVertexBuffer), 16);
|
||||||
tvb->size = _size;
|
tvb->size = _size;
|
||||||
tvb->startVertex = 0;
|
tvb->startVertex = 0;
|
||||||
tvb->stride = stride;
|
tvb->stride = stride;
|
||||||
|
@ -3700,8 +3706,8 @@ constexpr uint64_t kSortKeyComputeProgramMask = uint64_t(BGFX_CONFIG_MAX_PROGRA
|
||||||
{
|
{
|
||||||
BGFX_MUTEX_SCOPE(m_resourceApiLock);
|
BGFX_MUTEX_SCOPE(m_resourceApiLock);
|
||||||
|
|
||||||
uint16_t stride = BX_ALIGN_16(_stride);
|
const uint16_t stride = bx::alignUp(_stride, 16);
|
||||||
uint32_t offset = m_submit->allocTransientVertexBuffer(_num, stride);
|
const uint32_t offset = m_submit->allocTransientVertexBuffer(_num, stride);
|
||||||
|
|
||||||
TransientVertexBuffer& dvb = *m_submit->m_transientVb;
|
TransientVertexBuffer& dvb = *m_submit->m_transientVb;
|
||||||
_idb->data = &dvb.data[offset];
|
_idb->data = &dvb.data[offset];
|
||||||
|
|
|
@ -1903,7 +1903,7 @@ namespace bgfx { namespace d3d11
|
||||||
BX_FREE(g_allocator, m_uniforms[_handle.idx]);
|
BX_FREE(g_allocator, m_uniforms[_handle.idx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t size = BX_ALIGN_16(g_uniformTypeSize[_type]*_num);
|
const uint32_t size = bx::alignUp(g_uniformTypeSize[_type]*_num, 16);
|
||||||
void* data = BX_ALLOC(g_allocator, size);
|
void* data = BX_ALLOC(g_allocator, size);
|
||||||
bx::memSet(data, 0, size);
|
bx::memSet(data, 0, size);
|
||||||
m_uniforms[_handle.idx] = data;
|
m_uniforms[_handle.idx] = data;
|
||||||
|
|
|
@ -1789,7 +1789,7 @@ namespace bgfx { namespace d3d12
|
||||||
BX_FREE(g_allocator, m_uniforms[_handle.idx]);
|
BX_FREE(g_allocator, m_uniforms[_handle.idx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t size = BX_ALIGN_16(g_uniformTypeSize[_type] * _num);
|
const uint32_t size = bx::alignUp(g_uniformTypeSize[_type] * _num, 16);
|
||||||
void* data = BX_ALLOC(g_allocator, size);
|
void* data = BX_ALLOC(g_allocator, size);
|
||||||
bx::memSet(data, 0, size);
|
bx::memSet(data, 0, size);
|
||||||
m_uniforms[_handle.idx] = data;
|
m_uniforms[_handle.idx] = data;
|
||||||
|
@ -3481,7 +3481,7 @@ namespace bgfx { namespace d3d12
|
||||||
_gpuAddress = m_gpuVA + m_pos;
|
_gpuAddress = m_gpuVA + m_pos;
|
||||||
void* data = &m_data[m_pos];
|
void* data = &m_data[m_pos];
|
||||||
|
|
||||||
m_pos += BX_ALIGN_256(_size);
|
m_pos += bx::alignUp(_size, 256);
|
||||||
|
|
||||||
// D3D12_CONSTANT_BUFFER_VIEW_DESC desc;
|
// D3D12_CONSTANT_BUFFER_VIEW_DESC desc;
|
||||||
// desc.BufferLocation = _gpuAddress;
|
// desc.BufferLocation = _gpuAddress;
|
||||||
|
|
|
@ -1213,7 +1213,7 @@ namespace bgfx { namespace d3d9
|
||||||
BX_FREE(g_allocator, m_uniforms[_handle.idx]);
|
BX_FREE(g_allocator, m_uniforms[_handle.idx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t size = BX_ALIGN_16(g_uniformTypeSize[_type]*_num);
|
const uint32_t size = bx::alignUp(g_uniformTypeSize[_type]*_num, 16);
|
||||||
void* data = BX_ALLOC(g_allocator, size);
|
void* data = BX_ALLOC(g_allocator, size);
|
||||||
bx::memSet(data, 0, size);
|
bx::memSet(data, 0, size);
|
||||||
m_uniforms[_handle.idx] = data;
|
m_uniforms[_handle.idx] = data;
|
||||||
|
|
|
@ -913,9 +913,9 @@ namespace bgfx { namespace mtl
|
||||||
UniformBuffer* m_fshConstantBuffer;
|
UniformBuffer* m_fshConstantBuffer;
|
||||||
|
|
||||||
uint32_t m_vshConstantBufferSize;
|
uint32_t m_vshConstantBufferSize;
|
||||||
uint32_t m_vshConstantBufferAlignmentMask;
|
uint32_t m_vshConstantBufferAlignment;
|
||||||
uint32_t m_fshConstantBufferSize;
|
uint32_t m_fshConstantBufferSize;
|
||||||
uint32_t m_fshConstantBufferAlignmentMask;
|
uint32_t m_fshConstantBufferAlignment;
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
|
|
|
@ -967,7 +967,7 @@ namespace bgfx { namespace mtl
|
||||||
BX_FREE(g_allocator, m_uniforms[_handle.idx]);
|
BX_FREE(g_allocator, m_uniforms[_handle.idx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t size = BX_ALIGN_16(g_uniformTypeSize[_type]*_num);
|
const uint32_t size = bx::alignUp(g_uniformTypeSize[_type]*_num, 16);
|
||||||
void* data = BX_ALLOC(g_allocator, size);
|
void* data = BX_ALLOC(g_allocator, size);
|
||||||
bx::memSet(data, 0, size);
|
bx::memSet(data, 0, size);
|
||||||
m_uniforms[_handle.idx] = data;
|
m_uniforms[_handle.idx] = data;
|
||||||
|
@ -1159,7 +1159,10 @@ namespace bgfx { namespace mtl
|
||||||
|
|
||||||
if (vertexUniformBufferSize)
|
if (vertexUniformBufferSize)
|
||||||
{
|
{
|
||||||
m_uniformBufferVertexOffset = BX_ALIGN_MASK(m_uniformBufferVertexOffset, pso->m_vshConstantBufferAlignmentMask);
|
m_uniformBufferVertexOffset = bx::alignUp(
|
||||||
|
m_uniformBufferVertexOffset
|
||||||
|
, pso->m_vshConstantBufferAlignment
|
||||||
|
);
|
||||||
rce.setVertexBuffer(m_uniformBuffer, m_uniformBufferVertexOffset, 0);
|
rce.setVertexBuffer(m_uniformBuffer, m_uniformBufferVertexOffset, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1167,7 +1170,10 @@ namespace bgfx { namespace mtl
|
||||||
|
|
||||||
if (0 != fragmentUniformBufferSize)
|
if (0 != fragmentUniformBufferSize)
|
||||||
{
|
{
|
||||||
m_uniformBufferFragmentOffset = BX_ALIGN_MASK(m_uniformBufferFragmentOffset, pso->m_fshConstantBufferAlignmentMask);
|
m_uniformBufferFragmentOffset = bx::alignUp(
|
||||||
|
m_uniformBufferFragmentOffset
|
||||||
|
, pso->m_fshConstantBufferAlignment
|
||||||
|
);
|
||||||
rce.setFragmentBuffer(m_uniformBuffer, m_uniformBufferFragmentOffset, 0);
|
rce.setFragmentBuffer(m_uniformBuffer, m_uniformBufferFragmentOffset, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1541,14 +1547,20 @@ namespace bgfx { namespace mtl
|
||||||
|
|
||||||
if (0 != vertexUniformBufferSize)
|
if (0 != vertexUniformBufferSize)
|
||||||
{
|
{
|
||||||
m_uniformBufferVertexOffset = BX_ALIGN_MASK(m_uniformBufferVertexOffset, pso->m_vshConstantBufferAlignmentMask);
|
m_uniformBufferVertexOffset = bx::alignUp(
|
||||||
|
m_uniformBufferVertexOffset
|
||||||
|
, pso->m_vshConstantBufferAlignment
|
||||||
|
);
|
||||||
m_renderCommandEncoder.setVertexBuffer(m_uniformBuffer, m_uniformBufferVertexOffset, 0);
|
m_renderCommandEncoder.setVertexBuffer(m_uniformBuffer, m_uniformBufferVertexOffset, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_uniformBufferFragmentOffset = m_uniformBufferVertexOffset + vertexUniformBufferSize;
|
m_uniformBufferFragmentOffset = m_uniformBufferVertexOffset + vertexUniformBufferSize;
|
||||||
if (fragmentUniformBufferSize)
|
if (fragmentUniformBufferSize)
|
||||||
{
|
{
|
||||||
m_uniformBufferFragmentOffset = BX_ALIGN_MASK(m_uniformBufferFragmentOffset, pso->m_fshConstantBufferAlignmentMask);
|
m_uniformBufferFragmentOffset = bx::alignUp(
|
||||||
|
m_uniformBufferFragmentOffset
|
||||||
|
, pso->m_fshConstantBufferAlignment
|
||||||
|
);
|
||||||
m_renderCommandEncoder.setFragmentBuffer(m_uniformBuffer, m_uniformBufferFragmentOffset, 0);
|
m_renderCommandEncoder.setFragmentBuffer(m_uniformBuffer, m_uniformBufferFragmentOffset, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1802,13 +1814,13 @@ namespace bgfx { namespace mtl
|
||||||
{
|
{
|
||||||
if (shaderType == 0)
|
if (shaderType == 0)
|
||||||
{
|
{
|
||||||
ps->m_vshConstantBufferSize = (uint32_t)arg.bufferDataSize;
|
ps->m_vshConstantBufferSize = uint32_t(arg.bufferDataSize);
|
||||||
ps->m_vshConstantBufferAlignmentMask = (uint32_t)arg.bufferAlignment - 1;
|
ps->m_vshConstantBufferAlignment = uint32_t(arg.bufferAlignment);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ps->m_fshConstantBufferSize = (uint32_t)arg.bufferDataSize;
|
ps->m_fshConstantBufferSize = uint32_t(arg.bufferDataSize);
|
||||||
ps->m_fshConstantBufferAlignmentMask = (uint32_t)arg.bufferAlignment - 1;
|
ps->m_fshConstantBufferAlignment = uint32_t(arg.bufferAlignment);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (MTLStructMember* uniform in arg.bufferStructType.members )
|
for (MTLStructMember* uniform in arg.bufferStructType.members )
|
||||||
|
@ -4075,7 +4087,10 @@ namespace bgfx { namespace mtl
|
||||||
|
|
||||||
if (0 != vertexUniformBufferSize)
|
if (0 != vertexUniformBufferSize)
|
||||||
{
|
{
|
||||||
m_uniformBufferVertexOffset = BX_ALIGN_MASK(m_uniformBufferVertexOffset, currentPso->m_vshConstantBufferAlignmentMask);
|
m_uniformBufferVertexOffset = bx::alignUp(
|
||||||
|
m_uniformBufferVertexOffset
|
||||||
|
, currentPso->m_vshConstantBufferAlignment
|
||||||
|
);
|
||||||
m_computeCommandEncoder.setBuffer(m_uniformBuffer, m_uniformBufferVertexOffset, 0);
|
m_computeCommandEncoder.setBuffer(m_uniformBuffer, m_uniformBufferVertexOffset, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4440,14 +4455,20 @@ namespace bgfx { namespace mtl
|
||||||
|
|
||||||
if (0 != vertexUniformBufferSize)
|
if (0 != vertexUniformBufferSize)
|
||||||
{
|
{
|
||||||
m_uniformBufferVertexOffset = BX_ALIGN_MASK(m_uniformBufferVertexOffset, currentPso->m_vshConstantBufferAlignmentMask);
|
m_uniformBufferVertexOffset = bx::alignUp(
|
||||||
|
m_uniformBufferVertexOffset
|
||||||
|
, currentPso->m_vshConstantBufferAlignment
|
||||||
|
);
|
||||||
rce.setVertexBuffer(m_uniformBuffer, m_uniformBufferVertexOffset, 0);
|
rce.setVertexBuffer(m_uniformBuffer, m_uniformBufferVertexOffset, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_uniformBufferFragmentOffset = m_uniformBufferVertexOffset + vertexUniformBufferSize;
|
m_uniformBufferFragmentOffset = m_uniformBufferVertexOffset + vertexUniformBufferSize;
|
||||||
if (0 != fragmentUniformBufferSize)
|
if (0 != fragmentUniformBufferSize)
|
||||||
{
|
{
|
||||||
m_uniformBufferFragmentOffset = BX_ALIGN_MASK(m_uniformBufferFragmentOffset, currentPso->m_fshConstantBufferAlignmentMask);
|
m_uniformBufferFragmentOffset = bx::alignUp(
|
||||||
|
m_uniformBufferFragmentOffset
|
||||||
|
, currentPso->m_fshConstantBufferAlignment
|
||||||
|
);
|
||||||
rce.setFragmentBuffer(m_uniformBuffer, m_uniformBufferFragmentOffset, 0);
|
rce.setFragmentBuffer(m_uniformBuffer, m_uniformBufferFragmentOffset, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2502,7 +2502,7 @@ VK_IMPORT_DEVICE
|
||||||
BX_FREE(g_allocator, m_uniforms[_handle.idx]);
|
BX_FREE(g_allocator, m_uniforms[_handle.idx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t size = BX_ALIGN_16(g_uniformTypeSize[_type] * _num);
|
const uint32_t size = bx::alignUp(g_uniformTypeSize[_type] * _num, 16);
|
||||||
void* data = BX_ALLOC(g_allocator, size);
|
void* data = BX_ALLOC(g_allocator, size);
|
||||||
bx::memSet(data, 0, size);
|
bx::memSet(data, 0, size);
|
||||||
m_uniforms[_handle.idx] = data;
|
m_uniforms[_handle.idx] = data;
|
||||||
|
|
|
@ -479,7 +479,7 @@ namespace bgfx { namespace hlsl
|
||||||
un.type = uniformType;
|
un.type = uniformType;
|
||||||
un.num = uint8_t(constDesc.Elements);
|
un.num = uint8_t(constDesc.Elements);
|
||||||
un.regIndex = uint16_t(varDesc.StartOffset);
|
un.regIndex = uint16_t(varDesc.StartOffset);
|
||||||
un.regCount = BX_ALIGN_16(varDesc.Size) / 16;
|
un.regCount = bx::alignUp(varDesc.Size, 16) / 16;
|
||||||
_uniforms.push_back(un);
|
_uniforms.push_back(un);
|
||||||
|
|
||||||
BX_TRACE("\t%s, %d, size %d, flags 0x%08x, %d (used)"
|
BX_TRACE("\t%s, %d, size %d, flags 0x%08x, %d (used)"
|
||||||
|
|
Loading…
Reference in New Issue