From 31cdf0b0ef523a99ce0490c53d05690ab0173098 Mon Sep 17 00:00:00 2001 From: MarkosTh09 Date: Wed, 27 May 2026 12:45:34 +0400 Subject: [PATCH 1/2] add support for ASTC formats --- plume_d3d12.cpp | 47 ++++- plume_metal.cpp | 284 ++++++++++++++++++++++----- plume_render_interface_types.h | 337 +++++++++++++++++++++++++++++++++ plume_vulkan.cpp | 115 ++++++++++- 4 files changed, 738 insertions(+), 45 deletions(-) diff --git a/plume_d3d12.cpp b/plume_d3d12.cpp index 2cdcf18..b0267c8 100644 --- a/plume_d3d12.cpp +++ b/plume_d3d12.cpp @@ -226,6 +226,50 @@ namespace plume { return DXGI_FORMAT_BC7_UNORM; case RenderFormat::BC7_UNORM_SRGB: return DXGI_FORMAT_BC7_UNORM_SRGB; + case RenderFormat::ASTC_4X4_TYPELESS: + case RenderFormat::ASTC_4X4_UNORM: + case RenderFormat::ASTC_4X4_UNORM_SRGB: + case RenderFormat::ASTC_5X4_TYPELESS: + case RenderFormat::ASTC_5X4_UNORM: + case RenderFormat::ASTC_5X4_UNORM_SRGB: + case RenderFormat::ASTC_5X5_TYPELESS: + case RenderFormat::ASTC_5X5_UNORM: + case RenderFormat::ASTC_5X5_UNORM_SRGB: + case RenderFormat::ASTC_6X5_TYPELESS: + case RenderFormat::ASTC_6X5_UNORM: + case RenderFormat::ASTC_6X5_UNORM_SRGB: + case RenderFormat::ASTC_6X6_TYPELESS: + case RenderFormat::ASTC_6X6_UNORM: + case RenderFormat::ASTC_6X6_UNORM_SRGB: + case RenderFormat::ASTC_8X5_TYPELESS: + case RenderFormat::ASTC_8X5_UNORM: + case RenderFormat::ASTC_8X5_UNORM_SRGB: + case RenderFormat::ASTC_8X6_TYPELESS: + case RenderFormat::ASTC_8X6_UNORM: + case RenderFormat::ASTC_8X6_UNORM_SRGB: + case RenderFormat::ASTC_8X8_TYPELESS: + case RenderFormat::ASTC_8X8_UNORM: + case RenderFormat::ASTC_8X8_UNORM_SRGB: + case RenderFormat::ASTC_10X5_TYPELESS: + case RenderFormat::ASTC_10X5_UNORM: + case RenderFormat::ASTC_10X5_UNORM_SRGB: + case RenderFormat::ASTC_10X6_TYPELESS: + case RenderFormat::ASTC_10X6_UNORM: + case RenderFormat::ASTC_10X6_UNORM_SRGB: + case RenderFormat::ASTC_10X8_TYPELESS: + case RenderFormat::ASTC_10X8_UNORM: + case RenderFormat::ASTC_10X8_UNORM_SRGB: + case RenderFormat::ASTC_10X10_TYPELESS: + case RenderFormat::ASTC_10X10_UNORM: + case RenderFormat::ASTC_10X10_UNORM_SRGB: + case RenderFormat::ASTC_12X10_TYPELESS: + case RenderFormat::ASTC_12X10_UNORM: + case RenderFormat::ASTC_12X10_UNORM_SRGB: + case RenderFormat::ASTC_12X12_TYPELESS: + case RenderFormat::ASTC_12X12_UNORM: + case RenderFormat::ASTC_12X12_UNORM_SRGB: + assert(false && "ASTC formats are not supported in D3D12."); + return DXGI_FORMAT_FORCE_UINT; default: assert(false && "Unknown format."); return DXGI_FORMAT_FORCE_UINT; @@ -692,13 +736,14 @@ namespace plume { case RenderTextureCopyType::PLACED_FOOTPRINT: { const D3D12Buffer *interfaceBuffer = static_cast(location.buffer); const uint32_t blockWidth = RenderFormatBlockWidth(location.placedFootprint.format); + const uint32_t blockHeight = RenderFormatBlockHeight(location.placedFootprint.format); const uint32_t blockCount = (location.placedFootprint.rowWidth + blockWidth - 1) / blockWidth; loc.pResource = (interfaceBuffer != nullptr) ? interfaceBuffer->d3d : nullptr; loc.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT; loc.PlacedFootprint.Offset = location.placedFootprint.offset; loc.PlacedFootprint.Footprint.Format = toDXGI(location.placedFootprint.format); loc.PlacedFootprint.Footprint.Width = ((location.placedFootprint.width + blockWidth - 1) / blockWidth) * blockWidth; - loc.PlacedFootprint.Footprint.Height = ((location.placedFootprint.height + blockWidth - 1) / blockWidth) * blockWidth; + loc.PlacedFootprint.Footprint.Height = ((location.placedFootprint.height + blockHeight - 1) / blockHeight) * blockHeight; loc.PlacedFootprint.Footprint.Depth = location.placedFootprint.depth; loc.PlacedFootprint.Footprint.RowPitch = blockCount * RenderFormatSize(location.placedFootprint.format); diff --git a/plume_metal.cpp b/plume_metal.cpp index 2abe67c..dcf1484 100644 --- a/plume_metal.cpp +++ b/plume_metal.cpp @@ -285,6 +285,90 @@ namespace plume { return RenderFormat::BC7_UNORM; case MTL::PixelFormatBC7_RGBAUnorm_sRGB: return RenderFormat::BC7_UNORM_SRGB; + case MTL::PixelFormatASTC_4x4_LDR: + return RenderFormat::ASTC_4X4_UNORM; + case MTL::PixelFormatASTC_4x4_sRGB: + return RenderFormat::ASTC_4X4_UNORM_SRGB; + case MTL::PixelFormatASTC_4x4_HDR: + return RenderFormat::ASTC_4X4_FLOAT; + case MTL::PixelFormatASTC_5x4_LDR: + return RenderFormat::ASTC_5X4_UNORM; + case MTL::PixelFormatASTC_5x4_sRGB: + return RenderFormat::ASTC_5X4_UNORM_SRGB; + case MTL::PixelFormatASTC_5x4_HDR: + return RenderFormat::ASTC_5X4_FLOAT; + case MTL::PixelFormatASTC_5x5_LDR: + return RenderFormat::ASTC_5X5_UNORM; + case MTL::PixelFormatASTC_5x5_sRGB: + return RenderFormat::ASTC_5X5_UNORM_SRGB; + case MTL::PixelFormatASTC_5x5_HDR: + return RenderFormat::ASTC_5X5_FLOAT; + case MTL::PixelFormatASTC_6x5_LDR: + return RenderFormat::ASTC_6X5_UNORM; + case MTL::PixelFormatASTC_6x5_sRGB: + return RenderFormat::ASTC_6X5_UNORM_SRGB; + case MTL::PixelFormatASTC_6x5_HDR: + return RenderFormat::ASTC_6X5_FLOAT; + case MTL::PixelFormatASTC_6x6_LDR: + return RenderFormat::ASTC_6X6_UNORM; + case MTL::PixelFormatASTC_6x6_sRGB: + return RenderFormat::ASTC_6X6_UNORM_SRGB; + case MTL::PixelFormatASTC_6x6_HDR: + return RenderFormat::ASTC_6X6_FLOAT; + case MTL::PixelFormatASTC_8x5_LDR: + return RenderFormat::ASTC_8X5_UNORM; + case MTL::PixelFormatASTC_8x5_sRGB: + return RenderFormat::ASTC_8X5_UNORM_SRGB; + case MTL::PixelFormatASTC_8x5_HDR: + return RenderFormat::ASTC_8X5_FLOAT; + case MTL::PixelFormatASTC_8x6_LDR: + return RenderFormat::ASTC_8X6_UNORM; + case MTL::PixelFormatASTC_8x6_sRGB: + return RenderFormat::ASTC_8X6_UNORM_SRGB; + case MTL::PixelFormatASTC_8x6_HDR: + return RenderFormat::ASTC_8X6_FLOAT; + case MTL::PixelFormatASTC_8x8_LDR: + return RenderFormat::ASTC_8X8_UNORM; + case MTL::PixelFormatASTC_8x8_sRGB: + return RenderFormat::ASTC_8X8_UNORM_SRGB; + case MTL::PixelFormatASTC_8x8_HDR: + return RenderFormat::ASTC_8X8_FLOAT; + case MTL::PixelFormatASTC_10x5_LDR: + return RenderFormat::ASTC_10X5_UNORM; + case MTL::PixelFormatASTC_10x5_sRGB: + return RenderFormat::ASTC_10X5_UNORM_SRGB; + case MTL::PixelFormatASTC_10x5_HDR: + return RenderFormat::ASTC_10X5_FLOAT; + case MTL::PixelFormatASTC_10x6_LDR: + return RenderFormat::ASTC_10X6_UNORM; + case MTL::PixelFormatASTC_10x6_sRGB: + return RenderFormat::ASTC_10X6_UNORM_SRGB; + case MTL::PixelFormatASTC_10x6_HDR: + return RenderFormat::ASTC_10X6_FLOAT; + case MTL::PixelFormatASTC_10x8_LDR: + return RenderFormat::ASTC_10X8_UNORM; + case MTL::PixelFormatASTC_10x8_sRGB: + return RenderFormat::ASTC_10X8_UNORM_SRGB; + case MTL::PixelFormatASTC_10x8_HDR: + return RenderFormat::ASTC_10X8_FLOAT; + case MTL::PixelFormatASTC_10x10_LDR: + return RenderFormat::ASTC_10X10_UNORM; + case MTL::PixelFormatASTC_10x10_sRGB: + return RenderFormat::ASTC_10X10_UNORM_SRGB; + case MTL::PixelFormatASTC_10x10_HDR: + return RenderFormat::ASTC_10X10_FLOAT; + case MTL::PixelFormatASTC_12x10_LDR: + return RenderFormat::ASTC_12X10_UNORM; + case MTL::PixelFormatASTC_12x10_sRGB: + return RenderFormat::ASTC_12X10_UNORM_SRGB; + case MTL::PixelFormatASTC_12x10_HDR: + return RenderFormat::ASTC_12X10_FLOAT; + case MTL::PixelFormatASTC_12x12_LDR: + return RenderFormat::ASTC_12X12_UNORM; + case MTL::PixelFormatASTC_12x12_sRGB: + return RenderFormat::ASTC_12X12_UNORM_SRGB; + case MTL::PixelFormatASTC_12x12_HDR: + return RenderFormat::ASTC_12X12_FLOAT; default: assert(false && "Unknown Metal format."); return RenderFormat::UNKNOWN; @@ -402,48 +486,161 @@ namespace plume { case RenderFormat::R8_SINT: return MTL::PixelFormatR8Sint; // Block compressed formats - case RenderFormat::BC1_TYPELESS: - return MTL::PixelFormatBC1_RGBA; - case RenderFormat::BC1_UNORM: - return MTL::PixelFormatBC1_RGBA; - case RenderFormat::BC1_UNORM_SRGB: - return MTL::PixelFormatBC1_RGBA_sRGB; - case RenderFormat::BC2_TYPELESS: - return MTL::PixelFormatBC2_RGBA; - case RenderFormat::BC2_UNORM: - return MTL::PixelFormatBC2_RGBA; - case RenderFormat::BC2_UNORM_SRGB: - return MTL::PixelFormatBC2_RGBA_sRGB; - case RenderFormat::BC3_TYPELESS: - return MTL::PixelFormatBC3_RGBA; - case RenderFormat::BC3_UNORM: - return MTL::PixelFormatBC3_RGBA; - case RenderFormat::BC3_UNORM_SRGB: - return MTL::PixelFormatBC3_RGBA_sRGB; - case RenderFormat::BC4_TYPELESS: - return MTL::PixelFormatBC4_RUnorm; - case RenderFormat::BC4_UNORM: - return MTL::PixelFormatBC4_RUnorm; - case RenderFormat::BC4_SNORM: - return MTL::PixelFormatBC4_RSnorm; - case RenderFormat::BC5_TYPELESS: - return MTL::PixelFormatBC5_RGUnorm; - case RenderFormat::BC5_UNORM: - return MTL::PixelFormatBC5_RGUnorm; - case RenderFormat::BC5_SNORM: - return MTL::PixelFormatBC5_RGSnorm; - case RenderFormat::BC6H_TYPELESS: - return MTL::PixelFormatBC6H_RGBFloat; - case RenderFormat::BC6H_UF16: - return MTL::PixelFormatBC6H_RGBUfloat; - case RenderFormat::BC6H_SF16: - return MTL::PixelFormatBC6H_RGBFloat; - case RenderFormat::BC7_TYPELESS: - return MTL::PixelFormatBC7_RGBAUnorm; - case RenderFormat::BC7_UNORM: - return MTL::PixelFormatBC7_RGBAUnorm; - case RenderFormat::BC7_UNORM_SRGB: - return MTL::PixelFormatBC7_RGBAUnorm_sRGB; + case RenderFormat::BC1_TYPELESS: + return MTL::PixelFormatBC1_RGBA; + case RenderFormat::BC1_UNORM: + return MTL::PixelFormatBC1_RGBA; + case RenderFormat::BC1_UNORM_SRGB: + return MTL::PixelFormatBC1_RGBA_sRGB; + case RenderFormat::BC2_TYPELESS: + return MTL::PixelFormatBC2_RGBA; + case RenderFormat::BC2_UNORM: + return MTL::PixelFormatBC2_RGBA; + case RenderFormat::BC2_UNORM_SRGB: + return MTL::PixelFormatBC2_RGBA_sRGB; + case RenderFormat::BC3_TYPELESS: + return MTL::PixelFormatBC3_RGBA; + case RenderFormat::BC3_UNORM: + return MTL::PixelFormatBC3_RGBA; + case RenderFormat::BC3_UNORM_SRGB: + return MTL::PixelFormatBC3_RGBA_sRGB; + case RenderFormat::BC4_TYPELESS: + return MTL::PixelFormatBC4_RUnorm; + case RenderFormat::BC4_UNORM: + return MTL::PixelFormatBC4_RUnorm; + case RenderFormat::BC4_SNORM: + return MTL::PixelFormatBC4_RSnorm; + case RenderFormat::BC5_TYPELESS: + return MTL::PixelFormatBC5_RGUnorm; + case RenderFormat::BC5_UNORM: + return MTL::PixelFormatBC5_RGUnorm; + case RenderFormat::BC5_SNORM: + return MTL::PixelFormatBC5_RGSnorm; + case RenderFormat::BC6H_TYPELESS: + return MTL::PixelFormatBC6H_RGBFloat; + case RenderFormat::BC6H_UF16: + return MTL::PixelFormatBC6H_RGBUfloat; + case RenderFormat::BC6H_SF16: + return MTL::PixelFormatBC6H_RGBFloat; + case RenderFormat::BC7_TYPELESS: + return MTL::PixelFormatBC7_RGBAUnorm; + case RenderFormat::BC7_UNORM: + return MTL::PixelFormatBC7_RGBAUnorm; + case RenderFormat::BC7_UNORM_SRGB: + return MTL::PixelFormatBC7_RGBAUnorm_sRGB; + // ASTC formats + case RenderFormat::ASTC_4X4_TYPELESS: + return MTL::PixelFormatASTC_4x4_HDR; + case RenderFormat::ASTC_4X4_UNORM: + return MTL::PixelFormatASTC_4x4_LDR; + case RenderFormat::ASTC_4X4_FLOAT: + return MTL::PixelFormatASTC_4x4_HDR; + case RenderFormat::ASTC_4X4_UNORM_SRGB: + return MTL::PixelFormatASTC_4x4_sRGB; + case RenderFormat::ASTC_5X4_TYPELESS: + return MTL::PixelFormatASTC_5x4_HDR; + case RenderFormat::ASTC_5X4_UNORM: + return MTL::PixelFormatASTC_5x4_LDR; + case RenderFormat::ASTC_5X4_FLOAT: + return MTL::PixelFormatASTC_5x4_HDR; + case RenderFormat::ASTC_5X4_UNORM_SRGB: + return MTL::PixelFormatASTC_5x4_sRGB; + case RenderFormat::ASTC_5X5_TYPELESS: + return MTL::PixelFormatASTC_5x5_HDR; + case RenderFormat::ASTC_5X5_UNORM: + return MTL::PixelFormatASTC_5x5_LDR; + case RenderFormat::ASTC_5X5_FLOAT: + return MTL::PixelFormatASTC_5x5_HDR; + case RenderFormat::ASTC_5X5_UNORM_SRGB: + return MTL::PixelFormatASTC_5x5_sRGB; + case RenderFormat::ASTC_6X5_TYPELESS: + return MTL::PixelFormatASTC_6x5_HDR; + case RenderFormat::ASTC_6X5_UNORM: + return MTL::PixelFormatASTC_6x5_LDR; + case RenderFormat::ASTC_6X5_FLOAT: + return MTL::PixelFormatASTC_6x5_HDR; + case RenderFormat::ASTC_6X5_UNORM_SRGB: + return MTL::PixelFormatASTC_6x5_sRGB; + case RenderFormat::ASTC_6X6_TYPELESS: + return MTL::PixelFormatASTC_6x6_HDR; + case RenderFormat::ASTC_6X6_UNORM: + return MTL::PixelFormatASTC_6x6_LDR; + case RenderFormat::ASTC_6X6_FLOAT: + return MTL::PixelFormatASTC_6x6_HDR; + case RenderFormat::ASTC_6X6_UNORM_SRGB: + return MTL::PixelFormatASTC_6x6_sRGB; + case RenderFormat::ASTC_8X5_TYPELESS: + return MTL::PixelFormatASTC_8x5_HDR; + case RenderFormat::ASTC_8X5_UNORM: + return MTL::PixelFormatASTC_8x5_LDR; + case RenderFormat::ASTC_8X5_FLOAT: + return MTL::PixelFormatASTC_8x5_HDR; + case RenderFormat::ASTC_8X5_UNORM_SRGB: + return MTL::PixelFormatASTC_8x5_sRGB; + case RenderFormat::ASTC_8X6_TYPELESS: + return MTL::PixelFormatASTC_8x6_HDR; + case RenderFormat::ASTC_8X6_UNORM: + return MTL::PixelFormatASTC_8x6_LDR; + case RenderFormat::ASTC_8X6_FLOAT: + return MTL::PixelFormatASTC_8x6_HDR; + case RenderFormat::ASTC_8X6_UNORM_SRGB: + return MTL::PixelFormatASTC_8x6_sRGB; + case RenderFormat::ASTC_8X8_TYPELESS: + return MTL::PixelFormatASTC_8x8_HDR; + case RenderFormat::ASTC_8X8_UNORM: + return MTL::PixelFormatASTC_8x8_LDR; + case RenderFormat::ASTC_8X8_FLOAT: + return MTL::PixelFormatASTC_8x8_HDR; + case RenderFormat::ASTC_8X8_UNORM_SRGB: + return MTL::PixelFormatASTC_8x8_sRGB; + case RenderFormat::ASTC_10X5_TYPELESS: + return MTL::PixelFormatASTC_10x5_HDR; + case RenderFormat::ASTC_10X5_UNORM: + return MTL::PixelFormatASTC_10x5_LDR; + case RenderFormat::ASTC_10X5_FLOAT: + return MTL::PixelFormatASTC_10x5_HDR; + case RenderFormat::ASTC_10X5_UNORM_SRGB: + return MTL::PixelFormatASTC_10x5_sRGB; + case RenderFormat::ASTC_10X6_TYPELESS: + return MTL::PixelFormatASTC_10x6_HDR; + case RenderFormat::ASTC_10X6_UNORM: + return MTL::PixelFormatASTC_10x6_LDR; + case RenderFormat::ASTC_10X6_FLOAT: + return MTL::PixelFormatASTC_10x6_HDR; + case RenderFormat::ASTC_10X6_UNORM_SRGB: + return MTL::PixelFormatASTC_10x6_sRGB; + case RenderFormat::ASTC_10X8_TYPELESS: + return MTL::PixelFormatASTC_10x8_HDR; + case RenderFormat::ASTC_10X8_UNORM: + return MTL::PixelFormatASTC_10x8_LDR; + case RenderFormat::ASTC_10X8_FLOAT: + return MTL::PixelFormatASTC_10x8_HDR; + case RenderFormat::ASTC_10X8_UNORM_SRGB: + return MTL::PixelFormatASTC_10x8_sRGB; + case RenderFormat::ASTC_10X10_TYPELESS: + return MTL::PixelFormatASTC_10x10_HDR; + case RenderFormat::ASTC_10X10_UNORM: + return MTL::PixelFormatASTC_10x10_LDR; + case RenderFormat::ASTC_10X10_FLOAT: + return MTL::PixelFormatASTC_10x10_HDR; + case RenderFormat::ASTC_10X10_UNORM_SRGB: + return MTL::PixelFormatASTC_10x10_sRGB; + case RenderFormat::ASTC_12X10_TYPELESS: + return MTL::PixelFormatASTC_12x10_HDR; + case RenderFormat::ASTC_12X10_UNORM: + return MTL::PixelFormatASTC_12x10_LDR; + case RenderFormat::ASTC_12X10_FLOAT: + return MTL::PixelFormatASTC_12x10_HDR; + case RenderFormat::ASTC_12X10_UNORM_SRGB: + return MTL::PixelFormatASTC_12x10_sRGB; + case RenderFormat::ASTC_12X12_TYPELESS: + return MTL::PixelFormatASTC_12x12_HDR; + case RenderFormat::ASTC_12X12_UNORM: + return MTL::PixelFormatASTC_12x12_LDR; + case RenderFormat::ASTC_12X12_FLOAT: + return MTL::PixelFormatASTC_12x12_HDR; + case RenderFormat::ASTC_12X12_UNORM_SRGB: + return MTL::PixelFormatASTC_12x12_sRGB; default: assert(false && "Unknown format."); return MTL::PixelFormatInvalid; @@ -2998,12 +3195,13 @@ namespace plume { // Calculate block size based on destination texture format const uint32_t blockWidth = RenderFormatBlockWidth(dstTexture->desc.format); + const uint32_t blockHeight = RenderFormatBlockHeight(dstTexture->desc.format); // Use actual dimensions for the copy size const MTL::Size size = { srcLocation.placedFootprint.width, srcLocation.placedFootprint.height, srcLocation.placedFootprint.depth}; const uint32_t horizontalBlocks = (srcLocation.placedFootprint.rowWidth + blockWidth - 1) / blockWidth; - const uint32_t verticalBlocks = (srcLocation.placedFootprint.height + blockWidth - 1) / blockWidth; + const uint32_t verticalBlocks = (srcLocation.placedFootprint.height + blockHeight - 1) / blockHeight; const uint32_t bytesPerRow = horizontalBlocks * RenderFormatSize(dstTexture->desc.format); const uint32_t bytesPerImage = bytesPerRow * verticalBlocks; diff --git a/plume_render_interface_types.h b/plume_render_interface_types.h index 9dcfedf..8031f6a 100644 --- a/plume_render_interface_types.h +++ b/plume_render_interface_types.h @@ -160,6 +160,62 @@ namespace plume { BC7_TYPELESS, BC7_UNORM, BC7_UNORM_SRGB, + ASTC_4X4_TYPELESS, + ASTC_4X4_FLOAT, + ASTC_4X4_UNORM, + ASTC_4X4_UNORM_SRGB, + ASTC_5X4_TYPELESS, + ASTC_5X4_FLOAT, + ASTC_5X4_UNORM, + ASTC_5X4_UNORM_SRGB, + ASTC_5X5_TYPELESS, + ASTC_5X5_FLOAT, + ASTC_5X5_UNORM, + ASTC_5X5_UNORM_SRGB, + ASTC_6X5_TYPELESS, + ASTC_6X5_UNORM, + ASTC_6X5_FLOAT, + ASTC_6X5_UNORM_SRGB, + ASTC_6X6_TYPELESS, + ASTC_6X6_FLOAT, + ASTC_6X6_UNORM, + ASTC_6X6_UNORM_SRGB, + ASTC_8X5_TYPELESS, + ASTC_8X5_FLOAT, + ASTC_8X5_UNORM, + ASTC_8X5_UNORM_SRGB, + ASTC_8X6_TYPELESS, + ASTC_8X6_FLOAT, + ASTC_8X6_UNORM, + ASTC_8X6_UNORM_SRGB, + ASTC_8X8_TYPELESS, + ASTC_8X8_FLOAT, + ASTC_8X8_UNORM, + ASTC_8X8_UNORM_SRGB, + ASTC_10X5_TYPELESS, + ASTC_10X5_FLOAT, + ASTC_10X5_UNORM, + ASTC_10X5_UNORM_SRGB, + ASTC_10X6_TYPELESS, + ASTC_10X6_FLOAT, + ASTC_10X6_UNORM, + ASTC_10X6_UNORM_SRGB, + ASTC_10X8_TYPELESS, + ASTC_10X8_FLOAT, + ASTC_10X8_UNORM, + ASTC_10X8_UNORM_SRGB, + ASTC_10X10_TYPELESS, + ASTC_10X10_FLOAT, + ASTC_10X10_UNORM, + ASTC_10X10_UNORM_SRGB, + ASTC_12X10_TYPELESS, + ASTC_12X10_FLOAT, + ASTC_12X10_UNORM, + ASTC_12X10_UNORM_SRGB, + ASTC_12X12_TYPELESS, + ASTC_12X12_FLOAT, + ASTC_12X12_UNORM, + ASTC_12X12_UNORM_SRGB, MAX }; @@ -584,12 +640,71 @@ namespace plume { case RenderFormat::BC3_UNORM: case RenderFormat::BC3_UNORM_SRGB: case RenderFormat::BC3_TYPELESS: + case RenderFormat::BC5_TYPELESS: case RenderFormat::BC5_UNORM: case RenderFormat::BC5_SNORM: + case RenderFormat::BC6H_TYPELESS: case RenderFormat::BC6H_UF16: case RenderFormat::BC6H_SF16: + case RenderFormat::BC7_TYPELESS: case RenderFormat::BC7_UNORM: case RenderFormat::BC7_UNORM_SRGB: + case RenderFormat::ASTC_4X4_TYPELESS: + case RenderFormat::ASTC_4X4_FLOAT: + case RenderFormat::ASTC_4X4_UNORM: + case RenderFormat::ASTC_4X4_UNORM_SRGB: + case RenderFormat::ASTC_5X4_TYPELESS: + case RenderFormat::ASTC_5X4_FLOAT: + case RenderFormat::ASTC_5X4_UNORM: + case RenderFormat::ASTC_5X4_UNORM_SRGB: + case RenderFormat::ASTC_5X5_TYPELESS: + case RenderFormat::ASTC_5X5_FLOAT: + case RenderFormat::ASTC_5X5_UNORM: + case RenderFormat::ASTC_5X5_UNORM_SRGB: + case RenderFormat::ASTC_6X5_TYPELESS: + case RenderFormat::ASTC_6X5_FLOAT: + case RenderFormat::ASTC_6X5_UNORM: + case RenderFormat::ASTC_6X5_UNORM_SRGB: + case RenderFormat::ASTC_6X6_TYPELESS: + case RenderFormat::ASTC_6X6_FLOAT: + case RenderFormat::ASTC_6X6_UNORM: + case RenderFormat::ASTC_6X6_UNORM_SRGB: + case RenderFormat::ASTC_8X5_TYPELESS: + case RenderFormat::ASTC_8X5_FLOAT: + case RenderFormat::ASTC_8X5_UNORM: + case RenderFormat::ASTC_8X5_UNORM_SRGB: + case RenderFormat::ASTC_8X6_TYPELESS: + case RenderFormat::ASTC_8X6_FLOAT: + case RenderFormat::ASTC_8X6_UNORM: + case RenderFormat::ASTC_8X6_UNORM_SRGB: + case RenderFormat::ASTC_8X8_TYPELESS: + case RenderFormat::ASTC_8X8_FLOAT: + case RenderFormat::ASTC_8X8_UNORM: + case RenderFormat::ASTC_8X8_UNORM_SRGB: + case RenderFormat::ASTC_10X5_TYPELESS: + case RenderFormat::ASTC_10X5_FLOAT: + case RenderFormat::ASTC_10X5_UNORM: + case RenderFormat::ASTC_10X5_UNORM_SRGB: + case RenderFormat::ASTC_10X6_TYPELESS: + case RenderFormat::ASTC_10X6_FLOAT: + case RenderFormat::ASTC_10X6_UNORM: + case RenderFormat::ASTC_10X6_UNORM_SRGB: + case RenderFormat::ASTC_10X8_TYPELESS: + case RenderFormat::ASTC_10X8_FLOAT: + case RenderFormat::ASTC_10X8_UNORM: + case RenderFormat::ASTC_10X8_UNORM_SRGB: + case RenderFormat::ASTC_10X10_TYPELESS: + case RenderFormat::ASTC_10X10_FLOAT: + case RenderFormat::ASTC_10X10_UNORM: + case RenderFormat::ASTC_10X10_UNORM_SRGB: + case RenderFormat::ASTC_12X10_TYPELESS: + case RenderFormat::ASTC_12X10_FLOAT: + case RenderFormat::ASTC_12X10_UNORM: + case RenderFormat::ASTC_12X10_UNORM_SRGB: + case RenderFormat::ASTC_12X12_TYPELESS: + case RenderFormat::ASTC_12X12_FLOAT: + case RenderFormat::ASTC_12X12_UNORM: + case RenderFormat::ASTC_12X12_UNORM_SRGB: return 16; default: assert(false && "Unknown format."); @@ -674,7 +789,229 @@ namespace plume { case RenderFormat::BC7_TYPELESS: case RenderFormat::BC7_UNORM: case RenderFormat::BC7_UNORM_SRGB: + case RenderFormat::ASTC_4X4_TYPELESS: + case RenderFormat::ASTC_4X4_FLOAT: + case RenderFormat::ASTC_4X4_UNORM: + case RenderFormat::ASTC_4X4_UNORM_SRGB: return 4; + case RenderFormat::ASTC_5X4_TYPELESS: + case RenderFormat::ASTC_5X4_FLOAT: + case RenderFormat::ASTC_5X4_UNORM: + case RenderFormat::ASTC_5X4_UNORM_SRGB: + return 5; + case RenderFormat::ASTC_5X5_TYPELESS: + case RenderFormat::ASTC_5X5_FLOAT: + case RenderFormat::ASTC_5X5_UNORM: + case RenderFormat::ASTC_5X5_UNORM_SRGB: + return 5; + case RenderFormat::ASTC_6X5_TYPELESS: + case RenderFormat::ASTC_6X5_FLOAT: + case RenderFormat::ASTC_6X5_UNORM: + case RenderFormat::ASTC_6X5_UNORM_SRGB: + return 6; + case RenderFormat::ASTC_6X6_TYPELESS: + case RenderFormat::ASTC_6X6_FLOAT: + case RenderFormat::ASTC_6X6_UNORM: + case RenderFormat::ASTC_6X6_UNORM_SRGB: + return 6; + case RenderFormat::ASTC_8X5_TYPELESS: + case RenderFormat::ASTC_8X5_FLOAT: + case RenderFormat::ASTC_8X5_UNORM: + case RenderFormat::ASTC_8X5_UNORM_SRGB: + return 8; + case RenderFormat::ASTC_8X6_TYPELESS: + case RenderFormat::ASTC_8X6_FLOAT: + case RenderFormat::ASTC_8X6_UNORM: + case RenderFormat::ASTC_8X6_UNORM_SRGB: + return 8; + case RenderFormat::ASTC_8X8_TYPELESS: + case RenderFormat::ASTC_8X8_FLOAT: + case RenderFormat::ASTC_8X8_UNORM: + case RenderFormat::ASTC_8X8_UNORM_SRGB: + return 8; + case RenderFormat::ASTC_10X5_TYPELESS: + case RenderFormat::ASTC_10X5_FLOAT: + case RenderFormat::ASTC_10X5_UNORM: + case RenderFormat::ASTC_10X5_UNORM_SRGB: + return 10; + case RenderFormat::ASTC_10X6_TYPELESS: + case RenderFormat::ASTC_10X6_FLOAT: + case RenderFormat::ASTC_10X6_UNORM: + case RenderFormat::ASTC_10X6_UNORM_SRGB: + return 10; + case RenderFormat::ASTC_10X8_TYPELESS: + case RenderFormat::ASTC_10X8_FLOAT: + case RenderFormat::ASTC_10X8_UNORM: + case RenderFormat::ASTC_10X8_UNORM_SRGB: + return 10; + case RenderFormat::ASTC_10X10_TYPELESS: + case RenderFormat::ASTC_10X10_FLOAT: + case RenderFormat::ASTC_10X10_UNORM: + case RenderFormat::ASTC_10X10_UNORM_SRGB: + return 10; + case RenderFormat::ASTC_12X10_TYPELESS: + case RenderFormat::ASTC_12X10_FLOAT: + case RenderFormat::ASTC_12X10_UNORM: + case RenderFormat::ASTC_12X10_UNORM_SRGB: + return 12; + case RenderFormat::ASTC_12X12_TYPELESS: + case RenderFormat::ASTC_12X12_FLOAT: + case RenderFormat::ASTC_12X12_UNORM: + case RenderFormat::ASTC_12X12_UNORM_SRGB: + return 12; + default: + assert(false && "Unknown format."); + return 1; + } + }; + + constexpr uint32_t RenderFormatBlockHeight(RenderFormat format) { + switch (format) { + case RenderFormat::R32G32B32A32_TYPELESS: + case RenderFormat::R32G32B32A32_FLOAT: + case RenderFormat::R32G32B32A32_UINT: + case RenderFormat::R32G32B32A32_SINT: + case RenderFormat::R32G32B32_TYPELESS: + case RenderFormat::R32G32B32_FLOAT: + case RenderFormat::R32G32B32_UINT: + case RenderFormat::R32G32B32_SINT: + case RenderFormat::R16G16B16A16_TYPELESS: + case RenderFormat::R16G16B16A16_FLOAT: + case RenderFormat::R16G16B16A16_UNORM: + case RenderFormat::R16G16B16A16_UINT: + case RenderFormat::R16G16B16A16_SNORM: + case RenderFormat::R16G16B16A16_SINT: + case RenderFormat::R32G32_TYPELESS: + case RenderFormat::R32G32_FLOAT: + case RenderFormat::R32G32_UINT: + case RenderFormat::R32G32_SINT: + case RenderFormat::R8G8B8A8_TYPELESS: + case RenderFormat::R8G8B8A8_UNORM: + case RenderFormat::R8G8B8A8_UINT: + case RenderFormat::R8G8B8A8_SNORM: + case RenderFormat::R8G8B8A8_SINT: + case RenderFormat::B8G8R8A8_UNORM: + case RenderFormat::R16G16_TYPELESS: + case RenderFormat::R16G16_FLOAT: + case RenderFormat::R16G16_UNORM: + case RenderFormat::R16G16_UINT: + case RenderFormat::R16G16_SNORM: + case RenderFormat::R16G16_SINT: + case RenderFormat::R32_TYPELESS: + case RenderFormat::D32_FLOAT: + case RenderFormat::D32_FLOAT_S8_UINT: + case RenderFormat::R32_FLOAT: + case RenderFormat::R32_UINT: + case RenderFormat::R32_SINT: + case RenderFormat::R8G8_TYPELESS: + case RenderFormat::R8G8_UNORM: + case RenderFormat::R8G8_UINT: + case RenderFormat::R8G8_SNORM: + case RenderFormat::R8G8_SINT: + case RenderFormat::R16_TYPELESS: + case RenderFormat::R16_FLOAT: + case RenderFormat::D16_UNORM: + case RenderFormat::R16_UNORM: + case RenderFormat::R16_UINT: + case RenderFormat::R16_SNORM: + case RenderFormat::R16_SINT: + case RenderFormat::R8_TYPELESS: + case RenderFormat::R8_UNORM: + case RenderFormat::R8_UINT: + case RenderFormat::R8_SNORM: + case RenderFormat::R8_SINT: + return 1; + case RenderFormat::BC1_TYPELESS: + case RenderFormat::BC1_UNORM: + case RenderFormat::BC1_UNORM_SRGB: + case RenderFormat::BC2_TYPELESS: + case RenderFormat::BC2_UNORM: + case RenderFormat::BC2_UNORM_SRGB: + case RenderFormat::BC3_TYPELESS: + case RenderFormat::BC3_UNORM: + case RenderFormat::BC3_UNORM_SRGB: + case RenderFormat::BC4_TYPELESS: + case RenderFormat::BC4_UNORM: + case RenderFormat::BC4_SNORM: + case RenderFormat::BC5_TYPELESS: + case RenderFormat::BC5_UNORM: + case RenderFormat::BC5_SNORM: + case RenderFormat::BC6H_TYPELESS: + case RenderFormat::BC6H_UF16: + case RenderFormat::BC6H_SF16: + case RenderFormat::BC7_TYPELESS: + case RenderFormat::BC7_UNORM: + case RenderFormat::BC7_UNORM_SRGB: + case RenderFormat::ASTC_4X4_TYPELESS: + case RenderFormat::ASTC_4X4_FLOAT: + case RenderFormat::ASTC_4X4_UNORM: + case RenderFormat::ASTC_4X4_UNORM_SRGB: + return 4; + case RenderFormat::ASTC_5X4_TYPELESS: + case RenderFormat::ASTC_5X4_FLOAT: + case RenderFormat::ASTC_5X4_UNORM: + case RenderFormat::ASTC_5X4_UNORM_SRGB: + return 4; + case RenderFormat::ASTC_5X5_TYPELESS: + case RenderFormat::ASTC_5X5_FLOAT: + case RenderFormat::ASTC_5X5_UNORM: + case RenderFormat::ASTC_5X5_UNORM_SRGB: + return 5; + case RenderFormat::ASTC_6X5_TYPELESS: + case RenderFormat::ASTC_6X5_FLOAT: + case RenderFormat::ASTC_6X5_UNORM: + case RenderFormat::ASTC_6X5_UNORM_SRGB: + return 5; + case RenderFormat::ASTC_6X6_TYPELESS: + case RenderFormat::ASTC_6X6_FLOAT: + case RenderFormat::ASTC_6X6_UNORM: + case RenderFormat::ASTC_6X6_UNORM_SRGB: + return 6; + case RenderFormat::ASTC_8X5_TYPELESS: + case RenderFormat::ASTC_8X5_FLOAT: + case RenderFormat::ASTC_8X5_UNORM: + case RenderFormat::ASTC_8X5_UNORM_SRGB: + return 5; + case RenderFormat::ASTC_8X6_TYPELESS: + case RenderFormat::ASTC_8X6_FLOAT: + case RenderFormat::ASTC_8X6_UNORM: + case RenderFormat::ASTC_8X6_UNORM_SRGB: + return 6; + case RenderFormat::ASTC_8X8_TYPELESS: + case RenderFormat::ASTC_8X8_FLOAT: + case RenderFormat::ASTC_8X8_UNORM: + case RenderFormat::ASTC_8X8_UNORM_SRGB: + return 8; + case RenderFormat::ASTC_10X5_TYPELESS: + case RenderFormat::ASTC_10X5_FLOAT: + case RenderFormat::ASTC_10X5_UNORM: + case RenderFormat::ASTC_10X5_UNORM_SRGB: + return 5; + case RenderFormat::ASTC_10X6_TYPELESS: + case RenderFormat::ASTC_10X6_FLOAT: + case RenderFormat::ASTC_10X6_UNORM: + case RenderFormat::ASTC_10X6_UNORM_SRGB: + return 6; + case RenderFormat::ASTC_10X8_TYPELESS: + case RenderFormat::ASTC_10X8_FLOAT: + case RenderFormat::ASTC_10X8_UNORM: + case RenderFormat::ASTC_10X8_UNORM_SRGB: + return 8; + case RenderFormat::ASTC_10X10_TYPELESS: + case RenderFormat::ASTC_10X10_FLOAT: + case RenderFormat::ASTC_10X10_UNORM: + case RenderFormat::ASTC_10X10_UNORM_SRGB: + return 10; + case RenderFormat::ASTC_12X10_TYPELESS: + case RenderFormat::ASTC_12X10_FLOAT: + case RenderFormat::ASTC_12X10_UNORM: + case RenderFormat::ASTC_12X10_UNORM_SRGB: + return 10; + case RenderFormat::ASTC_12X12_TYPELESS: + case RenderFormat::ASTC_12X12_FLOAT: + case RenderFormat::ASTC_12X12_UNORM: + case RenderFormat::ASTC_12X12_UNORM_SRGB: + return 12; default: assert(false && "Unknown format."); return 1; diff --git a/plume_vulkan.cpp b/plume_vulkan.cpp index f1dd503..f13115a 100644 --- a/plume_vulkan.cpp +++ b/plume_vulkan.cpp @@ -249,6 +249,118 @@ namespace plume { return VK_FORMAT_BC7_UNORM_BLOCK; case RenderFormat::BC7_UNORM_SRGB: return VK_FORMAT_BC7_SRGB_BLOCK; + case RenderFormat::ASTC_4X4_TYPELESS: + return VK_FORMAT_ASTC_4x4_SFLOAT_BLOCK; + case RenderFormat::ASTC_4X4_FLOAT: + return VK_FORMAT_ASTC_4x4_SFLOAT_BLOCK; + case RenderFormat::ASTC_4X4_UNORM: + return VK_FORMAT_ASTC_4x4_UNORM_BLOCK; + case RenderFormat::ASTC_4X4_UNORM_SRGB: + return VK_FORMAT_ASTC_4x4_SRGB_BLOCK; + case RenderFormat::ASTC_5X4_TYPELESS: + return VK_FORMAT_ASTC_5x4_SFLOAT_BLOCK; + case RenderFormat::ASTC_5X4_FLOAT: + return VK_FORMAT_ASTC_5x4_SFLOAT_BLOCK; + case RenderFormat::ASTC_5X4_UNORM: + return VK_FORMAT_ASTC_5x4_UNORM_BLOCK; + case RenderFormat::ASTC_5X4_UNORM_SRGB: + return VK_FORMAT_ASTC_5x4_SRGB_BLOCK; + case RenderFormat::ASTC_5X5_TYPELESS: + return VK_FORMAT_ASTC_5x5_SFLOAT_BLOCK; + case RenderFormat::ASTC_5X5_FLOAT: + return VK_FORMAT_ASTC_5x5_SFLOAT_BLOCK; + case RenderFormat::ASTC_5X5_UNORM: + return VK_FORMAT_ASTC_5x5_UNORM_BLOCK; + case RenderFormat::ASTC_5X5_UNORM_SRGB: + return VK_FORMAT_ASTC_5x5_SRGB_BLOCK; + case RenderFormat::ASTC_6X5_TYPELESS: + return VK_FORMAT_ASTC_6x5_SFLOAT_BLOCK; + case RenderFormat::ASTC_6X5_FLOAT: + return VK_FORMAT_ASTC_6x5_SFLOAT_BLOCK; + case RenderFormat::ASTC_6X5_UNORM: + return VK_FORMAT_ASTC_6x5_UNORM_BLOCK; + case RenderFormat::ASTC_6X5_UNORM_SRGB: + return VK_FORMAT_ASTC_6x5_SRGB_BLOCK; + case RenderFormat::ASTC_6X6_TYPELESS: + return VK_FORMAT_ASTC_6x6_SFLOAT_BLOCK; + case RenderFormat::ASTC_6X6_FLOAT: + return VK_FORMAT_ASTC_6x6_SFLOAT_BLOCK; + case RenderFormat::ASTC_6X6_UNORM: + return VK_FORMAT_ASTC_6x6_UNORM_BLOCK; + case RenderFormat::ASTC_6X6_UNORM_SRGB: + return VK_FORMAT_ASTC_6x6_SRGB_BLOCK; + case RenderFormat::ASTC_8X5_TYPELESS: + return VK_FORMAT_ASTC_8x5_SFLOAT_BLOCK; + case RenderFormat::ASTC_8X5_FLOAT: + return VK_FORMAT_ASTC_8x5_SFLOAT_BLOCK; + case RenderFormat::ASTC_8X5_UNORM: + return VK_FORMAT_ASTC_8x5_UNORM_BLOCK; + case RenderFormat::ASTC_8X5_UNORM_SRGB: + return VK_FORMAT_ASTC_8x5_SRGB_BLOCK; + case RenderFormat::ASTC_8X6_TYPELESS: + return VK_FORMAT_ASTC_8x6_SFLOAT_BLOCK; + case RenderFormat::ASTC_8X6_FLOAT: + return VK_FORMAT_ASTC_8x6_SFLOAT_BLOCK; + case RenderFormat::ASTC_8X6_UNORM: + return VK_FORMAT_ASTC_8x6_UNORM_BLOCK; + case RenderFormat::ASTC_8X6_UNORM_SRGB: + return VK_FORMAT_ASTC_8x6_SRGB_BLOCK; + case RenderFormat::ASTC_8X8_TYPELESS: + return VK_FORMAT_ASTC_8x8_SFLOAT_BLOCK; + case RenderFormat::ASTC_8X8_FLOAT: + return VK_FORMAT_ASTC_8x8_SFLOAT_BLOCK; + case RenderFormat::ASTC_8X8_UNORM: + return VK_FORMAT_ASTC_8x8_UNORM_BLOCK; + case RenderFormat::ASTC_8X8_UNORM_SRGB: + return VK_FORMAT_ASTC_8x8_SRGB_BLOCK; + case RenderFormat::ASTC_10X5_TYPELESS: + return VK_FORMAT_ASTC_10x5_SFLOAT_BLOCK; + case RenderFormat::ASTC_10X5_FLOAT: + return VK_FORMAT_ASTC_10x5_SFLOAT_BLOCK; + case RenderFormat::ASTC_10X5_UNORM: + return VK_FORMAT_ASTC_10x5_UNORM_BLOCK; + case RenderFormat::ASTC_10X5_UNORM_SRGB: + return VK_FORMAT_ASTC_10x5_SRGB_BLOCK; + case RenderFormat::ASTC_10X6_TYPELESS: + return VK_FORMAT_ASTC_10x6_SFLOAT_BLOCK; + case RenderFormat::ASTC_10X6_FLOAT: + return VK_FORMAT_ASTC_10x6_SFLOAT_BLOCK; + case RenderFormat::ASTC_10X6_UNORM: + return VK_FORMAT_ASTC_10x6_UNORM_BLOCK; + case RenderFormat::ASTC_10X6_UNORM_SRGB: + return VK_FORMAT_ASTC_10x6_SRGB_BLOCK; + case RenderFormat::ASTC_10X8_TYPELESS: + return VK_FORMAT_ASTC_10x8_SFLOAT_BLOCK; + case RenderFormat::ASTC_10X8_FLOAT: + return VK_FORMAT_ASTC_10x8_SFLOAT_BLOCK; + case RenderFormat::ASTC_10X8_UNORM: + return VK_FORMAT_ASTC_10x8_UNORM_BLOCK; + case RenderFormat::ASTC_10X8_UNORM_SRGB: + return VK_FORMAT_ASTC_10x8_SRGB_BLOCK; + case RenderFormat::ASTC_10X10_TYPELESS: + return VK_FORMAT_ASTC_10x10_SFLOAT_BLOCK; + case RenderFormat::ASTC_10X10_FLOAT: + return VK_FORMAT_ASTC_10x10_SFLOAT_BLOCK; + case RenderFormat::ASTC_10X10_UNORM: + return VK_FORMAT_ASTC_10x10_UNORM_BLOCK; + case RenderFormat::ASTC_10X10_UNORM_SRGB: + return VK_FORMAT_ASTC_10x10_SRGB_BLOCK; + case RenderFormat::ASTC_12X10_TYPELESS: + return VK_FORMAT_ASTC_12x10_SFLOAT_BLOCK; + case RenderFormat::ASTC_12X10_FLOAT: + return VK_FORMAT_ASTC_12x10_SFLOAT_BLOCK; + case RenderFormat::ASTC_12X10_UNORM: + return VK_FORMAT_ASTC_12x10_UNORM_BLOCK; + case RenderFormat::ASTC_12X10_UNORM_SRGB: + return VK_FORMAT_ASTC_12x10_SRGB_BLOCK; + case RenderFormat::ASTC_12X12_TYPELESS: + return VK_FORMAT_ASTC_12x12_SFLOAT_BLOCK; + case RenderFormat::ASTC_12X12_FLOAT: + return VK_FORMAT_ASTC_12x12_SFLOAT_BLOCK; + case RenderFormat::ASTC_12X12_UNORM: + return VK_FORMAT_ASTC_12x12_UNORM_BLOCK; + case RenderFormat::ASTC_12X12_UNORM_SRGB: + return VK_FORMAT_ASTC_12x12_SRGB_BLOCK; default: assert(false && "Unknown format."); return VK_FORMAT_UNDEFINED; @@ -3213,10 +3325,11 @@ namespace plume { assert(srcBuffer != nullptr); const uint32_t blockWidth = RenderFormatBlockWidth(dstTexture->desc.format); + const uint32_t blockHeight = RenderFormatBlockHeight(dstTexture->desc.format); VkBufferImageCopy imageCopy = {}; imageCopy.bufferOffset = srcLocation.placedFootprint.offset; imageCopy.bufferRowLength = ((srcLocation.placedFootprint.rowWidth + blockWidth - 1) / blockWidth) * blockWidth; - imageCopy.bufferImageHeight = ((srcLocation.placedFootprint.height + blockWidth - 1) / blockWidth) * blockWidth; + imageCopy.bufferImageHeight = ((srcLocation.placedFootprint.height + blockHeight - 1) / blockHeight) * blockHeight; imageCopy.imageSubresource.aspectMask = toAspectFlags(dstTexture->desc.format, dstTexture->desc.flags); imageCopy.imageSubresource.baseArrayLayer = dstLocation.subresource.arrayIndex; imageCopy.imageSubresource.layerCount = 1; From 76e6461e486ed6b666de868d2f821123d1dbc7f2 Mon Sep 17 00:00:00 2001 From: MarkosTh09 Date: Wed, 27 May 2026 15:25:20 +0400 Subject: [PATCH 2/2] optimize ClearPipelineKey --- plume_metal.cpp | 18 +++++++++++++++++- plume_metal.h | 20 +++++++++++--------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/plume_metal.cpp b/plume_metal.cpp index dcf1484..a26604c 100644 --- a/plume_metal.cpp +++ b/plume_metal.cpp @@ -16,6 +16,7 @@ #include #include +#include #include "plume_metal.h" @@ -43,6 +44,21 @@ namespace plume { return (n + alignment - 1) & ~(alignment - 1); } + inline constexpr uint64_t encodeDepthFormat(MTL::PixelFormat format) { + switch (format) { + case MTL::PixelFormatDepth16Unorm: + return 1; + case MTL::PixelFormatDepth32Float: + return 2; + case MTL::PixelFormatDepth24Unorm_Stencil8: + return 3; + case MTL::PixelFormatDepth32Float_Stencil8: + return 4; + default: + assert(false && "Unknown depth format."); + } + } + uint64_t createClearPipelineKey(MTL::RenderPipelineDescriptor *pipelineDesc, bool depthWriteEnabled, bool stencilWriteEnabled) { auto colorFormat = [&](uint32_t index) { if (auto colorAttachment = pipelineDesc->colorAttachments()->object(index)) { @@ -63,7 +79,7 @@ namespace plume { key.colorFormat4 = colorFormat(4); key.colorFormat5 = colorFormat(5); key.colorFormat6 = colorFormat(6); - key.depthFormat = static_cast(mapRenderFormat(pipelineDesc->depthAttachmentPixelFormat())); + key.depthFormat = encodeDepthFormat(pipelineDesc->depthAttachmentPixelFormat()); return key.value; } diff --git a/plume_metal.h b/plume_metal.h index 59ae129..9dfc276 100644 --- a/plume_metal.h +++ b/plume_metal.h @@ -66,7 +66,7 @@ namespace plume { }; struct ClearPipelineKey { - static_assert(static_cast(RenderFormat::MAX) < 128, + static_assert(static_cast(RenderFormat::MAX) < 256, "ClearPipelineKey needs to use more bits for each render target format."); union { @@ -75,14 +75,16 @@ namespace plume { uint64_t depthClear: 1; uint64_t stencilClear: 1; uint64_t msaaCount: 4; - uint64_t colorFormat0: 7; - uint64_t colorFormat1: 7; - uint64_t colorFormat2: 7; - uint64_t colorFormat3: 7; - uint64_t colorFormat4: 7; - uint64_t colorFormat5: 7; - uint64_t colorFormat6: 7; - uint64_t depthFormat: 7; + uint64_t colorFormat0: 8; + uint64_t colorFormat1: 8; + uint64_t colorFormat2: 8; + uint64_t colorFormat3: 8; + uint64_t colorFormat4: 8; + uint64_t colorFormat5: 8; + uint64_t colorFormat6: 8; + // There are effectively 4 depth buffer formats so using more bits + // is wasteful + uint64_t depthFormat: 2; }; }; };