diff --git a/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawLookup.cpp b/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawLookup.cpp index e32a64564128..2f3a32e6095a 100644 --- a/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawLookup.cpp +++ b/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawLookup.cpp @@ -74,6 +74,8 @@ void Driver::lookupDraw(const Submission& submission, const std::shared_ptr(pixel.depthExportMin)); + mix(std::bit_cast(pixel.depthExportMax)); for (const auto value : pixel.targetOutputMode) mix(value); for (const auto value : pixel.targetExportMapping) mix(value); for (const auto value : pixel.targetExportPacking) mix(static_cast(value)); diff --git a/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawRegisterKey.cpp b/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawRegisterKey.cpp index 876709f64548..a30e3b754243 100644 --- a/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawRegisterKey.cpp +++ b/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawRegisterKey.cpp @@ -255,7 +255,7 @@ bool Driver::sameDecode(const DrawDecode& a, const DrawDecode& b) { if (std::memcmp(&s.viewport, &t.viewport, sizeof(VkViewport)) != 0 || std::memcmp(&s.scissor, &t.scissor, sizeof(VkRect2D)) != 0) return false; const auto& p = a.pixel; const auto& q = b.pixel; - if (p.interpolatorCount != q.interpolatorCount || p.interpolatorSettings != q.interpolatorSettings || p.wave32 != q.wave32 || p.inputAddr != q.inputAddr || p.hasPerspectiveCenterVgpr != q.hasPerspectiveCenterVgpr || p.perspectiveCentroid != q.perspectiveCentroid || p.posX != q.posX || p.posY != q.posY || p.posZ != q.posZ || p.posW != q.posW || p.frontFace != q.frontFace || p.frontFaceAllBits != q.frontFaceAllBits || p.ancillary != q.ancillary || p.sampleShading != q.sampleShading || p.noPerspective != q.noPerspective || p.linearCentroid != q.linearCentroid || p.pixelKillEnable != q.pixelKillEnable || p.depthExportEnable != q.depthExportEnable || p.sampleMaskExportEnable != q.sampleMaskExportEnable || p.earlyZ != q.earlyZ || p.executeOnNoop != q.executeOnNoop || p.conservativeZExport != q.conservativeZExport || p.orderedPixelShader != q.orderedPixelShader || p.stencilRefExportEnable != q.stencilRefExportEnable || p.stencilOperationValueExport != q.stencilOperationValueExport || p.targetOutputMode != q.targetOutputMode || p.targetExportMapping != q.targetExportMapping) return false; + if (p.interpolatorCount != q.interpolatorCount || p.interpolatorSettings != q.interpolatorSettings || p.wave32 != q.wave32 || p.inputAddr != q.inputAddr || p.hasPerspectiveCenterVgpr != q.hasPerspectiveCenterVgpr || p.perspectiveCentroid != q.perspectiveCentroid || p.posX != q.posX || p.posY != q.posY || p.posZ != q.posZ || p.posW != q.posW || p.frontFace != q.frontFace || p.frontFaceAllBits != q.frontFaceAllBits || p.ancillary != q.ancillary || p.sampleShading != q.sampleShading || p.noPerspective != q.noPerspective || p.linearCentroid != q.linearCentroid || p.pixelKillEnable != q.pixelKillEnable || p.depthExportEnable != q.depthExportEnable || p.depthExportMin != q.depthExportMin || p.depthExportMax != q.depthExportMax || p.sampleMaskExportEnable != q.sampleMaskExportEnable || p.earlyZ != q.earlyZ || p.executeOnNoop != q.executeOnNoop || p.conservativeZExport != q.conservativeZExport || p.orderedPixelShader != q.orderedPixelShader || p.stencilRefExportEnable != q.stencilRefExportEnable || p.stencilOperationValueExport != q.stencilOperationValueExport || p.targetOutputMode != q.targetOutputMode || p.targetExportMapping != q.targetExportMapping) return false; if (a.roles != b.roles || a.programs.size() != b.programs.size()) return false; for (std::size_t i = 0; i < a.programs.size(); ++i) { const auto& x = a.programs[i]; diff --git a/core/libs/prx/libSceAgcDriver/Graphics/include/State.hpp b/core/libs/prx/libSceAgcDriver/Graphics/include/State.hpp index ad8b43941074..190dd06e8454 100644 --- a/core/libs/prx/libSceAgcDriver/Graphics/include/State.hpp +++ b/core/libs/prx/libSceAgcDriver/Graphics/include/State.hpp @@ -306,7 +306,7 @@ struct DrawKeyRange { std::uint32_t count; }; inline constexpr std::array DrawKeyRegisters{{ - {RegisterBank::Context, 0x000, 1}, {RegisterBank::Context, 0x002, 1}, {RegisterBank::Context, 0x005, 1}, {RegisterBank::Context, 0x007, 7}, {RegisterBank::Context, 0x010, 6}, {RegisterBank::Context, 0x01a, 5}, + {RegisterBank::Context, 0x000, 1}, {RegisterBank::Context, 0x002, 2}, {RegisterBank::Context, 0x005, 1}, {RegisterBank::Context, 0x007, 7}, {RegisterBank::Context, 0x010, 6}, {RegisterBank::Context, 0x01a, 5}, {RegisterBank::Context, 0x080, 4}, {RegisterBank::Context, 0x08c, 4}, {RegisterBank::Context, 0x090, 2}, {RegisterBank::Context, 0x094, 2}, {RegisterBank::Context, 0x0b4, 2}, {RegisterBank::Context, 0x105, 4}, {RegisterBank::Context, 0x10b, 3}, {RegisterBank::Context, 0x10f, 6}, // SPI_PS_INPUT_CNTL_0..31, SPI_PS_INPUT_ENA/ADDR, SPI_PS_IN_CONTROL .. SPI_BARYC_CNTL, SPI_SHADER_POS/Z/COL_FORMAT, // CB_BLEND0..7_CONTROL, GE_MAX_OUTPUT_PER_SUBGROUP. diff --git a/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderInputState.cpp b/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderInputState.cpp index 30ea58080316..08278405d19f 100644 --- a/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderInputState.cpp +++ b/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderInputState.cpp @@ -6,6 +6,9 @@ #include "prx/libc/include/HostThreadLocal.hpp" #include #include +#include +#include +#include #include #include #include @@ -27,6 +30,9 @@ constexpr std::uint32_t spiPsInputAddr = 0x1B4; constexpr std::uint32_t spiPsInControl = 0x1B6; constexpr std::uint32_t spiBarycCntl = 0x1B8; constexpr std::uint32_t dbShaderControl = 0x203; +constexpr std::uint32_t dbRenderOverride = 0x003; +constexpr std::uint32_t paScVportZmin0 = 0x0B4; +constexpr std::uint32_t paScVportZmax0 = 0x0B5; constexpr std::uint32_t spiShaderColFormat = 0x1C5; constexpr std::uint32_t defaultPixelInputs = 0x2u; @@ -143,6 +149,20 @@ ShaderRecompiler::ShaderPixelStageInfo DecodePixelStageInfo(const Registers& con } const bool pixelKillEnable = ((shaderControl >> 6u) & 0x1u) != 0; const bool depthExportEnable = (shaderControl & 0x1u) != 0; + float depthExportMin = 0.0f; + float depthExportMax = 1.0f; + if (depthExportEnable) { + if ((read(context, dbRenderOverride, RegisterBank::Context) & 0x10000u) != 0) { + depthExportMin = -std::numeric_limits::infinity(); + depthExportMax = std::numeric_limits::infinity(); + } else { + depthExportMin = std::bit_cast(read(context, paScVportZmin0, RegisterBank::Context)); + depthExportMax = std::bit_cast(read(context, paScVportZmax0, RegisterBank::Context)); + if (!std::isfinite(depthExportMin) || !std::isfinite(depthExportMax) || depthExportMin > depthExportMax) { + throw std::runtime_error("AGC graphics: invalid viewport depth clamp bounds for depth export"); + } + } + } const bool sampleMaskExportEnable = ((shaderControl >> 8u) & 0x1u) != 0; const bool stencilOperationValue = !nullProgram && StencilOperationValueReplaces(context); const bool stencilRefExportEnable = ((shaderControl >> 1u) & 0x1u) != 0 || stencilOperationValue; @@ -176,6 +196,8 @@ ShaderRecompiler::ShaderPixelStageInfo DecodePixelStageInfo(const Registers& con .linearCentroid = loaded(PixelInput::LinearCentroid), .pixelKillEnable = pixelKillEnable, .depthExportEnable = depthExportEnable, + .depthExportMin = depthExportMin, + .depthExportMax = depthExportMax, .sampleMaskExportEnable = sampleMaskExportEnable, .earlyZ = PixelEarlyZ(shaderControl), .executeOnNoop = ((shaderControl >> 10u) & 0x1u) != 0, diff --git a/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp b/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp index 95e0d7203131..20db2ac9bf0e 100644 --- a/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp +++ b/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp @@ -31,6 +31,7 @@ #include "prx/libc/include/GuestHeap.hpp" #include "ImageTableAbi.hpp" #include "SpirvBackend/SpirvSpecialization.hpp" +#include #include #ifdef _WIN32 #include @@ -103,6 +104,7 @@ AgcDriver::QueueState makeState() { queue.context[0x114] = 0; queue.context[0xb4] = 0; queue.context[0xb5] = std::bit_cast(1.0f); + queue.context[0x3] = 0; queue.shader[0x008] = 0x100; queue.shader[0x009] = 0; return queue; @@ -313,6 +315,9 @@ void retainedPixelStageTests() { Require(!PixelProgramSkipped(queue), "an enabled high render target lost its pixel program"); queue.context[0x8e] = queue.context[0x8f] = 0; } + queue.context[0x3] = 0; + queue.context[0xb4] = std::bit_cast(0.0f); + queue.context[0xb5] = std::bit_cast(1.0f); queue.context[0x1b3] = queue.context[0x1b4] = 2; for (const auto [format, control] : {std::pair{1u, 1u}, std::pair{2u, 2u}, std::pair{9u, 0x100u}, std::pair{9u, 0x103u}}) { queue.context[0x1c4] = format; @@ -322,6 +327,25 @@ void retainedPixelStageTests() { const auto pixel = DecodePixelStageInfo(queue.context, ExportMappings(state), PixelProgramSkipped(queue)); Require(pixel.depthExportEnable == ((control & 1u) != 0) && pixel.stencilRefExportEnable == ((control & 2u) != 0) && pixel.sampleMaskExportEnable == ((control & 0x100u) != 0), "decoding lost an enabled pixel export"); } + queue.context[0x1c4] = 1; + queue.context[0x203] = 1; + queue.context[0xb4] = std::bit_cast(0.25f); + queue.context[0xb5] = std::bit_cast(0.75f); + const auto clampState = DecodeState(queue); + const auto clamped = DecodePixelStageInfo(queue.context, ExportMappings(clampState)); + Require(clamped.depthExportEnable && clamped.depthExportMin == 0.25f && clamped.depthExportMax == 0.75f, "PA_SC_VPORT_ZMIN_0/ZMAX_0 did not become the exported depth clamp"); + queue.context[0x3] = 0x10000; + const auto unclamped = DecodePixelStageInfo(queue.context, ExportMappings(clampState)); + Require(unclamped.depthExportEnable && unclamped.depthExportMin == -std::numeric_limits::infinity() && unclamped.depthExportMax == std::numeric_limits::infinity(), "DB_RENDER_OVERRIDE.DISABLE_VIEWPORT_CLAMP did not leave the exported depth unclamped"); + queue.context[0x3] = 0; + queue.context[0xb4] = std::bit_cast(0.9f); + expectFailure([&] { static_cast(DecodePixelStageInfo(queue.context, ExportMappings(clampState))); }, "invalid viewport depth clamp bounds"); + queue.context[0xb4] = std::bit_cast(std::numeric_limits::quiet_NaN()); + expectFailure([&] { static_cast(DecodePixelStageInfo(queue.context, ExportMappings(clampState))); }, "invalid viewport depth clamp bounds"); + queue.context[0x1c4] = 0; + queue.context[0x203] = 0x10; + const auto notExporting = DecodePixelStageInfo(queue.context, ExportMappings(clampState)); + Require(!notExporting.depthExportEnable && notExporting.depthExportMin == 0.0f && notExporting.depthExportMax == 1.0f, "a draw without depth export took the viewport depth clamp"); queue.context[0x203] = 0; for (const auto alpha : {0xaa00u, 0xaa01u}) { queue.context[0x2dc] = alpha; diff --git a/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp b/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp index 3550a828f45d..e9386d142645 100644 --- a/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp +++ b/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp @@ -30,6 +30,7 @@ #include "BdaAbi.hpp" #include "ImageTableAbi.hpp" #include "ShaderDiskCache.hpp" +#include #include #include #include @@ -6241,7 +6242,7 @@ void verifyPixelRequestSerialization() { minimal.context.pixel->layerExported = true; minimal.context.pixel->ditheredAlphaToCoverage = true; const auto encoded = serializer.Serialize(minimal); - require(requestPrefix(encoded, 8u) == "NVNQQTAAAAA=", "new requests did not use serialization version 48"); + require(requestPrefix(encoded, 8u) == "NVNQQTEAAAA=", "new requests did not use serialization version 49"); auto withBarycentric = minimal; withBarycentric.target.fragmentBarycentricBuiltins = true; require(serializer.Deserialize(serializer.Serialize(withBarycentric)).request.target.fragmentBarycentricBuiltins && !serializer.Deserialize(encoded).request.target.fragmentBarycentricBuiltins, "barycentric built-ins were lost in serialization"); @@ -6362,7 +6363,7 @@ void verifyPixelRequestSerialization() { for (std::size_t bytes = 0; bytes < 45u; ++bytes) { expectFailure([&] { static_cast(serializer.Deserialize(requestPrefix(encoded, mappingOffset + bytes))); }, "truncated data", "a truncated pixel mapping, packing, dual-source, alpha-to-coverage, stencil reference export flag, primitive class, layer export, dither or front-face flag, quad pixel mask or quad sample mask was accepted"); } - for (const auto unsupported : {"NVNQQQAAAAA=", "NVNQQTEAAAA="}) { + for (const auto unsupported : {"NVNQQQAAAAA=", "NVNQQTIAAAA="}) { expectFailure([&] { static_cast(serializer.Deserialize(unsupported)); }, "serialization version", "an unsupported request version was accepted"); } static constexpr std::string_view version18Request{ @@ -6434,6 +6435,132 @@ std::string encodeBase64(const std::vector& bytes) { return text; } +void verifyDepthExportClamp() { + using namespace ShaderRecompiler; + static constexpr std::array code{0xf8001881u, 0x00000000u, 0xbf810000u}; + ShaderPixelStageInfo pixel{}; + pixel.inputAddr = PixelInputBit(PixelInput::PerspectiveCenter); + pixel.hasPerspectiveCenterVgpr = true; + pixel.depthExportEnable = true; + pixel.depthExportMin = 0.25f; + pixel.depthExportMax = 0.75f; + RecompileRequest request{}; + request.shader = {ShaderStage::Fragment, 0x30000u, code, 0, {}}; + request.context.waveSize = 64; + request.context.pixel = pixel; + request.target.vulkanVersion = 0x00401000u; + request.target.spirvVersion = 0x00010300u; + request.target.subgroupSize = 64; + request.layout.pushConstantSizeBytes = 128; + request.useCache = false; + const auto result = Recompile(request); + const auto& words = result.spirv.Words(); + std::map floats; + std::vector> clamps; + std::vector stored; + std::uint32_t depthVariable = 0; + bool depthReplacing = false; + for (std::size_t at = 5; at < words.size() && (words[at] >> 16u) != 0; at += words[at] >> 16u) { + const auto op = static_cast(words[at] & 0xffffu); + if (op == spv::OpConstant && (words[at] >> 16u) == 4u) floats[words[at + 2]] = words[at + 3]; + if (op == spv::OpExtInst && words[at + 4] == 81u) clamps.push_back({words[at + 2], words[at + 6], words[at + 7]}); + if (op == spv::OpDecorate && words[at + 2] == spv::DecorationBuiltIn && words[at + 3] == spv::BuiltInFragDepth) depthVariable = words[at + 1]; + if (op == spv::OpStore) stored.push_back(words[at + 1]), stored.push_back(words[at + 2]); + if (op == spv::OpExecutionMode && words[at + 2] == spv::ExecutionModeDepthReplacing) depthReplacing = true; + } + require(depthVariable != 0u && depthReplacing, "depth export: the pixel shader does not replace gl_FragDepth"); + require(clamps.size() == 1u && floats[clamps[0][1]] == 0x3e800000u && floats[clamps[0][2]] == 0x3f400000u, "depth export: the exported depth was not NClamped to [ZMIN, ZMAX]"); + bool clampStored = false; + for (std::size_t i = 0; i + 1 < stored.size(); i += 2) clampStored = clampStored || (stored[i] == depthVariable && stored[i + 1] == clamps[0][0]); + require(clampStored, "depth export: gl_FragDepth was not written from the clamped value"); + const auto replay = RequestSerializer{}.Deserialize(RequestSerializer{}.Serialize(request)); + require(replay.request.context.pixel->depthExportMin == 0.25f && replay.request.context.pixel->depthExportMax == 0.75f, "depth export: the clamp did not survive serialization"); + { + auto tail = request; + tail.target.largePixelFunctionLdsBuffer = true; + tail.target.pixelFunctionStorageDwords = 2048u; + const auto both = RequestSerializer{}.Deserialize(RequestSerializer{}.Serialize(tail)); + require(both.request.target.largePixelFunctionLdsBuffer && both.request.target.pixelFunctionStorageDwords == 2048u && + both.request.context.pixel->depthExportMin == 0.25f && both.request.context.pixel->depthExportMax == 0.75f, + "depth export: a version 49 request lost the bounds or the version 45 target tail"); + auto bytes = decodeBase64(RequestSerializer{}.Serialize(tail)); + require(bytes.size() > 8u && bytes[4] == 49u, "depth export: a depth exporting request did not use serialization version 49"); + static constexpr std::array boundBytes{0x00u, 0x00u, 0x80u, 0x3eu, 0x00u, 0x00u, 0x40u, 0x3fu}; + const auto found = std::search(bytes.begin(), bytes.end(), boundBytes.begin(), boundBytes.end()); + require(found != bytes.end() && std::search(found + 1, bytes.end(), boundBytes.begin(), boundBytes.end()) == bytes.end(), + "depth export: the clamp bounds were not written exactly once"); + bytes.erase(found, found + boundBytes.size()); + for (const std::uint8_t legacyVersion : {48u, 47u, 46u}) { + if (legacyVersion == 47u) bytes.pop_back(); + bytes[4] = legacyVersion; + const auto legacy = RequestSerializer{}.Deserialize(encodeBase64(bytes)); + require(legacy.request.context.pixel->depthExportEnable && legacy.request.context.pixel->depthExportMin == 0.0f && + legacy.request.context.pixel->depthExportMax == 1.0f && legacy.request.target.largePixelFunctionLdsBuffer && + legacy.request.target.pixelFunctionStorageDwords == 2048u, + legacyVersion == 46u ? "depth export: a version 46 depth exporting request did not read with default bounds and its target tail" + : legacyVersion == 47u ? "depth export: a version 47 depth exporting request did not read with default bounds and its target tail" + : "depth export: a version 48 depth exporting request did not read with default bounds and its target tail"); + } + for (const bool depthExport : {false, true}) { + auto dithered = request; + auto ditheredPixel = *dithered.context.pixel; + ditheredPixel.depthExportEnable = depthExport; + ditheredPixel.ditheredAlphaToCoverage = true; + ditheredPixel.ditheredAlphaSamples = 2u; + dithered.context.pixel = ditheredPixel; + auto ditheredBytes = decodeBase64(RequestSerializer{}.Serialize(dithered)); + require(ditheredBytes.size() > 8u && ditheredBytes[4] == 49u, "a two-sample dithered request did not use serialization version 49"); + if (depthExport) { + const auto bounds = std::search(ditheredBytes.begin(), ditheredBytes.end(), boundBytes.begin(), boundBytes.end()); + require(bounds != ditheredBytes.end(), "a two-sample dithered depth exporting request lacks the clamp bounds"); + ditheredBytes.erase(bounds, bounds + boundBytes.size()); + } + ditheredBytes[4] = 48u; + const auto main48 = RequestSerializer{}.Deserialize(encodeBase64(ditheredBytes)); + require(main48.request.context.pixel->ditheredAlphaToCoverage && main48.request.context.pixel->ditheredAlphaSamples == 2u && main48.request.context.pixel->depthExportEnable == depthExport && + (!depthExport || (main48.request.context.pixel->depthExportMin == 0.0f && main48.request.context.pixel->depthExportMax == 1.0f)), + "a version 48 two-sample dithered request, as main writes it with no depth tail, did not decode as written"); + } + } + std::vector key; + RecompileCacheKey::Build(request, key); + const auto first = key; + auto other = request; + auto changed = pixel; + changed.depthExportMax = 1.0f; + other.context.pixel = changed; + RecompileCacheKey::Build(other, key); + require(key != first && RecompileCacheKey::ContextHash(request) != RecompileCacheKey::ContextHash(other), "depth export: the cache keys ignore the clamp"); + auto plain = pixel; + plain.depthExportEnable = false; + auto unexported = request; + unexported.context.pixel = plain; + RecompileCacheKey::Build(unexported, key); + const auto plainKey = key; + plain.depthExportMin = 0.0f; + plain.depthExportMax = 1.0f; + unexported.context.pixel = plain; + RecompileCacheKey::Build(unexported, key); + require(key == plainKey, "depth export: the clamp keyed a shader without depth export"); + auto open = pixel; + open.depthExportMin = -std::numeric_limits::infinity(); + open.depthExportMax = std::numeric_limits::infinity(); + auto unclamped = request; + unclamped.context.pixel = open; + const auto unclampedResult = Recompile(unclamped); + const auto& openWords = unclampedResult.spirv.Words(); + bool openClamp = false; + bool openStore = false; + std::uint32_t openDepth = 0; + for (std::size_t at = 5; at < openWords.size() && (openWords[at] >> 16u) != 0; at += openWords[at] >> 16u) { + const auto op = static_cast(openWords[at] & 0xffffu); + if (op == spv::OpExtInst && openWords[at + 4] == 81u) openClamp = true; + if (op == spv::OpDecorate && openWords[at + 2] == spv::DecorationBuiltIn && openWords[at + 3] == spv::BuiltInFragDepth) openDepth = openWords[at + 1]; + if (op == spv::OpStore && openWords[at + 1] == openDepth && openDepth != 0u) openStore = true; + } + require(!openClamp && openStore, "depth export: an unclamped export (DISABLE_VIEWPORT_CLAMP) was clamped or not stored"); +} + void verifyVertexInfoVersion19() { using namespace ShaderRecompiler; const std::array code{0xbf810000u}; @@ -6752,7 +6879,7 @@ void verifyMergedHullConfiguration() { require(!serializer.Deserialize(separate).request.graphics->tessellation->mergedHull, "a separate hull configuration was read as merged"); constexpr std::size_t pointTailBytes = 13u; auto legacy = decodeBase64(merged); - require(legacy.size() > 55u + pointTailBytes && legacy[4] == 48u, "a merged hull request did not use serialization version 48"); + require(legacy.size() > 55u + pointTailBytes && legacy[4] == 49u, "a merged hull request did not use serialization version 49"); legacy.resize(legacy.size() - sizeof(std::uint32_t) - 3u - pointTailBytes); legacy.pop_back(); require(legacy[legacy.size() - 52u] == 1u, "the merged hull flag is not the last byte of the tessellation configuration"); @@ -9325,6 +9452,7 @@ int main(int argc, char** argv) { verifyVertexInfoVersion19(); verifyDepthRemapRequests(); verifyMergedHullConfiguration(); + verifyDepthExportClamp(); verifyPositionExportComponents(); verifyLegacyPixelRequests(); verifyPixelExportReplay(); diff --git a/core/libs/prx/libSceAgcDriver/tests/execution/DepthExportClamp.cpp b/core/libs/prx/libSceAgcDriver/tests/execution/DepthExportClamp.cpp new file mode 100644 index 000000000000..19084d49af11 --- /dev/null +++ b/core/libs/prx/libSceAgcDriver/tests/execution/DepthExportClamp.cpp @@ -0,0 +1,75 @@ +#include "DepthFastClearHarness.hpp" +#include "VulkanTestDevice.hpp" +#include +#include +#include +#include + +namespace { + +using DepthFastClearHarness::Compile; +using DepthFastClearHarness::Covered; +using DepthFastClearHarness::Draw; +using DepthFastClearHarness::Height; +using DepthFastClearHarness::Require; +using DepthFastClearHarness::Shaders; +using DepthFastClearHarness::Surface; +using DepthFastClearHarness::Width; + +alignas(4096) std::array Depth{}; + +alignas(256) constexpr std::array ExportOnePointFive{0x7e0002f2, 0xf800100f, 0x00000000, 0x7e0202ff, 0x3fc00000, 0xf8001881, 0x00000001, 0xbf810000}; +alignas(256) constexpr std::array ExportMinusHalf{0x7e0002f2, 0xf800100f, 0x00000000, 0x7e0202ff, 0xbf000000, 0xf8001881, 0x00000001, 0xbf810000}; + +Shaders WithDepthExport(AgcDriver::VulkanDevice& device, const Shaders& plain, std::span code, float minimum, float maximum) { + Shaders shaders = plain; + const auto target = device.Target(); + ShaderRecompiler::ShaderPixelStageInfo pixel{}; + pixel.wave32 = true; + pixel.inputAddr = ShaderRecompiler::PixelInputBit(ShaderRecompiler::PixelInput::PositionX) | ShaderRecompiler::PixelInputBit(ShaderRecompiler::PixelInput::PositionY); + pixel.posX = true; + pixel.posY = true; + pixel.targetOutputMode[0] = 9; + pixel.targetExportMapping.fill(0xe4u); + pixel.depthExportEnable = true; + pixel.depthExportMin = minimum; + pixel.depthExportMax = maximum; + std::vector pixelUserData(4, 0u); + const std::array pixelMemory{{{reinterpret_cast(code.data()), std::as_bytes(code)}}}; + ShaderRecompiler::RecompileRequest fragment{ + {ShaderRecompiler::ShaderStage::Fragment, reinterpret_cast(code.data()), code, 0, {}}, + {32, 0, pixelUserData, std::nullopt, pixel, std::nullopt, pixelMemory}, + target, + PixelPushLayout(plain.vertexPush, target) + }; + fragment.useCache = false; + shaders.pixel = ShaderRecompiler::Recompile(fragment); + return shaders; +} + +} + +int main() { + try { + const auto device = OpenVulkanTestDevice(); + if (!device) return VulkanTestSkipped; + const auto plain = Compile(*device); + const Surface surface{reinterpret_cast(Depth.data()), 0, 0, false, VK_FORMAT_D32_SFLOAT}; + constexpr float low = 0.25f; + constexpr float high = 0.75f; + const auto high15 = WithDepthExport(*device, plain, ExportOnePointFive, low, high); + Require(Draw(*device, high15, surface, {.depthTest = true, .depthWrite = true, .depthCompare = VK_COMPARE_OP_ALWAYS}) == Covered, "the depth-exporting draw did not cover the target"); + Require(Draw(*device, plain, surface, {.depthTest = true, .depthWrite = false, .depthCompare = VK_COMPARE_OP_GREATER, .minDepth = 0.9f, .maxDepth = 0.9f}) == Covered, "an exported depth of 1.5 was not clamped to ZMAX 0.75"); + const auto minus = WithDepthExport(*device, plain, ExportMinusHalf, low, high); + Require(Draw(*device, minus, surface, {.depthTest = true, .depthWrite = true, .depthCompare = VK_COMPARE_OP_ALWAYS}) == Covered, "the second depth-exporting draw did not cover the target"); + Require(Draw(*device, plain, surface, {.depthTest = true, .depthWrite = false, .depthCompare = VK_COMPARE_OP_LESS, .minDepth = 0.1f, .maxDepth = 0.1f}) == Covered, "an exported depth of -0.5 was not clamped to ZMIN 0.25"); + const auto open = WithDepthExport(*device, plain, ExportOnePointFive, -std::numeric_limits::infinity(), std::numeric_limits::infinity()); + Require(Draw(*device, open, surface, {.depthTest = true, .depthWrite = true, .depthCompare = VK_COMPARE_OP_ALWAYS}) == Covered, "the unclamped depth-exporting draw did not cover the target"); + Require(Draw(*device, plain, surface, {.depthTest = true, .depthWrite = false, .depthCompare = VK_COMPARE_OP_GREATER, .minDepth = 0.9f, .maxDepth = 0.9f}) == 0u, "an unclamped depth export (DISABLE_VIEWPORT_CLAMP) was clamped"); + std::puts("depth export clamp tests passed"); + return 0; + } catch (const std::exception& error) { + std::cerr << error.what() << '\n'; + return 1; + } +} diff --git a/core/libs/prx/libSceAgcDriver/tests/execution/StencilReplay.cpp b/core/libs/prx/libSceAgcDriver/tests/execution/StencilReplay.cpp index 14d571cf481c..c2b8beaf477d 100644 --- a/core/libs/prx/libSceAgcDriver/tests/execution/StencilReplay.cpp +++ b/core/libs/prx/libSceAgcDriver/tests/execution/StencilReplay.cpp @@ -83,7 +83,7 @@ std::array BufferDescriptor(const void* data, std::uint32_t st ShaderRecompiler::ShaderPixelStageInfo PixelInfo(std::uint32_t shaderControl) { const AgcDriver::Registers context{ - {0x1b3, 0x700u}, {0x1b4, 0x700u}, {0x1b6, 0u}, {0x1c5, 9u}, {0x203, shaderControl}, + {0x003, 0u}, {0x0b4, 0u}, {0x0b5, 0x3f800000u}, {0x1b3, 0x700u}, {0x1b4, 0x700u}, {0x1b6, 0u}, {0x1c5, 9u}, {0x203, shaderControl}, }; return AgcDriver::Graphics::DecodePixelStageInfo(context, {0xe4u, 0xe4u, 0xe4u, 0xe4u, 0xe4u, 0xe4u, 0xe4u, 0xe4u}); } diff --git a/core/shader/recompiler/CacheKey.hpp b/core/shader/recompiler/CacheKey.hpp index 5d8cbad14899..488666299c23 100644 --- a/core/shader/recompiler/CacheKey.hpp +++ b/core/shader/recompiler/CacheKey.hpp @@ -210,6 +210,10 @@ class RecompileCacheKey { append(key, value.linearCentroid); append(key, value.pixelKillEnable); append(key, value.depthExportEnable); + if (value.depthExportEnable) { + append(key, std::bit_cast(value.depthExportMin)); + append(key, std::bit_cast(value.depthExportMax)); + } append(key, value.sampleMaskExportEnable); append(key, value.earlyZ); append(key, value.executeOnNoop); diff --git a/core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp b/core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp index f68b0b021e87..1dbf48e7359c 100644 --- a/core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp +++ b/core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp @@ -363,6 +363,10 @@ void writePixelInfo(Writer& writer, const ShaderPixelStageInfo& info) { for (const std::uint32_t word : info.targetMerge.descriptor) writer.WriteU32(word); writer.WriteBool(info.targetMerge.depthStencilWrites); writer.WriteBool(info.targetMerge.depthStencilTests); + if (info.depthExportEnable) { + writer.WriteU32(std::bit_cast(info.depthExportMin)); + writer.WriteU32(std::bit_cast(info.depthExportMax)); + } } ShaderPixelStageInfo readPixelInfo(Reader& reader, std::uint32_t version) { @@ -449,6 +453,10 @@ ShaderPixelStageInfo readPixelInfo(Reader& reader, std::uint32_t version) { info.targetMerge.depthStencilWrites = reader.ReadBool(); info.targetMerge.depthStencilTests = reader.ReadBool(); } + if (version >= 49u && info.depthExportEnable) { + info.depthExportMin = std::bit_cast(reader.ReadU32()); + info.depthExportMax = std::bit_cast(reader.ReadU32()); + } if (version < 5u) { const auto input = [](PixelInput value, bool present) { return present ? PixelInputBit(value) : 0u; }; info.inputAddr = input(PixelInput::PerspectiveSample, info.hasPerspectiveCenterVgpr && inputAddrOrCenterVgpr == 2u) | input(PixelInput::PerspectiveCenter, info.hasPerspectiveCenterVgpr) | @@ -853,7 +861,7 @@ std::string RequestSerializer::Serialize(const RecompileRequest& request) const std::string buffer; Writer writer(buffer); writer.WriteU32(0x41505335u); - writer.WriteU32(48u); + writer.WriteU32(49u); writeShaderBinary(writer, request.shader); writeGuestContext(writer, request.context); writeSpirvTarget(writer, request.target); @@ -903,7 +911,7 @@ DeserializedRequest RequestSerializer::Deserialize(std::string_view text) const Reader reader(decoded); if (reader.ReadU32() != 0x41505335u) throw std::runtime_error("invalid recompile request signature"); const auto version = reader.ReadU32(); - if (version < 1u || version > 48u) throw std::runtime_error("unsupported recompile request serialization version"); + if (version < 1u || version > 49u) throw std::runtime_error("unsupported recompile request serialization version"); DeserializedRequest result{}; result.request.shader = readShaderBinary(reader, result.shaderCode, result.shaderHeader); result.request.context = readGuestContext(reader, result, version); diff --git a/core/shader/recompiler/Optimization/include/Optimization/ShaderStageInputInfo.hpp b/core/shader/recompiler/Optimization/include/Optimization/ShaderStageInputInfo.hpp index d25bcc11438a..b1c83952ae56 100644 --- a/core/shader/recompiler/Optimization/include/Optimization/ShaderStageInputInfo.hpp +++ b/core/shader/recompiler/Optimization/include/Optimization/ShaderStageInputInfo.hpp @@ -186,6 +186,8 @@ struct ShaderPixelInputInfo { bool psNoPerspective = false; bool psPixelKillEnable = false; bool psDepthExportEnable = false; + float psDepthExportMin = 0.0f; + float psDepthExportMax = 1.0f; bool psSampleMaskExportEnable = false; bool psStencilRefExportEnable = false; bool psStencilOperationValueExport = false; diff --git a/core/shader/recompiler/Recompiler.hpp b/core/shader/recompiler/Recompiler.hpp index 51a0b52768d4..d7b1938cce1e 100644 --- a/core/shader/recompiler/Recompiler.hpp +++ b/core/shader/recompiler/Recompiler.hpp @@ -196,6 +196,8 @@ struct ShaderPixelStageInfo { bool linearCentroid; bool pixelKillEnable; bool depthExportEnable; + float depthExportMin = 0.0f; + float depthExportMax = 1.0f; bool sampleMaskExportEnable; bool earlyZ; bool executeOnNoop; diff --git a/core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp b/core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp index eb38969f9a8d..1f7cf2a2bd78 100644 --- a/core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp +++ b/core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp @@ -4,6 +4,7 @@ #include "SpirvBackend/SpirvEmitterInstructions.hpp" #include "SpirvBackend/SpirvFlowEmitter.hpp" #include "SpirvBackend/SpirvBda.hpp" +#include #include #include #include "PipelineSpecialization.hpp" @@ -2025,7 +2026,14 @@ void EmitSetAttribute(SpirvValueEmitContext& ctx, const IrValue& inst) { const auto raw = ExportRawComponent(ctx, data, 0); const auto f32 = state.module.AllocateId(); state.module.AddFunction(spv::OpBitcast, TypeF32(state), f32, raw); - state.module.AddFunction(spv::OpStore, state.depthVariable, f32); + const auto& pixel = *state.inputInfo.pixel; + if (std::isinf(pixel.psDepthExportMin) && std::isinf(pixel.psDepthExportMax)) { + state.module.AddFunction(spv::OpStore, state.depthVariable, f32); + } else { + const auto clamped = state.module.AllocateId(); + state.module.AddFunction(spv::OpExtInst, TypeF32(state), clamped, GlslStd450(state), GLSLstd450NClamp, f32, ConstantF32Value(state, pixel.psDepthExportMin), ConstantF32Value(state, pixel.psDepthExportMax)); + state.module.AddFunction(spv::OpStore, state.depthVariable, clamped); + } } if ((exp.en & 2u) != 0u && state.stencilRefVariable != 0u) { auto raw = ExportRawComponent(ctx, data, 1); diff --git a/core/shader/recompiler/Translation/src/ShaderInputInfoBuilder.cpp b/core/shader/recompiler/Translation/src/ShaderInputInfoBuilder.cpp index b35a4a79dfcb..08a22fba04f3 100644 --- a/core/shader/recompiler/Translation/src/ShaderInputInfoBuilder.cpp +++ b/core/shader/recompiler/Translation/src/ShaderInputInfoBuilder.cpp @@ -151,6 +151,8 @@ ShaderStageInputInfo BuildShaderStageInputInfo(ShaderStageKind stage, const Gues pixelStorage.psNoPerspective = pixel.noPerspective; pixelStorage.psPixelKillEnable = pixel.pixelKillEnable; pixelStorage.psDepthExportEnable = pixel.depthExportEnable; + pixelStorage.psDepthExportMin = pixel.depthExportMin; + pixelStorage.psDepthExportMax = pixel.depthExportMax; pixelStorage.psSampleMaskExportEnable = pixel.sampleMaskExportEnable; pixelStorage.psStencilRefExportEnable = pixel.stencilRefExportEnable; pixelStorage.psStencilOperationValueExport = pixel.stencilOperationValueExport; diff --git a/core/shader/recompiler/tests/RequestSerializerTests.cpp b/core/shader/recompiler/tests/RequestSerializerTests.cpp index ee4d5d7d72ac..dc1ca02aae56 100644 --- a/core/shader/recompiler/tests/RequestSerializerTests.cpp +++ b/core/shader/recompiler/tests/RequestSerializerTests.cpp @@ -298,7 +298,7 @@ int main() { Require(request.graphics->draw.indexAddress == 0xabcdef3400u && request.graphics->draw.indexCount == 57u && request.graphics->draw.indexElementBytes == 4u && request.graphics->draw.instanceCount == 9u); Require(request.target.float16DenormPreserve == preserve); auto upgraded = bytes; - upgraded[4] = 48u; + upgraded[4] = 49u; InsertMeshBarycentricFlag(upgraded); if (fixture.pixel) upgraded.insert(upgraded.begin() + 258u, {0u, 0u, 0u}); if (fixture.pixel) InsertPixelDefaultsAfterFrontFace(upgraded); @@ -342,7 +342,7 @@ int main() { layerRejected = std::string_view(error.what()) == "RequestSerializer: truncated data"; } Require(layerRejected); - layered[4] = 48u; + layered[4] = 49u; InsertMeshBarycentricFlag(layered); layered.insert(layered.begin() + 259u, {0u, 0u}); InsertPixelDefaultsAfterFrontFace(layered); @@ -372,7 +372,7 @@ int main() { Require(replay.request.context.pixel->rasterPrimitive == ShaderRecompiler::RasterPrimitive::Rectangle); Require(replay.request.context.vertex->paClVsOutCntl == 0x00050a05u); Require(replay.request.target.float16DenormPreserve == preserve); - bytes[4] = 48u; + bytes[4] = 49u; InsertMeshBarycentricFlag(bytes); bytes.insert(bytes.begin() + 259u, {0u, 0u}); InsertPixelDefaultsAfterFrontFace(bytes); @@ -506,7 +506,7 @@ int main() { if (fixture.pixel) main38.insert(main38.begin() + 259u, {0u, 0u}); if (fixture.pixel) InsertPixelDefaultsAfterFrontFace(main38, false, false); auto upgraded = main38; - upgraded[4] = 48u; + upgraded[4] = 49u; if (fixture.pixel) { const auto tail = PixelTailDefaults(true, true); upgraded.insert(upgraded.begin() + 317u, tail.begin(), tail.end()); @@ -533,8 +533,10 @@ int main() { pointed.context.vertex->pointSize = 3.0f; pointed.context.vertex->pointSizeMin = 1.0f; pointed.context.vertex->pointSizeMax = 8.0f; - auto version48 = DecodeBase64(serializer.Serialize(pointed)); - Require(version48.size() > 16u && version48[4] == 48u); + auto version49 = DecodeBase64(serializer.Serialize(pointed)); + Require(version49.size() > 16u && version49[4] == 49u); + auto version48 = version49; + version48[4] = 48u; auto version46 = version48; version46.pop_back(); version46[4] = 46u; @@ -551,7 +553,7 @@ int main() { version43.pop_back(); version43[4] = 43u; const auto replay43 = serializer.Deserialize(EncodeBase64(version43)); - Require(serializer.Serialize(replay43.request) == EncodeBase64(version48)); + Require(serializer.Serialize(replay43.request) == EncodeBase64(version49)); Require(replay43.request.graphics->tessellation->mergedHull == merged && replay43.request.context.vertex->pointList && replay43.request.context.vertex->pointSize == 3.0f && replay43.request.context.vertex->pointSizeMin == 1.0f && replay43.request.context.vertex->pointSizeMax == 8.0f); auto version42 = version43; version42.resize(version42.size() - 13u); @@ -578,7 +580,7 @@ int main() { const auto replay25 = serializer.Deserialize(EncodeBase64(main25)); Require(!fixture.pixel || (replay25.request.context.pixel->layerExported == layer && replay25.request.context.pixel->ditheredAlphaToCoverage == dither && replay25.request.context.pixel->reversedBlend == 0u)); Require(replay25.request.target.float16DenormPreserve == preserve && (!fixture.tessellation || replay25.request.graphics->tessellation->primitiveGroupSize == 37u)); - main25[4] = 48u; + main25[4] = 49u; InsertMeshBarycentricFlag(main25); if (fixture.pixel) { main25.insert(main25.begin() + 260u, 0u); @@ -607,7 +609,7 @@ int main() { const auto replay = serializer.Deserialize(encoded); Require(replay.request.target.float16DenormPreserve == preserve && replay.request.target.float32FlushToZero == !preserve && replay.request.target.float32DenormPreserve == preserve && replay.request.target.largePixelFunctionLdsBuffer == !preserve && replay.request.target.pixelFunctionStorageDwords == request.target.pixelFunctionStorageDwords); auto bytes = DecodeBase64(encoded); - Require(bytes.size() >= 8u && bytes[4] == 48u && bytes[5] == 0u && bytes[6] == 0u && bytes[7] == 0u); + Require(bytes.size() >= 8u && bytes[4] == 49u && bytes[5] == 0u && bytes[6] == 0u && bytes[7] == 0u); auto version40 = bytes; version40.resize(version40.size() - sizeof(std::uint32_t)); version40.pop_back(); @@ -618,7 +620,7 @@ int main() { const auto replay40 = serializer.Deserialize(EncodeBase64(version40)); Require(!replay40.request.target.float32DenormPreserve && replay40.request.target.float32FlushToZero == !preserve); auto future = bytes; - future[4] = 49u; + future[4] = 50u; bool futureRejected = false; try { static_cast(serializer.Deserialize(EncodeBase64(future))); @@ -748,7 +750,7 @@ int main() { Require(!replayLegacy.request.context.vertex->pointList && replayLegacy.request.context.vertex->pointSize == 1.0f); Require(replayLegacy.request.context.vertex->pointSizeMin == 0.0f && replayLegacy.request.context.vertex->pointSizeMax == 0.0f); const auto upgradedLegacy = DecodeBase64(serializer.Serialize(replayLegacy.request)); - Require(upgradedLegacy[4] == 48u && upgradedLegacy.size() == legacy.size() + (version >= 36u ? 21u : version >= 35u ? 22u : 27u)); + Require(upgradedLegacy[4] == 49u && upgradedLegacy.size() == legacy.size() + (version >= 36u ? 21u : version >= 35u ? 22u : 27u)); } } diff --git a/docs/dev/debt/libSceAgcDriver.md b/docs/dev/debt/libSceAgcDriver.md index 5bc99b85723d..b0dcdfef3413 100644 --- a/docs/dev/debt/libSceAgcDriver.md +++ b/docs/dev/debt/libSceAgcDriver.md @@ -274,6 +274,7 @@ - [Multisample image upload](../../../core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleUpload.cpp) does not model guest layouts, native ownership or CMASK/FMASK/DCC publication; console equivalence and large-title initialization costs remain unmeasured. It stores 1/2/4/8/16-byte elements from a storage buffer into an unsigned 2D multisample array view in layer/y/x/fragment order. It requires enabled multisample storage images and formatless image writes, 2/4/8 fragments and valid aligned buffer and dispatch ranges. The caller supplies the matching storage view in GENERAL and owns barriers, completion and resource lifetimes. - [Thick SW_4KB_S_X volumes](../../../core/libs/prx/libSceAgcDriver/Graphics/src/TextureTiling.cpp) use AMD addrlib's GFX10 non-RB+ 16-pipe `GFX10_SW_4K_S3_X_PATINFO` equations for 1, 2, 4, 8 and 16-byte elements, including packed mip tails. The layout follows [AMD PAL c5e80007](https://github.com/GPUOpen-Drivers/pal/blob/c5e800072a32f68b6ccc4422936d96167c6e0728/src/core/imported/addrlib/src/gfx10/gfx10addrlib.cpp); it has not been measured on console hardware. Other thick swizzle modes outside the supported families still throw. Mipmapped 3D color targets remain refused by the color-register decoder. - [Viewport depth range remap](../../../core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp) (libSceAgcDriver) - mesh draws with a viewport depth range outside [0, 1] still throw on devices without `VK_EXT_depth_range_unrestricted`, including combined tessellation and geometry draws. The vertex and tessellation fallback clips `PA_SC_VPORT_ZMIN/ZMAX` to [0, 1], so a negative depth on a float target is stored as 0: Minecraft PPSA17221 requests [-1, 1], which a later test or read at 0 can distinguish. The fallback needs depth clamping and two free components out of the eight combined clip/cull distances. Console clamp/bias ordering and clamp ranges narrower than the viewport transform remain unmeasured. +- [Exported depth clamp](../../../core/libs/prx/libSceAgcDriver/Graphics/src/ShaderInputState.cpp) (libSceAgcDriver) - only the depth range of viewport 0 (`PA_SC_VPORT_ZMIN_0` and `PA_SC_VPORT_ZMAX_0`) is read, so a pixel shader that exports depth in a draw that selects another viewport is clamped to viewport 0's range, not to its own. `DB_RENDER_OVERRIDE.DISABLE_VIEWPORT_CLAMP` still stores the exported value as it is. - [Benchmark rewrite failure test off Windows](../../../core/libs/prx/libSceAgcDriver/tests/PerformanceTrace.cpp) (libSceAgcDriver) - `ReplaceGzipFile` checks that a write failing at `.tmp` keeps the previous `aps5-bench.json.gz` only on non-Windows builds: the `std::ios_base::failure` thrown inside the MinGW ofstream did not unwind to the test's catch, so Windows CI covers only the failed move. - [Sampled array windows](../../../core/libs/prx/libSceAgcDriver/Graphics/src/TextureTiling.cpp) (libSceAgcDriver) - a sampled 2D array, 1D array or cube view past slice 0 is built from its viewed slices only (`ViewedArrayWindow`). The window needs a thin surface without DCC metadata, or with keys that resolve over the whole surface to Uncompressed (the window then drops the metadata; keys are rescanned at each lookup). For a 64 KiB XOR swizzle it starts at the last slice at or before the base whose swizzle slice bits are zero (R_X 1-byte and Z_X 4-byte: a multiple of 16); when that is slice 0 the view builds slices 0 to its last slice. A window and a whole-array view of the same surface are separate images over overlapping memory, kept coherent by the existing overlap rules, at the cost of both. PPSA26344 samples a cube array at slices 4299..7232 at 1467 MiB instead of about 3.8 GB; PPSA01341 samples slice 636 of a DCC 2D array at 52 MiB instead of 2.5 GiB.