Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ constexpr std::uint32_t Format32Float = 22;
constexpr std::uint32_t Type3D = 10;
constexpr std::uint32_t TypeCube = 11;
constexpr std::uint32_t Type2DArray = 13;
constexpr std::uint32_t Type2DMsaa = 14;
alignas(256) std::array<std::uint32_t, Threads * 4> Output{};
alignas(256) std::array<std::uint8_t, 65536> Texels{};

Expand All @@ -33,21 +34,22 @@ alignas(256) constexpr auto Query1D = Code(0u);
alignas(256) constexpr auto Query3D = Code(2u);
alignas(256) constexpr auto QueryCube = Code(3u);
alignas(256) constexpr auto Query2DArray = Code(5u);
alignas(256) constexpr auto Query2DMsaa = Code(6u);

std::array<std::uint32_t, 4> BufferDescriptor(const void* data, std::uint32_t bytes) {
const auto address = reinterpret_cast<std::uintptr_t>(data);
return {static_cast<std::uint32_t>(address), static_cast<std::uint32_t>((address >> 32u) & 0xffffu), bytes, 0x31016facu};
}

std::array<std::uint32_t, 8> Descriptor(std::uint32_t type, std::uint32_t depth) {
std::array<std::uint32_t, 8> Descriptor(std::uint32_t type, std::uint32_t depth, std::uint32_t lastLevel = 0u) {
const auto address = static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(Texels.data()));
return {
static_cast<std::uint32_t>(address >> 8u),
static_cast<std::uint32_t>((address >> 40u) & 0xffu) | (Format32Float << 20u) | (((Size - 1u) & 3u) << 30u),
((Size - 1u) >> 2u) | ((Size - 1u) << 14u),
0xfacu | (type << 28u),
0xfacu | (lastLevel << 16u) | ((lastLevel != 0u ? 9u : 0u) << 20u) | (type << 28u),
depth - 1u,
0u,
lastLevel << 4u,
0u,
0u,
};
Expand Down Expand Up @@ -99,6 +101,10 @@ int main() {
Check(*device, QueryCube, Descriptor(TypeCube, 6u), "cube", {Size, Size, 6u, 1u}, {Size, Size, 0u, 1u});
Check(*device, Query3D, Descriptor(Type3D, 4u), "3D", {Size, Size, 4u, 1u}, {Size, Size, 4u, 1u});
Check(*device, Query2DArray, Descriptor(Type2DArray, 3u), "2D array", {Size, Size, 3u, 1u}, {Size, Size, 0u, 1u});
for (std::uint32_t log2Fragments = 1; log2Fragments <= 3; ++log2Fragments) {
const auto msaa = Descriptor(Type2DMsaa, 1u, log2Fragments);
Check(*device, Query2DMsaa, msaa, "2D MSAA", {Size, Size, 0u, 1u}, {Size, Size, 0u, 1u});
}
std::puts("image resinfo dimension tests passed");
return 0;
} catch (const std::exception& error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2338,6 +2338,11 @@ std::vector<ImageResource> ResourceMaterializer::RuntimeImageModes(const ImageRe
cube.cube = true;
modes.push_back(cube);
}
if (image.dimensionQueryOnly && !storage && !depth && conversion == IrBufferFormat::Invalid && packed == IrBufferFormat::Invalid && image.dimension == RdnaImageDimension::Dim1D) {
auto view = mode;
view.dimension = RdnaImageDimension::Dim2DMsaa;
modes.push_back(view);
}
if (layerRowsCandidate(image) && image.maxArrayLayers != 0u && !depth && conversion == IrBufferFormat::Invalid && packed == IrBufferFormat::Invalid) {
auto rows = mode;
rows.dimension = RdnaImageDimension::Dim2D;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ std::uint32_t QueryDimensions(SpirvValueEmitContext& ctx, const ImageEmitAccess&
state.module.AddFunction(spv::OpImageQuerySizeLod, ImageViewSizeType(state, dimension), size, image, AddressU32(ctx, access, 0));
}
const auto components = info.coordinateComponents;
std::uint32_t result[4] = {ConstantU32(state, 0), ConstantU32(state, 0), ConstantU32(state, 0), ConstantU32(state, 0)};
std::uint32_t result[4] = {ConstantU32(state, 0), ConstantU32(state, 0), ConstantU32(state, 0), ConstantU32(state, info.multisampled != 0u ? 1u : 0u)};
if (components == 1u) {
result[0] = size;
} else {
Expand Down
4 changes: 3 additions & 1 deletion docs/dev/debt/shader.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@
- [MIMG BY2/BY4 loads](../../../core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp) (`image_load[_mip]_by2/by4`, opcodes 0x42, 0x43, 0x4a and 0x4b) were measured on RDNA2 (gfx1035) with the [hardware oracle](../HW_ORACLE.md) for 2D images with identity swizzle. They read N texels (BY2: 2, BY4: 4) from `x & ~(N - 1)` on row y, texel by texel and component by component within each texel, with each texel converted like `image_load`. Every register is zero when the mip level is past the last level, `x + N - 1` is outside the level's width (unaligned x, unsigned), or y is outside its height. Data only comes back when the N texels fit in one dword: R8 and R16 (DMASK 0x3) or RG8 (0xf) for BY2, and R8 (0xf) for BY4. With 32-bit texels (R32, RG32, RG16, RGBA8) the hardware returns zeros. Other formats, masks, dimensions, swizzles, D16/A16 throw; runtime image tables retain the same restrictions. The stores (0x52, 0x53, 0x5a and 0x5b) decode but throw at translation. Measured on hardware, they write from the unaligned x up to the end of its dword, which is not implemented.
- [2D stores to 1D storage images](../../../core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp): an `image_store` with DIM 2D through a 1D T# writes texel x and ignores y, as measured on RDNA2 (gfx1035) for y from 0 to 4 and 0xffffffff, single- and four-component formats and a 1x1 8_8_8_8_UNORM T#: the T# type decides the addressing, DIM only how many address VGPRs are read. An `image_store` with DIM 2D_ARRAY through a 1D T# writes texel x, ignoring y, only when the slice is 0, and is dropped for any other slice: measured on RDNA2 (gfx1036) with the [hardware oracle](../HW_ORACLE.md) through the AMD Windows driver's comgr and HIP runtime (wave32, IEEE off, DX10 clamp on, denormals preserved, round to nearest even) on a 64-texel linear 32_UINT T# with DEPTH 0 and 3, for x of 0, 5 and 63, y of 0, 1, 3 and 0xffffffff and slices 0, 1, 2, 5 and 0xffffffff; the PS5's gfx1013 is not measured. Storage loads, atomics and `image_store_mip` through such a pair still throw
- [MIMG PCK2/PCK4 loads](../../../core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp) (`image_load[_mip]_pck2/pck4`, opcodes 0x70, 0x71, 0x73 and 0x74) were measured on RDNA2 (gfx1035) with the [hardware oracle](../HW_ORACLE.md) for 2D images with identity swizzle. With data mask 0x1, they write one dword: the raw bits of the N texels (PCK2: 2, PCK4: 4) from `x & ~(N - 1)` on row y, concatenated (element k at bit `k * texel bits`) and zero-extended. The dword is zero when the mip level is past the last level, `x + N - 1` is outside the level's width (unaligned x, unsigned), or y is outside its height. Data only comes back when N texels fit in 32 bits: R8, R16 or RG8 for PCK2, R8 for PCK4. Wider texels (R32, RG16, RGBA8) and masks other than 0x1 write zeros on hardware. Those masks throw at decode, and formats outside UNORM/UINT/SINT R8, R16 and RG8 throw. #1314's earlier measurement saw only zeros because it used masks 0x3 and 0xf. The stores (0x76, 0x77, 0x79 and 0x7a) decode but throw at translation. They are not measured, and opcode 0x76 on 32_32_32_32_FLOAT hung the GPU (#1314).
- [`image_get_resinfo` through DIM 1D on a cube, 2D-array or 3D T#](../../../core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp) follows thuanquang's measurement on RDNA2 (RX 6700 XT, gfx1031, #7550), not the PS5's gfx1013: width, height and the level count come from the T#, and the third component is the 3D T#'s depth, or 0 for a cube or 2D array, as for every DIM without layers (1D, 2D, 2D MSAA). Such a query on a 1D-array T# still reads it as its first layer, whose height is measured as 0 on RDNA2 (gfx1036, driver 31.0.22044.1) with the hardware oracle, which reports (width, 0, 0, levels) at 1, 4 and 16 slices and widths 1,024 and 4,096, the slice count appearing only under DIM 1D_ARRAY, in the height component. On a 2D MSAA or 2D MSAA-array T# it throws: gfx1031 was measured only with one fragment, which the driver cannot bind. Measured on RDNA2 (gfx1036, driver 31.0.22044.1) with the hardware oracle, separate from the implementation, the level component is 1: a 2D MSAA T# with 2, 4, 8 or 16 fragments returns (width, height, 0, 1) under DIM 1D, 2D and 2D_MSAA at wave32 and wave64, and a 2D MSAA-array T# with 1 to 16 fragments and 1 or 4 slices returns (width, height, slices, 1) under DIM 2D_MSAA_ARRAY and (width, height, 0, 1) under DIM 1D, 2D and 2D_MSAA at wave32 and wave64; with 1 to 16 fragments, a BASE_ARRAY of 1, 2, 3, 4 or 7 and a last slice (DEPTH) of 3, 5 or 7 give DEPTH - BASE_ARRAY + 1 slices, as a 2D-array T# does under DIM 2D_ARRAY and a 1D-array T# does in the height under DIM 1D_ARRAY, while DIM 1D, 2D and 2D_MSAA still return 0.
- [`image_get_resinfo` through DIM 1D on a cube, 2D-array or 3D T#](../../../core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp) follows thuanquang's measurement on RDNA2 (RX 6700 XT, gfx1031, #7550), not the PS5's gfx1013: width, height and the level count come from the T#, and the third component is the 3D T#'s depth, or 0 for a cube or 2D array, as for every DIM without layers (1D, 2D, 2D MSAA). Such a query on a 1D-array T# still reads it as its first layer, whose height is measured as 0 on RDNA2 (gfx1036, driver 31.0.22044.1) with the hardware oracle, which reports (width, 0, 0, levels) at 1, 4 and 16 slices and widths 1,024 and 4,096, the slice count appearing only under DIM 1D_ARRAY, in the height component.
- [`image_get_resinfo` on a 2D MSAA or 2D MSAA-array T#](../../../core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp) - a 2D MSAA T# with 2, 4 or 8 fragments returns (width, height, 0, 1) under DIM 1D and 2D_MSAA, as measured in the entry below, and still throws under DIM 2D, whose views are shared with 2D reads; [ImageResinfoDimension](../../../core/libs/prx/libSceAgcDriver/tests/execution/ImageResinfoDimension.cpp) checks it through Vulkan on RDNA3 (RX 7700 XT). A 2D MSAA-array T# still throws, since the driver binds no type-15 texture, and a 16-fragment T# is refused as an invalid descriptor.
- [`image_get_resinfo` on 2D MSAA and 2D MSAA-array T#s, measured](../../../core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp) on RDNA2 (gfx1036, driver 31.0.22044.1) with the hardware oracle, separate from the implementation, not on the PS5's gfx1013: the level component is 1; a 2D MSAA T# with 2, 4, 8 or 16 fragments returns (width, height, 0, 1) under DIM 1D, 2D and 2D_MSAA at wave32 and wave64, and a 2D MSAA-array T# with 1 to 16 fragments and 1 or 4 slices returns (width, height, slices, 1) under DIM 2D_MSAA_ARRAY and (width, height, 0, 1) under DIM 1D, 2D and 2D_MSAA at wave32 and wave64; with 1 to 16 fragments, a BASE_ARRAY of 1, 2, 3, 4 or 7 and a last slice (DEPTH) of 3, 5 or 7 give DEPTH - BASE_ARRAY + 1 slices, as a 2D-array T# does under DIM 2D_ARRAY and a 1D-array T# does in the height under DIM 1D_ARRAY, while DIM 1D, 2D and 2D_MSAA still return 0.
- [3D image accesses bound to a 2D or 2D-array T#](../../../core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp) follow CouchRiv's [hardware oracle](../HW_ORACLE.md) measurement on RDNA2 (gfx1036, #2023) and adriadam10's (gfx1035, #2140), not the PS5's gfx1013. On a 2D T#, `image_sample_lz` ignores r and reads the (u,v) texel, `image_load` and `image_load_mip` read the (x,y) texel when z is 0 and return zero otherwise, and `image_get_resinfo` returns (width, height, 1, levels). On a 2D-array T#, these accesses behave like dim 2D-array: r or z is the layer, and `image_get_resinfo` returns the layer count as its third component. Every other access of such an image, including samples with an LOD, bias, derivatives, offset or comparison, gathers and `image_get_lod`, keeps throwing because it is not measured. DIM 3D `image_store` and `image_store_mip` at mip 0 were measured on RDNA2 (gfx1036, driver 31.0.22044.1) with the hardware oracle, `dmask` 0x1 on an 8x8 32_FLOAT T#: on a 2D T# a lane writes its (x,y) texel when z is 0 and nothing when z is 1; on a two-layer 2D-array T# z is the layer and z 2 writes nothing. The recompiler implements the 2D-array store; a store through a 2D T# keeps throwing.
- [2D-array samples through a 3D T#](../../../core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp) (`image_sample`, `image_sample_l` and `image_sample_lz` with DIM 2D_ARRAY) are measured only on RDNA2 (gfx1031, [hardware oracle](../HW_ORACLE.md)), not on the PS5's gfx1013, and only with wrap addressing. They sample the volume as DIM 3D does: the third address VGPR is the normalized r coordinate, addressed by the S#'s `CLAMP_Z`, not a layer index. The host sampler ignores `Z_FILTER`, as for every 3D sample, so r is filtered with the XY filter. Other samples through such a pair (bias, LOD clamp, derivatives, offsets, comparison, `_a`, 16-bit addresses), gathers, `image_get_lod` and `image_get_resinfo` throw, as do the three samples of a T# selected from an image table, of a T# the program also loads with DIM 2D_ARRAY, and of an 11_11_10_UNORM, 11_11_10_UINT or depth-bits T#.
- AMD image descriptors with `TYPE=0` are treated as null for [read-only image slots](../../../core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp) even when the base and other words are nonzero: `image_load` on a gfx1035 with such a T# returns 0,0,0,0, and the same descriptors were seen in direct reads in PPSA01341 on an RTX 4070. Writable and atomic image slots and entries of an image table keep faulting because there is no hardware measurement for them, and the reserved types 2-7 also fault. `TYPE=1` is treated as null in the same read-only slots: gfx1035 reads it as zeros too, and gfx1010 returns zeros for `image_sample_lz`, `image_sample_b`, `image_load` and `image_get_resinfo` with format 22 (#5828); it is not measured on RDNA2, with other formats or with depth-compare reads (`image_sample_c*`). gfx1013 behavior is unverified
Expand Down
Loading