diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 12260c495..e2b8aacbd 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -4107,7 +4107,7 @@ namespace bgfx void allocInstanceDataBuffer(InstanceDataBuffer* _idb, uint32_t _num, uint16_t _stride) { 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."); s_ctx->allocInstanceDataBuffer(_idb, _num, _stride); BX_CHECK(_num == _idb->size / _stride diff --git a/src/bgfx_p.h b/src/bgfx_p.h index 764d9527f..fa535cbfe 100644 --- a/src/bgfx_p.h +++ b/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); - uint32_t size = BX_ALIGN_16(_size); + uint32_t size = bx::alignUp(_size, 16); void* data = BX_ALLOC(g_allocator, size+structSize); 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) { 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); uniformBuffer = reinterpret_cast(data); 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; - uint32_t size = BX_ALIGN_16(_num*indexSize); + const uint32_t size = bx::alignUp(_num*indexSize, 16); uint64_t ptr = 0; 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; 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->data = (uint8_t *)tib + BX_ALIGN_16(sizeof(TransientIndexBuffer) ); + tib->data = (uint8_t *)tib + bx::alignUp(sizeof(TransientIndexBuffer), 16); tib->size = _size; tib->handle = handle; @@ -3644,9 +3647,12 @@ constexpr uint64_t kSortKeyComputeProgramMask = uint64_t(BGFX_CONFIG_MAX_PROGRA uint16_t flags = BGFX_BUFFER_NONE; 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->data = (uint8_t *)tvb + BX_ALIGN_16(sizeof(TransientVertexBuffer) ); + tvb->data = (uint8_t *)tvb + bx::alignUp(sizeof(TransientVertexBuffer), 16); tvb->size = _size; tvb->startVertex = 0; tvb->stride = stride; @@ -3700,8 +3706,8 @@ constexpr uint64_t kSortKeyComputeProgramMask = uint64_t(BGFX_CONFIG_MAX_PROGRA { BGFX_MUTEX_SCOPE(m_resourceApiLock); - uint16_t stride = BX_ALIGN_16(_stride); - uint32_t offset = m_submit->allocTransientVertexBuffer(_num, stride); + const uint16_t stride = bx::alignUp(_stride, 16); + const uint32_t offset = m_submit->allocTransientVertexBuffer(_num, stride); TransientVertexBuffer& dvb = *m_submit->m_transientVb; _idb->data = &dvb.data[offset]; diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index 2e90aba2b..43bcb9d78 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -1903,7 +1903,7 @@ namespace bgfx { namespace d3d11 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); bx::memSet(data, 0, size); m_uniforms[_handle.idx] = data; diff --git a/src/renderer_d3d12.cpp b/src/renderer_d3d12.cpp index 16077e3a4..65a55c0ae 100644 --- a/src/renderer_d3d12.cpp +++ b/src/renderer_d3d12.cpp @@ -1789,7 +1789,7 @@ namespace bgfx { namespace d3d12 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); bx::memSet(data, 0, size); m_uniforms[_handle.idx] = data; @@ -3481,7 +3481,7 @@ namespace bgfx { namespace d3d12 _gpuAddress = m_gpuVA + 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; // desc.BufferLocation = _gpuAddress; diff --git a/src/renderer_d3d9.cpp b/src/renderer_d3d9.cpp index 34c50d673..2d0e15e1c 100644 --- a/src/renderer_d3d9.cpp +++ b/src/renderer_d3d9.cpp @@ -1213,7 +1213,7 @@ namespace bgfx { namespace d3d9 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); bx::memSet(data, 0, size); m_uniforms[_handle.idx] = data; diff --git a/src/renderer_mtl.h b/src/renderer_mtl.h index 5e03be36c..5aa3b2f96 100644 --- a/src/renderer_mtl.h +++ b/src/renderer_mtl.h @@ -913,9 +913,9 @@ namespace bgfx { namespace mtl UniformBuffer* m_fshConstantBuffer; uint32_t m_vshConstantBufferSize; - uint32_t m_vshConstantBufferAlignmentMask; + uint32_t m_vshConstantBufferAlignment; uint32_t m_fshConstantBufferSize; - uint32_t m_fshConstantBufferAlignmentMask; + uint32_t m_fshConstantBufferAlignment; enum { diff --git a/src/renderer_mtl.mm b/src/renderer_mtl.mm index b2330a80c..48a0d4b3f 100644 --- a/src/renderer_mtl.mm +++ b/src/renderer_mtl.mm @@ -540,12 +540,12 @@ namespace bgfx { namespace mtl || BX_ENABLED(BX_PLATFORM_OSX) || (BX_ENABLED(BX_PLATFORM_IOS) && iOSVersionEqualOrGreater("9.0.0") ) ; - + m_hasStoreActionStoreAndMultisampleResolve = false || (BX_ENABLED(BX_PLATFORM_OSX) && macOSVersionEqualOrGreater(10,12,0)) || (BX_ENABLED(BX_PLATFORM_IOS) && iOSVersionEqualOrGreater("10.0.0") ) ; - + m_macOS11Runtime = true && BX_ENABLED(BX_PLATFORM_OSX) && macOSVersionEqualOrGreater(10,11,0) @@ -967,7 +967,7 @@ namespace bgfx { namespace mtl 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); bx::memSet(data, 0, size); m_uniforms[_handle.idx] = data; @@ -1159,7 +1159,10 @@ namespace bgfx { namespace mtl 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); } @@ -1167,7 +1170,10 @@ namespace bgfx { namespace mtl 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); } @@ -1541,14 +1547,20 @@ namespace bgfx { namespace mtl 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_uniformBufferFragmentOffset = m_uniformBufferVertexOffset + vertexUniformBufferSize; 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); } @@ -1802,13 +1814,13 @@ namespace bgfx { namespace mtl { if (shaderType == 0) { - ps->m_vshConstantBufferSize = (uint32_t)arg.bufferDataSize; - ps->m_vshConstantBufferAlignmentMask = (uint32_t)arg.bufferAlignment - 1; + ps->m_vshConstantBufferSize = uint32_t(arg.bufferDataSize); + ps->m_vshConstantBufferAlignment = uint32_t(arg.bufferAlignment); } else { - ps->m_fshConstantBufferSize = (uint32_t)arg.bufferDataSize; - ps->m_fshConstantBufferAlignmentMask = (uint32_t)arg.bufferAlignment - 1; + ps->m_fshConstantBufferSize = uint32_t(arg.bufferDataSize); + ps->m_fshConstantBufferAlignment = uint32_t(arg.bufferAlignment); } for (MTLStructMember* uniform in arg.bufferStructType.members ) @@ -3081,7 +3093,7 @@ namespace bgfx { namespace mtl [contentView setLayer:m_metalLayer]; } }; - + if ([NSThread isMainThread]) { setLayer(); @@ -3090,7 +3102,7 @@ namespace bgfx { namespace mtl { bx::Semaphore semaphore; bx::Semaphore* psemaphore = &semaphore; - + CFRunLoopPerformBlock([[NSRunLoop mainRunLoop] getCFRunLoop], kCFRunLoopCommonModes, ^{ @@ -4075,7 +4087,10 @@ namespace bgfx { namespace mtl 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); } @@ -4440,14 +4455,20 @@ namespace bgfx { namespace mtl 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); } m_uniformBufferFragmentOffset = m_uniformBufferVertexOffset + vertexUniformBufferSize; 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); } diff --git a/src/renderer_vk.cpp b/src/renderer_vk.cpp index 0fb89d8bd..b9f21789d 100644 --- a/src/renderer_vk.cpp +++ b/src/renderer_vk.cpp @@ -2502,7 +2502,7 @@ VK_IMPORT_DEVICE 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); bx::memSet(data, 0, size); m_uniforms[_handle.idx] = data; diff --git a/tools/shaderc/shaderc_hlsl.cpp b/tools/shaderc/shaderc_hlsl.cpp index fa4e99d60..ce377444b 100644 --- a/tools/shaderc/shaderc_hlsl.cpp +++ b/tools/shaderc/shaderc_hlsl.cpp @@ -479,7 +479,7 @@ namespace bgfx { namespace hlsl un.type = uniformType; un.num = uint8_t(constDesc.Elements); 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); BX_TRACE("\t%s, %d, size %d, flags 0x%08x, %d (used)"