Skip to content
Open
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
18 changes: 11 additions & 7 deletions core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1033,8 +1033,12 @@ bool UintPacked(ShaderRecompiler::ColorExportPacking packing) {
return packing == ShaderRecompiler::ColorExportPacking::Uint || packing == ShaderRecompiler::ColorExportPacking::UintClamp8 || packing == ShaderRecompiler::ColorExportPacking::UintClamp16 || packing == ShaderRecompiler::ColorExportPacking::UintMask8 || packing == ShaderRecompiler::ColorExportPacking::UintMask16;
}

bool NibblePacked(ShaderRecompiler::ColorExportPacking packing) {
return packing == ShaderRecompiler::ColorExportPacking::Unorm4_4_4_4 || packing == ShaderRecompiler::ColorExportPacking::Unorm4_4_4_4Truncated;
}

const char* PackedColorTargetName(ShaderRecompiler::ColorExportPacking packing) {
if (packing == ShaderRecompiler::ColorExportPacking::Unorm4_4_4_4) return "4_4_4_4 unorm";
if (NibblePacked(packing)) return "4_4_4_4 unorm";
if (UintPacked(packing)) return "unsigned integer";
return packing == ShaderRecompiler::ColorExportPacking::Float11_11_10 ? "11_11_10 float" : "10_11_11 unorm";
}
Expand All @@ -1046,7 +1050,7 @@ ShaderRecompiler::ColorExportPacking NarrowUintPacking(VkFormat format, ShaderRe
}

bool WordPacked(ShaderRecompiler::ColorExportPacking packing) {
return packing == ShaderRecompiler::ColorExportPacking::Unorm10_11_11 || packing == ShaderRecompiler::ColorExportPacking::Float11_11_10 || packing == ShaderRecompiler::ColorExportPacking::Unorm4_4_4_4;
return packing == ShaderRecompiler::ColorExportPacking::Unorm10_11_11 || packing == ShaderRecompiler::ColorExportPacking::Unorm10_11_11Truncated || packing == ShaderRecompiler::ColorExportPacking::Float11_11_10 || NibblePacked(packing);
}

