diff --git a/core/libs/prx/libSceAgcDriver/CMakeLists.txt b/core/libs/prx/libSceAgcDriver/CMakeLists.txt index 1ad0a76d9..b5e0d2eda 100644 --- a/core/libs/prx/libSceAgcDriver/CMakeLists.txt +++ b/core/libs/prx/libSceAgcDriver/CMakeLists.txt @@ -1031,6 +1031,15 @@ if(BUILD_TESTING) endif() if(BUILD_TESTING) + add_test_executable(image_by_tests ${LIBS_INCLUDE_DIR}/tests/ImageBy.cpp) + target_link_libraries(image_by_tests PRIVATE shader_recompiler_agc_driver libc) + configure_windows_unwind(image_by_tests) + add_test(NAME image_by COMMAND image_by_tests) + if(WIN32) + set_tests_properties(image_by PROPERTIES ENVIRONMENT_MODIFICATION + "PATH=path_list_prepend:$") + endif() + add_test_executable(image_msaa_load_tests ${LIBS_INCLUDE_DIR}/tests/ImageMsaaLoad.cpp) target_link_libraries(image_msaa_load_tests PRIVATE shader_recompiler_agc_driver libc) configure_windows_unwind(image_msaa_load_tests) diff --git a/core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp b/core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp index cd3bddc08..38ca0eb78 100644 --- a/core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp +++ b/core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp @@ -192,6 +192,8 @@ CompiledVariant sampleVariant() { image.r128 = true; image.fmaskCompatible = false; image.depthBitsCompatible = false; + image.byElements = 4; + image.byComponents = 1; image.indirectRoot = 0; image.indirectMappingOffset = 12; image.indirectSearchIterations = 3; diff --git a/core/libs/prx/libSceAgcDriver/tests/execution/ImageBy.cpp b/core/libs/prx/libSceAgcDriver/tests/execution/ImageBy.cpp new file mode 100644 index 000000000..fccae5c4f --- /dev/null +++ b/core/libs/prx/libSceAgcDriver/tests/execution/ImageBy.cpp @@ -0,0 +1,193 @@ +#include "prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp" +#include "prx/libSceAgcDriver/Graphics/include/Draw.hpp" +#include "prx/libSceAgcDriver/Graphics/include/Texture.hpp" +#include "prx/libSceAgcDriver/Graphics/include/TextureTiling.hpp" +#include "prx/libc/include/GuestAllocations.hpp" +#include "Recompiler.hpp" +#include "VulkanTestDevice.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace { + +using AgcDriver::Graphics::Require; + +constexpr std::uint32_t Threads = 32; +constexpr std::uint32_t Width = 61; +constexpr std::uint32_t Height = 3; +constexpr std::uint32_t Levels = 2; +constexpr std::size_t Bytes = 16384; +constexpr std::uint32_t Sentinel = 0xcafe0000u; +constexpr std::uint32_t R8UInt = 5; +constexpr std::uint32_t R16UInt = 11; +constexpr std::uint32_t Rg8UInt = 18; +constexpr std::uint32_t R32UInt = 20; +alignas(256) std::array Texels{}; +alignas(256) std::array Input{}; +alignas(256) std::array Output{}; + +struct Format { + std::uint32_t id; + std::uint32_t bytes; + std::uint32_t components; +}; + +std::vector Code(std::uint32_t opcode, std::uint32_t dmask) { + std::vector code{0x34060084u, 0xe0381000u, 0x80031e03u, 0xbf8c3f70u}; + for (std::uint32_t index = 0; index < 4u; ++index) { + code.push_back(0x7e0002ffu | ((10u + index) << 17u)); + code.push_back(Sentinel + index); + } + code.push_back(0xf0000008u | (opcode << 18u) | (dmask << 8u)); + code.push_back(0x00010a1eu); + code.push_back(0xbf8c3f70u); + code.push_back(0xe0781000u); + code.push_back(0x80000a03u); + code.push_back(0xbf810000u); + return code; +} + +std::array Descriptor(std::uint32_t format, std::uint32_t swizzle) { + const auto address = reinterpret_cast(Texels.data()); + return {static_cast(address >> 8u), static_cast(address >> 40u) | (format << 20u) | (((Width - 1u) & 3u) << 30u), + ((Width - 1u) >> 2u) | ((Height - 1u) << 14u), swizzle | ((Levels - 1u) << 16u) | (9u << 28u), 0u, 1u << 4u, 0u, 0u}; +} + +std::array BufferDescriptor(const void* data, std::uint32_t bytes) { + const auto address = reinterpret_cast(data); + return {static_cast(address), static_cast((address >> 32u) & 0xffffu), bytes, 0x31016facu}; +} + +std::uint32_t TexelValue(std::uint32_t level, std::uint32_t x, std::uint32_t y, std::uint32_t component, std::uint32_t bytes) { + const auto value = level * 0x9e37u + y * 0x51u + x * 0x13u + component * 0x2bu + 1u; + return bytes == 1u ? value & 0xffu : value & 0xffffu; +} + +void FillTexels(const Format& format) { + Texels.fill(0xeeu); + const auto descriptor = Descriptor(format.id, 0xfacu); + const auto surface = AgcDriver::Graphics::DescribeSurface(AgcDriver::Graphics::DecodeTextureResource(descriptor)); + Require(surface.mips.size() == Levels, "image BY mip count"); + for (std::uint32_t level = 0; level < Levels; ++level) { + const auto& mip = surface.mips[level]; + const auto width = std::max(Width >> level, 1u); + const auto height = std::max(Height >> level, 1u); + for (std::uint32_t y = 0; y < height; ++y) { + for (std::uint32_t x = 0; x < width; ++x) { + for (std::uint32_t component = 0; component < format.components; ++component) { + const auto value = TexelValue(level, x, y, component, format.bytes); + const auto offset = mip.tiledOffset + static_cast(y) * mip.pitchBytes + (x * format.components + component) * format.bytes; + Require(offset + format.bytes <= Texels.size(), "image BY texture size"); + std::memcpy(Texels.data() + offset, &value, format.bytes); + } + } + } + } +} + +void FillInput() { + constexpr std::array xs{0u, 1u, 2u, 3u, 5u, 6u, 7u, Width - 4u, Width - 3u, Width - 2u, Width - 1u, Width, 29u, 30u, 0xffffffffu, 0x80000000u}; + constexpr std::array ys{0u, 1u, 2u, Height, 0xffffffffu}; + constexpr std::array mips{0u, 1u, Levels}; + for (std::uint32_t thread = 0; thread < Threads; ++thread) { + Input[thread * 4u + 0u] = xs[thread % xs.size()]; + Input[thread * 4u + 1u] = ys[(thread * 3u) % ys.size()]; + Input[thread * 4u + 2u] = mips[(thread / 2u) % mips.size()]; + Input[thread * 4u + 3u] = 0u; + } +} + +void Run(AgcDriver::VulkanDevice& device, std::uint32_t opcode, std::uint32_t format, std::uint32_t dmask, std::uint32_t swizzle = 0xfacu) { + const auto code = Code(opcode, dmask); + std::vector userData(16, 0u); + const auto output = BufferDescriptor(Output.data(), static_cast(sizeof(Output))); + const auto descriptor = Descriptor(format, swizzle); + const auto input = BufferDescriptor(Input.data(), static_cast(sizeof(Input))); + std::copy(output.begin(), output.end(), userData.begin()); + std::copy(descriptor.begin(), descriptor.end(), userData.begin() + 4); + std::copy(input.begin(), input.end(), userData.begin() + 12); + const std::span words(code); + const std::array memory{{{reinterpret_cast(code.data()), std::as_bytes(words)}}}; + const ShaderRecompiler::ShaderComputeStageInfo compute{{Threads, 1, 1}, 0u, {false, false, false}, false, 1}; + ShaderRecompiler::RecompileRequest request{ + {ShaderRecompiler::ShaderStage::Compute, reinterpret_cast(code.data()), words, 0, {}}, + {32, 0, userData, compute, std::nullopt, std::nullopt, memory}, device.Target(), {0, 0, 0, 128}}; + request.useCache = false; + const auto result = ShaderRecompiler::Recompile(request); + device.Dispatch(result, 1, 1, 1, {}, reinterpret_cast(code.data())); + device.WaitIdle(); +} + +void Check(AgcDriver::VulkanDevice& device, std::uint32_t opcode, const Format& format, std::uint32_t dmask) { + const auto elements = (opcode & 1u) != 0u ? 4u : 2u; + const bool mip = (opcode & 8u) != 0u; + const auto dwords = static_cast(std::popcount(dmask)); + const auto name = "image BY opcode " + std::to_string(opcode) + " format " + std::to_string(format.id) + " dmask " + std::to_string(dmask); + FillTexels(format); + FillInput(); + const auto initial = Texels; + Output.fill(0xdeadbeefu); + Run(device, opcode, format.id, dmask); + for (std::uint32_t thread = 0; thread < Threads; ++thread) { + const auto x = Input[thread * 4u + 0u]; + const auto y = Input[thread * 4u + 1u]; + const auto level = mip ? Input[thread * 4u + 2u] : 0u; + const auto width = level < Levels ? std::max(Width >> level, 1u) : 0u; + const auto height = level < Levels ? std::max(Height >> level, 1u) : 0u; + const bool inside = level < Levels && x < width && width - x >= elements && y < height; + const auto first = x & ~(elements - 1u); + for (std::uint32_t index = 0; index < 4u; ++index) { + auto expected = Sentinel + index; + if (index < dwords) expected = inside ? TexelValue(level, first + index / format.components, y, index % format.components, format.bytes) : 0u; + const auto actual = Output[thread * 4u + index]; + Require(actual == expected, name + ": thread " + std::to_string(thread) + " (x " + std::to_string(x) + ", y " + std::to_string(y) + ", mip " + std::to_string(level) + ") v" + std::to_string(10u + index) + " is " + std::to_string(actual) + ", expected " + std::to_string(expected)); + } + } + Require(Texels == initial, name + ": the load changed the texture"); +} + +void Refused(AgcDriver::VulkanDevice& device, std::uint32_t opcode, std::uint32_t format, std::uint32_t dmask, std::uint32_t swizzle, const char* reason) { + bool refused = false; + try { Run(device, opcode, format, dmask, swizzle); } + catch (const std::exception& error) { refused = std::string(error.what()).find(reason) != std::string::npos; } + Require(refused, "image BY opcode " + std::to_string(opcode) + " format " + std::to_string(format) + " was not refused"); +} + +} + +int main() { + try { + const auto device = OpenVulkanTestDevice(); + if (!device) return VulkanTestSkipped; + GuestAllocations::Mutation().Add(Texels.data(), Bytes, true, true); + constexpr Format r8{R8UInt, 1u, 1u}; + constexpr Format r16{R16UInt, 2u, 1u}; + constexpr Format rg8{Rg8UInt, 1u, 2u}; + for (const auto opcode : {0x42u, 0x4au}) { + Check(*device, opcode, r8, 0x3u); + Check(*device, opcode, r16, 0x3u); + Check(*device, opcode, rg8, 0xfu); + } + for (const auto opcode : {0x43u, 0x4bu}) Check(*device, opcode, r8, 0xfu); + constexpr auto layout = "elements fill one dword"; + Refused(*device, 0x42u, R32UInt, 0x3u, 0xfacu, layout); + Refused(*device, 0x42u, R8UInt, 0xfu, 0xfacu, layout); + Refused(*device, 0x43u, R16UInt, 0xfu, 0xfacu, layout); + Refused(*device, 0x43u, Rg8UInt, 0xfu, 0xfacu, layout); + Refused(*device, 0x42u, R16UInt, 0x3u, 0xf2eu, layout); + for (const auto opcode : {0x52u, 0x53u, 0x5au, 0x5bu}) Refused(*device, opcode, R8UInt, 0xfu, 0xfacu, "stores are not implemented"); + GuestAllocations::Mutation().Remove(Texels.data()); + std::cout << "image BY2/BY4 execution tests passed\n"; + return 0; + } catch (const std::exception& error) { + std::cerr << error.what() << '\n'; + return 1; + } +} diff --git a/core/libs/tests/ImageBy.cpp b/core/libs/tests/ImageBy.cpp new file mode 100644 index 000000000..c636525f0 --- /dev/null +++ b/core/libs/tests/ImageBy.cpp @@ -0,0 +1,110 @@ +#include "Translation/TranslationContext.hpp" +#include "RdnaDecoder/RdnaImageOpDecoder.hpp" +#include +#include +#include +#include +#include +#include + +using namespace ShaderRecompiler; + +namespace { + +void Require(bool value, std::source_location location = std::source_location::current()) { + if (!value) throw std::runtime_error("image BY2/BY4 regression at line " + std::to_string(location.line())); +} + +constexpr std::array Encodings{0x42u, 0x43u, 0x4au, 0x4bu, 0x52u, 0x53u, 0x5au, 0x5bu}; +constexpr std::array Opcodes{RdnaOpcode::ImageLoadBy2, RdnaOpcode::ImageLoadBy4, RdnaOpcode::ImageLoadMipBy2, RdnaOpcode::ImageLoadMipBy4, RdnaOpcode::ImageStoreBy2, RdnaOpcode::ImageStoreBy4, RdnaOpcode::ImageStoreMipBy2, RdnaOpcode::ImageStoreMipBy4}; + +RdnaInstruction Decode(std::uint32_t encoding, std::uint32_t controls = 0u, std::uint32_t word1 = 0x00101e1eu, std::uint32_t mask = 15u, std::uint32_t dimension = 1u) { + const std::array code{0xf0000000u | (dimension << 3u) | (encoding << 18u) | (mask << 8u) | controls, word1, 0x0000201fu}; + return DecodeRdnaMimg(0u, code, 0u); +} + +void Check(std::uint32_t index, bool nsa, std::uint32_t mask) { + const auto encoding = Encodings[index]; + const auto inst = Decode(encoding, nsa ? 2u : 0u, 0x00101e1eu, mask); + const auto elements = (encoding & 1u) != 0u ? 4u : 2u; + const auto dwords = static_cast(std::popcount(mask)); + const bool store = (encoding & 0x10u) != 0u; + Require(inst.op == Opcodes[index] && IsImageOpcode(inst.op)); + Require(inst.dataDwordCount == dwords && inst.dataComponents == dwords); + Require(inst.imageAddressComponents == ((encoding & 8u) != 0u ? 3u : 2u)); + Require(inst.wordCount == (nsa ? 3u : 2u)); + IrProgram program; + auto& block = program.CreateBlock(); + program.SetEntryBlock(block); + TranslationContext context(program, block, 256); + if (store) { + bool refused = false; + try { context.TranslateInstruction(inst); } + catch (const std::runtime_error& error) { refused = std::string(error.what()).find("stores are not implemented") != std::string::npos; } + Require(refused); + return; + } + context.TranslateInstruction(inst); + std::vector reads; + std::uint32_t writes = 0; + for (auto* value : block.Instructions()) { + if (value->Opcode() == IrOpcode::SetVectorRegister) ++writes; + if (value->Opcode() == IrOpcode::ImageRead) { + Require(writes == 0u); + reads.push_back(value); + } + } + Require(reads.size() == 1u && writes == dwords); + const auto& memory = program.Resources().memoryInfo[reads[0]->Flags().index]; + Require(memory.imageByElements == elements && memory.dmask == mask && memory.dataDwords == dwords); + Require(memory.imageHasMip == ((encoding & 8u) != 0u)); +} + +void CheckOrdinary(std::uint32_t encoding) { + const auto inst = Decode(encoding); + const bool store = (encoding & 8u) != 0u; + IrProgram program; + auto& block = program.CreateBlock(); + program.SetEntryBlock(block); + TranslationContext context(program, block, 256); + context.TranslateInstruction(inst); + std::uint32_t operations = 0; + for (auto* value : block.Instructions()) { + if (value->Opcode() == (store ? IrOpcode::ImageWrite : IrOpcode::ImageRead)) { + const auto& memory = program.Resources().memoryInfo[value->Flags().index]; + Require(memory.imageByElements == 0u && memory.dmask == 15u && memory.dataDwords == 4u); + ++operations; + } + } + Require(operations == 1u); +} + +void Refused(std::uint32_t encoding, std::uint32_t control, std::uint32_t word1 = 0x00101e1eu, std::uint32_t mask = 15u, std::uint32_t dimension = 1u) { + bool refused = false; + try { (void)Decode(encoding, control, word1, mask, dimension); } + catch (const std::runtime_error&) { refused = true; } + Require(refused); +} + +} + +int main() { + for (auto encoding : {0u, 1u, 8u, 9u}) CheckOrdinary(encoding); + for (std::uint32_t index = 0; index < Encodings.size(); ++index) { + const bool by2 = (Encodings[index] & 1u) == 0u; + for (const bool nsa : {false, true}) { + Check(index, nsa, 15u); + if (by2) Check(index, nsa, 3u); + } + for (std::uint32_t mask = 0u; mask < 15u; ++mask) { + if (!(by2 && mask == 3u)) Refused(Encodings[index], 0u, 0x00101e1eu, mask); + } + for (auto bits : {0x8000u, 0x10000u, 0x20000u}) Refused(Encodings[index], bits); + for (auto bits : {0x40000000u, 0x80000000u}) Refused(Encodings[index], 0u, 0x00101e1eu | bits); + Refused(Encodings[index], 0u, 0x0010fd1eu); + Refused(Encodings[index], 0u, 0x00101effu); + for (std::uint32_t dimension = 0; dimension < 8u; ++dimension) { + if (dimension != 1u) Refused(Encodings[index], 0u, 0x00101e1eu, 15u, dimension); + } + } +} diff --git a/core/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrMetadata/ResourceInfo.hpp b/core/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrMetadata/ResourceInfo.hpp index ee85759d2..a8216cc16 100644 --- a/core/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrMetadata/ResourceInfo.hpp +++ b/core/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrMetadata/ResourceInfo.hpp @@ -44,6 +44,7 @@ struct MemoryInfo { bool imageHasMip = false; bool imageR128 = false; bool imagePacked = false; + std::uint32_t imageByElements = 0; bool idxen = false; bool offen = false; bool planningOnly = false; diff --git a/core/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrMetadata/Resources.hpp b/core/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrMetadata/Resources.hpp index aa631636b..ec2d0c79f 100644 --- a/core/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrMetadata/Resources.hpp +++ b/core/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrMetadata/Resources.hpp @@ -83,6 +83,8 @@ struct ImageResource { bool packed = false; bool fmaskCompatible = true; bool depthBitsCompatible = true; + std::uint32_t byElements = 0; + std::uint32_t byComponents = 0; IrBufferFormat packedFormat = IrBufferFormat::Invalid; std::uint32_t emulatedCompare = 0; std::uint32_t indirectRoot = NoIndirectImage; diff --git a/core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp b/core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp index a9338ee07..c2134f4cd 100644 --- a/core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp +++ b/core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp @@ -169,6 +169,15 @@ DecodedImage decodeImageDescriptor(const DescriptorValue& descriptor, const Imag } decoded.packedFormat = format; } + if (base.byElements != 0u) { + const bool eightBit = format == IrBufferFormat::Format8UNorm || format == IrBufferFormat::Format8SNorm || format == IrBufferFormat::Format8UInt || format == IrBufferFormat::Format8SInt; + const bool sixteenBit = format == IrBufferFormat::Format16UNorm || format == IrBufferFormat::Format16SNorm || format == IrBufferFormat::Format16UInt || format == IrBufferFormat::Format16SInt || format == IrBufferFormat::Format16Float; + const bool eightBitPair = format == IrBufferFormat::Format8_8UNorm || format == IrBufferFormat::Format8_8SNorm || format == IrBufferFormat::Format8_8UInt || format == IrBufferFormat::Format8_8SInt; + const bool measured = base.byElements == 4u ? base.byComponents == 1u && eightBit : base.byElements == 2u && (base.byComponents == 1u ? eightBit || sixteenBit : base.byComponents == 2u && eightBitPair); + if (!measured || descriptorImageSwizzle(descriptor) != ShaderImageIdentitySwizzle || rawImageType(descriptor) != ImageType::Color2D || base.indirectRoot != ImageResource::NoIndirectImage) { + throw std::runtime_error("MIMG BY2/BY4 requires a direct, identity-swizzled 2D image whose elements fill one dword: R8, R16 or RG8 for BY2, R8 for BY4"); + } + } decoded.conversionFormat = RemapTextureFormat(format) != format ? format : IrBufferFormat::Invalid; if (format == IrBufferFormat::Format11_11_10UNorm || format == IrBufferFormat::Format10_11_11Float) { const bool floating = format == IrBufferFormat::Format10_11_11Float; @@ -311,8 +320,8 @@ void resolveTableImage(const IrResourcePlan& plan, std::uint32_t imageIndex, con if (image.resourceClass != ImageResourceClass::Sampled) { rejectTable(BindlessRejection::Storage, "bindless storage image tables are unsupported"); } - if (image.packed) { - throw std::runtime_error("bindless packed image tables are unsupported"); + if (image.packed || image.byElements != 0u) { + throw std::runtime_error("bindless packed and BY2/BY4 image tables are unsupported"); } const auto slots = ResourceMaterializer::BindlessSlots(); DescriptorValue heapValue; @@ -597,7 +606,7 @@ std::vector ResourceMaterializer::RuntimeImageModes(const ImageRe mode.shaderSwizzle = ShaderImageIdentitySwizzle; if (conversion == IrBufferFormat::Format11_11_10UNorm || conversion == IrBufferFormat::Format10_11_11Float) mode.shaderSwizzle = 0x2acu; modes.push_back(mode); - if (image.dimension == RdnaImageDimension::Dim2D && image.fmaskCompatible && !depth && packed == IrBufferFormat::Invalid) { + if (image.dimension == RdnaImageDimension::Dim2D && image.fmaskCompatible && !depth && packed == IrBufferFormat::Invalid && image.byElements == 0u) { auto volume = mode; volume.dimension = RdnaImageDimension::Dim3D; modes.push_back(volume); diff --git a/core/shader/recompiler/Optimization/src/ResourceTracker.cpp b/core/shader/recompiler/Optimization/src/ResourceTracker.cpp index 32a8b5230..ddeeb2cb0 100644 --- a/core/shader/recompiler/Optimization/src/ResourceTracker.cpp +++ b/core/shader/recompiler/Optimization/src/ResourceTracker.cpp @@ -867,7 +867,7 @@ private: const bool depth = (memory.imageSampleFlags & RdnaImageSampleFlagCompare) != 0; for (std::uint32_t i = 0; i < m_info.images.size(); i++) { auto& image = m_info.images[i]; - if (image.source == source && image.resourceClass == resourceClass && image.dimension == memory.imageDimension && image.mipMode == mip && image.depthCompare == depth && image.r128 == memory.imageR128 && image.packed == memory.imagePacked) { + if (image.source == source && image.resourceClass == resourceClass && image.dimension == memory.imageDimension && image.mipMode == mip && image.depthCompare == depth && image.r128 == memory.imageR128 && image.packed == memory.imagePacked && image.byElements == memory.imageByElements && image.byComponents == (memory.imageByElements != 0u ? memory.dataDwords / memory.imageByElements : 0u)) { Merge(image, memory, op, pc); return i; } @@ -884,6 +884,8 @@ private: image.depthCompare = depth; image.r128 = memory.imageR128; image.packed = memory.imagePacked; + image.byElements = memory.imageByElements; + image.byComponents = memory.imageByElements != 0u ? memory.dataDwords / memory.imageByElements : 0u; Merge(image, memory, op, pc); m_info.images.push_back(image); return static_cast(m_info.images.size() - 1); diff --git a/core/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaOpcode.hpp b/core/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaOpcode.hpp index e85bc7b45..c6963dcd8 100644 --- a/core/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaOpcode.hpp +++ b/core/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaOpcode.hpp @@ -962,6 +962,14 @@ enum class RdnaOpcode : std::uint16_t { ImageStoreMip, ImageStorePck, ImageStoreMipPck, + ImageLoadBy2, + ImageLoadBy4, + ImageLoadMipBy2, + ImageLoadMipBy4, + ImageStoreBy2, + ImageStoreBy4, + ImageStoreMipBy2, + ImageStoreMipBy4, ImageMsaaLoad, ImageAtomicSwap, ImageAtomicAdd, diff --git a/core/shader/recompiler/RdnaDecoder/src/RdnaImageOpDecoder.cpp b/core/shader/recompiler/RdnaDecoder/src/RdnaImageOpDecoder.cpp index 4746595a4..7a93a085f 100644 --- a/core/shader/recompiler/RdnaDecoder/src/RdnaImageOpDecoder.cpp +++ b/core/shader/recompiler/RdnaDecoder/src/RdnaImageOpDecoder.cpp @@ -134,6 +134,14 @@ constexpr ImageOpcodeInfo imageOpcodes[] = { {0x0au, RdnaOpcode::ImageStorePck, nullptr, 0, false, false, false}, {0x0bu, RdnaOpcode::ImageStoreMipPck, nullptr, 0, false, false, false}, {0x0eu, RdnaOpcode::ImageGetResinfo, nullptr, 0, false, false, false}, + {0x42u, RdnaOpcode::ImageLoadBy2, nullptr, 0, false, false, false}, + {0x43u, RdnaOpcode::ImageLoadBy4, nullptr, 0, false, false, false}, + {0x4au, RdnaOpcode::ImageLoadMipBy2, nullptr, 0, false, false, false}, + {0x4bu, RdnaOpcode::ImageLoadMipBy4, nullptr, 0, false, false, false}, + {0x52u, RdnaOpcode::ImageStoreBy2, nullptr, 0, false, false, false}, + {0x53u, RdnaOpcode::ImageStoreBy4, nullptr, 0, false, false, false}, + {0x5au, RdnaOpcode::ImageStoreMipBy2, nullptr, 0, false, false, false}, + {0x5bu, RdnaOpcode::ImageStoreMipBy4, nullptr, 0, false, false, false}, {0x80u, RdnaOpcode::ImageMsaaLoad, nullptr, 0, false, false, false}, {0x60u, RdnaOpcode::ImageGetLod, nullptr, 0, false, false, false}, {0xe6u, RdnaOpcode::ImageBvhIntersectRay, "image_bvh_intersect_ray", 0, false, false, false}, @@ -350,6 +358,10 @@ RdnaInstruction DecodeRdnaMimg(std::uint32_t programCounter, std::span> 8u) & 15u; const bool pckGather = opcode == 0x62u || opcode == 0x63u; + const bool by = opcode == 0x42u || opcode == 0x43u || opcode == 0x4au || opcode == 0x4bu || opcode == 0x52u || opcode == 0x53u || opcode == 0x5au || opcode == 0x5bu; + if (by && ((dmask != 15u && (dmask != 3u || (opcode & 1u) != 0u)) || a16 || d16 || dimension != RdnaImageDimension::Dim2D || (word0 & 0x8000u) != 0u)) { + throw std::runtime_error("MIMG BY2/BY4 requires a data mask that covers every element (BY2 0x3 or 0xf, BY4 0xf), 32-bit addresses and data, a 2D image and a full descriptor"); + } const bool compareSwap = info.opcode == RdnaOpcode::ImageAtomicCmpswap || info.opcode == RdnaOpcode::ImageAtomicFcmpswap; const bool floatAtomic = info.opcode == RdnaOpcode::ImageAtomicFcmpswap || info.opcode == RdnaOpcode::ImageAtomicFmin || info.opcode == RdnaOpcode::ImageAtomicFmax; const bool atomic64 = info.atomic && !floatAtomic && !d16 && dmask == (compareSwap ? 15u : 3u); @@ -362,7 +374,7 @@ RdnaInstruction DecodeRdnaMimg(std::uint32_t programCounter, std::span