feat(agc): select viewports from vertex and mesh viewport index exports #19373
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/19373"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by c1b3r-p3d1a on 2026-11-13T06:53:32Z.
What
PA_CL_VS_OUT_CNTL.USE_VTX_VIEWPORT_INDX(bit 19) was ignored with a warning, so every draw landed in viewport 0. With this change, vertex and mesh draws select one of 16 viewports per vertex:State.cpp): when bit 19 is set, viewports 1 to 15 are read fromPA_CL_VPORT_XSCALE_i..ZOFFSET_i(0x10f + 6i) with the same collapsed/usable rules as viewport 0. Their scissors are the screen, window and generic scissors intersected withPA_SC_VPORT_SCISSOR_i(0x94 + 2i) whenPA_SC_MODE_CNTL_0.VPORT_SCISSOR_ENABLEis set. A missing, non-finite or reserved-bit viewport becomes an empty one that draws nothing; it does not throw, because titles leave unused slots unwritten. The draw's single scissor becomes the union, and depth-clear pinning, unused-depth normalisation and depth-bounds emulation apply to every viewport.ApplyViewportIndexrequires it). No index is out of range, so nothing is clamped.multiViewportis enabled whenmaxViewports >= 16. Pipelines takeviewportCount/scissorCountfrom the state (it is part of the pipeline key and the draw-register key), andvkCmdSetViewport/vkCmdSetScissorset all 16.State.hpp):DrawKeyRegisterscoversPA_SC_VPORT_SCISSOR_0..15(0x094, 0x20 words) andPA_CL_VPORT_*_0..15(0x10f, 0x60 words), so with the register draw key a draw that changes only one of viewports 1 to 15 misses the cache instead of reusing the old viewports.PipelineJournal.cpp):CanonicalPipelineStatekeeps the viewport count, the recipe codec writes it (a count over 15 does not decode), the journal format is 19 (main is at 18) and theStatesize guard is 1008. Viewports and scissors are dynamic state, so the count is the only part of them a pipeline is built from.ViewportIndexthroughShaderViewportIndexLayerEXTwhen the device hasVK_EXT_shader_viewport_index_layer, otherwise through the SPIR-V 1.5 capability. The mesh shader writes a per-primitiveViewportIndexblock (PerPrimitiveEXT,MultiViewport) from the provoking vertex, the same wayLayeris handled. The index is bits 19:16 of the misc vector's z, as Mesa's radeonsi and RADV pack it on GFX9+; that extraction was already present.multiViewport, and vertex draws on devices withoutVK_EXT_shader_viewport_index_layer(which would otherwise fail shader validation), ignore the index and draw into viewport 0. A depth range outside [0, 1] on a multi-viewport draw throws withoutVK_EXT_depth_range_unrestricted, because the remap is single-viewport. OnlyPA_SC_VPORT_ZMIN/ZMAX_0is read. All of this is in the new debt entry.No open PR implements multi-viewport. #15548 and #17611 touch the same files but only use
ShaderViewportIndexLayerEXTfor layer output in their compute emulation.Overlap: #16752 rewrites the
vkCmdSetViewport/vkCmdSetScissorcalls inPipeline::Continue/ContinueBackFacesthatsetViewportsreplaces here, so whichever merges second has to movesetViewportsonto itsCommandState. I moved theDrawDecode.cppandShaderValidation.cpphunks off the lines #16025, #17022 and #17911 change; a merge simulation against them is clean.Tested
Head
b35560753eonmain92b550a7c4, no title. It merges cleanly withmaine22c5fb941.This head (draw key ranges and the
viewportIndexLayergate), Windows 11 (26300), AMD Radeon RX 7700 XT, AMD driver 32.0.32015.7029:agc_driver_viewport_indexnow records every register the multi-viewport decode reads through the register facade, requires that it read viewports 1 and 15 (0x96,0xb3,0x115,0x16e), thatDrawKeyCoversholds every one of them, and that0x16fis not covered. It also checks that a vertex draw on amultiViewportdevice withoutVK_EXT_shader_viewport_index_layerfalls back to viewport 0. The pin attests/Graphics.cpp:638still holds.viewportIndexLayercondition.VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_REQUIRE_VULKAN=1),agc_driver_viewport_indexpasses 3 of 3 runs with the vertex and mesh draws; each log shows the layer inserted and noVUID-messages.agc_driver|shadersuite (1268 tests), every test executable rebuilt: 1258 pass. Eight f16 checks (agc_driver_f16_conversion_float_mode,float16_misc,float16_modifiers,float16_rounding,fp16_overflow,ldexp_f16_inline_constants,sdwa_ldexp_f16,vop2_modifier_forms) andagc_driver_sample_order_grid_referencefail. They test shader arithmetic and sample positions this PR does not touch, and they failed the same way onmainin my earlier baseline run; I did not rerunmainfor this head.agc_driver_dumped_constant_capturefailed in the suite and in 1 of 9 runs alone (8 passed), so it is intermittent.Previous head
3f211973f3:agc_driver_viewport_index:PA_CL_VPORTregisters andPA_SC_VPORT_SCISSOR, the other slots are empty, 16 scissors and their union, stripping withoutmultiViewportor on tessellation, a draw keeping the index with fewer than 16 viewports is rejected, a reserved-bit scissor gives an empty viewport, and the depth remap rejection.PA_SC_VPORT_SCISSORregister, and reading the index from bit 17.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer ctest --test-dir build -R <pattern> -V, Khronos validation layer 1.4.363.1:agc_driver_viewport_index(vertex and mesh draws),agc_driver_mesh_provoking_layerandagc_driver_layered_array_color_drawpass. Each log showsInsert instance layer "VK_LAYER_KHRONOS_validation", there is nowas not found but was requested, and there are noVUID-messages.main, the two existing tests run the same way, also with noVUID-messages.agc_driver_viewport_indexpasses 3 of 3 runs, 0.4 s each.agc_driver|shadersuite (1267 tests): 1266 pass.agc_driver_sample_order_grid_referencefails, and fails the same way onmainon this GPU.agc_driver_graphicsfailed once under-j 8on a partially resident depth plane check and passes 3 of 3 runs alone.Statesize guard inPipelineJournal.cpp.agc_driver_viewport_indexpasses with the vertex draws; its mesh draws skip because llvmpipe has no mesh compiler for these programs.agc_driver_pipeline_journal,agc_pipeline_journal,agc_driver_graphicsandagc_driver_layered_array_color_drawpass;agc_driver_mesh_provoking_layerskips for the same reason. No validation layer on this Linux setup.python3 tools/check_conventions.py --base origin/mainpasses.tools/pr_overlap.pycould not confirm overlaps, so I compared the PRs that share files by hand (see What).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)