diff options
Diffstat (limited to '3rdparty/bgfx/src/renderer_mtl.mm')
-rw-r--r-- | 3rdparty/bgfx/src/renderer_mtl.mm | 128 |
1 files changed, 82 insertions, 46 deletions
diff --git a/3rdparty/bgfx/src/renderer_mtl.mm b/3rdparty/bgfx/src/renderer_mtl.mm index ce2bf3b8b51..d3721c9062d 100644 --- a/3rdparty/bgfx/src/renderer_mtl.mm +++ b/3rdparty/bgfx/src/renderer_mtl.mm @@ -310,9 +310,9 @@ namespace bgfx { namespace mtl { MTLPixelFormatRG32Sint, MTLPixelFormatInvalid }, // RG32I { MTLPixelFormatRG32Uint, MTLPixelFormatInvalid }, // RG32U { MTLPixelFormatRG32Float, MTLPixelFormatInvalid }, // RG32F - { MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // RGB8 - { MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // RGB8I - { MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // RGB8U + { MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // RGB8 + { MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // RGB8I + { MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // RGB8U { MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // RGB8S { MTLPixelFormatRGB9E5Float, MTLPixelFormatInvalid }, // RGB9E5F { MTLPixelFormatBGRA8Unorm, MTLPixelFormatBGRA8Unorm_sRGB }, // BGRA8 @@ -474,26 +474,27 @@ namespace bgfx { namespace mtl m_screenshotBlitRenderPipelineState = m_device.newRenderPipelineStateWithDescriptor(m_renderPipelineDescriptor); g_caps.supported |= (0 - | BGFX_CAPS_TEXTURE_COMPARE_LEQUAL //NOTE: on IOS Gpu Family 1/2 have to set compare in shader - | BGFX_CAPS_TEXTURE_COMPARE_ALL - | BGFX_CAPS_TEXTURE_3D - | BGFX_CAPS_VERTEX_ATTRIB_HALF - | BGFX_CAPS_VERTEX_ATTRIB_UINT10 - | BGFX_CAPS_INSTANCING - | BGFX_CAPS_FRAGMENT_DEPTH - | BGFX_CAPS_BLEND_INDEPENDENT - //| BGFX_CAPS_COMPUTE // TODO: api/hw supports it but metal compute shaders are not yet supported - | BGFX_CAPS_INDEX32 - //| BGFX_CAPS_DRAW_INDIRECT // TODO: support on iOS9+gpu family3+ and on macOS - | BGFX_CAPS_TEXTURE_BLIT - | BGFX_CAPS_TEXTURE_READ_BACK - | BGFX_CAPS_OCCLUSION_QUERY - | BGFX_CAPS_ALPHA_TO_COVERAGE - ); + | BGFX_CAPS_TEXTURE_COMPARE_LEQUAL //NOTE: on IOS Gpu Family 1/2 have to set compare in shader + | BGFX_CAPS_TEXTURE_COMPARE_ALL + | BGFX_CAPS_TEXTURE_3D + | BGFX_CAPS_VERTEX_ATTRIB_HALF + | BGFX_CAPS_VERTEX_ATTRIB_UINT10 + | BGFX_CAPS_INSTANCING + | BGFX_CAPS_FRAGMENT_DEPTH + | BGFX_CAPS_BLEND_INDEPENDENT +// | BGFX_CAPS_COMPUTE // TODO: api/hw supports it but metal compute shaders are not yet supported + | BGFX_CAPS_INDEX32 +// | BGFX_CAPS_DRAW_INDIRECT // TODO: support on iOS9+gpu family3+ and on macOS + | BGFX_CAPS_TEXTURE_BLIT + | BGFX_CAPS_TEXTURE_READ_BACK + | BGFX_CAPS_OCCLUSION_QUERY + | BGFX_CAPS_ALPHA_TO_COVERAGE + | BGFX_CAPS_TEXTURE_2D_ARRAY // supported on all platforms + ); if (BX_ENABLED(BX_PLATFORM_IOS) ) { - if ( iOSVersionEqualOrGreater("9.0.0") ) + if (iOSVersionEqualOrGreater("9.0.0") ) { g_caps.maxTextureSize = m_device.supportsFeatureSet((MTLFeatureSet)4 /* iOS_GPUFamily3_v1 */) ? 16384 : 8192; } @@ -501,20 +502,30 @@ namespace bgfx { namespace mtl { g_caps.maxTextureSize = 4096; } - g_caps.maxFBAttachments = uint8_t(bx::uint32_min(m_device.supportsFeatureSet((MTLFeatureSet)1 /* MTLFeatureSet_iOS_GPUFamily2_v1 */) ? 8 : 4, BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS)); - } else if (BX_ENABLED(BX_PLATFORM_OSX) ) + g_caps.maxFBAttachments = uint8_t(bx::uint32_min(m_device.supportsFeatureSet((MTLFeatureSet)1 /* MTLFeatureSet_iOS_GPUFamily2_v1 */) ? 8 : 4, BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS)); + } + else if (BX_ENABLED(BX_PLATFORM_OSX) ) { - g_caps.maxTextureSize = 16384; + g_caps.maxTextureSize = 16384; g_caps.maxFBAttachments = 8; + g_caps.supported |= BGFX_CAPS_TEXTURE_CUBE_ARRAY; } //todo: vendor id, device id, gpu enum - m_hasPixelFormatDepth32Float_Stencil8 = (BX_ENABLED(BX_PLATFORM_OSX) || - ( BX_ENABLED(BX_PLATFORM_IOS) && iOSVersionEqualOrGreater("9.0.0") ) ); - m_macOS11Runtime = (BX_ENABLED(BX_PLATFORM_OSX) && macOSVersionEqualOrGreater(10,11,0) ); - m_iOS9Runtime = (BX_ENABLED(BX_PLATFORM_IOS) && iOSVersionEqualOrGreater("9.0.0") ); + m_hasPixelFormatDepth32Float_Stencil8 = false + || BX_ENABLED(BX_PLATFORM_OSX) + || (BX_ENABLED(BX_PLATFORM_IOS) && iOSVersionEqualOrGreater("9.0.0") ) + ; + m_macOS11Runtime = true + && BX_ENABLED(BX_PLATFORM_OSX) + && macOSVersionEqualOrGreater(10,11,0) + ; + m_iOS9Runtime = true + && BX_ENABLED(BX_PLATFORM_IOS) + && iOSVersionEqualOrGreater("9.0.0") + ; if (BX_ENABLED(BX_PLATFORM_OSX) ) { @@ -809,14 +820,14 @@ namespace bgfx { namespace mtl bx::write(&writer, magic); TextureCreate tc; - tc.m_width = _width; - tc.m_height = _height; - tc.m_sides = 0; - tc.m_depth = 0; - tc.m_numMips = _numMips; - tc.m_format = TextureFormat::Enum(texture.m_requestedFormat); - tc.m_cubeMap = false; - tc.m_mem = NULL; + tc.m_width = _width; + tc.m_height = _height; + tc.m_depth = 0; + tc.m_numLayers = 1; + tc.m_numMips = _numMips; + tc.m_format = TextureFormat::Enum(texture.m_requestedFormat); + tc.m_cubeMap = false; + tc.m_mem = NULL; bx::write(&writer, tc); texture.destroy(); @@ -2384,8 +2395,9 @@ namespace bgfx { namespace mtl const ImageBlockInfo& blockInfo = getBlockInfo(TextureFormat::Enum(imageContainer.m_format) ); 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); + const uint16_t numLayers = imageContainer.m_numLayers; - m_flags = _flags; + m_flags = _flags; m_width = textureWidth; m_height = textureHeight; m_depth = imageContainer.m_depth; @@ -2396,7 +2408,20 @@ namespace bgfx { namespace mtl TextureDescriptor desc = s_renderMtl->m_textureDescriptor; - if (imageContainer.m_cubeMap) + if (1 < numLayers) + { + if (imageContainer.m_cubeMap) + { + desc.textureType = MTLTextureTypeCubeArray; + } + else + { + desc.textureType = MTLTextureType2DArray; + } + + desc.arrayLength = numLayers; + } + else if (imageContainer.m_cubeMap) { desc.textureType = MTLTextureTypeCube; } @@ -2410,23 +2435,28 @@ namespace bgfx { namespace mtl } m_numMips = numMips; + const uint16_t numSides = numLayers * (imageContainer.m_cubeMap ? 6 : 1); - const bool compressed = isCompressed(TextureFormat::Enum(m_textureFormat) ); + const bool compressed = isCompressed(TextureFormat::Enum(m_textureFormat) ); + const bool writeOnly = 0 != (_flags&BGFX_TEXTURE_RT_WRITE_ONLY); + const bool computeWrite = 0 != (_flags&BGFX_TEXTURE_COMPUTE_WRITE); + const bool renderTarget = 0 != (_flags&BGFX_TEXTURE_RT_MASK); + const bool srgb = 0 != (_flags&BGFX_TEXTURE_SRGB) || imageContainer.m_srgb; - BX_TRACE("Texture %3d: %s (requested: %s), %dx%d%s%s." + BX_TRACE("Texture %3d: %s (requested: %s), layers %d, %dx%d%s RT[%c], WO[%c], CW[%c], sRGB[%c]" , this - s_renderMtl->m_textures , getName( (TextureFormat::Enum)m_textureFormat) , getName( (TextureFormat::Enum)m_requestedFormat) + , numLayers , textureWidth , textureHeight , imageContainer.m_cubeMap ? "x6" : "" - , 0 != (_flags&BGFX_TEXTURE_RT_MASK) ? " (render target)" : "" + , renderTarget ? 'x' : '.' + , writeOnly ? 'x' : '.' + , computeWrite ? 'x' : '.' + , srgb ? 'x' : '.' ); - const bool writeOnly = 0 != (_flags&BGFX_TEXTURE_RT_WRITE_ONLY); - const bool computeWrite = 0 != (_flags&BGFX_TEXTURE_COMPUTE_WRITE); - const bool renderTarget = 0 != (_flags&BGFX_TEXTURE_RT_MASK); - const bool srgb = 0 != (_flags&BGFX_TEXTURE_SRGB) || imageContainer.m_srgb; const uint32_t msaaQuality = bx::uint32_satsub( (_flags&BGFX_TEXTURE_RT_MSAA_MASK)>>BGFX_TEXTURE_RT_MSAA_SHIFT, 1); int sampleCount = s_msaa[msaaQuality]; @@ -2455,7 +2485,7 @@ namespace bgfx { namespace mtl if (s_renderMtl->m_iOS9Runtime || s_renderMtl->m_macOS11Runtime) { - desc.cpuCacheMode = MTLCPUCacheModeDefaultCache; + desc.cpuCacheMode = MTLCPUCacheModeDefaultCache; desc.storageMode = (MTLStorageMode)(writeOnly||isDepth(TextureFormat::Enum(m_textureFormat)) ? 2 /*MTLStorageModePrivate*/ @@ -2493,7 +2523,7 @@ namespace bgfx { namespace mtl temp = (uint8_t*)BX_ALLOC(g_allocator, textureWidth*textureHeight*4); } - for (uint8_t side = 0, numSides = imageContainer.m_cubeMap ? 6 : 1; side < numSides; ++side) + for (uint8_t side = 0; side < numSides; ++side) { uint32_t width = textureWidth; uint32_t height = textureHeight; @@ -3023,23 +3053,29 @@ namespace bgfx { namespace mtl uint32_t width = bx::uint32_min(srcWidth, dstWidth); uint32_t height = bx::uint32_min(srcHeight, dstHeight); uint32_t depth = bx::uint32_min(srcDepth, dstDepth); +#if BX_PLATFORM_OSX bool readBack = !!(dst.m_flags & BGFX_TEXTURE_READ_BACK); +#endif // BX_PLATFORM_OSX if ( MTLTextureType3D == src.m_ptr.textureType()) { m_blitCommandEncoder.copyFromTexture(src.m_ptr, 0, 0, MTLOriginMake(blit.m_srcX, blit.m_srcY, blit.m_srcZ), MTLSizeMake(width, height, bx::uint32_imax(depth, 1)), dst.m_ptr, 0, 0, MTLOriginMake(blit.m_dstX, blit.m_dstY, blit.m_dstZ)); +#if BX_PLATFORM_OSX if (m_macOS11Runtime &&readBack) { m_blitCommandEncoder.synchronizeResource(dst.m_ptr); } +#endif // BX_PLATFORM_OSX } else { m_blitCommandEncoder.copyFromTexture(src.m_ptr, blit.m_srcZ, blit.m_srcMip, MTLOriginMake(blit.m_srcX, blit.m_srcY, 0), MTLSizeMake(width, height, 1), dst.m_ptr, blit.m_dstZ, blit.m_dstMip, MTLOriginMake(blit.m_dstX, blit.m_dstY, 0)); +#if BX_PLATFORM_OSX if (m_macOS11Runtime && readBack) { m_blitCommandEncoder.synchronizeTexture(dst.m_ptr, 0, blit.m_dstMip); } +#endif // BX_PLATFORM_OSX } } |