mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
Merge pull request #557 from adriadam10/feat/image-load-pck
feat(shader): implement image_load_pck and image_load_mip_pck with signed variants
This commit is contained in:
@@ -0,0 +1,209 @@
|
||||
#include "prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp"
|
||||
#include "prx/libSceAgcDriver/Graphics/include/Draw.hpp"
|
||||
#include "prx/libSceAgcDriver/Graphics/include/TextureTiling.hpp"
|
||||
#include "Recompiler.hpp"
|
||||
#include "VulkanTestDevice.hpp"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
|
||||
using AgcDriver::Graphics::Require;
|
||||
using ShaderRecompiler::ShaderStage;
|
||||
|
||||
constexpr std::uint32_t Threads = 32;
|
||||
constexpr std::uint32_t Words = 32;
|
||||
constexpr std::uint32_t Results = 17;
|
||||
constexpr std::uint32_t Width = 32;
|
||||
constexpr std::uint32_t Levels = 2;
|
||||
constexpr std::uint32_t Type2D = 9;
|
||||
constexpr std::uint32_t IdentitySwizzle = 0xfacu;
|
||||
alignas(256) std::array<std::uint32_t, Threads * Words> Buffer{};
|
||||
alignas(256) std::array<std::uint8_t, 4096> Texels{};
|
||||
|
||||
alignas(256) constexpr std::array<std::uint32_t, 55> Code{
|
||||
0x34060087, 0x7e3c0300, 0x7e3e0280, 0x36420087, 0x7e440280, 0xd5480023, 0x02050700, 0xf0081f08,
|
||||
0x00010a1e, 0xf00c1f08, 0x00010e1e, 0xf0081a08, 0x0001121e, 0xf00c1408, 0x0001141e, 0xf0101f08,
|
||||
0x00011521, 0xf0141308, 0x00011921, 0xbf8c3f70, 0xe0701000, 0x80000a03, 0xe0701004, 0x80000b03,
|
||||
0xe0701008, 0x80000c03, 0xe070100c, 0x80000d03, 0xe0701010, 0x80000e03, 0xe0701014, 0x80000f03,
|
||||
0xe0701018, 0x80001003, 0xe070101c, 0x80001103, 0xe0701020, 0x80001203, 0xe0701024, 0x80001303,
|
||||
0xe0701028, 0x80001403, 0xe070102c, 0x80001503, 0xe0701030, 0x80001603, 0xe0701034, 0x80001703,
|
||||
0xe0701038, 0x80001803, 0xe070103c, 0x80001903, 0xe0701040, 0x80001a03, 0xbf810000,
|
||||
};
|
||||
|
||||
struct Format {
|
||||
const char* name;
|
||||
std::uint32_t format;
|
||||
std::uint32_t bytes;
|
||||
bool floating;
|
||||
};
|
||||
|
||||
constexpr std::array<Format, 11> Formats{{
|
||||
{"8_UNORM", 1u, 1u, false},
|
||||
{"16_UNORM", 7u, 2u, false},
|
||||
{"16_SINT", 12u, 2u, false},
|
||||
{"8_8_UNORM", 14u, 2u, false},
|
||||
{"32_FLOAT", 22u, 4u, true},
|
||||
{"16_16_SINT", 28u, 4u, false},
|
||||
{"8_8_8_8_UNORM", 56u, 4u, false},
|
||||
{"8_8_8_8_SINT", 61u, 4u, false},
|
||||
{"32_32_UINT", 62u, 8u, false},
|
||||
{"16_16_16_16_UNORM", 65u, 8u, false},
|
||||
{"32_32_32_32_FLOAT", 77u, 16u, true},
|
||||
}};
|
||||
|
||||
std::string Hex(std::uint32_t value) {
|
||||
char text[16];
|
||||
std::snprintf(text, sizeof(text), "0x%08x", value);
|
||||
return text;
|
||||
}
|
||||
|
||||
std::vector<AgcDriver::Graphics::TileMipLayout> Mips(const Format& format) {
|
||||
return AgcDriver::Graphics::ComputeMipLayout(AgcDriver::Graphics::TextureTileMode::kLinear, format.format, Width, 1u, Levels);
|
||||
}
|
||||
|
||||
std::uint8_t* Texel(const AgcDriver::Graphics::TileMipLayout& mip, const Format& format, std::uint32_t x) {
|
||||
return &Texels[mip.tiledOffset + static_cast<std::uint64_t>(x) * format.bytes];
|
||||
}
|
||||
|
||||
void FillTexture(const Format& format) {
|
||||
const auto mips = Mips(format);
|
||||
Require(AgcDriver::Graphics::ComputeSurfaceSize(mips, 1) <= Texels.size(), std::string("image load packed: the mip chain of ") + format.name + " does not fit the texel storage");
|
||||
Texels.fill(0xeeu);
|
||||
for (std::uint32_t level = 0; level < Levels; ++level) {
|
||||
for (std::uint32_t x = 0; x < mips[level].width; ++x) {
|
||||
auto* texel = Texel(mips[level], format, x);
|
||||
for (std::uint32_t byte = 0; byte < format.bytes; ++byte) {
|
||||
texel[byte] = static_cast<std::uint8_t>(0x80u + 37u * (x * format.bytes + byte) + 7u * x + 101u * level);
|
||||
}
|
||||
if (format.floating) {
|
||||
for (std::uint32_t word = 0; word < format.bytes / 4u; ++word) {
|
||||
std::uint32_t bits;
|
||||
std::memcpy(&bits, texel + word * 4u, 4u);
|
||||
bits = (bits & 0x807fffffu) | ((0x60u + ((bits >> 23u) & 0x3fu)) << 23u);
|
||||
std::memcpy(texel + word * 4u, &bits, 4u);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::array<std::uint32_t, 4> RawTexel(const Format& format, std::uint32_t level, std::uint32_t x, bool sign) {
|
||||
const auto mips = Mips(format);
|
||||
std::array<std::uint32_t, 4> words{};
|
||||
std::memcpy(words.data(), Texel(mips[level], format, x), format.bytes);
|
||||
if (sign && format.bytes < 4u) {
|
||||
const auto shift = 32u - format.bytes * 8u;
|
||||
words[0] = static_cast<std::uint32_t>(static_cast<std::int32_t>(words[0] << shift) >> shift);
|
||||
}
|
||||
return words;
|
||||
}
|
||||
|
||||
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, 0x01016facu};
|
||||
}
|
||||
|
||||
std::array<std::uint32_t, 8> TextureDescriptor(const void* data, std::uint32_t format, std::uint32_t swizzle) {
|
||||
const auto address = static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(data));
|
||||
return {
|
||||
static_cast<std::uint32_t>(address >> 8u),
|
||||
static_cast<std::uint32_t>((address >> 40u) & 0xffu) | (format << 20u) | (((Width - 1u) & 3u) << 30u),
|
||||
(Width - 1u) >> 2u,
|
||||
swizzle | ((Levels - 1u) << 16u) | (Type2D << 28u),
|
||||
0u,
|
||||
(Levels - 1u) << 4u,
|
||||
0u,
|
||||
0u,
|
||||
};
|
||||
}
|
||||
|
||||
void Run(AgcDriver::VulkanDevice& device, std::uint32_t format, std::uint32_t swizzle) {
|
||||
Buffer.fill(0xdeadbeefu);
|
||||
std::vector<std::uint32_t> userData(16, 0u);
|
||||
const auto buffer = BufferDescriptor(Buffer.data(), static_cast<std::uint32_t>(Buffer.size() * 4u));
|
||||
const auto texture = TextureDescriptor(Texels.data(), format, swizzle);
|
||||
std::copy(buffer.begin(), buffer.end(), userData.begin());
|
||||
std::copy(texture.begin(), texture.end(), userData.begin() + 4);
|
||||
const std::span<const std::uint32_t> code(Code);
|
||||
const std::array<ShaderRecompiler::MemoryRegion, 1> memory{{{reinterpret_cast<std::uintptr_t>(code.data()), std::as_bytes(code)}}};
|
||||
const ShaderRecompiler::ShaderComputeStageInfo compute{{Threads, 1, 1}, 0u, {false, false, false}, false, 1};
|
||||
ShaderRecompiler::RecompileRequest request{
|
||||
{ShaderStage::Compute, reinterpret_cast<std::uintptr_t>(code.data()), code, 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<std::uintptr_t>(code.data()));
|
||||
device.WaitIdle();
|
||||
}
|
||||
|
||||
void Check(const Format& format) {
|
||||
for (std::uint32_t tid = 0; tid < Threads; ++tid) {
|
||||
const auto plain = RawTexel(format, 0u, tid, false);
|
||||
const auto sign = RawTexel(format, 0u, tid, true);
|
||||
const auto level = (tid >> 3u) & 1u;
|
||||
const auto mipPlain = RawTexel(format, level, tid & 7u, false);
|
||||
const auto mipSign = RawTexel(format, level, tid & 7u, true);
|
||||
const std::array<std::uint32_t, Results> expected{
|
||||
plain[0], plain[1], plain[2], plain[3],
|
||||
sign[0], sign[1], sign[2], sign[3],
|
||||
plain[1], plain[3],
|
||||
sign[2],
|
||||
mipPlain[0], mipPlain[1], mipPlain[2], mipPlain[3],
|
||||
mipSign[0], mipSign[1],
|
||||
};
|
||||
constexpr std::array<const char*, Results> names{
|
||||
"image_load_pck dmask:0xf [0]", "image_load_pck dmask:0xf [1]", "image_load_pck dmask:0xf [2]", "image_load_pck dmask:0xf [3]",
|
||||
"image_load_pck_sgn dmask:0xf [0]", "image_load_pck_sgn dmask:0xf [1]", "image_load_pck_sgn dmask:0xf [2]", "image_load_pck_sgn dmask:0xf [3]",
|
||||
"image_load_pck dmask:0xa [0]", "image_load_pck dmask:0xa [1]",
|
||||
"image_load_pck_sgn dmask:0x4",
|
||||
"image_load_mip_pck dmask:0xf [0]", "image_load_mip_pck dmask:0xf [1]", "image_load_mip_pck dmask:0xf [2]", "image_load_mip_pck dmask:0xf [3]",
|
||||
"image_load_mip_pck_sgn dmask:0x3 [0]", "image_load_mip_pck_sgn dmask:0x3 [1]",
|
||||
};
|
||||
for (std::uint32_t index = 0; index < Results; ++index) {
|
||||
const auto actual = Buffer[tid * Words + index];
|
||||
Require(actual == expected[index], std::string(format.name) + " " + names[index] + ": thread " + std::to_string(tid) + " is " + Hex(actual) + ", expected " + Hex(expected[index]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RequireRefused(AgcDriver::VulkanDevice& device, std::uint32_t format, std::uint32_t swizzle, const std::string& reason, const std::string& what) {
|
||||
std::string refusal;
|
||||
try {
|
||||
Run(device, format, swizzle);
|
||||
} catch (const std::exception& error) {
|
||||
refusal = error.what();
|
||||
}
|
||||
Require(refusal.find(reason) != std::string::npos, "image_load_pck of " + what + " was not refused: " + refusal);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
try {
|
||||
const auto device = OpenVulkanTestDevice();
|
||||
if (!device) return VulkanTestSkipped;
|
||||
for (const auto& format : Formats) {
|
||||
FillTexture(format);
|
||||
Run(*device, format.format, IdentitySwizzle);
|
||||
Check(format);
|
||||
}
|
||||
FillTexture(Formats[6]);
|
||||
RequireRefused(*device, 57u, IdentitySwizzle, "not recoverable", "8_8_8_8_SNORM");
|
||||
RequireRefused(*device, 56u, 0xf2eu, "identity swizzle", "a swizzled texture");
|
||||
std::puts("image load packed tests passed");
|
||||
return 0;
|
||||
} catch (const std::exception& error) {
|
||||
std::cerr << error.what() << '\n';
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
+1
@@ -43,6 +43,7 @@ struct MemoryInfo {
|
||||
bool d16 = false;
|
||||
bool imageHasMip = false;
|
||||
bool imageR128 = false;
|
||||
bool imagePacked = false;
|
||||
bool idxen = false;
|
||||
bool offen = false;
|
||||
bool planningOnly = false;
|
||||
|
||||
+2
@@ -52,6 +52,8 @@ struct ImageResource {
|
||||
bool r128 = false;
|
||||
bool depthBits = false;
|
||||
bool depthUnorm16 = false;
|
||||
bool packed = false;
|
||||
IrBufferFormat packedFormat = IrBufferFormat::Invalid;
|
||||
std::uint32_t indirectRoot = NoIndirectImage;
|
||||
std::uint32_t indirectMappingOffset = 0;
|
||||
std::uint32_t indirectSearchIterations = 0;
|
||||
|
||||
@@ -31,6 +31,7 @@ struct ResourceSpecialization {
|
||||
bool fmask = false;
|
||||
bool depthBits = false;
|
||||
bool depthUnorm16 = false;
|
||||
IrBufferFormat packedFormat = IrBufferFormat::Invalid;
|
||||
|
||||
bool operator==(const Image& other) const;
|
||||
};
|
||||
|
||||
@@ -45,6 +45,7 @@ struct DecodedImage {
|
||||
bool fmask = false;
|
||||
bool depthBits = false;
|
||||
bool depthUnorm16 = false;
|
||||
IrBufferFormat packedFormat = IrBufferFormat::Invalid;
|
||||
};
|
||||
|
||||
ShaderBufferResource decodeBufferDescriptor(const DescriptorValue& value) {
|
||||
@@ -158,6 +159,12 @@ DecodedImage decodeImageDescriptor(const DescriptorValue& descriptor, const Imag
|
||||
if (decoded.fmask && (storage || base.depthCompare || base.indirectRoot != ImageResource::NoIndirectImage)) {
|
||||
throw std::runtime_error("FMASK requires a direct sampled image load");
|
||||
}
|
||||
if (base.packed) {
|
||||
if (storage || base.indirectRoot != ImageResource::NoIndirectImage || descriptorImageSwizzle(descriptor) != ShaderImageIdentitySwizzle) {
|
||||
throw std::runtime_error("packed image load requires a direct sampled image with identity swizzle");
|
||||
}
|
||||
decoded.packedFormat = format;
|
||||
}
|
||||
decoded.conversionFormat = RemapTextureFormat(format) != format ? format : IrBufferFormat::Invalid;
|
||||
if (storage || decoded.conversionFormat != IrBufferFormat::Invalid) {
|
||||
decoded.shaderSwizzle = descriptorImageSwizzle(descriptor);
|
||||
@@ -291,6 +298,9 @@ 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");
|
||||
}
|
||||
const auto slots = ResourceMaterializer::BindlessSlots();
|
||||
DescriptorValue heapValue;
|
||||
walker.EvaluateDescriptorSource(plan, table.heapSource, runtime, heapValue);
|
||||
@@ -534,6 +544,7 @@ void buildResourceSpecialization(const IrResourcePlan& plan, ResourceSnapshot& s
|
||||
entry.fmask = decoded.fmask;
|
||||
entry.depthBits = decoded.depthBits;
|
||||
entry.depthUnorm16 = decoded.depthUnorm16;
|
||||
entry.packedFormat = decoded.packedFormat;
|
||||
result.images.push_back(entry);
|
||||
}
|
||||
|
||||
@@ -620,6 +631,7 @@ void ResourceMaterializer::Apply(IrProgram& program, const ResourceSpecializatio
|
||||
image.cube = source.cube;
|
||||
image.depthBits = source.depthBits;
|
||||
image.depthUnorm16 = source.depthUnorm16;
|
||||
image.packedFormat = source.packedFormat;
|
||||
image.indirectResources.clear();
|
||||
}
|
||||
for (std::uint32_t index = 0; index < images.size(); index++) {
|
||||
@@ -948,7 +960,7 @@ bool ResourceSpecialization::Buffer::operator==(const Buffer& other) const {
|
||||
}
|
||||
|
||||
bool ResourceSpecialization::Image::operator==(const Image& other) const {
|
||||
return numericClass == other.numericClass && dimension == other.dimension && mipCount == other.mipCount && conversionFormat == other.conversionFormat && shaderSwizzle == other.shaderSwizzle && indirectRoot == other.indirectRoot && indirectMappingOffset == other.indirectMappingOffset && indirectSearchIterations == other.indirectSearchIterations && cube == other.cube && fmask == other.fmask && depthBits == other.depthBits && depthUnorm16 == other.depthUnorm16;
|
||||
return numericClass == other.numericClass && dimension == other.dimension && mipCount == other.mipCount && conversionFormat == other.conversionFormat && shaderSwizzle == other.shaderSwizzle && indirectRoot == other.indirectRoot && indirectMappingOffset == other.indirectMappingOffset && indirectSearchIterations == other.indirectSearchIterations && cube == other.cube && fmask == other.fmask && depthBits == other.depthBits && depthUnorm16 == other.depthUnorm16 && packedFormat == other.packedFormat;
|
||||
}
|
||||
|
||||
bool ResourceSpecialization::operator==(const ResourceSpecialization& other) const {
|
||||
|
||||
@@ -861,7 +861,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) {
|
||||
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) {
|
||||
Merge(image, op, pc);
|
||||
return i;
|
||||
}
|
||||
@@ -877,6 +877,7 @@ private:
|
||||
image.mipMode = mip;
|
||||
image.depthCompare = depth;
|
||||
image.r128 = memory.imageR128;
|
||||
image.packed = memory.imagePacked;
|
||||
Merge(image, op, pc);
|
||||
m_info.images.push_back(image);
|
||||
return static_cast<std::uint32_t>(m_info.images.size() - 1);
|
||||
|
||||
@@ -823,6 +823,10 @@ enum class RdnaOpcode : std::uint16_t {
|
||||
DsReadAddtidB32,
|
||||
ImageGetLod,
|
||||
ImageLoadMip,
|
||||
ImageLoadPck,
|
||||
ImageLoadPckSgn,
|
||||
ImageLoadMipPck,
|
||||
ImageLoadMipPckSgn,
|
||||
ImageStoreMip,
|
||||
ImageAtomicSwap,
|
||||
ImageAtomicAdd,
|
||||
|
||||
@@ -97,6 +97,10 @@ constexpr ImageOpcodeInfo imageOpcodes[] = {
|
||||
{0x1cu, RdnaOpcode::ImageAtomicDec, nullptr, 0, false, false, true},
|
||||
{0x00u, RdnaOpcode::ImageLoad, nullptr, 0, false, false, false},
|
||||
{0x01u, RdnaOpcode::ImageLoadMip, nullptr, 0, false, false, false},
|
||||
{0x02u, RdnaOpcode::ImageLoadPck, nullptr, 0, false, false, false},
|
||||
{0x03u, RdnaOpcode::ImageLoadPckSgn, nullptr, 0, false, false, false},
|
||||
{0x04u, RdnaOpcode::ImageLoadMipPck, nullptr, 0, false, false, false},
|
||||
{0x05u, RdnaOpcode::ImageLoadMipPckSgn, nullptr, 0, false, false, false},
|
||||
{0x08u, RdnaOpcode::ImageStore, nullptr, 0, false, false, false},
|
||||
{0x09u, RdnaOpcode::ImageStoreMip, nullptr, 0, false, false, false},
|
||||
{0x0eu, RdnaOpcode::ImageGetResinfo, nullptr, 0, false, false, false},
|
||||
@@ -282,7 +286,7 @@ RdnaInstruction DecodeRdnaMimg(std::uint32_t programCounter, std::span<const std
|
||||
validateFlags(flags);
|
||||
const auto dimension = decodeDimension((word0 >> 3u) & 7u);
|
||||
const bool multisampled = dimension == RdnaImageDimension::Dim2DMsaa || dimension == RdnaImageDimension::Dim2DMsaaArray;
|
||||
if (multisampled && (info.sample || info.gather || opcode == 0x60u || opcode == 1u || opcode == 9u)) {
|
||||
if (multisampled && (info.sample || info.gather || opcode == 0x60u || (opcode >= 1u && opcode <= 5u) || opcode == 9u)) {
|
||||
throw std::runtime_error("unsupported multisampled MIMG operation");
|
||||
}
|
||||
const auto dmask = (word0 >> 8u) & 15u;
|
||||
@@ -295,7 +299,7 @@ RdnaInstruction DecodeRdnaMimg(std::uint32_t programCounter, std::span<const std
|
||||
}
|
||||
const bool rayQuery = info.opcode == RdnaOpcode::ImageBvhIntersectRay;
|
||||
std::uint32_t components = rayQuery ? (a16 ? 8u : 11u) : opcode == 0x0Eu ? 1u : coordinateCount(dimension);
|
||||
if (opcode == 1u || opcode == 9u) {
|
||||
if (opcode == 1u || opcode == 4u || opcode == 5u || opcode == 9u) {
|
||||
++components;
|
||||
}
|
||||
if (info.sample || info.gather) {
|
||||
|
||||
@@ -758,6 +758,10 @@ bool IsImageOpcode(RdnaOpcode opcode) {
|
||||
case RdnaOpcode::ImageGetResinfo:
|
||||
case RdnaOpcode::ImageGetLod:
|
||||
case RdnaOpcode::ImageLoadMip:
|
||||
case RdnaOpcode::ImageLoadPck:
|
||||
case RdnaOpcode::ImageLoadPckSgn:
|
||||
case RdnaOpcode::ImageLoadMipPck:
|
||||
case RdnaOpcode::ImageLoadMipPckSgn:
|
||||
case RdnaOpcode::ImageStoreMip:
|
||||
case RdnaOpcode::ImageAtomicSwap:
|
||||
case RdnaOpcode::ImageAtomicAdd:
|
||||
|
||||
@@ -69,7 +69,7 @@ static_assert(sizeof(FragmentParameter) == 12, "FragmentParameter changed: updat
|
||||
static_assert(sizeof(CompiledShaderInfo) == 304, "CompiledShaderInfo changed: update the info encoder");
|
||||
static_assert(sizeof(ShaderInfo) == 200, "ShaderInfo changed: update the info encoder");
|
||||
static_assert(sizeof(BufferResource) == 36, "BufferResource changed: update the info encoder");
|
||||
static_assert(sizeof(ImageResource) == 80, "ImageResource changed: update the info encoder");
|
||||
static_assert(sizeof(ImageResource) == 88, "ImageResource changed: update the info encoder");
|
||||
static_assert(sizeof(SamplerResource) == 12, "SamplerResource changed: update the info encoder");
|
||||
static_assert(sizeof(SampledResourcePair) == 12, "SampledResourcePair changed: update the info encoder");
|
||||
static_assert(sizeof(StageInput) == 56, "StageInput changed: update the info encoder");
|
||||
@@ -79,7 +79,7 @@ static_assert(sizeof(IrDescriptorBinding) == 32, "IrDescriptorBinding changed: u
|
||||
static_assert(sizeof(BindingAllocationResult) == 120, "BindingAllocationResult changed: update the allocation encoder");
|
||||
static_assert(sizeof(ResourceSpecialization) == 72, "ResourceSpecialization changed: update BuildKey");
|
||||
static_assert(sizeof(ResourceSpecialization::Buffer) == 16, "ResourceSpecialization::Buffer changed: update BuildKey");
|
||||
static_assert(sizeof(ResourceSpecialization::Image) == 36, "ResourceSpecialization::Image changed: update BuildKey");
|
||||
static_assert(sizeof(ResourceSpecialization::Image) == 40, "ResourceSpecialization::Image changed: update BuildKey");
|
||||
static_assert(sizeof(BindingLayout) == 16, "BindingLayout changed: update BuildKey");
|
||||
#endif
|
||||
|
||||
@@ -403,6 +403,8 @@ void encodeInfo(Writer& writer, const CompiledShaderInfo& compiled) {
|
||||
out.Value(image.r128);
|
||||
out.Value(image.depthBits);
|
||||
out.Value(image.depthUnorm16);
|
||||
out.Value(image.packed);
|
||||
out.Value(image.packedFormat);
|
||||
out.Value(image.indirectRoot);
|
||||
out.Value(image.indirectMappingOffset);
|
||||
out.Value(image.indirectSearchIterations);
|
||||
@@ -490,6 +492,8 @@ void decodeInfo(Reader& reader, CompiledShaderInfo& compiled) {
|
||||
in.Value(image.r128);
|
||||
in.Value(image.depthBits);
|
||||
in.Value(image.depthUnorm16);
|
||||
in.Value(image.packed);
|
||||
in.Value(image.packedFormat);
|
||||
in.Value(image.indirectRoot);
|
||||
in.Value(image.indirectMappingOffset);
|
||||
in.Value(image.indirectSearchIterations);
|
||||
@@ -802,6 +806,7 @@ void BuildKey(const RecompileRequest& request, std::uint32_t hostSubgroupSize, c
|
||||
out.Value(image.fmask);
|
||||
out.Value(image.depthBits);
|
||||
out.Value(image.depthUnorm16);
|
||||
out.Value(image.packedFormat);
|
||||
});
|
||||
writer.Values(std::span<const std::uint32_t>(specialization.boundDescriptors));
|
||||
const auto& switches = switchKey();
|
||||
|
||||
@@ -448,6 +448,55 @@ std::uint32_t UnpackImageTexel(SpirvValueEmitContext& ctx, const ImageEmitAccess
|
||||
return result;
|
||||
}
|
||||
|
||||
std::uint32_t PackedImageTexel(SpirvValueEmitContext& ctx, const ImageEmitAccess& access, std::uint32_t texel) {
|
||||
auto& state = ctx.state;
|
||||
const auto format = access.image.packedFormat;
|
||||
if (format == IrBufferFormat::Invalid || access.table.mapped != 0 || access.image.depthBits || access.image.conversionFormat != IrBufferFormat::Invalid) {
|
||||
ctx.Fail(access.inst, "reads packed texels from an image without a packed format");
|
||||
}
|
||||
const auto info = GetFormatInfo(format);
|
||||
std::uint32_t texelBits = 0;
|
||||
for (std::uint32_t component = 0; component < info.componentCount; component++) {
|
||||
const auto bits = info.componentBits[component];
|
||||
const bool exact = info.type == SpirvFormatComponentType::Uint || info.type == SpirvFormatComponentType::Sint || (info.type == SpirvFormatComponentType::Unorm && bits <= 16u) || (info.type == SpirvFormatComponentType::Float && bits == 32u);
|
||||
if (info.packedBitfield || !exact) {
|
||||
ctx.Fail(access.inst, "reads packed texels of a format whose bits are not recoverable from the view");
|
||||
}
|
||||
texelBits += bits;
|
||||
}
|
||||
const auto numericClass = access.image.numericClass;
|
||||
std::uint32_t words[4] = {ConstantU32(state, 0), ConstantU32(state, 0), ConstantU32(state, 0), ConstantU32(state, 0)};
|
||||
std::uint32_t position = 0;
|
||||
for (std::uint32_t component = 0; component < info.componentCount; component++) {
|
||||
const auto bits = info.componentBits[component];
|
||||
const auto scalar = state.module.AllocateId();
|
||||
state.module.AddFunction(spv::OpCompositeExtract, ImageScalarType(state, numericClass), scalar, texel, component);
|
||||
std::uint32_t value;
|
||||
if (info.type == SpirvFormatComponentType::Unorm) {
|
||||
const auto scaled = Binary(state, spv::OpFMul, TypeF32(state), scalar, ConstantF32Value(state, static_cast<float>((1u << bits) - 1u)));
|
||||
value = Unary(state, spv::OpConvertFToU, TypeU32(state), Binary(state, spv::OpFAdd, TypeF32(state), scaled, ConstantF32Value(state, 0.5f)));
|
||||
} else {
|
||||
value = SampledComponentBits(ctx, scalar, numericClass);
|
||||
}
|
||||
if (bits < 32u) {
|
||||
value = Binary(state, spv::OpBitwiseAnd, TypeU32(state), value, ConstantU32(state, (1u << bits) - 1u));
|
||||
}
|
||||
const auto word = position / 32u;
|
||||
if (position % 32u != 0u) {
|
||||
value = Binary(state, spv::OpShiftLeftLogical, TypeU32(state), value, ConstantU32(state, position % 32u));
|
||||
}
|
||||
words[word] = Binary(state, spv::OpBitwiseOr, TypeU32(state), words[word], value);
|
||||
position += bits;
|
||||
}
|
||||
if (access.mem.dataSigned && texelBits < 32u) {
|
||||
const auto shift = ConstantU32(state, 32u - texelBits);
|
||||
words[0] = Binary(state, spv::OpShiftRightArithmetic, TypeU32(state), Binary(state, spv::OpShiftLeftLogical, TypeU32(state), words[0], shift), shift);
|
||||
}
|
||||
const auto result = state.module.AllocateId();
|
||||
state.module.AddFunction(spv::OpCompositeConstruct, TypeU32Vector(state, 4), result, words[0], words[1], words[2], words[3]);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::uint32_t UnpackImageGather(SpirvValueEmitContext& ctx, const ImageEmitAccess& access, std::uint32_t gathered) {
|
||||
auto& state = ctx.state;
|
||||
const auto info = ImageConversionFormat(access.image);
|
||||
@@ -621,6 +670,9 @@ void EmitReadOp(SpirvValueEmitContext& ctx, const ImageEmitAccess& access) {
|
||||
} else {
|
||||
state.module.AddFunction(spv::OpImageFetch, ImageVectorType(state, numericClass, 4), color, descriptor, coord, spv::ImageOperandsLodMask, LodU32(ctx, access));
|
||||
}
|
||||
if (access.mem.imagePacked) {
|
||||
return PackedImageTexel(ctx, access, color);
|
||||
}
|
||||
return TableResult(ctx, access, ResultVector(ctx, access, UnpackImageTexel(ctx, access, color), numericClass, false, false));
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -34,7 +34,9 @@ MemoryInfo imageMemoryInfoFromInstruction(const RdnaInstruction& inst) {
|
||||
memory.imageSampleFlags = inst.imageSampleFlags;
|
||||
memory.imageDimension = inst.imageDimension;
|
||||
memory.imageAddressComponents = inst.imageAddressComponents;
|
||||
memory.imageHasMip = inst.op == RdnaOpcode::ImageLoadMip || inst.op == RdnaOpcode::ImageStoreMip;
|
||||
memory.imageHasMip = inst.op == RdnaOpcode::ImageLoadMip || inst.op == RdnaOpcode::ImageStoreMip || inst.op == RdnaOpcode::ImageLoadMipPck || inst.op == RdnaOpcode::ImageLoadMipPckSgn;
|
||||
memory.imagePacked = inst.op == RdnaOpcode::ImageLoadPck || inst.op == RdnaOpcode::ImageLoadPckSgn || inst.op == RdnaOpcode::ImageLoadMipPck || inst.op == RdnaOpcode::ImageLoadMipPckSgn;
|
||||
memory.dataSigned = inst.op == RdnaOpcode::ImageLoadPckSgn || inst.op == RdnaOpcode::ImageLoadMipPckSgn;
|
||||
memory.imageR128 = inst.imageR128;
|
||||
return memory;
|
||||
}
|
||||
|
||||
+4
@@ -377,6 +377,10 @@ bool TranslationContext::emitMemory(const RdnaInstruction& inst) {
|
||||
return imageAtomic(inst, IrOpcode::ImageAtomicDec32);
|
||||
case RdnaOpcode::ImageLoad:
|
||||
case RdnaOpcode::ImageLoadMip:
|
||||
case RdnaOpcode::ImageLoadPck:
|
||||
case RdnaOpcode::ImageLoadPckSgn:
|
||||
case RdnaOpcode::ImageLoadMipPck:
|
||||
case RdnaOpcode::ImageLoadMipPckSgn:
|
||||
return imageLoad(inst);
|
||||
case RdnaOpcode::ImageStore:
|
||||
case RdnaOpcode::ImageStoreMip:
|
||||
|
||||
Reference in New Issue
Block a user