Metal: Fixed texture format fallback.

This commit is contained in:
Branimir Karadžić 2015-10-23 14:59:03 -07:00
parent 70ad9aac0e
commit 1fad44b477

View file

@ -1807,7 +1807,14 @@ namespace bgfx { namespace mtl
const uint32_t textureWidth = bx::uint32_max(blockInfo.blockWidth, imageContainer.m_width >>startLod);
const uint32_t textureHeight = bx::uint32_max(blockInfo.blockHeight, imageContainer.m_height>>startLod);
bool convert = BGFX_CAPS_FORMAT_TEXTURE_NONE == g_caps.formats[m_requestedFormat];
const uint16_t formatMask = imageContainer.m_cubeMap
? BGFX_CAPS_FORMAT_TEXTURE_CUBE_EMULATED
: imageContainer.m_depth > 1
? BGFX_CAPS_FORMAT_TEXTURE_3D_EMULATED
: BGFX_CAPS_FORMAT_TEXTURE_2D_EMULATED
;
const bool convert = 0 != (g_caps.formats[m_requestedFormat] & formatMask);
m_flags = _flags;
m_requestedFormat = (uint8_t)imageContainer.m_format;
@ -1816,9 +1823,6 @@ namespace bgfx { namespace mtl
: m_requestedFormat
;
const TextureFormatInfo& tfi = s_textureFormat[m_requestedFormat];
convert = MTLPixelFormatInvalid == tfi.m_fmt;
uint8_t bpp = getBitsPerPixel(TextureFormat::Enum(m_textureFormat) );
if (convert)
{
@ -1855,7 +1859,6 @@ namespace bgfx { namespace mtl
, 0 != (_flags&BGFX_TEXTURE_RT_MASK) ? " (render target)" : ""
);
const bool bufferOnly = 0 != (_flags&BGFX_TEXTURE_RT_BUFFER_ONLY);
const bool computeWrite = 0 != (_flags&BGFX_TEXTURE_COMPUTE_WRITE);
// const bool renderTarget = 0 != (_flags&BGFX_TEXTURE_RT_MASK);
@ -1944,8 +1947,8 @@ namespace bgfx { namespace mtl
MTLRegion region = { { 0, 0, 0 }, { width, height, depth } };
uint32_t bytesPerRow;
uint32_t bytesPerImage;
uint32_t bytesPerRow = 0;
uint32_t bytesPerImage = 0;
if (compressed && !convert)
{
@ -1957,22 +1960,24 @@ namespace bgfx { namespace mtl
}
else
{
bytesPerRow = (mip.m_width / blockInfo.blockWidth )*mip.m_blockSize;
bytesPerImage = (desc.textureType == MTLTextureType3D) ? (mip.m_height/blockInfo.blockHeight)*bytesPerRow : 0;
bytesPerRow = (mip.m_width / blockInfo.blockWidth)*mip.m_blockSize;
bytesPerImage = desc.textureType == MTLTextureType3D
? (mip.m_height/blockInfo.blockHeight)*bytesPerRow
: 0
;
}
}
else
{
bytesPerRow = width * bpp / 8;
bytesPerImage = (desc.textureType == MTLTextureType3D) ? width * height * bpp / 8 : 0;
bytesPerImage = desc.textureType == MTLTextureType3D
? bytesPerRow * height
: 0
;
}
m_ptr.replaceRegion(region, lod, side, data, bytesPerRow, bytesPerImage);
}
else if (!computeWrite)
{
//TODO: do we need to clear to zero??
}
width >>= 1;
height >>= 1;
@ -1989,7 +1994,11 @@ namespace bgfx { namespace mtl
void TextureMtl::update(uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem)
{
MTLRegion region = { { _rect.m_x, _rect.m_y, _z }, { _rect.m_width, _rect.m_height, _depth } };
MTLRegion region =
{
{ _rect.m_x, _rect.m_y, _z },
{ _rect.m_width, _rect.m_height, _depth },
};
const uint32_t bpp = getBitsPerPixel(TextureFormat::Enum(m_textureFormat) );
const uint32_t rectpitch = _rect.m_width*bpp/8;