mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-21 03:16:54 +02:00
shader: specialize cube image descriptors (#134)
* shader: specialize cube image descriptors Track whether image descriptors refer to cube maps during resource specialization, and apply the coordinate offset conversion when sampling cube maps as 2D image arrays in SPIR-V emission. * shader: fix cube array coordinate lowering --------- Co-authored-by: nmzik <Nmzik@mail.ru>
This commit is contained in:
@@ -1217,6 +1217,34 @@ void TestResourceSpecializationIsTypedAndTransactional() {
|
||||
Decoder::ImageDimension::Dim2DArray,
|
||||
"array MIMG intent did not produce a 2D-array view");
|
||||
|
||||
Program cube_view;
|
||||
cube_view.stage = ShaderType::Compute;
|
||||
cube_view.blocks.resize(1);
|
||||
cube_view.blocks[0].instructions = {
|
||||
ImageUse(0x24, Opcode::ImageLoad, ResourceKind::Image,
|
||||
Decoder::ImageDimension::Dim2DArray)};
|
||||
Prepare(cube_view);
|
||||
auto cube_snapshot = array_2d_snapshot;
|
||||
cube_snapshot.images[0].dwords[3] =
|
||||
Prospero::GpuEnumValue(Prospero::ImageType::kCube) << 28u;
|
||||
Check(SpecializeResources(cube_view, cube_snapshot, &error) &&
|
||||
ValidateResourceSpecialization(cube_view, cube_snapshot, &error) &&
|
||||
cube_view.info.images[0].cube &&
|
||||
cube_view.blocks[0].instructions[0].memory.image_cube,
|
||||
"cube descriptor identity did not reach the specialized image and IR");
|
||||
auto array_after_cube = cube_snapshot;
|
||||
array_after_cube.images[0].dwords[3] =
|
||||
Prospero::GpuEnumValue(Prospero::ImageType::kColor2DArray) << 28u;
|
||||
Check(!ValidateResourceSpecialization(cube_view, array_after_cube, &error),
|
||||
"2D-array descriptor reused a cube-coordinate specialization");
|
||||
auto null_after_cube = cube_snapshot;
|
||||
null_after_cube.images[0].dwords.fill(0);
|
||||
Check(SpecializeResources(cube_view, null_after_cube, &error) &&
|
||||
ValidateResourceSpecialization(cube_view, null_after_cube, &error) &&
|
||||
!cube_view.info.images[0].cube &&
|
||||
!cube_view.blocks[0].instructions[0].memory.image_cube,
|
||||
"canonical null respecialization retained stale cube-coordinate state");
|
||||
|
||||
Program program;
|
||||
program.stage = ShaderType::Compute;
|
||||
program.blocks.resize(1);
|
||||
|
||||
@@ -3020,6 +3020,37 @@ void TestNewShaderRecompilerImageQueryLowering() {
|
||||
CheckSpirvBinaryValidates(result.spirv);
|
||||
}
|
||||
|
||||
void TestNewShaderRecompilerCubeSampleCoordinates() {
|
||||
constexpr uint32_t MimgDimCube = 3;
|
||||
const uint32_t shader[] = {
|
||||
EncodeMimg0(0x20, 0xf, false, MimgDimCube),
|
||||
EncodeMimg1(0, 0, 1, 0), // image_sample cube
|
||||
EncodeMimg0(0x60, 0x3, false, MimgDimCube),
|
||||
EncodeMimg1(8, 0, 1, 4), // image_get_lod cube
|
||||
0xbf810000u,
|
||||
};
|
||||
|
||||
auto user_data = ImageTestUserData(Prospero::ImageType::kCube);
|
||||
ShaderRecompiler::CompileOptions options;
|
||||
options.stage = ShaderType::Compute;
|
||||
options.user_data = user_data.data();
|
||||
|
||||
ShaderRecompiler::CompileResult result;
|
||||
std::string error;
|
||||
Check(ShaderRecompiler::TryRecompile(shader, options, result, &error), error.c_str());
|
||||
Check(result.program.info.images.size() == 1 && result.program.info.images[0].cube,
|
||||
"cube descriptor identity was not preserved through compilation");
|
||||
Check(SpirvInstructionOpcodeCount(result.spirv, 131) == 4,
|
||||
"cube sample/get-lod did not remove the RDNA2 S/T bias");
|
||||
Check(SpirvInstructionOpcodeCount(result.spirv, 109) == 1 &&
|
||||
SpirvInstructionOpcodeCount(result.spirv, 112) == 1 &&
|
||||
SpirvInstructionOpcodeCount(result.spirv, 194) == 1 &&
|
||||
SpirvInstructionOpcodeCount(result.spirv, 196) == 1 &&
|
||||
SpirvInstructionOpcodeCount(result.spirv, 130) == 1,
|
||||
"cube sample did not repack its face ID exactly once, or get-lod used an array layer");
|
||||
CheckSpirvBinaryValidates(result.spirv);
|
||||
}
|
||||
|
||||
void TestNewShaderRecompilerImageSampleVariants() {
|
||||
const uint32_t shader[] = {
|
||||
EncodeMimg0(0x24, 0xf),
|
||||
@@ -6957,6 +6988,7 @@ int main() {
|
||||
TestNewShaderRecompilerScalarBitfieldAlu();
|
||||
TestNewShaderRecompilerMemoryFamilyLowering();
|
||||
TestNewShaderRecompilerImageQueryLowering();
|
||||
TestNewShaderRecompilerCubeSampleCoordinates();
|
||||
TestNewShaderRecompilerImageSampleVariants();
|
||||
TestNewShaderRecompilerImageSampleA16SamplerCoords();
|
||||
TestNewShaderRecompilerImageSampleOpcodeAliases();
|
||||
|
||||
Reference in New Issue
Block a user