diff --git a/src/bgfx.cpp b/src/bgfx.cpp index b0de4a2ce..7c2583a61 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -1559,8 +1559,7 @@ namespace bgfx void EncoderImpl::submit(ViewId _id, ProgramHandle _program, OcclusionQueryHandle _occlusionQuery, uint32_t _depth, uint8_t _flags) { - if (BX_ENABLED(BGFX_CONFIG_DEBUG_UNIFORM) - && (_flags & BGFX_DISCARD_STATE)) + if (BX_ENABLED(BGFX_CONFIG_DEBUG_UNIFORM) ) { m_uniformSet.clear(); } @@ -2321,6 +2320,34 @@ namespace bgfx return TextureFormat::Enum(_imageContainer.m_format); } + typedef void (*ImageDecodeFn)(bx::AllocatorI*, void*, const void*, uint32_t, uint32_t, uint32_t, bimg::TextureFormat::Enum); + + static void imageDecodeSlices(ImageDecodeFn _fn, void* _dst, const void* _src, uint32_t _width, uint32_t _height, uint32_t _depth, uint32_t _dstPitch, uint32_t _dstSlicePitch, bimg::TextureFormat::Enum _srcFormat) + { + const uint32_t srcSlicePitch = uint32_t(bimg::imageGetSize(NULL, _width, _height, 1, false, false, 1, _srcFormat) ); + + uint8_t* dst = (uint8_t*)_dst; + const uint8_t* src = (const uint8_t*)_src; + + for (uint32_t zz = 0; zz < _depth; ++zz) + { + _fn(g_allocator, dst, src, _width, _height, _dstPitch, _srcFormat); + + dst += _dstSlicePitch; + src += srcSlicePitch; + } + } + + void imageDecodeToBgra8(void* _dst, const void* _src, uint32_t _width, uint32_t _height, uint32_t _depth, uint32_t _dstPitch, uint32_t _dstSlicePitch, bimg::TextureFormat::Enum _srcFormat) + { + imageDecodeSlices(bimg::imageDecodeToBgra8, _dst, _src, _width, _height, _depth, _dstPitch, _dstSlicePitch, _srcFormat); + } + + void imageDecodeToRgba8(void* _dst, const void* _src, uint32_t _width, uint32_t _height, uint32_t _depth, uint32_t _dstPitch, uint32_t _dstSlicePitch, bimg::TextureFormat::Enum _srcFormat) + { + imageDecodeSlices(bimg::imageDecodeToRgba8, _dst, _src, _width, _height, _depth, _dstPitch, _dstSlicePitch, _srcFormat); + } + const char* getName(TextureFormat::Enum _fmt) { return bimg::getName(bimg::TextureFormat::Enum(_fmt)); diff --git a/src/bgfx_p.h b/src/bgfx_p.h index f2612a729..7cb14b211 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -694,6 +694,8 @@ namespace bgfx const char* getAttribNameShort(Attrib::Enum _attr); void getTextureSizeFromRatio(BackbufferRatio::Enum _ratio, uint16_t& _width, uint16_t& _height); TextureFormat::Enum getViableTextureFormat(const bimg::ImageContainer& _imageContainer); + void imageDecodeToBgra8(void* _dst, const void* _src, uint32_t _width, uint32_t _height, uint32_t _depth, uint32_t _dstPitch, uint32_t _dstSlicePitch, bimg::TextureFormat::Enum _srcFormat); + void imageDecodeToRgba8(void* _dst, const void* _src, uint32_t _width, uint32_t _height, uint32_t _depth, uint32_t _dstPitch, uint32_t _dstSlicePitch, bimg::TextureFormat::Enum _srcFormat); const char* getName(TextureFormat::Enum _fmt); const char* getName(UniformHandle _handle); const char* getName(ShaderHandle _handle); diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index 748351687..2b93363bd 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -5024,8 +5024,8 @@ namespace bgfx { namespace d3d11 if (convert) { uint32_t srcpitch = mip.m_width*bpp/8; - temp = (uint8_t*)bx::alloc(g_allocator, srcpitch*mip.m_height); - bimg::imageDecodeToBgra8(g_allocator, temp, mip.m_data, mip.m_width, mip.m_height, srcpitch, mip.m_format); + temp = (uint8_t*)bx::alloc(g_allocator, srcpitch*mip.m_height*mip.m_depth); + imageDecodeToBgra8(temp, mip.m_data, mip.m_width, mip.m_height, mip.m_depth, srcpitch, srcpitch*mip.m_height, mip.m_format); srd[kk].pSysMem = temp; srd[kk].SysMemPitch = srcpitch; @@ -5042,18 +5042,18 @@ namespace bgfx { namespace d3d11 switch (m_textureFormat) { case TextureFormat::R5G6B5: - temp = (uint8_t*)bx::alloc(g_allocator, srd[kk].SysMemPitch*mip.m_height); - bimg::imageConvert(temp, 16, bx::packB5G6R5, mip.m_data, bx::unpackR5G6B5, srd[kk].SysMemPitch*mip.m_height); + temp = (uint8_t*)bx::alloc(g_allocator, mip.m_size); + bimg::imageConvert(temp, 16, bx::packB5G6R5, mip.m_data, bx::unpackR5G6B5, mip.m_size); srd[kk].pSysMem = temp; break; case TextureFormat::RGBA4: - temp = (uint8_t*)bx::alloc(g_allocator, srd[kk].SysMemPitch*mip.m_height); - bimg::imageConvert(temp, 16, bx::packBgra4, mip.m_data, bx::unpackRgba4, srd[kk].SysMemPitch*mip.m_height); + temp = (uint8_t*)bx::alloc(g_allocator, mip.m_size); + bimg::imageConvert(temp, 16, bx::packBgra4, mip.m_data, bx::unpackRgba4, mip.m_size); srd[kk].pSysMem = temp; break; case TextureFormat::RGB5A1: - temp = (uint8_t*)bx::alloc(g_allocator, srd[kk].SysMemPitch*mip.m_height); - bimg::imageConvert(temp, 16, bx::packBgr5a1, mip.m_data, bx::unpackRgb5a1, srd[kk].SysMemPitch*mip.m_height); + temp = (uint8_t*)bx::alloc(g_allocator, mip.m_size); + bimg::imageConvert(temp, 16, bx::packBgr5a1, mip.m_data, bx::unpackRgb5a1, mip.m_size); srd[kk].pSysMem = temp; break; } @@ -5551,6 +5551,7 @@ namespace bgfx { namespace d3d11 const uint32_t srcPitch = UINT16_MAX == _pitch ? rectPitch : _pitch; const uint32_t slicePitch = rectPitch*srcRows; + const uint32_t numSlices = box.back - box.front; const bool convert = m_textureFormat != m_requestedFormat; @@ -5562,8 +5563,8 @@ namespace bgfx { namespace d3d11 if (convert) { copyPitch = rectPitch; - temp = (uint8_t*)bx::alloc(g_allocator, slicePitch); - bimg::imageDecodeToBgra8(g_allocator, temp, data, _rect.m_width, _rect.m_height, copyPitch, bimg::TextureFormat::Enum(m_requestedFormat) ); + temp = (uint8_t*)bx::alloc(g_allocator, slicePitch*numSlices); + imageDecodeToBgra8(temp, data, _rect.m_width, _rect.m_height, numSlices, copyPitch, slicePitch, bimg::TextureFormat::Enum(m_requestedFormat) ); data = temp; box.right = bx::clamp(box.right, box.left, bx::max(1u, m_width >> _mip) ); @@ -5574,20 +5575,20 @@ namespace bgfx { namespace d3d11 switch (m_textureFormat) { case TextureFormat::R5G6B5: - temp = (uint8_t*)bx::alloc(g_allocator, slicePitch); - bimg::imageConvert(temp, 16, bx::packB5G6R5, data, bx::unpackR5G6B5, slicePitch); + temp = (uint8_t*)bx::alloc(g_allocator, slicePitch*numSlices); + bimg::imageConvert(temp, 16, bx::packB5G6R5, data, bx::unpackR5G6B5, slicePitch*numSlices); data = temp; break; case TextureFormat::RGBA4: - temp = (uint8_t*)bx::alloc(g_allocator, slicePitch); - bimg::imageConvert(temp, 16, bx::packBgra4, data, bx::unpackRgba4, slicePitch); + temp = (uint8_t*)bx::alloc(g_allocator, slicePitch*numSlices); + bimg::imageConvert(temp, 16, bx::packBgra4, data, bx::unpackRgba4, slicePitch*numSlices); data = temp; break; case TextureFormat::RGB5A1: - temp = (uint8_t*)bx::alloc(g_allocator, slicePitch); - bimg::imageConvert(temp, 16, bx::packBgr5a1, data, bx::unpackRgb5a1, slicePitch); + temp = (uint8_t*)bx::alloc(g_allocator, slicePitch*numSlices); + bimg::imageConvert(temp, 16, bx::packBgr5a1, data, bx::unpackRgb5a1, slicePitch*numSlices); data = temp; break; @@ -5602,7 +5603,6 @@ namespace bgfx { namespace d3d11 ? bx::max(1, (box.bottom - box.top + blockInfo.blockHeight - 1) / blockInfo.blockHeight) : (box.bottom - box.top) ; - const uint32_t numSlices = TextureD3D11::Texture3D == m_type ? (box.back - box.front) : 1; const uint32_t needed = (numSlices - 1) * slicePitch + (numRows - 1) * copyPitch + rectPitch; if (_mem->size < needed) diff --git a/src/renderer_d3d12.cpp b/src/renderer_d3d12.cpp index 5e3268baf..f5e514aca 100644 --- a/src/renderer_d3d12.cpp +++ b/src/renderer_d3d12.cpp @@ -6947,13 +6947,14 @@ namespace bgfx { namespace d3d12 const uint32_t size = slice*mip.m_depth; uint8_t* temp = (uint8_t*)bx::alloc(g_allocator, size); - bimg::imageDecodeToBgra8( - g_allocator - , temp + imageDecodeToBgra8( + temp , mip.m_data , mip.m_width , mip.m_height + , mip.m_depth , pitch + , slice , mip.m_format ); @@ -7597,8 +7598,8 @@ namespace bgfx { namespace d3d12 if (convert) { copyPitch = rectPitch; - temp = (uint8_t*)bx::alloc(g_allocator, slicePitch); - bimg::imageDecodeToBgra8(g_allocator, temp, srcData, _rect.m_width, _rect.m_height, copyPitch, bimg::TextureFormat::Enum(m_requestedFormat) ); + temp = (uint8_t*)bx::alloc(g_allocator, slicePitch*_depth); + imageDecodeToBgra8(temp, srcData, _rect.m_width, _rect.m_height, _depth, copyPitch, slicePitch, bimg::TextureFormat::Enum(m_requestedFormat) ); srcData = temp; box.right = bx::clamp(box.right, box.left, bx::max(1u, m_width >> _mip) - _rect.m_x); @@ -7651,9 +7652,7 @@ namespace bgfx { namespace d3d12 const uint32_t dstSlicePitch = rowPitch * numRows; const uint32_t srcSlicePitch = copyPitch * numRows; - const uint32_t numSlices = convert ? 1 : _depth; - - for (uint32_t zz = 0; zz < numSlices; ++zz) + for (uint32_t zz = 0; zz < _depth; ++zz) { bx::memCopy(dstData + zz*dstSlicePitch, rowPitch, srcData + zz*srcSlicePitch, copyPitch, rectPitch, numRows); } diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index aba538a09..b85308e4b 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -6685,7 +6685,7 @@ namespace bgfx { namespace gl uint8_t* temp = NULL; if (convert) { - temp = (uint8_t*)bx::alloc(g_allocator, ti.width*ti.height*4); + temp = (uint8_t*)bx::alloc(g_allocator, ti.width*ti.height*ti.depth*4); } const uint16_t numSides = ti.numLayers * (imageContainer.m_cubeMap ? 6 : 1); @@ -6733,12 +6733,13 @@ namespace bgfx { namespace gl if (convert) { imageDecodeToRgba8( - g_allocator - , temp + temp , mip.m_data , mip.m_width , mip.m_height + , mip.m_depth , mip.m_width*4 + , mip.m_width*4*mip.m_height , mip.m_format ); data = temp; @@ -6919,7 +6920,7 @@ namespace bgfx { namespace gl || !unpackRowLength || (compressed && UINT16_MAX != _pitch && srcPitch != rectPitch) ) { - temp = (uint8_t*)bx::alloc(g_allocator, rectPitch*height); + temp = (uint8_t*)bx::alloc(g_allocator, rectPitch*height*_depth); } else if (unpackRowLength && !compressed) @@ -6962,7 +6963,7 @@ namespace bgfx { namespace gl if (convert) { - bimg::imageDecodeToRgba8(g_allocator, temp, data, width, height, rectPitch, bimg::TextureFormat::Enum(m_requestedFormat) ); + imageDecodeToRgba8(temp, data, width, height, _depth, rectPitch, rectPitch*height, bimg::TextureFormat::Enum(m_requestedFormat) ); data = temp; srcPitch = rectPitch; } diff --git a/src/renderer_mtl.cpp b/src/renderer_mtl.cpp index 336d30c64..5fee498e1 100644 --- a/src/renderer_mtl.cpp +++ b/src/renderer_mtl.cpp @@ -4501,7 +4501,7 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames uint8_t* temp = NULL; if (convert) { - temp = (uint8_t*)bx::alloc(g_allocator, ti.width*ti.height*4); + temp = (uint8_t*)bx::alloc(g_allocator, ti.width*ti.height*ti.depth*4); } for (uint16_t side = 0; side < numSides; ++side) @@ -4523,13 +4523,14 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames if (convert) { - bimg::imageDecodeToBgra8( - g_allocator - , temp + imageDecodeToBgra8( + temp , mip.m_data , mip.m_width , mip.m_height + , mip.m_depth , mip.m_width*4 + , mip.m_width*4*mip.m_height , mip.m_format ); data = temp; @@ -4663,14 +4664,15 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames if (convert) { - temp = (uint8_t*)bx::alloc(g_allocator, rectpitch*_rect.m_height); - bimg::imageDecodeToBgra8( - g_allocator - , temp + temp = (uint8_t*)bx::alloc(g_allocator, rectpitch*_rect.m_height*_depth); + imageDecodeToBgra8( + temp , data , _rect.m_width , _rect.m_height + , _depth , srcpitch + , srcpitch*_rect.m_height , bimg::TextureFormat::Enum(m_requestedFormat) ); data = temp; diff --git a/src/renderer_vk.cpp b/src/renderer_vk.cpp index ed5e325bd..d1fb70d5d 100644 --- a/src/renderer_vk.cpp +++ b/src/renderer_vk.cpp @@ -5044,7 +5044,7 @@ VK_IMPORT_DEVICE dsai.pSetLayouts = &_layout; VkDescriptorSet descriptorSet = VK_NULL_HANDLE; - const VkResult result = vkAllocateDescriptorSets(m_device, &dsai, &descriptorSet); + VkResult result = vkAllocateDescriptorSets(m_device, &dsai, &descriptorSet); if (VK_SUCCESS != result && uint32_t(m_descriptorPoolIdx + 1) < kMaxDescriptorPoolChunks) @@ -5058,7 +5058,7 @@ VK_IMPORT_DEVICE } dsai.descriptorPool = m_descriptorPool[frame][m_descriptorPoolIdx]; - VK_CHECK(vkAllocateDescriptorSets(m_device, &dsai, &descriptorSet) ); + result = vkAllocateDescriptorSets(m_device, &dsai, &descriptorSet); } BX_ASSERT(VK_SUCCESS == result @@ -7857,13 +7857,14 @@ VK_DESTROY const uint32_t size = slice * mip.m_depth; uint8_t* temp = (uint8_t*)bx::alloc(g_allocator, size); - bimg::imageDecodeToBgra8( - g_allocator - , temp + imageDecodeToBgra8( + temp , mip.m_data , mip.m_width , mip.m_height + , mip.m_depth , pitch + , slice , mip.m_format ); @@ -8159,8 +8160,8 @@ VK_DESTROY if (convert) { - temp = (uint8_t*)bx::alloc(g_allocator, slicePitch); - bimg::imageDecodeToBgra8(g_allocator, temp, data, _rect.m_width, _rect.m_height, rectPitch, bimg::TextureFormat::Enum(m_requestedFormat) ); + temp = (uint8_t*)bx::alloc(g_allocator, slicePitch * _depth); + imageDecodeToBgra8(temp, data, _rect.m_width, _rect.m_height, _depth, rectPitch, slicePitch, bimg::TextureFormat::Enum(m_requestedFormat) ); data = temp; } else if (repackPitch) diff --git a/src/renderer_webgpu.cpp b/src/renderer_webgpu.cpp index 554b16785..0cc84fe92 100644 --- a/src/renderer_webgpu.cpp +++ b/src/renderer_webgpu.cpp @@ -5042,8 +5042,6 @@ WGPU_IMPORT .aspect = WGPUTextureAspect_All, }; - uint8_t* temp = convert ? (uint8_t*)bx::alloc(g_allocator, m_width*m_height*bpp/8) : NULL; - for (uint16_t side = 0; side < m_numSides; ++side) { copyTextureDst.origin.z = side; @@ -5057,20 +5055,21 @@ WGPU_IMPORT { if (convert) { - const uint32_t mipWidth = bx::max(mip.m_width, 4); - const uint32_t mipHeight = bx::max(mip.m_height, 4); - const uint32_t bytesPerRow = mipWidth*bpp/8; + const uint32_t bytesPerRow = mip.m_width*bpp/8; const uint32_t width = bx::max(m_width >> lod, 1); const uint32_t height = bx::max(m_height >> lod, 1); - const uint32_t size = bytesPerRow*height*mip.m_depth; + const uint32_t size = bytesPerRow*mip.m_height*mip.m_depth; - bimg::imageDecodeToBgra8( - g_allocator - , temp + uint8_t* temp = (uint8_t*)bx::alloc(g_allocator, size); + + imageDecodeToBgra8( + temp , mip.m_data - , mipWidth - , mipHeight + , mip.m_width + , mip.m_height + , mip.m_depth , bytesPerRow + , bytesPerRow*mip.m_height , bimg::TextureFormat::Enum(m_requestedFormat) ); @@ -5081,13 +5080,15 @@ WGPU_IMPORT , { .offset = 0, .bytesPerRow = bytesPerRow, - .rowsPerImage = height, + .rowsPerImage = mip.m_height, } , { .width = width, .height = height, .depthOrArrayLayers = mip.m_depth, }); + + bx::free(g_allocator, temp); } else if (compressed) { @@ -5134,11 +5135,6 @@ WGPU_IMPORT } } } - - if (NULL != temp) - { - bx::free(g_allocator, temp); - } } } @@ -5249,8 +5245,8 @@ WGPU_IMPORT if (convert) { bytesPerRow = rectPitch; - temp = (uint8_t*)bx::alloc(g_allocator, slicePitch); - bimg::imageDecodeToBgra8(g_allocator, temp, srcData, _rect.m_width, _rect.m_height, rectPitch, bimg::TextureFormat::Enum(m_requestedFormat) ); + temp = (uint8_t*)bx::alloc(g_allocator, slicePitch*bx::max(1, _depth) ); + imageDecodeToBgra8(temp, srcData, _rect.m_width, _rect.m_height, bx::max(1, _depth), rectPitch, slicePitch, bimg::TextureFormat::Enum(m_requestedFormat) ); srcData = temp; } @@ -6495,7 +6491,7 @@ WGPU_IMPORT m_readback , WGPUMapMode_Read , 0 - , getBufferSize() + , size_t(getBufferSize() ) , { .nextInChain = NULL, .mode = WGPUCallbackMode_AllowProcessEvents, @@ -6507,7 +6503,7 @@ WGPU_IMPORT void TimerQueryWGPU::consumeResults() { - const uint64_t* timestamp = (const uint64_t*)wgpuBufferGetConstMappedRange(m_readback, 0, getBufferSize() ); + const uint64_t* timestamp = (const uint64_t*)wgpuBufferGetConstMappedRange(m_readback, 0, size_t(getBufferSize() ) ); if (NULL != timestamp) { diff --git a/src/video_vk.cpp b/src/video_vk.cpp index 4e84443e0..57518b570 100644 --- a/src/video_vk.cpp +++ b/src/video_vk.cpp @@ -612,7 +612,7 @@ namespace bgfx { namespace vk { const VkDeviceSize pixelFootprint = VkDeviceSize(m_codedWidth) * VkDeviceSize(m_codedHeight) * 3 / 2; m_bitstreamBufferSize = bx::max(4 * 1024 * 1024, pixelFootprint); - m_bitstreamBufferSize = bx::alignUp(m_bitstreamBufferSize, bx::max(m_bitstreamAlignment, 1) ); + m_bitstreamBufferSize = bx::alignUp(m_bitstreamBufferSize, size_t(bx::max(m_bitstreamAlignment, 1) ) ); VkBufferCreateInfo bi { diff --git a/tools/shaderc/shaderc_glsl.cpp b/tools/shaderc/shaderc_glsl.cpp index 134b1cce4..0fd666502 100644 --- a/tools/shaderc/shaderc_glsl.cpp +++ b/tools/shaderc/shaderc_glsl.cpp @@ -340,7 +340,7 @@ namespace bgfx { namespace glsl Uniform un; un.name = compiler.get_name(resource.id); - un.type = UniformType::Sampler; + un.type = UniformType::Enum(kUniformSamplerBit | UniformType::Sampler); un.num = 1; un.regIndex = 0; un.regCount = 1;