Skip to content
Merged
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
4 changes: 3 additions & 1 deletion core/libs/prx/libSceAgcDriver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1782,6 +1782,8 @@ if(BUILD_TESTING)
endif()
add_test(NAME agc_driver_undithered_alpha_to_coverage_state COMMAND agc_driver_graphics_tests --undithered-alpha-to-coverage-state)
add_test(NAME agc_driver_msaa_dcc_state COMMAND agc_driver_graphics_tests --multisample-dcc-state)
add_test(NAME agc_driver_unused_viewport_depth COMMAND agc_driver_graphics_tests --unused-viewport-depth)
set_tests_properties(agc_driver_unused_viewport_depth PROPERTIES TIMEOUT 30)
set_tests_properties(agc_driver_undithered_alpha_to_coverage_state PROPERTIES
ENVIRONMENT "ANYPS5_NO_SHADER_CACHE=1" TIMEOUT 30 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
add_test(NAME agc_driver_alpha_to_coverage_state COMMAND agc_driver_graphics_tests --alpha-to-coverage-state)
Expand All @@ -1800,7 +1802,7 @@ if(BUILD_TESTING)
set_tests_properties(agc_driver_dithered_alpha_to_coverage PROPERTIES
ENVIRONMENT "ANYPS5_NO_SHADER_CACHE=1" SKIP_RETURN_CODE 77 TIMEOUT 30 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
if(WIN32)
set_tests_properties(agc_driver_alpha_to_coverage_state agc_driver_undithered_alpha_to_coverage_state agc_driver_msaa_dcc_state PROPERTIES ENVIRONMENT_MODIFICATION
set_tests_properties(agc_driver_alpha_to_coverage_state agc_driver_undithered_alpha_to_coverage_state agc_driver_msaa_dcc_state agc_driver_unused_viewport_depth PROPERTIES ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
set_tests_properties(agc_driver_dithered_alpha_to_coverage ${multisampledDccClearTests} PROPERTIES ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@ void DecodeGraphicsPrograms(DrawDecode& decoded, const QueueState& queue, const
std::shared_ptr<DrawDecode> Driver::decodeDraw(const QueueState& queue, const Submission& submission, const Graphics::Context& context) {
auto product = std::make_shared<DrawDecode>();
product->state = Graphics::DecodeState(queue, VertexWorkgroupRequired(queue, *submission.shaders));
Graphics::ApplyDepthRemap(context, product->state);
DecodeGraphicsPrograms(*product, queue, *submission.shaders, false, true);
product->pixel = Graphics::DecodePixelStageInfo(queue.context, Graphics::ExportMappings(product->state), Graphics::PixelProgramSkipped(queue));
Graphics::NormalizeUnusedViewportDepth(product->state, product->pixel);
Graphics::ApplyDepthRemap(context, product->state);
product->pixel.targetExportPacking = Graphics::ExportPackings(product->state);
product->pixel.dualSourceBlend = product->state.dualSourceBlend;
product->pixel.reversedBlend = product->state.reversedBlend;
Expand Down
1 change: 1 addition & 0 deletions core/libs/prx/libSceAgcDriver/Graphics/include/State.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ inline constexpr std::uint32_t PositionExportLayoutBits = 0xffffu | (1u << 21u)
ShaderStages DecodeShaderStages(const QueueState& queue, bool vertexWorkgroup = false);
State DecodeState(const QueueState& queue, bool vertexWorkgroup = false);
void ApplyDepthRemap(const Context& context, State& state);
void NormalizeUnusedViewportDepth(State& state, const ShaderRecompiler::ShaderPixelStageInfo& pixel);
std::array<VkSampleLocationEXT, 32> SampleLocations(const State& state);
std::array<std::uint8_t, 32> PixelSampleLocations(const State& state, const ShaderRecompiler::ShaderPixelStageInfo& pixel);
VkExtent2D SampleLocationGrid(const State& state);
Expand Down
8 changes: 8 additions & 0 deletions core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
#include <string_view>

namespace AgcDriver::Graphics {

void NormalizeUnusedViewportDepth(State& state, const ShaderRecompiler::ShaderPixelStageInfo& pixel) {
if (state.depth || pixel.posZ) return;
if (!std::isfinite(state.viewport.minDepth) || !std::isfinite(state.viewport.maxDepth)) return;
state.viewport.minDepth = std::clamp(state.viewport.minDepth, 0.0f, 1.0f);
state.viewport.maxDepth = std::clamp(state.viewport.maxDepth, 0.0f, 1.0f);
}

namespace {

std::uint32_t read(const Registers& registers, std::uint32_t offset, RegisterBank bank = RegisterBank::Context) {
Expand Down
57 changes: 57 additions & 0 deletions core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4025,6 +4025,57 @@ void DepthRemapTests() {
Require(floating.depthRemap.mode == 1 && floating.viewport.minDepth == 0 && floating.viewport.maxDepth == 1 && floating.depthClamp, "a written float depth target refused clipped clamp bounds");
}

void UnusedViewportDepthTests() {
auto queue = makeState();
queue.context[0x204] = 0;
queue.context[0x113] = std::bit_cast<std::uint32_t>(1.0f);
queue.context[0x114] = 0;
const auto decoded = AgcDriver::Graphics::DecodeState(queue);
Require(!decoded.depth && decoded.viewport.minDepth == -1 && decoded.viewport.maxDepth == 1, "unused depth fixture changed");
AgcDriver::Graphics::Context context{};
context.limits.maxViewportDimensions[0] = context.limits.maxViewportDimensions[1] = 16384;
context.limits.viewportBoundsRange[0] = -32768;
context.limits.viewportBoundsRange[1] = 32767;
ShaderRecompiler::ShaderPixelStageInfo pixel{};
pixel.posX = pixel.posY = pixel.posW = true;
auto color = decoded;
AgcDriver::Graphics::NormalizeUnusedViewportDepth(color, pixel);
AgcDriver::Graphics::ValidateViewport(context, color.viewport);
Require(color.viewport.minDepth == 0 && color.viewport.maxDepth == 1, "unused viewport depth is not representable");
AgcDriver::Graphics::Context remapping{};
remapping.depthClamp = true;
const auto normalized = color;
AgcDriver::Graphics::ApplyDepthRemap(remapping, color);
Require(color.depthRemap.mode == 0 && color.viewport.minDepth == 0 && color.viewport.maxDepth == 1 && color.negativeOneToOne == normalized.negativeOneToOne && color.depthClamp == normalized.depthClamp, "the depth remap acted on a normalized viewport");
Require(color.viewport.x == decoded.viewport.x && color.viewport.y == decoded.viewport.y && color.viewport.width == decoded.viewport.width && color.viewport.height == decoded.viewport.height && color.negativeOneToOne == decoded.negativeOneToOne && color.depthClamp == decoded.depthClamp, "unused depth changed coverage or clipping");
auto observed = decoded;
pixel.posZ = true;
AgcDriver::Graphics::NormalizeUnusedViewportDepth(observed, pixel);
Require(observed.viewport.minDepth == -1, "fragment position depth was changed");
expectFailure([&] { AgcDriver::Graphics::ValidateViewport(context, observed.viewport); }, "viewport depth outside");
pixel.posZ = false;
auto attached = decoded;
attached.depth.emplace();
AgcDriver::Graphics::NormalizeUnusedViewportDepth(attached, pixel);
Require(attached.viewport.minDepth == -1, "attached depth was changed");
expectFailure([&] { AgcDriver::Graphics::ValidateViewport(context, attached.viewport); }, "viewport depth outside");
auto reversed = decoded;
reversed.viewport.minDepth = 2;
reversed.viewport.maxDepth = -1;
AgcDriver::Graphics::NormalizeUnusedViewportDepth(reversed, pixel);
AgcDriver::Graphics::ValidateViewport(context, reversed.viewport);
Require(reversed.viewport.minDepth == 1 && reversed.viewport.maxDepth == 0, "reversed unused depth is not representable");
auto bounded = decoded;
bounded.viewport.minDepth = 0.25f;
bounded.viewport.maxDepth = 0.75f;
AgcDriver::Graphics::NormalizeUnusedViewportDepth(bounded, pixel);
Require(bounded.viewport.minDepth == 0.25f && bounded.viewport.maxDepth == 0.75f, "an in-range viewport changed");
auto invalid = decoded;
invalid.viewport.minDepth = std::numeric_limits<float>::infinity();
AgcDriver::Graphics::NormalizeUnusedViewportDepth(invalid, pixel);
expectFailure([&] { AgcDriver::Graphics::ValidateViewport(context, invalid.viewport); }, "non-finite viewport");
}

void DepthClipTests() {
auto queue = makeState();
const auto direct = AgcDriver::Graphics::DecodeState(queue);
Expand Down Expand Up @@ -9581,6 +9632,11 @@ int main(int argc, char** argv) {
descriptorCacheTests();
return 0;
}
if (argc == 2 && std::string_view(argv[1]) == "--unused-viewport-depth") {
UnusedViewportDepthTests();
DepthClipTests();
return 0;
}
if (argc == 2 && std::string_view(argv[1]) == "--unused-stencil-reference") {
stencilReferenceUnusedTests();
return 0;
Expand Down Expand Up @@ -9740,6 +9796,7 @@ int main(int argc, char** argv) {
srgb8TargetTests();
DepthClipTests();
DepthRemapTests();
UnusedViewportDepthTests();
DepthStencilTests();
OneDimensionalColorTests();
htileDepthClearTests();
Expand Down
Loading