fix(shader): lower MIMG offset/clamp/bias/LOD sample variants #15
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/uiliannn--VItoriaBr!15
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/15/head"
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?
@mathcx on GitHub · 2026-11-25 11:08 UTC · original
mathcx:fix/mimg-offset-variants→main· +1175 −797 · 2 files · 1 commits · merged 2026-11-25 12:50 UTC1. Problema / Contexto
Conforme levantado na Issue #4 (paridade parcial com
2471a62), o decodificador GFX10 e o cálculo de registradores de endereço (image_addr_dwordsemcrates/victory-shader/src/gfx10/fields.rs) já reconheciam todas as variantes de amostragemMIMGcom texel offset imediato/programável (_o), porém o emissor DXIL apresentava quatro lacunas técnicas:_oausentes na tabela de despacho:image_sample_cl_o,image_sample_b_o,image_sample_b_cl_o,image_sample_l_o,image_sample_d_o,image_sample_d_cl_o,image_sample_c_o,image_sample_c_cl_oeimage_sample_c_lz_ocaíam emErr(name)por não estarem listadas nomatchdeLower::image.has_clna presença de_o:let has_cl = name.ends_with("_cl")avaliava comofalseem instruções cujo sufixo final é_cl_o(image_sample_cl_o,image_sample_b_cl_o,image_sample_d_cl_o,image_sample_c_cl_o), descartando silenciosamente o operando de LOD clamp e passandoundefpara o DXIL.image_sample_l_o: O ramoop == 62verificava apenasname == "image_sample_l", fazendo com queimage_sample_l_oforçasse nível0.0(comoimage_sample_lz_o) em vez de ler o LOD explícito empacotado após as coordenadas.offsettruncada coma16e restrita a 2D /op == 60: Na ISA RDNA2/GFX10, a palavra de offset (vaddr[0]) é sempre um registradoru32completo de 32 bits com campos de 6 bits com sinal em0..=5(x),8..=13(y) e16..=21(z), mesmo quandoa16 = 1. O uso anterior deaddr_val(self, 0)mascarava os 16 bits superiores com0xFFFFquandoa16 = true(zerando o offsetzem texturas 3D e impedindoint_value(w)de reconhecer constantes diretas), além de converter offsets constantes em imediatos-8..=7apenas no ramoop == 60de pixel shaders.Adicionalmente,
crates/victory-shader/src/emit/lower.rsencontrava-se muito próximo do teto de512 KiBimposto porcargo xtask policy.2. Alterações Técnicas
crates/victory-shader/src/emit/lower.rsecrates/victory-shader/src/emit/image.rs:Lower::imageeLower::cube_directionpara o submódulo filho#[path = "image.rs"] mod image;(seguindo o padrão já adotado pordot.rseintersect.rs), reduzindolower.rsem ~32 KiB e mantendo ampla margem abaixo do limite de 512 KiB da política do repositório.has_clparaname.split('_').any(|t| t == "cl"), cobrindo tanto*_clquanto*_cl_o.image_sample_cl_o(op = 60),image_sample_l_o(op = 62),image_sample_b_o/image_sample_b_cl_o(op = 61),image_sample_d_o/image_sample_d_cl_o(op = 63),image_sample_c_lz_o(op = 65) eimage_sample_c_o/image_sample_c_cl_o(op = 64em pixel shaders).op == 62para ler o operando de LOD explícito emmatches!(name, "image_sample_l" | "image_sample_l_o").addr_u32(self, 0)para até 3 dimensões ([(0, 26), (1, 18), (2, 10)]), materializando constantes imediatas em-8..=7diretamente para todas as operações de amostragem DXIL (60..=65) e constantes de 6 bits paratextureGather(73), com fallback em deslocamento aritmético para offsets dinâmicos.emit::lower::image::testscobrindo todas as novas variantes em Pixel e Compute shaders (coma16 = falseea16 = true), preservação do offsetzem texturas 3D coma16, validação de containers viadxil.dlle verificação do consumo exato dos registradores VGPR debias,z-compare,lodeclamp.3. Validação e Testes
rustfmt --edition 2024 crates/victory-shader/src/emit/image.rs: aprovado sem alterações pendentes.cargo clippy -p victory-shader --all-targets -- -D warnings: aprovado com zero avisos.cargo test -p victory-shader: 225 testes aprovados, 0 falhas (incluindo os novos testes unitários deMIMGvalidados comdxil.dlle testes de execução em GPU/WARP).cargo xtask policy: aprovado (asset policy: 176 files ok).cargo run --release -p victory -- translate --validate --pipelines: validado sem regressões (25.744 / 25.758shaders DXIL emitidos,25.673validados pelodxil.dlle25.345PSOs aceitos pela GPU D3D12 local).1. Problem / Context
As noted in Issue #4 (partial parity with
2471a62), the GFX10 decoder and address register sizing (image_addr_dwordsincrates/victory-shader/src/gfx10/fields.rs) already accounted forMIMGsampling opcodes carrying a texel offset word (_o), but DXIL lowering still had four technical gaps:_ovariants in the dispatch table:image_sample_cl_o,image_sample_b_o,image_sample_b_cl_o,image_sample_l_o,image_sample_d_o,image_sample_d_cl_o,image_sample_c_o,image_sample_c_cl_o, andimage_sample_c_lz_ofell through toErr(name)inLower::image.has_cldetection when combined with_o:let has_cl = name.ends_with("_cl")evaluated tofalsefor*_cl_oopcodes (image_sample_cl_o,image_sample_b_cl_o,image_sample_d_cl_o,image_sample_c_cl_o), silently dropping the LOD clamp operand and passingundefto DXIL.image_sample_l_o: Theop == 62arm checkedname == "image_sample_l"only, causingimage_sample_l_oto sample mip level0.0(likeimage_sample_lz_o) instead of reading the explicit LOD packed after the coordinates.offsetread undera16and narrow constant folding: In the RDNA2/GFX10 ISA, the_otexel offset register (vaddr[0]) is always a full 32-bitu32word holding signed 6-bit fields in bits0..=5(x),8..=13(y), and16..=21(z), even whena16 = 1. Callingaddr_val(self, 0)masked the upper 16 bits with0xFFFFwhena16 = true(zeroing the 3Dzoffset and preventingint_value(w)from matching constants directly), while immediate-8..=7offset extraction was only performed in the pixel-shaderop == 60arm.Additionally,
crates/victory-shader/src/emit/lower.rswas right against the512 KiBfile-size ceiling enforced bycargo xtask policy.2. Technical Changes
crates/victory-shader/src/emit/lower.rs&crates/victory-shader/src/emit/image.rs:Lower::imageandLower::cube_directioninto a child module#[path = "image.rs"] mod image;(matching the existingdot.rsandintersect.rslayout), shrinkinglower.rsby ~32 KiB well under the 512 KiB repository policy limit.has_cltoname.split('_').any(|t| t == "cl")so both*_cland*_cl_oopcodes read their LOD clamp operand.image_sample_cl_o(op = 60),image_sample_l_o(op = 62),image_sample_b_o/image_sample_b_cl_o(op = 61),image_sample_d_o/image_sample_d_cl_o(op = 63),image_sample_c_lz_o(op = 65), and pixel-stageimage_sample_c_o/image_sample_c_cl_o(op = 64).op == 62arm to read the explicit LOD operand formatches!(name, "image_sample_l" | "image_sample_l_o").addr_u32(self, 0)across up to 3 spatial dimensions ([(0, 26), (1, 18), (2, 10)]), emitting immediatei32constants directly across all DXIL sampling ops (60..=65) when within-8..=7(and all 6-bit constants fortextureGatherop = 73), falling back to arithmetic shifts for dynamic offsets.emit::lower::image::testsverifying lowering anddxil.dllvalidation across Pixel and Compute stages (a16 = falseanda16 = true), 3Da16z-offset preservation, and exact VGPR consumption forbias,z-compare,lod, andclamp.3. Verification & Testing
rustfmt --edition 2024 crates/victory-shader/src/emit/image.rs: clean.cargo clippy -p victory-shader --all-targets -- -D warnings: clean with zero warnings.cargo test -p victory-shader: 225 passed, 0 failed (including the newdxil.dll-validatedMIMGtests and GPU/WARP execution tests).cargo xtask policy: passed (asset policy: 176 files ok).cargo run --release -p victory -- translate --validate --pipelines: verified zero regressions (25,744 / 25,758DXIL shaders emitted,25,673validated bydxil.dll, and25,345host D3D12 PSOs created).