// CB_COLOR_INFO FORMAT / NUMBER_TYPE / COMP_SWAP to a Vulkan attachment format. AMD formats list
Expand Down Expand Up @@ -2111,7 +2115,7 @@ State DecodeState(const QueueState& queue, bool vertexWorkgroup) {
state.blendEnable = VK_FALSE;
}
Require(!state.blendEnable, "blending into " + packed + " color target is unsupported");
const bool nibbles = color.packing == ShaderRecompiler::ColorExportPacking::Unorm4_4_4_4;
const bool nibbles = NibblePacked(color.packing);
const std::uint32_t packedMask = nibbles ? 0xfu : 7u;
Require(nibbles || floating || (exportedMask & packedMask) == packedMask, "partial writes of " + packed + " color target are unsupported");
if ((exportedMask & packedMask) != packedMask || color.mergeBlend != 0u) {
Expand Down Expand Up @@ -2208,8 +2212,8 @@ std::uint32_t PackedWriteMask(std::uint8_t componentMapping, std::uint32_t expor
std::uint32_t PackedWriteMask(ShaderRecompiler::ColorExportPacking packing, std::uint8_t componentMapping, std::uint32_t exportedMask) {
constexpr std::array<std::uint32_t, 4> nibbles{0x000fu, 0x00f0u, 0x0f00u, 0xf000u};
constexpr std::array<std::uint32_t, 4> floats{0x000003ffu, 0x001ffc00u, 0xffe00000u, 0u};
Require(packing == ShaderRecompiler::ColorExportPacking::Unorm4_4_4_4 || packing == ShaderRecompiler::ColorExportPacking::Float11_11_10, "a write mask of a packed color target that is neither 4_4_4_4 unorm nor 11_11_10 float");
const auto& fields = packing == ShaderRecompiler::ColorExportPacking::Unorm4_4_4_4 ? nibbles : floats;
Require(NibblePacked(packing) || packing == ShaderRecompiler::ColorExportPacking::Float11_11_10, "a write mask of a packed color target that is neither 4_4_4_4 unorm nor 11_11_10 float");
const auto& fields = NibblePacked(packing) ? nibbles : floats;
std::uint32_t mask = 0;
for (std::uint32_t component = 0; component < 4; ++component) {
if (((exportedMask >> ((componentMapping >> (2u * component)) & 3u)) & 1u) != 0) mask |= fields[component];
Expand Down Expand Up @@ -2621,8 +2625,8 @@ ColorTarget DecodeColorBuffer(const Registers& cx, std::uint32_t slot, bool allo
color.componentMapping = decoded.componentMapping;
color.packing = decoded.packing;
if (WordPacked(color.packing) && (info & 0x10000000u) != 0) throw std::runtime_error("AGC graphics: DCC-compressed " + std::string(PackedColorTargetName(color.packing)) + " color targets are unsupported");
Require(color.packing != ShaderRecompiler::ColorExportPacking::Unorm10_11_11 || (info & 0x00040000u) == 0, "truncating (ROUND_MODE) 10_11_11 unorm color targets are unsupported");
Require(color.packing != ShaderRecompiler::ColorExportPacking::Unorm4_4_4_4 || (info & 0x00040000u) == 0, "truncating (ROUND_MODE) 4_4_4_4 unorm color targets are unsupported");
if (color.packing == ShaderRecompiler::ColorExportPacking::Unorm10_11_11 && (info & 0x00040000u) != 0) color.packing = ShaderRecompiler::ColorExportPacking::Unorm10_11_11Truncated;
if (color.packing == ShaderRecompiler::ColorExportPacking::Unorm4_4_4_4 && (info & 0x00040000u) != 0) color.packing = ShaderRecompiler::ColorExportPacking::Unorm4_4_4_4Truncated;
for (std::uint32_t word = 0; word < 2; ++word) {
const auto clear = find(cx, 0x323 + word + stride);
color.clearWords[word] = clear == cx.end() ? 0u : clear->second;
Expand Down
8 changes: 5 additions & 3 deletions core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12169,7 +12169,8 @@ void unorm10_11_11TargetTests() {
expectFailure([&] { AgcDriver::Graphics::DecodeState(changed); }, "DCC-compressed 10_11_11 unorm color targets");
changed = queue;
changed.context[0x31c] |= 0x40000u;
expectFailure([&] { AgcDriver::Graphics::DecodeState(changed); }, "truncating (ROUND_MODE) 10_11_11 unorm color targets");
const auto truncating = AgcDriver::Graphics::DecodeState(changed);
Require(truncating.color.format == state.color.format && truncating.color.componentMapping == state.color.componentMapping && truncating.color.packing == ColorExportPacking::Unorm10_11_11Truncated, "a 10_11_11 unorm target with ROUND_MODE set did not decode as a truncating packed target");

constexpr std::array<std::uint32_t, 3> code{0xf800180fu, 0x07060504u, 0xbf810000u};
const auto request = packedExportRequest(queue, state, code);
Expand Down Expand Up @@ -12526,7 +12527,8 @@ void unorm4_4_4_4TargetTests() {
expectFailure([&] { AgcDriver::Graphics::DecodeState(changed); }, "DCC-compressed 4_4_4_4 unorm color targets");
changed = queue;
changed.context[0x31c] |= 0x40000u;
expectFailure([&] { AgcDriver::Graphics::DecodeState(changed); }, "truncating (ROUND_MODE) 4_4_4_4 unorm color targets");
const auto truncating = AgcDriver::Graphics::DecodeState(changed);
Require(truncating.color.format == state.color.format && truncating.color.componentMapping == state.color.componentMapping && truncating.color.packing == ShaderRecompiler::ColorExportPacking::Unorm4_4_4_4Truncated, "a 4_4_4_4 unorm target with ROUND_MODE set did not decode as a truncating packed target");

constexpr std::array<std::uint32_t, 3> code{0xf800180fu, 0x07060504u, 0xbf810000u};
const auto request = packedExportRequest(queue, state, code);
Expand Down Expand Up @@ -12678,7 +12680,7 @@ void float11_11_10TargetTests() {
const std::array<AgcDriver::Graphics::CompiledShader, 2> shaders{{{ShaderRecompiler::ShaderStage::Vertex, &vertex, 0}, {ShaderRecompiler::ShaderStage::Fragment, &packed, 0}}};
Require(AgcDriver::Graphics::ValidateShaders(shaders, state, subgroup, false) == std::set<std::uint32_t>{0u}, "the packed float export did not reach attachment 0");
auto invalid = request;
invalid.context.pixel->targetExportPacking[0] = static_cast<ColorExportPacking>(9);
invalid.context.pixel->targetExportPacking[0] = static_cast<ColorExportPacking>(static_cast<std::uint8_t>(ColorExportPacking::Unorm10_11_11Truncated) + 1u);
expectFailure([&] { static_cast<void>(ShaderRecompiler::Recompile(invalid)); }, "invalid prepared fragment export packing");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ constexpr std::uint32_t Height = 128;
constexpr std::uint32_t ScissorWidth = 128;
constexpr std::size_t BlockBytes = 65536;
constexpr std::uint32_t Unorm4_4_4_4Info = 0x8000u | (19u << 2u) | (2u << 11u);
constexpr std::uint32_t RoundModeBit = 0x40000u;
constexpr std::uint32_t LinearAttrib3 = 0x09000000u;
constexpr std::uint32_t Float32Export = 9;
constexpr std::uint32_t Float16Export = 4;
Expand All @@ -56,12 +57,13 @@ constexpr std::array<std::array<float, 4>, 3> Triangle{{
{-1.0f, -1.0f, 0.5f, 1.0f}, {3.0f, -1.0f, 0.5f, 1.0f}, {-1.0f, 3.0f, 0.5f, 1.0f}
}};

alignas(256) std::array<std::array<std::uint32_t, 64>, 32> Programs{};
alignas(256) std::array<std::array<std::uint32_t, 64>, 64> Programs{};
std::size_t programCount = 0;

struct Golden {
std::array<float, 4> rgba;
std::uint16_t word;
std::uint16_t truncatedWord;
};

std::uint32_t Half(float value) {
Expand Down Expand Up @@ -152,17 +154,17 @@ struct Block {
std::uint8_t* data = nullptr;
};

AgcDriver::Graphics::ColorTarget DecodeTarget(const Block& block, std::uint32_t attrib3) {
AgcDriver::Graphics::ColorTarget DecodeTarget(const Block& block, std::uint32_t attrib3, bool truncate) {
AgcDriver::Registers cx;
cx[0x318] = static_cast<std::uint32_t>(block.Address() >> 8u);
cx[0x31b] = 0;
cx[0x31c] = Unorm4_4_4_4Info;
cx[0x31c] = Unorm4_4_4_4Info | (truncate ? RoundModeBit : 0u);
cx[0x31d] = 0;
cx[0x3b0] = ((Width - 1u) << 14u) | (Height - 1u);
cx[0x3b8] = attrib3;
cx[0x390] = static_cast<std::uint32_t>(block.Address() >> 40u);
auto color = AgcDriver::Graphics::DecodeColorBuffer(cx, 0);
Require(color.format == VK_FORMAT_R16_UINT && color.elementBytes == 2 && color.componentMapping == 0x1bu && color.packing == ShaderRecompiler::ColorExportPacking::Unorm4_4_4_4 && color.bytes == block.bytes, "the 4_4_4_4 unorm target did not decode as a packed R16_UINT target");
Require(color.format == VK_FORMAT_R16_UINT && color.elementBytes == 2 && color.componentMapping == 0x1bu && color.packing == (truncate ? ShaderRecompiler::ColorExportPacking::Unorm4_4_4_4Truncated : ShaderRecompiler::ColorExportPacking::Unorm4_4_4_4) && color.bytes == block.bytes, "the 4_4_4_4 unorm target did not decode as a packed R16_UINT target");
return color;
}

Expand Down Expand Up @@ -272,43 +274,44 @@ std::string Describe(std::array<float, 4> rgba) {
return text;
}

void TargetTests(AgcDriver::VulkanDevice& device, Block& block, std::uint32_t attrib3, ColorTileMode mode, const char* kind) {
void TargetTests(AgcDriver::VulkanDevice& device, Block& block, std::uint32_t attrib3, ColorTileMode mode, const char* kind, bool truncate) {
const ColorTargetLayout layout(Width, Height, mode, 2);
Require(layout.Bytes() == block.bytes, "the test surface size disagrees with its layout");
const auto color = DecodeTarget(block, attrib3);
const auto color = DecodeTarget(block, attrib3, truncate);
auto before = Fill(block);
const float nan = std::numeric_limits<float>::quiet_NaN();
const float infinity = std::numeric_limits<float>::infinity();
const std::array<Golden, 11> float32Cases{{
{{1.0f, 0.0f, 0.0f, 0.0f}, 0xf000u},
{{0.0f, 1.0f, 0.0f, 0.0f}, 0x0f00u},
{{0.0f, 0.0f, 1.0f, 0.0f}, 0x00f0u},
{{0.0f, 0.0f, 0.0f, 1.0f}, 0x000fu},
{{1.0f, 1.0f, 1.0f, 1.0f}, 0xffffu},
{{1.0f, 0.5f, 0.0f, 0.25f}, 0xf804u},
{{0.0f, 1.0f, 0.5f, 0.25f}, 0x0f84u},
{{nan, -1.0f, 2.0f, infinity}, 0x00ffu},
{{1.0f / 15.0f, 2.0f / 15.0f, 7.0f / 15.0f, 14.0f / 15.0f}, 0x127eu},
{{0.1f, 0.7f, 0.9f, 0.3f}, 0x2ad5u},
{{-infinity, std::numeric_limits<float>::min(), 0.999999940f, std::numeric_limits<float>::denorm_min()}, 0x00f0u},
const std::array<Golden, 12> float32Cases{{
{{1.0f, 0.0f, 0.0f, 0.0f}, 0xf000u, 0xf000u},
{{0.0f, 1.0f, 0.0f, 0.0f}, 0x0f00u, 0x0f00u},
{{0.0f, 0.0f, 1.0f, 0.0f}, 0x00f0u, 0x00f0u},
{{0.0f, 0.0f, 0.0f, 1.0f}, 0x000fu, 0x000fu},
{{1.0f, 1.0f, 1.0f, 1.0f}, 0xffffu, 0xffffu},
{{1.0f, 0.5f, 0.0f, 0.25f}, 0xf804u, 0xf703u},
{{0.0f, 1.0f, 0.5f, 0.25f}, 0x0f84u, 0x0f73u},
{{nan, -1.0f, 2.0f, infinity}, 0x00ffu, 0x00ffu},
{{1.0f / 15.0f, 2.0f / 15.0f, 7.0f / 15.0f, 14.0f / 15.0f}, 0x127eu, 0x127eu},
{{0.1f, 0.7f, 0.9f, 0.3f}, 0x2ad5u, 0x1ad4u},
{{-infinity, std::numeric_limits<float>::min(), 0.999999940f, std::numeric_limits<float>::denorm_min()}, 0x00f0u, 0x00e0u},
{{std::bit_cast<float>(0x3d888888u), std::bit_cast<float>(0x3d888889u), std::bit_cast<float>(0x3f088888u), std::bit_cast<float>(0x3f088889u)}, 0x1188u, 0x0178u},
}};
for (const auto& golden : float32Cases) {
Draw(device, color, Float32Export, Float32Program(golden.rgba));
ExpectSurface(device, block, layout, before, golden.word, std::string("a 32_ABGR export of ") + Describe(golden.rgba) + " into a " + kind + " 4_4_4_4 unorm target");
ExpectSurface(device, block, layout, before, truncate ? golden.truncatedWord : golden.word, std::string("a 32_ABGR export of ") + Describe(golden.rgba) + " into a " + kind + " 4_4_4_4 unorm target");
before = ReadBack(device, block);
}
const std::array<Golden, 7> float16Cases{{
{{1.0f, 0.0f, 0.0f, 0.0f}, 0xf000u},
{{0.0f, 1.0f, 0.0f, 0.0f}, 0x0f00u},
{{0.0f, 0.0f, 1.0f, 0.0f}, 0x00f0u},
{{0.0f, 0.0f, 0.0f, 1.0f}, 0x000fu},
{{1.0f, 1.0f, 1.0f, 1.0f}, 0xffffu},
{{1.0f, 0.5f, 0.0f, 0.25f}, 0xf804u},
{{0.5f, 0.75f, 0.125f, 0.25f}, 0x8b24u},
{{1.0f, 0.0f, 0.0f, 0.0f}, 0xf000u, 0xf000u},
{{0.0f, 1.0f, 0.0f, 0.0f}, 0x0f00u, 0x0f00u},
{{0.0f, 0.0f, 1.0f, 0.0f}, 0x00f0u, 0x00f0u},
{{0.0f, 0.0f, 0.0f, 1.0f}, 0x000fu, 0x000fu},
{{1.0f, 1.0f, 1.0f, 1.0f}, 0xffffu, 0xffffu},
{{1.0f, 0.5f, 0.0f, 0.25f}, 0xf804u, 0xf703u},
{{0.5f, 0.75f, 0.125f, 0.25f}, 0x8b24u, 0x7b13u},
}};
for (const auto& golden : float16Cases) {
Draw(device, color, Float16Export, Float16Program(golden.rgba));
ExpectSurface(device, block, layout, before, golden.word, std::string("an FP16_ABGR export of ") + Describe(golden.rgba) + " into a " + kind + " 4_4_4_4 unorm target");
ExpectSurface(device, block, layout, before, truncate ? golden.truncatedWord : golden.word, std::string("an FP16_ABGR export of ") + Describe(golden.rgba) + " into a " + kind + " 4_4_4_4 unorm target");
before = ReadBack(device, block);
}
}
Expand All @@ -320,7 +323,8 @@ int main() {
const auto device = OpenVulkanTestDevice();
if (!device) return VulkanTestSkipped;
Block linear(ColorTargetLayout(Width, Height, ColorTileMode::Linear, 2).Bytes());
TargetTests(*device, linear, LinearAttrib3, ColorTileMode::Linear, "linear");
TargetTests(*device, linear, LinearAttrib3, ColorTileMode::Linear, "linear", false);
TargetTests(*device, linear, LinearAttrib3, ColorTileMode::Linear, "linear ROUND_MODE 1", true);
std::puts("4_4_4_4 unorm color target tests passed");
return 0;
} catch (const std::exception& error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ constexpr std::uint32_t Height = 128;
constexpr std::uint32_t ScissorWidth = 128;
constexpr std::size_t BlockBytes = 65536;
constexpr std::uint32_t Unorm4_4_4_4Info = 0x8000u | (19u << 2u) | (2u << 11u);
constexpr std::uint32_t RoundModeBit = 0x40000u;
constexpr std::uint32_t TiledAttrib3 = 0x4dc6c000u;
constexpr std::uint32_t Float32Export = 9;
constexpr std::uint32_t Float16Export = 4;
Expand Down Expand Up @@ -205,17 +206,17 @@ struct Block {
std::uint8_t* data = nullptr;
};

AgcDriver::Graphics::ColorTarget DecodeTarget(const Block& block) {
AgcDriver::Graphics::ColorTarget DecodeTarget(const Block& block, bool truncate) {
AgcDriver::Registers cx;
cx[0x318] = static_cast<std::uint32_t>(block.Address() >> 8u);
cx[0x31b] = 0;
cx[0x31c] = Unorm4_4_4_4Info;
cx[0x31c] = Unorm4_4_4_4Info | (truncate ? RoundModeBit : 0u);
cx[0x31d] = 0;
cx[0x3b0] = ((Width - 1u) << 14u) | (Height - 1u);
cx[0x3b8] = TiledAttrib3;
cx[0x390] = static_cast<std::uint32_t>(block.Address() >> 40u);
auto color = AgcDriver::Graphics::DecodeColorBuffer(cx, 0);
Require(color.format == VK_FORMAT_R16_UINT && color.componentMapping == 0x1bu && color.packing == ShaderRecompiler::ColorExportPacking::Unorm4_4_4_4 && color.tileMode == ColorTileMode::RenderTarget && color.bytes == block.bytes, "the tiled 4_4_4_4 unorm target did not decode as a packed R16_UINT target");
Require(color.format == VK_FORMAT_R16_UINT && color.componentMapping == 0x1bu && color.packing == (truncate ? ShaderRecompiler::ColorExportPacking::Unorm4_4_4_4Truncated : ShaderRecompiler::ColorExportPacking::Unorm4_4_4_4) && color.tileMode == ColorTileMode::RenderTarget && color.bytes == block.bytes, "the tiled 4_4_4_4 unorm target did not decode as a packed R16_UINT target");
return color;
}

Expand Down Expand Up @@ -481,7 +482,7 @@ int main() {
}
const ColorTargetLayout layout(Width, Height, ColorTileMode::RenderTarget, 2);
Block block(layout.Bytes());
const auto color = DecodeTarget(block);
const auto color = DecodeTarget(block, false);
Require(AgcDriver::Graphics::PackedWriteMask(color.componentMapping, 1u) == 0xf000u && AgcDriver::Graphics::PackedWriteMask(color.componentMapping, 8u) == 0x000fu && AgcDriver::Graphics::PackedWriteMask(color.componentMapping, 5u) == 0xf0f0u, "the export components did not map to the guest nibbles (X in 15..12, W in 3..0)");
const std::array<Case, 9> cases{{
{0x1u, 0xf000u, {1.0f, 0.0f, 0.0f, 0.0f}},
Expand All @@ -502,6 +503,14 @@ int main() {
ExpectSurface(*device, block, layout, before, goldens[index], wordMask, "a 32_ABGR " + Describe(mask, rgba) + " into a tiled 4_4_4_4 unorm target");
before = ReadBack(*device, block);
}
const auto truncating = DecodeTarget(block, true);
const std::array<std::uint16_t, 9> truncatedGoldens{0xf000u, 0x7fffu, 0x369cu, 0x02ffu, 0xfffbu, 0x0000u, 0x0f73u, 0x1ad4u, 0x0000u};
for (std::size_t index = 0; index < cases.size(); ++index) {
const auto& [mask, wordMask, rgba] = cases[index];
DrawCase(*device, truncating, mask, wordMask, Float32Export, Float32Program(rgba));
ExpectSurface(*device, block, layout, before, truncatedGoldens[index], wordMask, "a 32_ABGR " + Describe(mask, rgba) + " into a tiled ROUND_MODE 1 4_4_4_4 unorm target");
before = ReadBack(*device, block);
}
const std::array<float, 4> b{2.0f / 15.0f, 1.0f, 1.0f, 1.0f};
const std::array<float, 4> c{0.6f, 0.2f, 0.8f, 0.4f};
const std::array<float, 4> d{1.0f, 0.0f, 9.0f / 15.0f, 0.0f};
Expand Down
Loading
Loading