Repository navigation
Shaders: DXBC/DXIL parser and sampler/SP3 robustness fixes - #326
SkippySteve wants to merge 101 commits into
Conversation
…ry host constant_color() was used only by the two Windows-gated tests, so off Windows it was dead code and victory-shader's tests built with a warning. A new test parses the container it builds, checks the size field, the pixel-shader parts in order, the DXIL program header and that the digest is container::hash of the bytes after it. It needs neither D3D12 nor dxil.dll, so it runs on Linux.
Only constant_color uses them, so they live inside it (from #258). The helper itself stays on every host for the hermetic container test.
Container::parse accepted part offsets that point back into the 0x20-byte header or the part offset table, so offset 0 read "DXBC" as a part's FourCC and the digest as its size. Parts start after the offset table; reject anything earlier, and cover each Malformed branch of the parser with synthetic containers.
DxilProgram::parse has five rejections (program size, DXIL magic, bitcode bounds, LLVM magic, bitcode offset) and trims a part to the program's own size before reading the trailer, but the tests only reached the LLVM-magic rejection. Synthetic headers now hit each one by name, check that padding after the program is not taken for an Xbox trailer, and that an unknown program kind is kept rather than refused. Tests only; runs on any host.
The sampler word's LOD bias is a 14-bit signed 5.8 field, so it decodes to anything from -32 to 31.996. D3D12 takes a static sampler's MipLODBias only from -16 to 15.99 (D3D12_MIP_LOD_BIAS_MIN/MAX) and refuses a root signature holding one outside that, which would lose the whole pipeline. Clamp the decoded bias to that range; values inside it are unchanged. The test covers both clamped ends and in-range values on either side, and runs on every host.
The disassembler wrote every s_sendmsg as if it were a GS message, with a GS operation and a stream, so the mesh stage's allocation request read "sendmsg(MSG_GS_ALLOC_REQ, GS_OP_NOP, 0)", and only four of the GFX10 message ids had names. Now messages are spelled the way LLVM's AMDGPU assembler spells them: the operation only for GS, GS_DONE and SYSMSG, the stream only for a GS emit or cut, and every GFX10 message id named. An operand whose bits no field accounts for (an unknown id, a stream on a NOP, an operation on a message that has none, bits above the stream) stays as raw hex instead of losing those bits. The text is only used for shader dumps; translation does not read it.
7a6bfde to
aa28828
Compare
The far-jump resolver took any literal: one that is not a multiple of 4 sent decoding into the middle of a dword, reading words that straddle two instructions. Such a target is now an ISA error. Tests also pin the exact offset and reason of each way decode refuses code: odd size, branch or call out of range, a truncated instruction or literal, running off the end, a reserved FLAT segment, an unknown encoding, a branch into an instruction, and far jumps off the code.
The sampler word's minimum and maximum LOD fields are independent, so a maximum below the minimum decodes as is. A host sampler needs MaxLOD >= MinLOD (Vulkan VUID-VkSamplerCreateInfo-maxLod-01973 under vkd3d-proton). The maximum is now raised to the minimum, which gives the same clamp result; ordered pairs are unchanged.
A VGPR is named by a byte. With a count past 256, M0-relative access (v_movrels/v_movreld) listed registers up to the count and wrapped round to v0, aliasing the registers it reads and writes. native.rs already caps the count it reads; ir::build is public, so it now checks too.
A vertex shader's stage data names each attribute's first VGPR with a
byte, and io::raise added the channel to it as a u8. A base of 253 or
more with a high channel overflowed: a panic in debug builds, and in
release a wrap onto v0-v2, so an attribute channel claimed the vertex
or primitive id register. Such an input now fails with
Malformed("vertex attribute past v255").
Test vertex_attributes_stay_below_v256: bases that reach v255 exactly
are kept, ones that pass it are refused (it panicked before the fix).
…lved The far-jump resolver looked back over s_getpc_b64 / s_add_u32 / s_addc_u32 / s_setpc_b64 and ignored any other instruction in that run, even one that writes the jump's register pair. A second s_add_u32 to the low dword or a move into the high dword sent the jump somewhere else than the resolver computed. Such a jump is now left unresolved (an indirect exit) instead of being followed to the wrong target.
…ting
signature() reserved room for the part's stated row count before reading
any row. A count of 2^32 - 1 asked for ~206 GB and the failed allocation
aborted the process. Rows must now fit in the part (base + 32 * count),
else Malformed("signature rows out of bounds").
D3D12_FILTER_REDUCTION_TYPE (bits 7-8) is one of filtering, comparison, minimum or maximum. OR-ing bit 7 into a minimum-reduction filter made it maximum, and left maximum without comparison. StaticSampler::comparison() now sets the field to comparison and keeps the other filter bits.
…es no register RootParam::user_data is a byte of the title's root layout. On a merged stage (Ls/Hs/Es/Gs/Ms) user data starts at s8, so HwStage::user_sgpr overflowed its u8 for values past 247: a panic in a debug build, and in a release build a wrap onto s0-s7, where the tracer claimed registers the hardware fills for a root parameter. resource.rs now counts the first SGPR in u32, so such a parameter matches no register. New test: user_data_past_the_sgprs_names_no_register.
… for v_writelane_b32 and v_readlane_b32 take the lane from the low 5 (wave32) or 6 (wave64) bits of their select. The spill tracer compared selects unmasked, so a write to lane 35 of a wave32 was not seen to replace the one to lane 3, and a read of lane 3 traced the older SGPR's root parameter.
v_readlane_b32 and v_writelane_b32 take their lane from the low 5 (wave32) or 6 (wave64) bits of the select. Lowering passed the select through unmasked, so a write to lane 35 of a wave32 compared equal to no lane and a read of it asked the host for a lane past its wave. Console lane selects are now masked (constants folded); a computed host lane in a pixel or vertex program stays as it is.
A compute program's numthreads comes from the title's stage data as three
raw u32s. Lowering multiplied them (the one-wave check and the console
thread id) and divided by them unchecked, so 65536 x 65536 panicked with
"attempt to multiply with overflow" in a debug build and wrapped to 0 in
a release one, and a 0 component became a division by zero in the host
code. lower() now refuses a group D3D12 cannot run (1-1024 x 1-1024 x
1-64, at most 1024 threads) with Malformed("a thread group past D3D12's
limits"); mesh programs already check their limits.
|
Verified Not covered: refusing a real compute thread group beyond D3D12's limits at device time (no game data) and Windows/Wine validation of the emitted modules. |
An ISG1/OSG1 row's register is a raw u32 of the title's container, and emit kept it as the row. The PSV0 writer multiplied it by four and wrote a dependency mask for every input scalar up to it, so a register of 2^30 panicked with `attempt to multiply with overflow` in a debug build, and smaller ones past 32 sized the masks by the register rather than the rows. D3D12 links stages through 32 registers, so signature() now refuses anything past them (u32::MAX still means no register). New test a_signature_register_past_32_is_refused.
…ALU source name the mesh group exactly
…st EMIT_CUT, stray bits, sendmsghalt) stay raw or are named exactly
…tcnt counters and hwreg names and slices
|
A libFuzzer target that would keep these fixes from regressing: it calls AI-assisted. |
…uffer formats at their range bounds
…DPP masks and flags, SDWA destination and source modifiers, permlane fi/bound_ctrl and packed half selects
…ins or splits DS offsets by access, and follows the segment for FLAT offsets and addresses
…nstruction, names only the set parts of a scalar load offset, and sizes image addresses by every dimension with dlc first
…er with the operands they reshape, and names interpolation parameters with the attribute last
…one space after the mnemonic, and test the invalidations' operandless text
|
Cross-check from someone new to this code: I initially suspected DxilProgram::is_standard_layout() misclassified PC DXIL with zero padding after a ragged BitcodeSize. Checking the DXIL headers and LLVM's bitcode rules, that input is invalid — LLVM bitcode streams must be a multiple of 4 bytes, and SizeInUint32 is dword-rounded. This PR's bitcode size not a multiple of 4 check is the right fix. I wrote a local synthetic 17-byte test, confirmed the reasoning, and reverted my change rather than contribute a wrong relaxation. This PR also covers the DXBC part-inside-header case I had flagged. Verified locally on main at ffe310e: cargo test -p victory-shader dxil::tests → 4 passed. No hardware-dependent tests run (RX 580, no SM 6.6). PR creation is collaborator-only for me right now, hence a comment rather than a PR. |
…mmediates as hex, and puts a SOPK register before its immediate with s_version alone
…and image dmask edges Co-authored-by: Cursor <cursoragent@cursor.com>
Hermetic containers hit the two refusals after DXBC parse: one with no DXIL part, and a PC-layout DXIL part with no XDAT native entry. Co-authored-by: Cursor <cursoragent@cursor.com>
…isak#306 Marvisak#333 Marvisak#105 Marvisak#288 Marvisak#343 Marvisak#353 Marvisak#326 Marvisak#259 Marvisak#179 Marvisak#176 Marvisak#226 Marvisak#286) Conflicts: - emit/lower.rs: shader-opcodes and shader-tracking each keyed heap handles by the resource properties (a tuple vs two flattened words); the same key, shader-tracking's form and comment kept. Lowered's test-only fields, test imports and tests of both sides kept. - emit/wave.rs: tests of both sides kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Automated triage for the maintainers. Needs rebase. This PR does not merge cleanly into current The content has not been reviewed yet; it will be once the branch is rebased onto Generated by Claude Code |
Shader parser and translation robustness: small, independent fixes in
victory-shader, each in its own file and commit. This combines #326, #300, #327 and #283.1. DXBC: a part inside the container header is malformed (
dxbc.rs)Container::parsechecked that each part lies inside the container, but not that it comes after the header. A part offset of 0 read"DXBC"as the part's FourCC and the first digest dword as its size. An offset inside the part offset table read the offsets themselves as a part. Shader containers come from title files, so the parser should reject these.0x20 + 4 * count) now fail withMalformed("part overlaps the container header").Malformedbranch has a test built from synthetic containers: stated size too large or smaller than the header, an implausible part count, an offset table past the end, part header or data out of bounds, and parts inside the header or offset table. One test checks that bytes past the stated size are ignored.Valid containers put parts after the table, so they parse as before.
2. DXIL: tests for each way a program header is refused (
dxil.rs)Tests only, no code change.
DxilProgram::parsecan refuse a program in five ways, and the tests only reached one of them. New synthetic-header tests cover a bad declared size (too large, below 24 bytes,u32::MAXdwords), a truncated header, a wrong magic, bitcode out of bounds, a bitcode offset inside the header, padding after the program that must not become a trailer, and an unknown program kind kept asShaderKind::Unknown. Each rejection test checks the exactMalformedmessage.3. Immediate sampler LOD bias stays in D3D12's range (
emit/sampler.rs)The sampler's LOD bias is signed 5.8 fixed point, so it decodes to anything from -32 to 31.996. D3D12 only accepts a static sampler
MipLODBiasbetween -16 and 15.99. A root signature with an out-of-range value is refused, and the pipeline is lost with it. The decoded bias is now clamped to D3D12's range; values inside it are unchanged. New test:lod_bias_stays_in_the_host_range.4. SP3 text gives a message only the fields it has (
gfx10/sp3.rs)s_sendmsgoperands were all written as GS messages, so the NGG allocation request showed assendmsg(MSG_GS_ALLOC_REQ, GS_OP_NOP, 0). Messages are now spelled the way LLVM's AMDGPU assembler spells them: the operation appears only forMSG_GS,MSG_GS_DONEandMSG_SYSMSG, and the stream only for a GS emit or cut. Every GFX10 id has a name. Operands with bits no field accounts for stay as raw hex.0x0009sendmsg(MSG_GS_ALLOC_REQ, GS_OP_NOP, 0)sendmsg(MSG_GS_ALLOC_REQ)0x0008sendmsg(8, GS_OP_NOP, 0)sendmsg(MSG_EARLY_PRIM_DEALLOC)0x002Fsendmsg(15, GS_OP_EMIT, 0)sendmsg(MSG_SYSMSG, SYSMSG_OP_REG_RD)0x0122sendmsg(MSG_GS, GS_OP_EMIT, 1)0x0019sendmsg(MSG_GS_ALLOC_REQ, GS_OP_CUT, 0)0x0019Only shader dumps use this text. Translation reads the raw immediate, so its behaviour does not change.
All tests use synthetic bytes, with no shader or game data.
5. GFX10 decode: a far jump to an unaligned target is refused (
gfx10/mod.rs)The far-jump resolver (
s_getpc_b64/s_add_u32 sN, sN, literal/s_addc_u32/s_setpc_b64) checked that the target lies inside the code, but not that it is dword aligned. A literal that is not a multiple of 4 sent decoding into the middle of a dword, reading words that straddle two instructions. That target now fails withIsa { reason: "far jump target is not dword aligned" }. Bothgfx10::decodeandir::buildgo through this resolver.rejects_far_jumps_off_the_code_or_off_a_dword: a valid far jump, targets past the end and before the start, and literals 13/14/15/17.each_refusal_names_its_reason_and_offsetchecks the exact offset and reason for each waydecoderefuses code: odd size, a branch ors_call_b64out of range (forward and backward), a missing literal, running off the end withouts_endpgm, a truncated VOP3 or MTBUF, a reserved FLAT segment, an unknown encoding, and a branch into an instruction. The oldrejects_bad_codetest only checkedis_err().6. Immediate sampler max LOD is never below its min LOD (
emit/sampler.rs)Word 1 holds the minimum and maximum LOD as independent 4.8 fields, so a sampler can encode a maximum below its minimum. That went straight into the static sampler's
MinLOD/MaxLOD. A host sampler withMaxLOD < MinLODis invalid: under Proton, vkd3d-proton creates a Vulkan sampler, and Vulkan requiresmaxLod >= minLod(VUID-VkSamplerCreateInfo-maxLod-01973). The maximum is now raised to the minimum. The hardware clamp gives the minimum LOD in that case, and an equal pair does the same. Ordered pairs and samplers without a mip filter are unchanged. New test:max_lod_is_never_below_min_lod.Testing after this commit (Linux):
cargo test -p victory-shader72 passed;cargo clippy -p victory-shader --all-targets -- -D warningsclean;rustfmt --check --edition 2024onsampler.rsclean;cargo xtask policyok.7.
ir::buildrefuses more than 256 VGPRs (ir.rs)A VGPR is named by a byte (
Reg::V(u8)). M0-relative access (v_movrels_b32,v_movreld_b32and the like) lists every register from its base up to the program's VGPR count, casting each index tou8. With a count above 256 those indices wrapped round to v0, so the instruction claimed to read and write registers it never touches, and SSA linked the wrong values.native.rsalready refuses a count above 256 in the records it reads, butir::buildis public and took anyu16. It now fails withMalformed("more than 256 VGPRs"); counts of 256 and below are unchanged.New test
refuses_more_vgprs_than_a_byte_names: av_movrels_b32with 256 VGPRs reaches v255, and 257 andu16::MAXare refused.Testing after this commit (Linux):
cargo test -p victory-shader73 passed;cargo clippy -p victory-shader --all-targets -- -D warningsclean;rustfmt --check --edition 2024onir.rsclean;cargo xtask policyok.8. A vertex attribute past v255 is refused (
io.rs)A vertex shader's stage data names each attribute's first VGPR with a byte (
VsInput::vgpr), andio::raiseadded the channel to it as au8. A base of 253 or more with a high channel overflowed. In debug builds that panicked. In release it wrapped onto v0-v2, so an attribute channel claimed the register that holds the vertex id or primitive id. Such an input now fails withMalformed("vertex attribute past v255"). Bases whose channels end at v255 or below are unchanged.native.rsis not touched.New test
vertex_attributes_stay_below_v256: v252 withxyzwand v255 withxare kept; v253xyzw, v255yand v254ware refused. Before the fix, the test panicked with an add overflow atio.rs.Testing after this commit (Linux):
cargo test -p victory-shader74 passed;cargo clippy -p victory-shader --all-targets -- -D warningsclean;rustfmt --check --edition 2024onio.rsclean;cargo xtask policyok.9. A far jump whose registers change before
s_setpcis not resolved (gfx10/mod.rs)The far-jump resolver walks back from
s_setpc_b64 s[n:n+1]overs_getpc_b64,s_add_u32|s_sub_u32 sn, sn, literaland the carry into s(n+1). It skipped every other instruction in that run, even one that writes the pair. A seconds_add_u32 s8, s8, 16, ans_mov_b32 s9, 0, ans_load_dwordor av_readfirstlane_b32into s8/s9 sends the jump somewhere other than where the resolver says it goes, and decoding then followed the wrong target. Now any write to s[n:n+1] that is not the add or its carry leaves the jump unresolved:decodestops there andir::buildgivesExit::Indirect, as for any others_setpc_b64. Writes to other registers, and the compiler's own four-instruction form, are unchanged.New test
a_far_jump_whose_registers_change_is_not_resolved: the plain form,s_mov_b32 s10andv_readfirstlane_b32 s7between are still followed. A second add, moves into s9, s[8:9] and s[7:8],v_readfirstlane_b32 s9,s_load_dword s8and a carry into s8 are not. Without the fix the test fails because decoding follows the wrong target.Testing after this commit (Linux):
cargo test -p victory-shader75 passed;cargo clippy -p victory-shader --all-targets -- -D warningsclean;rustfmt --check --edition 2024ongfx10/mod.rsclean;cargo xtask policyok.10. A signature row count past its part is refused before allocating (
emit/mod.rs)signature()read theISG1/OSG1row count and calledVec::with_capacity(count)before reading any row. Signature parts come from title files. A count of0xFFFF_FFFFasked for 206,158,430,160 bytes up front. The allocation failed and the process aborted (SIGABRT), so the error never came back as aShaderError. Now the rows must fit in the part (base + 32 * count <= len, with checked arithmetic), or the call fails withMalformed("signature rows out of bounds"). Valid parts already put every row inside the part, so they parse as before.New test
a_signature_row_count_past_the_part_is_refused: a one-row part parses, and so does an empty one. Counts ofu32::MAX,0x0800_0000and 2 are refused, as are rows that start past the end. Without the fix the test aborts withmemory allocation of 206158430160 bytes failed.11. A comparison sampler replaces the reduction instead of OR-ing into it (
emit/sampler.rs,emit/mod.rs)When an
image_sample_c*used an immediate sampler, the code set comparison mode withfilter |= 0x80.D3D12_FILTER_REDUCTION_TYPEis the two-bit field at bits 7-8: 0 standard, 1 comparison, 2 minimum, 3 maximum. OR-ing bit 7 into a minimum-reduction sampler (0x115) gave0x195, which is a maximum filter. A maximum sampler stayed maximum with no comparison. Either way the static sampler stopped matching the shader'sSamplerComparisonStatedeclaration. The newStaticSampler::comparison()writes the reduction field as comparison and keeps the min/mag/mip and anisotropy bits.New test
comparison_replaces_the_reduction: point, linear and anisotropic filters, with minimum and maximum reductions, all come out as their comparison form. The other sampler fields are unchanged. Without the fix it fails withminimum: left 405 (0x195), right 149 (0x95).Testing after these commits (Linux):
cargo test -p victory-shader77 passed;cargo clippy -p victory-shader --all-targets -- -D warningsclean;rustfmt --check --edition 2024on both files clean;cargo xtask policyok. Each commit builds and passes on its own. Separately, 200k random GFX10 programs went throughgfx10::decode, the SP3 text,ir::build(random VGPR counts, wave32/64) andstructurewith no panics. That harness was not committed.Testing (Linux,
x86_64-unknown-linux-gnu)cargo test -p victory-shader: 71 passedcargo clippy -p victory-shader --lib -- -D warnings: cleanrustfmt --check --edition 2024on the four touched files: cleancargo xtask policy: okAlso in this PR (folded from #262, now closed)
emit/mod.rs:constant_color()was only called by the two#[cfg(windows)]tests, so on Linuxcargo clippy --all-targets -p victory-shaderwarnedfunction constant_color is never used. This is the clippy warning still left over from Build: gate Windows-only paths so the workspace builds and tests on Linux #235. A new test,constant_color_is_a_well_formed_container, runs on every host and needs neither D3D12 nordxil.dll. It checks that the container parses, that its size field matches its length, that the parts areSFI0 ISG1 OSG1 PSV0 HASH DXILin that order, that the DXIL program header is there, and that the digest is correct.bitcode::Attrandshader::Shaderimports move from the test module into the helper, which is the only code that uses them.After the fold (Linux):
cargo test -p victory-shader: 69 passedcargo clippy -p victory-shader --lib -- -D warnings: cleancargo clippy -p victory-shader --all-targets -- -D warnings: clean (noconstant_colorwarning)rustfmt --check --edition 2024on the touched files andcargo xtask policy: cleanAlso: a root parameter's user data past s247 names no register (
resource.rs)RootParam::user_datais a raw byte of the title's root layout. On a merged stage (LS/HS/ES/GS/mesh) user data starts at s8, soHwStage::user_sgproverflowed itsu8for values past 247. In a debug build that panicked. In a release build it wrapped onto s0-s7, and the tracer claimed registers the hardware fills there for a root parameter.resource.rsnow counts the first SGPR inu32, so a parameter past the register file matches no register and the load fails with the usual "no root parameter" reason.native.rsis unchanged.New test
user_data_past_the_sgprs_names_no_register: user data 250 and 255 on each merged stage. Without the fix it fails withattempt to add with overflow.After this commit (Linux):
cargo test -p victory-shader78 passed;cargo clippy -p victory-shader --all-targets -- -D warningsclean;rustfmt --check --edition 2024clean;cargo xtask policyok.Also: a compute thread group past D3D12's limits is refused (
emit/lower.rs)A compute program's
numthreadscomes from the title's stage data as three rawu32s. Lowering multiplied them (the one-wave check and the console thread id) and divided by them without checking. A size of 65536 x 65536 panicked withattempt to multiply with overflowin a debug build and wrapped to 0 in a release build, which made the one-wave check pass wrongly. A 0 component became a division by zero in the host code.lower()now refuses any group D3D12 cannot run (1-1024 x 1-1024 x 1-64, at most 1024 threads) withMalformed("a thread group past D3D12's limits"). Mesh programs already check their limits.native.rsis unchanged.New test
a_thread_group_past_d3d12s_limits_is_refused: zero components, each axis one past its limit, totals over 1024, 65536 x 65536 andu32::MAXon both wave sizes are refused, and sizes at the limits still lower. Without the fix it fails, and 65536 x 65536 panics with the overflow.After this commit (Linux):
cargo test -p victory-shader81 passed;cargo clippy -p victory-shader --all-targets -- -D warningsclean;rustfmt --check --edition 2024clean;cargo xtask policyok. Separately, about 3.2M random GFX10 programs (mutated from the crate's test words, with random stage data and root layouts) went throughir::build,resource::track,io::raise,structureandemitwith no panics. That harness was not committed.Also: a signature register past D3D12's 32 is refused (
emit/mod.rs)An
ISG1/OSG1row's register is a rawu32of the title's container, andemitkept it as the row. ThePSV0writer multiplied it by four and wrote a dependency mask for every input scalar up to it. A register of 2^30 panicked withattempt to multiply with overflow(container.rs:241) in a debug build. Registers past 32 but below that sized the masks by the register instead of the rows. D3D12 links stages through 32 registers, sosignature()now refuses anything past them withMalformed("signature register past the 32 D3D12 has").u32::MAXstill means no register.native.rsis unchanged.New test
a_signature_register_past_32_is_refused: registers 0, 31 andu32::MAXparse; 32, 255, 256, 2^30 andu32::MAX - 1are refused.After this commit (Linux):
cargo test -p victory-shader82 passed;cargo clippy -p victory-shader --all-targets -- -D warningsclean;rustfmt --check --edition 2024clean;cargo xtask policyok.Also: a mesh group id strides by every axis of the HLSL group (
emit/mod.rs)A mesh program's group id arrives multiplied by the HLSL group's thread count, and
emitreads that count fromPSV0(runtime info version 2 on) to divide it back out.PSV0stores the group asNumThreadsX,YandZ, but only X was read, sonumthreads(8, 8, 1)strode by 8 instead of 64 and neighbouring groups got overlapping ids. Every mesh diff test is one-dimensional, which is why this never showed. The newmesh_group_threadsmultiplies all three. The sizes are rawu32s of the title's part, so a group D3D12 cannot run (an empty axis, or more than 128 threads) fails withMalformed("a mesh thread group past D3D12's limits")before they are multiplied. Containers without version 2 runtime info fall back to the stage data's lane count as before.native.rsis unchanged.New test
a_mesh_group_counts_every_axis:[32,1,1],[8,8,1],[4,4,8],[1,1,128]and[1,1,1]give their products. Zero axes,[129,1,1],[16,16,1],65536 x 65536andu32::MAXon all three are refused. Older runtime info and a missing part give no count, and a version-2 part cut off before Z is refused. Synthetic bytes only.After this commit (Linux):
cargo test -p victory-shader86 passed;cargo clippy -p victory-shader --all-targets -- -D warningsclean;rustfmt --check --edition 2024clean;cargo xtask policyok.Also: a signature with more elements than PSV0 counts is refused (
emit/mod.rs)PSV0counts each signature's elements in a byte (container.rswritesinputs.len() as u8, and the same for outputs and per-primitive rows). The count comes from the title'sISG1/OSG1part as a rawu32, and rows without a register are not bounded by the 32 registers. A part with 256 such rows wrapped the emitted count to 0, so the container disagreed with its own signature and D3D12 refused it.signature()now refuses more than 253 elements (a byte, less the vertex and instance id rows lowering can add) withMalformed("signature with more elements than PSV0 counts"), after the bounds check and before anything is allocated.New test
a_signature_past_psv0s_element_count_is_refused: 1 and 253 unallocated rows parse; 254, 255, 256 and 300 are refused. Synthetic bytes only.After this commit (Linux):
cargo test -p victory-shader --lib87 passed;cargo clippy -p victory-shader --all-targets -- -D warningsclean on Linux andx86_64-pc-windows-msvc;cargo fmt --checkclean;cargo xtask policyok.Also: a compute thread id past z is refused (
io.rs)COMPUTE_PGM_RSRC2'sTIDIG_COMP_CNTis a two-bit field of the title's stage data: 0-2 enable the x, xy or xyz thread id VGPRs.ComputeIo::thread_id_vgprsreturns the field plus one, so its fourth value madeio::raiseload v3 asThreadIdInGroup(3), a component no thread id has. Lowering then passed component 3 tothreadIdInGroup(or, with console lanes, treated it as z).io::raisenow refuses that field withMalformed("a thread id component past z").native.rsis unchanged.New test
compute_thread_ids_stop_at_z: counts 1 and 3 map v0 and v2 to their components, v2 with only x and y is no thread id, and the fourth value is refused. Without the fix it fails withleft: Ok(Io { inputs: [(Value(1), ThreadIdInGroup(0))] .. }). Synthetic bytes only.After this commit (Linux):
cargo test -p victory-shader --lib88 passed;cargo clippy -p victory-shader --all-targets -- -D warningsclean;rustfmt --check --edition 2024clean;cargo xtask policyok.Also: two signature elements in one register component are refused (
emit/mod.rs)Lowering finds an input or output element by its register and component (
find_inputreturns the first match). A title'sISG1/OSG1part listing a second element over components another element already has left that second element never read or written, and D3D12 refuses a signature whose elements overlap.signature()now refuses it withMalformed("two signature elements in one register component"). Elements in a register's other components (x+yandz+w), in other registers, or without a register still parse.New test
signature_elements_sharing_a_component_are_refused: disjoint layouts parse; full overlap, partial overlap (xy/yz,x/xyzw,w/zw,yzw/yin r31) are refused. Without the fix the test fails. Synthetic bytes only.After this commit (Linux):
cargo test -p victory-shader --lib91 passed;cargo clippy -p victory-shader --all-targets -- -D warningsclean;cargo fmt --checkclean;cargo xtask policyok.Also: a semantic listed twice in a signature is refused (
emit/mod.rs)A semantic (its name, ignoring case, plus its index) names one signature element. The next stage links by it, and D3D12 refuses a signature that lists the same one twice. A title's
ISG1/OSG1/PSG1part could list a second element with the same semantic in another register, andsignature()let it through. D3D12 then refused the pipeline.signature()now refuses it withMalformed("two signature elements with one semantic").New test
a_semantic_listed_twice_is_refused: the same name with another index, or another name with the same index, still parses. The same semantic is refused in any case, with or without a register. Without the fix the test fails. Synthetic bytes only.After this commit (Linux):
cargo test -p victory-shader --lib92 passed;cargo clippy -p victory-shader --all-targets -- -D warningsclean;cargo fmt --checkclean;cargo xtask policyok.Also: a vertex or instance id past r31 is refused (
emit/lower.rs)The console signature leaves out the vertex and instance ids, so lowering gives each one the row after the last row the signature uses. A system input without a register gets the same treatment. A title's
ISG1that already uses r31 put the id at r32. D3D12 links stages through 32 registers, so it refused the pipeline. The id is now missing with the reason "a system input past the 32 input registers", so a program that reads it fails translation with that reason. Signatures with a free row are unchanged.native.rsis unchanged.New test
a_vertex_id_after_r31_is_refused: a vertex shader exports its vertex id. After an input in r0 the id goes to r1, and after r30 it goes to r31. After r31 the shader is refused. Without the fix, the test fails because the id is emitted at r32. Synthetic bytes only.After this commit (Linux):
cargo test -p victory-shader --lib93 passed;cargo clippy -p victory-shader --all-targets -- -D warningsclean on Linux andx86_64-pc-windows-msvc;cargo fmt --checkclean;cargo xtask policyok.Also: a DXBC container listing a known part twice is refused (
dxbc.rs)Container::partreturns the first part with a given FourCC. A title container with a secondISG1,PSV0orDXILhad that part silently ignored by translation, while anything else reading the container could take the other copy. DXC's validator refuses such a container ("More than one ... part").Container::parsenow fails withMalformed("a part listed twice")for the part types DXC knows (DXIL STAT RTS0 PSV0 ISG1 OSG1 PSG1 SFI0 HASH ILDB ILDN). A FourCC the crate does not know, which may be the title's own, can still repeat.native.rsis unchanged.New test
a_known_part_listed_twice_is_refused: each known part listed twice (with another part between) is refused. All eleven listed once parse, and a title's ownPRIVpart listed twice parses, withpart()returning the first. Without the fix the test fails. Synthetic bytes only.After this commit (Linux):
cargo test -p victory-shader --lib94 passed;cargo clippy -p victory-shader --all-targets -- -D warningsclean;rustfmt --check --edition 2024ondxbc.rsclean;cargo xtask policyok.Also: group shared memory past D3D12's limits is refused (
emit/lower.rs)A compute program's LDS size comes from
COMPUTE_PGM_RSRC2(up to 255.5 KB in the field, 64 KB on the hardware) and a mesh program's from its record as a rawu32. D3D12 caps group shared memory at 32 KB for compute and 28 KB for mesh programs, so a larger declaration gave a module the validator refuses. A mesh size nearu32::MAXalso overflowed rounding to dwords and back (attempt to multiply with overflowinshader.rs, debug builds).PSV0either way, so one past 28 KB is refused before lowering with "mesh group shared memory past D3D12's 28 KB".native.rsis unchanged.New test
group_shared_memory_past_d3d12s_limits_is_refused: a computeds_write_b32with 1, 32 and 64 granules translates, and 65, 128 and 511 are refused (unused, they translate). Mesh sizes 0, 4 and 28 KB translate; 28 KB + 1, 32 KB, 64 KB,u32::MAX - 2andu32::MAXare refused. Without the fix, the compute and 28 KB + 1 cases are accepted andu32::MAXpanics. Synthetic bytes only.After this commit (Linux):
cargo test -p victory-shader --lib97 passed;cargo clippy -p victory-shader --all-targets -- -D warningsclean on Linux andx86_64-pc-windows-msvc;cargo fmt --checkclean;cargo xtask policyok.Also: a colour or position export stays inside its element (
emit/lower.rs)An export's channels are the components of the register it targets. Lowering stored channel n of an
mrtorpos0export as column n of theSV_TargetorSV_Positionelement, whatever columns the element actually had. A target narrower than a row (afloat2orfloat3) gotstoreOutputcalls for columns past it, which DXC's validator refuses, and the emittedOSG1claimed those components were written. The channel now maps to the element's own column, the same way parameter exports already do, and a channel the element does not cover is dropped. Four-column elements are unchanged.native.rsis unchanged.New test
a_colour_export_stays_inside_its_element: anexp mrt0of all four channels intoSV_Targetelementsxyzw,xyz,xy,x,zwandw. The emittedOSG1lists exactly the components each element lacks as never written. Without the fix it fails forxyz(left: (7, 0),right: (7, 8)). Synthetic bytes only.After this commit (Linux):
cargo test -p victory-shader --lib98 passed;cargo clippy -p victory-shader --all-targets -- -D warningsclean on Linux andx86_64-pc-windows-msvc;cargo fmt --checkclean;cargo xtask policyok.Also: a signature name outside printable ASCII is refused (
emit/mod.rs)HLSL semantics are identifiers, but a signature row's name is raw bytes of the title's part, and it went through
String::from_utf8_lossy. Each invalid byte became U+FFFD, which is three bytes. A name could pass the 64-character check and still reach DXC's validator longer than that (Meta.SemanticLen): 64 bytes of0xFFbecame 192. Two different names, such as0xFEand0xFF, also became the same semantic. A name with any byte outside printable ASCII now fails withMalformed("signature name outside printable ASCII"). ASCII names are unchanged.New test
a_signature_name_outside_printable_ascii_is_refused:TEXCOORD,SV_Positionand_a1~!are kept byte for byte. These are refused: 64 ×0xFF,0xFE, an embedded0x80, UTF-8é, a space, a tab and0x7F. Without the fix, the test fails. Synthetic bytes only.After this commit (Linux):
cargo test -p victory-shader --lib100 passed;cargo clippy -p victory-shader --all-targets -- -D warningsclean on Linux andx86_64-pc-windows-msvc;cargo fmt --checkclean;cargo xtask policyok.Also: two DXBC parts that overlap are refused (
dxbc.rs)Container::parsechecked each part against the container and the header, but not against the other parts. Two offsets whose ranges share bytes made one part read the other's header or data as its own. DXC lays parts end to end, soparsenow fails withMalformed("two parts overlap"). Parts that only touch still parse.Also: a render target's semantic index matches its register (
emit/mod.rs)An
SV_Targetrow names its render target twice: its semantic index goes into the emitted signature metadata, and its register is what the pipeline description (RTVFormats) and lowering (exp mrtN) use. Both are raw fields of the title'sOSG1row. A row whose index disagreed with its register was refused by DXC's validator (SM.PSTargetIndexMatchesRow), so the pipeline was lost after translation. A target with no register went into format slot 0 and no export reached it.signature()now refuses both withMalformed("render target index disagrees with its register"). Other elements keep any index.native.rsis unchanged.New test
a_render_target_index_matches_its_register: targets 0, 3 and 7 with a matching index parse. Index/register pairs (1,0), (0,1), (7,6), (8,0), (u32::MAX,0) and a target with no register are refused. A non-target element keeps index 5 in register 2, and an unallocated one keeps its index. Without the fix the test fails (index 1, register 0parses). Synthetic bytes only.After this commit (Linux):
cargo test -p victory-shader --lib101 passed;cargo clippy -p victory-shader --all-targets -- -D warningsclean on Linux andx86_64-pc-windows-msvc;cargo fmt --checkclean;cargo xtask policyok.A pixel shader's parameter export is refused (
io.rs)A pixel shader has no parameter outputs, so
exp param0matched the vertex shader's dummy-export arm, becameTarget::Unread, and was dropped in lowering. Anyexp param<n>from a pixel shader now fails withMalformed("a pixel shader exporting a parameter"). New testexport_targets_map_or_are_refusedmaps every export target number and checks that the reserved gaps (10, 11, 17-19, 21-31) are refused.DXBC: overlap against every earlier part; a known part repeated at one offset (
dxbc.rs)Tests only.
overlap_is_checked_against_every_earlier_part: a third part pointed back into the first part's header or data, with the second part between them in the table, is refused as"two parts overlap".a_known_part_listed_twice_at_one_offset_is_a_repeat: two table entries for the sameDXILpart are reported as"a part listed twice"before the overlap check runs, while a title's own FourCC listed twice at the same offset is reported as an overlap.Testing (Linux):
cargo test -p victory-shader129 passed; clippy-D warningsclean;rustfmt --check --edition 2024clean;cargo xtask policyok.Immediate samplers: each field decodes on its own (
emit/sampler.rs)Tests only.
each_field_decodes_on_its_ownwalks every address mode on each axis (U, V, W independently), log2 anisotropy 0-7 (5-7 clamp to D3D12's 16), every comparison function (1-8), every border colour (custom falls back to transparent black), the reserved reduction 3 (filters, as 0 does), and checks bits outside the decoded fields change nothing.either_anisotropic_filter_is_anisotropiccovers all 48 mag/min/mip combinations: one anisotropic filter makes the sampler0x55, otherwise the point/linear bits map one to one.Also merges upstream
main(conflict inemit/lower.rstests:lowersnow takesrsrc2and routes throughdxil_io).cargo test -p victory-shader146 passed; clippy-D warningsclean; rustfmt clean;cargo xtask policyok.