diff options
| author | Vonsek <45567075+Vonsek@users.noreply.github.com> | 2026-11-22 15:51:40 +0100 |
|---|---|---|
| committer | Vonsek <45567075+Vonsek@users.noreply.github.com> | 2026-11-22 15:51:40 +0100 |
| commit | df91c6624b69ee4e6c6eeca20ed68d331ed0e728 (patch) | |
| tree | 323c88b9df89bf8abaa2b98d10808474ab675dc2 /runtime/src/resource_tiling.h | |
| parent | b40d8039a98f57b26bd05860febbabbe59b97873 (diff) | |
| parent | 6a6704df1592e1dc4a3215ddf1423a78adb52045 (diff) | |
Merge main into test/valu-int-misc (#1492)
Conflicted files: runtime/test/shaders/check.py, scripts/run_gpu_tests.py
AI-assisted.
Diffstat (limited to 'runtime/src/resource_tiling.h')
| -rw-r--r-- | runtime/src/resource_tiling.h | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/runtime/src/resource_tiling.h b/runtime/src/resource_tiling.h index 6bd890ae8..a9d95ae9f 100644 --- a/runtime/src/resource_tiling.h +++ b/runtime/src/resource_tiling.h | |||
| @@ -43,6 +43,7 @@ struct TilingDesc { | |||
| 43 | std::uint32_t mips = 1; | 43 | std::uint32_t mips = 1; |
| 44 | std::uint32_t element_bytes = 0; // bytes per texel, or per block of a block-compressed format | 44 | std::uint32_t element_bytes = 0; // bytes per texel, or per block of a block-compressed format |
| 45 | std::uint32_t block = 1; // texels per block side: 4 for BC1-7 | 45 | std::uint32_t block = 1; // texels per block side: 4 for BC1-7 |
| 46 | std::uint32_t samples = 1; // 1, or 4 for 2D single-mip MSAA | ||
| 46 | }; | 47 | }; |
| 47 | 48 | ||
| 48 | // D3D12_SUBRESOURCE_TILING: a packed mip has no tiles of its own and starts at packed_tile. | 49 | // D3D12_SUBRESOURCE_TILING: a packed mip has no tiles of its own and starts at packed_tile. |
| @@ -63,9 +64,22 @@ struct ResourceTiling { | |||
| 63 | std::vector<SubresourceTiling> subresources; // mip + layer * mips | 64 | std::vector<SubresourceTiling> subresources; // mip + layer * mips |
| 64 | }; | 65 | }; |
| 65 | 66 | ||
| 66 | // The standard tile shape in elements (D3D12 "standard swizzle" tile shapes for 64 KiB tiles), or {} for an | 67 | // The standard tile shape in elements (D3D12 "standard swizzle" tile shapes for 64 KiB tiles; 2D 4x MSAA scales the |
| 67 | // element size that cannot be tiled (3- and 12-byte formats). | 68 | // tile shape down by 4 samples per texel, measured on RTX 5070 Ti and WARP), or {} for an unsupported sample count or |
| 68 | constexpr TileShape element_tile_shape(bool volume, std::uint32_t element_bytes) { | 69 | // an element size that cannot be tiled (3- and 12-byte formats). |
| 70 | constexpr TileShape element_tile_shape(bool volume, std::uint32_t element_bytes, std::uint32_t samples = 1) { | ||
| 71 | if (samples == 4) { | ||
| 72 | if (volume) return {}; | ||
| 73 | switch (element_bytes) { | ||
| 74 | case 1: return {128, 128, 1}; | ||
| 75 | case 2: return {128, 64, 1}; | ||
| 76 | case 4: return {64, 64, 1}; | ||
| 77 | case 8: return {64, 32, 1}; | ||
| 78 | case 16: return {32, 32, 1}; | ||
| 79 | default: return {}; | ||
| 80 | } | ||
| 81 | } | ||
| 82 | if (samples != 1) return {}; | ||
| 69 | switch (element_bytes) { | 83 | switch (element_bytes) { |
| 70 | case 1: return volume ? TileShape{64, 32, 32} : TileShape{256, 256, 1}; | 84 | case 1: return volume ? TileShape{64, 32, 32} : TileShape{256, 256, 1}; |
| 71 | case 2: return volume ? TileShape{32, 32, 32} : TileShape{256, 128, 1}; | 85 | case 2: return volume ? TileShape{32, 32, 32} : TileShape{256, 128, 1}; |
| @@ -103,7 +117,8 @@ inline bool resource_tiling(const TilingDesc& desc, ResourceTiling& out) { | |||
| 103 | return true; | 117 | return true; |
| 104 | } | 118 | } |
| 105 | const bool volume = desc.kind == TiledKind::texture3d; | 119 | const bool volume = desc.kind == TiledKind::texture3d; |
| 106 | const TileShape elements = element_tile_shape(volume, desc.element_bytes); | 120 | if (desc.samples != 1 && (desc.samples != 4 || volume || desc.mips != 1 || desc.block != 1)) return false; |
| 121 | const TileShape elements = element_tile_shape(volume, desc.element_bytes, desc.samples); | ||
| 107 | if (!elements.width || !desc.mips || !desc.block || !desc.width || !desc.height || !desc.depth_or_layers) | 122 | if (!elements.width || !desc.mips || !desc.block || !desc.width || !desc.height || !desc.depth_or_layers) |
| 108 | return false; | 123 | return false; |
| 109 | out.shape = {elements.width * desc.block, elements.height * desc.block, elements.depth}; | 124 | out.shape = {elements.width * desc.block, elements.height * desc.block, elements.depth}; |
| @@ -124,7 +139,7 @@ inline bool resource_tiling(const TilingDesc& desc, ResourceTiling& out) { | |||
| 124 | ++out.standard_mips; | 139 | ++out.standard_mips; |
| 125 | } else { | 140 | } else { |
| 126 | slice[mip] = {0, 0, 0, packed_tile}; | 141 | slice[mip] = {0, 0, 0, packed_tile}; |
| 127 | packed_bytes += up(w, desc.block) * up(h, desc.block) * d * desc.element_bytes; | 142 | packed_bytes += up(w, desc.block) * up(h, desc.block) * d * desc.element_bytes * desc.samples; |
| 128 | ++out.packed_mips; | 143 | ++out.packed_mips; |
| 129 | } | 144 | } |
| 130 | } | 145 | } |