diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index 2f19ddd41..d6d08cc7f 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -4099,7 +4099,7 @@ namespace bgfx { namespace d3d11 const uint8_t startLod = bx::min(_skip, imageContainer.m_numMips-1); bimg::TextureInfo ti; - imageGetSize( + bimg::imageGetSize( &ti , uint16_t(imageContainer.m_width >>startLod) , uint16_t(imageContainer.m_height>>startLod) @@ -4110,19 +4110,11 @@ namespace bgfx { namespace d3d11 , imageContainer.m_format ); - const uint8_t numMips = ti.numMips; - const uint32_t textureWidth = ti.width; - const uint32_t textureHeight = ti.height; - const uint32_t textureDepth = ti.depth; - const uint16_t numLayers = ti.numLayers; - m_flags = _flags; - m_width = textureWidth; - m_height = textureHeight; - m_depth = 1 < imageContainer.m_depth - ? textureDepth - : imageContainer.m_numLayers - ; + m_width = ti.width; + m_height = ti.height; + m_depth = ti.depth; + m_requestedFormat = uint8_t(imageContainer.m_format); m_textureFormat = uint8_t(getViableTextureFormat(imageContainer) ); const bool convert = m_textureFormat != m_requestedFormat; @@ -4141,10 +4133,10 @@ namespace bgfx { namespace d3d11 m_type = Texture2D; } - m_numMips = numMips; + m_numMips = ti.numMips; - const uint16_t numSides = numLayers * (imageContainer.m_cubeMap ? 6 : 1); - const uint32_t numSrd = numSides * numMips; + const uint16_t numSides = ti.numLayers * (imageContainer.m_cubeMap ? 6 : 1); + const uint32_t numSrd = numSides * ti.numMips; D3D11_SUBRESOURCE_DATA* srd = (D3D11_SUBRESOURCE_DATA*)alloca(numSrd*sizeof(D3D11_SUBRESOURCE_DATA) ); uint32_t kk = 0; @@ -4156,9 +4148,9 @@ namespace bgfx { namespace d3d11 , getHandle() , getName( (TextureFormat::Enum)m_textureFormat) , getName( (TextureFormat::Enum)m_requestedFormat) - , numLayers - , textureWidth - , textureHeight + , ti.numLayers + , ti.width + , ti.height , imageContainer.m_cubeMap ? "x6" : "" , 0 != (m_flags&BGFX_TEXTURE_RT_MASK) ? " (render target)" : "" , swizzle ? " (swizzle BGRA8 -> RGBA8)" : "" @@ -4166,7 +4158,7 @@ namespace bgfx { namespace d3d11 for (uint16_t side = 0; side < numSides; ++side) { - for (uint8_t lod = 0, num = numMips; lod < num; ++lod) + for (uint8_t lod = 0, num = ti.numMips; lod < num; ++lod) { bimg::ImageMip mip; if (bimg::imageGetRawData(imageContainer, side, lod+startLod, _mem->data, _mem->size, mip) ) @@ -4253,9 +4245,9 @@ namespace bgfx { namespace d3d11 case TextureCube: { D3D11_TEXTURE2D_DESC desc = {}; - desc.Width = textureWidth; - desc.Height = textureHeight; - desc.MipLevels = numMips; + desc.Width = ti.width; + desc.Height = ti.height; + desc.MipLevels = ti.numMips; desc.ArraySize = numSides; desc.Format = format; desc.SampleDesc = msaa; @@ -4274,7 +4266,7 @@ namespace bgfx { namespace d3d11 desc.BindFlags |= D3D11_BIND_RENDER_TARGET; desc.Usage = D3D11_USAGE_DEFAULT; desc.MiscFlags |= 0 - | (1 < numMips ? D3D11_RESOURCE_MISC_GENERATE_MIPS : 0) + | (1 < ti.numMips ? D3D11_RESOURCE_MISC_GENERATE_MIPS : 0) ; } @@ -4294,26 +4286,26 @@ namespace bgfx { namespace d3d11 if (imageContainer.m_cubeMap) { desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE; - if (1 < numLayers) + if (1 < ti.numLayers) { srvd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBEARRAY; - srvd.TextureCubeArray.MipLevels = numMips; - srvd.TextureCubeArray.NumCubes = numLayers; + srvd.TextureCubeArray.MipLevels = ti.numMips; + srvd.TextureCubeArray.NumCubes = ti.numLayers; } else { srvd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE; - srvd.TextureCube.MipLevels = numMips; + srvd.TextureCube.MipLevels = ti.numMips; } } else { if (msaaSample) { - if (1 < numLayers) + if (1 < ti.numLayers) { srvd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY; - srvd.Texture2DMSArray.ArraySize = numLayers; + srvd.Texture2DMSArray.ArraySize = ti.numLayers; } else { @@ -4322,16 +4314,16 @@ namespace bgfx { namespace d3d11 } else { - if (1 < numLayers) + if (1 < ti.numLayers) { srvd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY; - srvd.Texture2DArray.MipLevels = numMips; - srvd.Texture2DArray.ArraySize = numLayers; + srvd.Texture2DArray.MipLevels = ti.numMips; + srvd.Texture2DArray.ArraySize = ti.numLayers; } else { srvd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; - srvd.Texture2D.MipLevels = numMips; + srvd.Texture2D.MipLevels = ti.numMips; } } } @@ -4357,10 +4349,10 @@ namespace bgfx { namespace d3d11 case Texture3D: { D3D11_TEXTURE3D_DESC desc = {}; - desc.Width = textureWidth; - desc.Height = textureHeight; - desc.Depth = textureDepth; - desc.MipLevels = numMips; + desc.Width = ti.width; + desc.Height = ti.height; + desc.Depth = ti.depth; + desc.MipLevels = ti.numMips; desc.Format = format; desc.Usage = kk == 0 || blit ? D3D11_USAGE_DEFAULT : D3D11_USAGE_IMMUTABLE; desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; @@ -4372,7 +4364,7 @@ namespace bgfx { namespace d3d11 desc.BindFlags |= D3D11_BIND_RENDER_TARGET; desc.Usage = D3D11_USAGE_DEFAULT; desc.MiscFlags |= 0 - | (1 < numMips ? D3D11_RESOURCE_MISC_GENERATE_MIPS : 0) + | (1 < ti.numMips ? D3D11_RESOURCE_MISC_GENERATE_MIPS : 0) ; } @@ -4390,7 +4382,7 @@ namespace bgfx { namespace d3d11 } srvd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D; - srvd.Texture3D.MipLevels = numMips; + srvd.Texture3D.MipLevels = ti.numMips; if (directAccess) { @@ -4420,7 +4412,7 @@ namespace bgfx { namespace d3d11 kk = 0; for (uint16_t side = 0; side < numSides; ++side) { - for (uint32_t lod = 0, num = numMips; lod < num; ++lod) + for (uint32_t lod = 0, num = ti.numMips; lod < num; ++lod) { BX_FREE(g_allocator, const_cast(srd[kk].pSysMem) ); ++kk; diff --git a/src/renderer_d3d12.cpp b/src/renderer_d3d12.cpp index a8a3f668f..c7c751432 100644 --- a/src/renderer_d3d12.cpp +++ b/src/renderer_d3d12.cpp @@ -4582,7 +4582,7 @@ namespace bgfx { namespace d3d12 const uint8_t startLod = bx::min(_skip, imageContainer.m_numMips-1); bimg::TextureInfo ti; - imageGetSize( + bimg::imageGetSize( &ti , uint16_t(imageContainer.m_width >>startLod) , uint16_t(imageContainer.m_height>>startLod) @@ -4593,19 +4593,10 @@ namespace bgfx { namespace d3d12 , imageContainer.m_format ); - const uint8_t numMips = ti.numMips; - const uint32_t textureWidth = ti.width; - const uint32_t textureHeight = ti.height; - const uint32_t textureDepth = ti.depth; - const uint16_t numLayers = ti.numLayers; - m_flags = _flags; - m_width = textureWidth; - m_height = textureHeight; - m_depth = 1 < imageContainer.m_depth - ? textureDepth - : imageContainer.m_numLayers - ; + m_width = ti.width; + m_height = ti.height; + m_depth = ti.depth; m_requestedFormat = uint8_t(imageContainer.m_format); m_textureFormat = uint8_t(getViableTextureFormat(imageContainer) ); const bool convert = m_textureFormat != m_requestedFormat; @@ -4624,9 +4615,9 @@ namespace bgfx { namespace d3d12 m_type = Texture2D; } - m_numMips = numMips; - const uint16_t numSides = numLayers * (imageContainer.m_cubeMap ? 6 : 1); - const uint32_t numSrd = numSides * numMips; + m_numMips = ti.numMips; + const uint16_t numSides = ti.numLayers * (imageContainer.m_cubeMap ? 6 : 1); + const uint32_t numSrd = numSides * ti.numMips; D3D12_SUBRESOURCE_DATA* srd = (D3D12_SUBRESOURCE_DATA*)alloca(numSrd*sizeof(D3D12_SUBRESOURCE_DATA) ); uint32_t kk = 0; @@ -4643,8 +4634,8 @@ namespace bgfx { namespace d3d12 , this - s_renderD3D12->m_textures , getName( (TextureFormat::Enum)m_textureFormat) , getName( (TextureFormat::Enum)m_requestedFormat) - , textureWidth - , textureHeight + , ti.width + , ti.height , imageContainer.m_cubeMap ? "x6" : "" , renderTarget ? 'x' : ' ' , writeOnly ? 'x' : ' ' @@ -4654,7 +4645,7 @@ namespace bgfx { namespace d3d12 for (uint8_t side = 0; side < numSides; ++side) { - for (uint8_t lod = 0; lod < numMips; ++lod) + for (uint8_t lod = 0; lod < ti.numMips; ++lod) { bimg::ImageMip mip; if (bimg::imageGetRawData(imageContainer, side, lod+startLod, _mem->data, _mem->size, mip) ) @@ -4743,9 +4734,9 @@ namespace bgfx { namespace d3d12 D3D12_RESOURCE_DESC resourceDesc; resourceDesc.Alignment = 1 < msaa.Count ? D3D12_DEFAULT_MSAA_RESOURCE_PLACEMENT_ALIGNMENT : 0; - resourceDesc.Width = textureWidth; - resourceDesc.Height = textureHeight; - resourceDesc.MipLevels = numMips; + resourceDesc.Width = ti.width; + resourceDesc.Height = ti.height; + resourceDesc.MipLevels = ti.numMips; resourceDesc.Format = format; resourceDesc.SampleDesc = msaa; resourceDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN; @@ -4810,34 +4801,34 @@ namespace bgfx { namespace d3d12 resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; if (imageContainer.m_cubeMap) { - if (1 < numLayers) + if (1 < ti.numLayers) { m_srvd.ViewDimension = D3D12_SRV_DIMENSION_TEXTURECUBEARRAY; m_srvd.TextureCubeArray.MostDetailedMip = 0; - m_srvd.TextureCubeArray.MipLevels = numMips; + m_srvd.TextureCubeArray.MipLevels = ti.numMips; m_srvd.TextureCubeArray.ResourceMinLODClamp = 0.0f; - m_srvd.TextureCubeArray.NumCubes = numLayers; + m_srvd.TextureCubeArray.NumCubes = ti.numLayers; } else { m_srvd.ViewDimension = D3D12_SRV_DIMENSION_TEXTURECUBE; m_srvd.TextureCube.MostDetailedMip = 0; - m_srvd.TextureCube.MipLevels = numMips; + m_srvd.TextureCube.MipLevels = ti.numMips; m_srvd.TextureCube.ResourceMinLODClamp = 0.0f; } } else { - if (1 < numLayers) + if (1 < ti.numLayers) { m_srvd.ViewDimension = 1 < msaa.Count ? D3D12_SRV_DIMENSION_TEXTURE2DMSARRAY : D3D12_SRV_DIMENSION_TEXTURE2DARRAY ; m_srvd.Texture2DArray.MostDetailedMip = 0; - m_srvd.Texture2DArray.MipLevels = numMips; + m_srvd.Texture2DArray.MipLevels = ti.numMips; m_srvd.Texture2DArray.ResourceMinLODClamp = 0.0f; - m_srvd.Texture2DArray.ArraySize = numLayers; + m_srvd.Texture2DArray.ArraySize = ti.numLayers; } else { @@ -4846,18 +4837,18 @@ namespace bgfx { namespace d3d12 : D3D12_SRV_DIMENSION_TEXTURE2D ; m_srvd.Texture2D.MostDetailedMip = 0; - m_srvd.Texture2D.MipLevels = numMips; + m_srvd.Texture2D.MipLevels = ti.numMips; m_srvd.Texture2D.ResourceMinLODClamp = 0.0f; } } - if (1 < numLayers) + if (1 < ti.numLayers) { m_uavd.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2DARRAY; m_uavd.Texture2DArray.MipSlice = 0; m_uavd.Texture2DArray.FirstArraySlice = 0; m_uavd.Texture2DArray.PlaneSlice = 0; - m_uavd.Texture2DArray.ArraySize = numLayers; + m_uavd.Texture2DArray.ArraySize = ti.numLayers; } else { @@ -4880,7 +4871,7 @@ namespace bgfx { namespace d3d12 resourceDesc.DepthOrArraySize = uint16_t(m_depth); m_srvd.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE3D; m_srvd.Texture3D.MostDetailedMip = 0; - m_srvd.Texture3D.MipLevels = numMips; + m_srvd.Texture3D.MipLevels = ti.numMips; m_srvd.Texture3D.ResourceMinLODClamp = 0.0f; m_uavd.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE3D; @@ -4931,7 +4922,7 @@ namespace bgfx { namespace d3d12 kk = 0; for (uint8_t side = 0; side < numSides; ++side) { - for (uint32_t lod = 0, num = numMips; lod < num; ++lod) + for (uint32_t lod = 0, num = ti.numMips; lod < num; ++lod) { BX_FREE(g_allocator, const_cast(srd[kk].pData) ); ++kk; diff --git a/src/renderer_d3d9.cpp b/src/renderer_d3d9.cpp index 1eedd04c5..3931112f2 100644 --- a/src/renderer_d3d9.cpp +++ b/src/renderer_d3d9.cpp @@ -2910,7 +2910,7 @@ namespace bgfx { namespace d3d9 const uint8_t startLod = bx::min(_skip, imageContainer.m_numMips-1); bimg::TextureInfo ti; - imageGetSize( + bimg::imageGetSize( &ti , uint16_t(imageContainer.m_width >>startLod) , uint16_t(imageContainer.m_height>>startLod) @@ -2921,17 +2921,11 @@ namespace bgfx { namespace d3d9 , imageContainer.m_format ); - const uint8_t numMips = ti.numMips; - const uint32_t textureWidth = ti.width; - const uint32_t textureHeight = ti.height; - const uint32_t textureDepth = ti.depth; - const uint16_t numLayers = ti.numLayers; - m_flags = _flags; - m_width = textureWidth; - m_height = textureHeight; - m_depth = textureDepth; - m_numMips = numMips; + m_width = ti.width; + m_height = ti.height; + m_depth = ti.depth; + m_numMips = ti.numMips; m_requestedFormat = uint8_t(imageContainer.m_format); m_textureFormat = uint8_t(getViableTextureFormat(imageContainer) ); const bool convert = m_textureFormat != m_requestedFormat; @@ -2940,23 +2934,23 @@ namespace bgfx { namespace d3d9 if (imageContainer.m_cubeMap) { - createCubeTexture(textureWidth, numMips); + createCubeTexture(ti.width, ti.numMips); } else if (imageContainer.m_depth > 1) { - createVolumeTexture(textureWidth, textureHeight, imageContainer.m_depth, numMips); + createVolumeTexture(ti.width, ti.height, ti.depth, ti.numMips); } else { - createTexture(textureWidth, textureHeight, numMips); + createTexture(ti.width, ti.height, ti.numMips); } BX_TRACE("Texture %3d: %s (requested: %s), %dx%d%s%s." , this - s_renderD3D9->m_textures , getName( (TextureFormat::Enum)m_textureFormat) , getName( (TextureFormat::Enum)m_requestedFormat) - , textureWidth - , textureHeight + , ti.width + , ti.height , imageContainer.m_cubeMap ? "x6" : "" , 0 != (m_flags&BGFX_TEXTURE_RT_MASK) ? " (render target)" : "" ); @@ -2970,25 +2964,25 @@ namespace bgfx { namespace d3d9 // bytes. If actual mip size is used it causes memory corruption. // http://www.aras-p.info/texts/D3D9GPUHacks.html#3dc const bool useMipSize = true - && imageContainer.m_format != bimg::TextureFormat::BC4 - && imageContainer.m_format != bimg::TextureFormat::BC5 - ; + && imageContainer.m_format != bimg::TextureFormat::BC4 + && imageContainer.m_format != bimg::TextureFormat::BC5 + ; for (uint8_t side = 0, numSides = imageContainer.m_cubeMap ? 6 : 1; side < numSides; ++side) { - uint32_t width = textureWidth; - uint32_t height = textureHeight; - uint32_t depth = imageContainer.m_depth; - uint32_t mipWidth = imageContainer.m_width; - uint32_t mipHeight = imageContainer.m_height; + uint32_t width = ti.width; + uint32_t height = ti.height; + uint32_t depth = ti.depth; + uint32_t mipWidth = ti.width; + uint32_t mipHeight = ti.height; - for (uint8_t lod = 0, num = numMips; lod < num; ++lod) + for (uint8_t lod = 0, num = ti.numMips; lod < num; ++lod) { - width = bx::uint32_max(1, width); - height = bx::uint32_max(1, height); - depth = bx::uint32_max(1, depth); - mipWidth = bx::uint32_max(blockInfo.blockWidth, mipWidth); - mipHeight = bx::uint32_max(blockInfo.blockHeight, mipHeight); + width = bx::max(1, width); + height = bx::max(1, height); + depth = bx::max(1, depth); + mipWidth = bx::max(blockInfo.blockWidth, mipWidth); + mipHeight = bx::max(blockInfo.blockHeight, mipHeight); uint32_t mipSize = width*height*depth*bpp/8; bimg::ImageMip mip; diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index 43f2eaf29..c5e542db7 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -4724,7 +4724,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); const uint8_t startLod = bx::min(_skip, imageContainer.m_numMips-1); bimg::TextureInfo ti; - imageGetSize( + bimg::imageGetSize( &ti , uint16_t(imageContainer.m_width >>startLod) , uint16_t(imageContainer.m_height>>startLod) @@ -4735,12 +4735,6 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); , imageContainer.m_format ); - const uint8_t numMips = ti.numMips; - const uint32_t textureWidth = ti.width; - const uint32_t textureHeight = ti.height; - const uint32_t textureDepth = ti.depth; - const uint16_t numLayers = ti.numLayers; - m_requestedFormat = uint8_t(imageContainer.m_format); m_textureFormat = uint8_t(getViableTextureFormat(imageContainer) ); @@ -4761,7 +4755,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); target = GL_TEXTURE_3D; } - const bool textureArray = 1 < numLayers; + const bool textureArray = 1 < ti.numLayers; if (textureArray) { switch (target) @@ -4773,12 +4767,12 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); } if (!init(target - , textureWidth - , textureHeight - , textureDepth - , numMips - , _flags - ) ) + , ti.width + , ti.height + , ti.depth + , ti.numMips + , _flags + ) ) { return; } @@ -4810,9 +4804,9 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); , getName( (TextureFormat::Enum)m_textureFormat) , srgb ? "+sRGB " : "" , getName( (TextureFormat::Enum)m_requestedFormat) - , numLayers - , textureWidth - , textureHeight + , ti.numLayers + , ti.width + , ti.height , imageContainer.m_cubeMap ? 6 : (1 < imageContainer.m_depth ? imageContainer.m_depth : 0) , 0 != (m_flags&BGFX_TEXTURE_RT_MASK) ? " (render target)" : "" ); @@ -4828,22 +4822,22 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); uint8_t* temp = NULL; if (convert) { - temp = (uint8_t*)BX_ALLOC(g_allocator, textureWidth*textureHeight*4); + temp = (uint8_t*)BX_ALLOC(g_allocator, ti.width*ti.height*4); } - const uint16_t numSides = numLayers * (imageContainer.m_cubeMap ? 6 : 1); + const uint16_t numSides = ti.numLayers * (imageContainer.m_cubeMap ? 6 : 1); for (uint16_t side = 0; side < numSides; ++side) { - uint32_t width = textureWidth; - uint32_t height = textureHeight; - uint32_t depth = imageContainer.m_depth; + uint32_t width = ti.width; + uint32_t height = ti.height; + uint32_t depth = ti.depth; GLenum imageTarget = imageContainer.m_cubeMap && !textureArray ? target+side : target ; - for (uint8_t lod = 0, num = numMips; lod < num; ++lod) + for (uint8_t lod = 0, num = ti.numMips; lod < num; ++lod) { width = bx::uint32_max(1, width); height = bx::uint32_max(1, height); @@ -4905,8 +4899,8 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); { if (compressed) { - uint32_t size = bx::uint32_max(1, (width + 3)>>2) - * bx::uint32_max(1, (height + 3)>>2) + uint32_t size = bx::max(1, (width + 3)>>2) + * bx::max(1, (height + 3)>>2) * 4*4* bimg::getBitsPerPixel(bimg::TextureFormat::Enum(m_textureFormat) )/8 ; diff --git a/src/renderer_mtl.mm b/src/renderer_mtl.mm index d3db0dba3..299fb69af 100644 --- a/src/renderer_mtl.mm +++ b/src/renderer_mtl.mm @@ -2581,7 +2581,7 @@ namespace bgfx { namespace mtl const uint8_t startLod = bx::min(_skip, imageContainer.m_numMips-1); bimg::TextureInfo ti; - imageGetSize( + bimg::imageGetSize( &ti , uint16_t(imageContainer.m_width >>startLod) , uint16_t(imageContainer.m_height>>startLod)