Files
mandy/runtime/test/shaders/vs_base_ids.asm
S1m0ne1997 07bd05fa95 Translator: zero-based VS v0/v3 (VertexIndex - BaseVertex, InstanceIndex - BaseInstance); VS is legacy, not NGG (SHADER-33)
Corpus (scripts/vs_input_survey.py, all 2,236 VS): no exp prim, no s_sendmsg, no v_mbcnt, every
VS exports pos0/param, so the console runs them as legacy hardware VS. Their input VGPRs are
Mesa's GFX10 legacy layout (radv_shader_args.c, declare_vs_input_vgprs, not is_ngg): v0 vertex
id, v1 unused, v2 primitive id, v3 instance id; no VS reads v1/v2 on entry, 788 start with the
fetch call and read attributes from v4.

Those ids are zero-based on the hardware (ac_nir_lower_intrinsics_to_args.c: vertex_id is
load_vertex_id_zero_base, instance_id is load_instance_id; the bases come in SGPRs), while
Vulkan's VertexIndex/InstanceIndex include firstVertex|vertexOffset/firstInstance. The
translator now seeds v0 = VertexIndex - BaseVertex and v3 = InstanceIndex - BaseInstance
(DrawParameters; feature shaderDrawParameters in every VS's metadata).

GPU test vs_base_ids.asm, drawn with VKH_DRAW=16,7 (new vk_harness option): 0x101 on every
pixel, where before it was 0x7111. Run by check.py and run_gpu_tests.py. vk_harness,
vk_pipeline_check, vk_bindless_test, vk_texture_test and the runtime's Vulkan device enable
shaderDrawParameters. design.md's "Inputs and outputs" row replaces the "unverified" note.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 11:59:04 +01:00

25 lines
1.3 KiB
NASM

; Vertex shader for the base-vertex / base-instance test. On AMD hardware the VS input VGPRs are zero-based: v0 is
; the vertex id without the draw's first vertex (Mesa: ac.vertex_id = load_vertex_id_zero_base, the base comes in
; the base_vertex SGPR), and v3 the instance id without its first instance (ac.instance_id = load_instance_id, the
; base in start_instance). Vulkan's VertexIndex / InstanceIndex include firstVertex / firstInstance.
; Same full-screen triangle as vs_ids (from v0's low bits), param0 = (u, v, 0, 1), and param1.x =
; 0x101 + v0 + 0x1000 * v3 as raw bits, so ps_flat (attr1.x from the provoking vertex) shows both ids.
; Run: VKH_DRAW=16,7 vk_harness vs_base_ids.spv ps_flat.spv out.raw
; -> mrt0 bits = 0x101, 0x102 on every pixel (vertex 0 of instance 0); 0x7111 means firstVertex/firstInstance
; leaked into v0 / v3. With VKH_DRAW unset (0,0) both read 0x101, as vs_ids.
v_lshlrev_b32_e32 v8, 12, v3
v_lshlrev_b32_e32 v1, 1, v0
v_and_b32_e32 v1, 2, v1
v_and_b32_e32 v2, 2, v0
v_cvt_f32_u32_e32 v1, v1
v_cvt_f32_u32_e32 v2, v2
v_fma_f32 v3, v1, 2.0, -1.0
v_fma_f32 v4, v2, 2.0, -1.0
v_mov_b32_e32 v5, 0
v_mov_b32_e32 v6, 1.0
exp pos0 v3, v4, v5, v6 done
exp param0 v1, v2, v5, v6
v_add3_u32 v7, v0, v8, 0x101
exp param1 v7, v7, v7, v7
s_endpgm