Commit Graph

156 Commits

Author SHA1 Message Date
Peterino2 077696151a github workflow 2026-11-02 14:22:40 -07:00
Peterino2 0de619c694 Merge remote-tracking branch 'origin/main' 2026-11-02 14:15:49 -07:00
peterino2 bb942b06c7 DXIL reflection for the DXC drop-in
Unreal Engine's D3D12 shader compiler needs DXC_OUT_REFLECTION and reads
every shader's parameters through ID3D12ShaderReflection; it also strips
parts with IDxcContainerBuilder and blobs through IDxcLibrary.

- The DXIL emitter builds the reflection with the object (dxil/reflect.zig):
  bound resources, constant buffers with their variables and types, and
  per-function data for libraries. A variable is marked used from the
  optimized code, by the cbuffer components actually loaded, as DXC marks
  them. Input signature usage is likewise taken from the optimized code.
- The drop-in returns it as DXC_OUT_REFLECTION, and IDxcUtils::
  CreateReflection serves ID3D12ShaderReflection and
  ID3D12LibraryReflection over it.
- New classes: DxcContainerBuilder and DxcContainerReflection; the utils
  object also answers IDxcLibrary.

On the 65 test/dxil shaders, reflection printed through the D3D12
interfaces matches DXC 1.8's on 46; the rest differ in details clients do
not read (bitfield members, -Zpr matrix classes, resource order).
2026-11-02 13:14:37 -08:00
Peterino2 7079b6385d adding reference to zdxc.org 2026-11-02 14:07:27 -07:00
Peterino2 951777a23d Udated readme, adding github actions 2026-11-02 13:58:46 -07:00
peterino2 2526fa65f7 --job: keep file I/O off the compile threads
Windows (here, with Defender's on-access scanning) serializes opening
files: creating the corpus's 8,772 outputs takes about 1.8 s whatever
the thread count. The compile threads blocked on it, so --job barely
gained past 8 threads.

- A reading thread reads each job's input ahead of the compiles (at
  most 256 jobs ahead), and a writing thread writes the outputs, in job
  order, after them. An output that cannot be written is reported after
  every job's output and fails its job.
- Files the jobs read through the compiler (headers) are cached for the
  whole run, with misses remembered, so each is opened once instead of
  once per job and include directory searched.

On the Glide corpus: compiles only, 13.6 -> 12.1 s on 1 thread and
2.75 -> 2.6 s on 24; preprocess and compile, 36.2 -> 17.1 s on 1 thread
and 7.3 -> 5.9 s on 24, which is about the time it takes to create its
17,544 output files. Outputs and diagnostics are identical to 0622292
on all 17,544 calls.
2026-11-02 07:28:12 -08:00
peterino2 b5eba0625f Allocate less per compile
Every compile ran in an arena, where a growing list leaves each old
buffer behind, and a few sites dominated: the Glide corpus's 8,772
compiles allocated 38 GB. Now 24 GB:

- intrinsics: build the Db once per process and share it read-only
  (it was rebuilt from the static table on every compile, 3.5 GB);
- parser: reserve the token list from the source size (5.2 GB of
  regrowth), and collect name parts on the stack (25M allocations);
- dxil emit: reserve the function's instruction list in finish (5.0 GB);
- sema: reserve resolutions from the token count (1.0 GB).

zdxc --job on the corpus: 15.4 -> 14.3 s on 1 thread, 3.0 -> 2.65 s on
24. Output is byte-identical on a 1,462-compile subset.
2026-11-02 07:06:58 -08:00
peterino2 22e1bcbc2a dxil emit: look instruction types up by id
valueType searched the prologue and every block for the instruction,
so lowering was quadratic in function size. On the Glide corpus it was
half of all samples in zdxc --job; with a type per id the corpus's
8,772 compiles take 15.4 s on 1 thread (was 21.6 s) and 3.0 s on 24
(was 7.4 s). Output is byte-identical on a 1,462-compile subset.
2026-11-02 06:46:52 -08:00
peterino2 db87b47e6f dxcapi: keep each thread's compile arena between calls
Freeing the arena after every Compile gave its blocks back to the OS
(smp_allocator maps 64 KiB and up directly), so each call faulted about
4 MB of fresh pages in again. On the Glide corpus's 8,770 compiles that
was 9.06M page faults and up to 28 s of kernel time; with the arena kept
(reset to at most 64 MiB) it is 0.4-1.0M, and the replay is 25% faster
on 1 thread, 30% on 8 and 16% on 24. Output is byte-identical.
2026-11-02 06:37:44 -08:00
peterino2 06222920e5 Merge dev/windows-fix: DXIL local promotion and copy elision, on the SPIR-V IR passes
Glide (Hyperion engine) now runs on zdxc's DXIL.

# Conflicts:
#	src/dxil/emit.zig
2026-11-02 01:16:31 -08:00
peterino2 4666275a0b DXIL: fold promoted values, pass constant buffer structs in place
GlimmerProbeTrace (Glide) still came out at 374 KB of DXIL against
dxc's 155 KB, with 130 allocas against 40. Most of the remainder:
by-value struct parameters copied out of the constant buffer at every
call (GlimmerGroundParams and GlimmerSpanParams, 32 i32s each), then
indexed dynamically, which pinned each copy in memory.

- Arguments loaded from a constant buffer are passed as the constant
  buffer place itself, structs as well as arrays (not with matrices,
  whose constant buffer access is narrower than a local's). Locals still
  alias only within a block with no write since. The alias now comes
  first in local_var lowering, so the skipped parameter store always
  matches.
- Peepholes on promoted values: bitcast round trips (int/float mixing
  locals store i32s), constant integer arithmetic and comparisons,
  identities, selects on a constant. A constant out-of-bounds array
  index this exposes (on a path that cannot run) becomes 0, since the
  validator rejects it.
- Inlined callees' array locals return to a per-type pool on return,
  for later callees to reuse.
- -Od and -zdxc-no-opt skip promotion, aliasing and reuse, as they skip
  the SPIR-V IR passes.

GlimmerProbeTrace: 374 KB to 191 KB, 21 allocas, 282 bitcasts (from
7198). Its pipeline builds in 3.6 s on an RX 9070 XT (was 5.1 s). All
of Glide's 400 DXIL compiles: 5.91 MB (dxc: 6.11 MB), 7.1x faster than
dxc. All pass dxc 1.8.2505's validator, and Glide renders.
2026-11-02 01:13:16 -08:00
peterino2 dce6d0eade DXIL: promote locals to SSA, elide by-value array copies
Locals were left as allocas, so every access was a store or a reload.
Glide's GlimmerProbeTrace came out as 2.3 MB of DXIL (DXC: 155 KB) that
AMD's driver took over ten minutes to build into a pipeline, and the game
stalled on a black screen.

- promote.zig: SROA + mem2reg over the finished function. An alloca whose
  accesses are loads and stores through constant indices becomes one SSA
  variable per element, with phis at the iterated dominance frontiers.
  Trivial phis fold away, and dead instructions go. Locals read before
  they are written read zero, since the validator rejects reads of undef.
- Dynamically indexed locals pin only what the index can reach. The
  emitter records each dynamic getelementptr's range (the indexed array's
  extent), and the rest of the local is still promoted.
- A by-value array parameter that the callee only reads aliases the
  caller's storage when the argument was loaded from a local in the same
  block with no write since. This drops the per-call copies.
- Declarations that lose their last call are pruned before writing, since
  the validator rejects unused external functions.

On Glide's 400 DXIL compiles, total output goes from 34.5 MB to 6.8 MB
(DXC: 6.1 MB), and GlimmerProbeTrace from 2.3 MB to 374 KB. Its
pipeline now builds in about 5 s. All 400 objects pass DXC 1.8.2505's
validator (checked with a copy built to claim validator 1.8), and Glide
renders on zdxc.
2026-11-02 00:57:49 -08:00
Peter Li cd951ea29b DXIL: dynamic constant buffer vector indices, library resource arrays, selected resource locals
- A constant buffer vector indexed at run time loads the whole vector and
  selects the component.
- Resource arrays in libraries: globals of class arrays, mangled as
  pointers to their element (as dxc); each access loads its element for
  createHandleForLib. NonUniform indices put !dx.nonuniform on the
  getelementptr, so the bitcode writer now writes metadata kinds and
  instruction attachments.
- Array types in mangled names count their dimensions as dxc does.
- A resource local assigned different elements of one resource array keeps
  the element's index and makes the handle where it is read.
2026-11-02 00:57:49 -08:00
Peter Li ab7b167270 DXIL: keep the library prologue's use marks per thread
markUses kept the array it marks in a static, which concurrent library
compiles under --job shared: one could mark into another's array, or index
past its own. Make it thread-local.
2026-11-02 00:57:49 -08:00
Peterino2 97517cc5b1 SPIR-V: selection controls from [branch] and [flatten]
[branch] and [flatten] on if and switch were dropped: every
OpSelectionMerge had selection control None, leaving the driver to
flatten or keep the branch by its own heuristics. They now become
DontFlatten and Flatten, as in dxc (the Hyperion engine's shaders use
them 21 times). The IR keeps them on the header block; unrolling and
inlining carry them over.
2026-11-02 08:00:54 +00:00
Peterino2 d39ee30a4c SPIR-V: promote locals to SSA values; inline top-down
ir/ssa.zig, after inlining:

1. A local struct or array accessed only whole and with constant
   indices is split into one local per leaf member / element (scalar
   replacement, up to 64 leaves): whole reads construct the value,
   whole writes store each part. Promoting whole aggregates instead
   made each member write a copy of the aggregate; on the Glide shader
   that has many of them RADV then spilled ten times as many scalar
   registers.
2. Locals loaded and stored only whole (no resources) become SSA
   values: semi-pruned phi placement over dominance frontiers,
   renaming over the dominator tree, trivial phis folded, dead phis
   (cycles included) dropped. Reads before any write are the new IR
   `undef` (OpUndef). Phis take one value per predecessor the emitter
   writes, unreachable merge and continue targets included.

Constants that were behind locals fold afterwards. The SPIR-V emitter
emits OpPhi, patching operands emitted after the phi.

The inliner now works top-down from the entry points (each call gets a
copy of the callee's own body, whose calls are inlined as the scan
reaches them), copies only instructions in the callee's blocks (and
locals on first use), and remaps only instructions naming a call
result; scans use a non-allocating operand visitor (opt.eachOperand).

On Glide: loads 115040 -> 20322, stores 63644 -> 5832 (dxc: 11423,
2498), SPIR-V 12.0 -> 13.2 MB (callee bodies copied); compile time
587 -> 771 ms on 327 shaders (dxc: 8.6 s). Two more corpus files
compile (texel offsets that are constants once promoted).
2026-11-02 07:54:10 +00:00
Peterino2 afc4587596 SPIR-V: inline calls in the IR
dxc's SPIR-V gets its calls inlined by legalization; zdxc emitted every
function and left inlining to the driver, with 10361 calls across the
Hyperion engine's Glide shaders. ir/inline.zig now inlines bottom-up
before emission:

- The calling block is split at the call: it branches to a copy of the
  callee, and the rest of the block (terminator and merge included)
  moves to a continuation block. Parameters become the arguments.
- A callee with one return outside every construct branches from it to
  the continuation. Returns inside selections or switches become
  breaks out of a loop that runs once around the callee, the return
  value going through a local.
- Callees that return from inside a loop, [noinline] ones, ones with
  RayQuery or by-reference resource parameters, and ones returning a
  resource from several places stay functions (resource arguments then
  still get specializations).
- Functions nothing reaches any more are marked dead and not emitted.

Only modules with vertex, pixel and compute entry points and no
rasterizer-ordered views for now (the emitter treats the others'
functions specially). -Od and the new -zdxc-no-opt skip it; -zdxc-ir
prints the IR after the SPIR-V passes.

On Glide: 37 calls left; the SPIR-V grows (517k to 838k instructions,
callee bodies copied, one-trip loops) until promotion to SSA values
removes the locals; compile time 597 to 765 ms. The driver's own
statistics barely move, except one compute shader passing float4[28]
arrays by value, whose copies now take more scratch.
2026-11-02 07:10:23 +00:00
Peterino2 2ed08b08e1 SPIR-V: loop controls from [unroll] and [loop]
Loops the IR keeps (its unrolling gave up, or [loop] asked it not to)
lost their attribute: every OpLoopMerge had loop control None. The
driver now gets Unroll for [unroll] and DontUnroll for [loop], as from
dxc.

On the Hyperion engine's Glide shaders this is what made its half
resolution Glimmer irradiance pass about 5% slower than with dxc: an
[unroll] loop over a run-time count that RADV unrolls for dxc's output
stayed a loop for zdxc's (2381 instructions against dxc's 5765; now
5856).
2026-11-02 06:55:33 +00:00
Peter Li 83f2298773 DXIL: dynamic constant buffer vector indices, library resource arrays, selected resource locals
- A constant buffer vector indexed at run time loads the whole vector and
  selects the component.
- Resource arrays in libraries: globals of class arrays, mangled as
  pointers to their element (as dxc); each access loads its element for
  createHandleForLib. NonUniform indices put !dx.nonuniform on the
  getelementptr, so the bitcode writer now writes metadata kinds and
  instruction attachments.
- Array types in mangled names count their dimensions as dxc does.
- A resource local assigned different elements of one resource array keeps
  the element's index and makes the handle where it is read.
2026-11-01 21:24:32 -08:00
Peter Li 5792d653b5 DXIL: keep the library prologue's use marks per thread
markUses kept the array it marks in a static, which concurrent library
compiles under --job shared: one could mark into another's array, or index
past its own. Make it thread-local.
2026-11-01 21:24:31 -08:00
Peter Li 01a66d456a SPIR-V: dynamically selected resources in calls and resource locals
A resource array element at a dynamic index (textures[i], bindless)
passed to a function failed: specializations re-create constant
elements only. The recipe now keeps dynamic index positions; the call
passes their values as extra arguments, the specialization takes them
as parameters and builds the access chain from them, and passes them
on to its own callees. A NonUniformResourceIndex selection stays
NonUniform in the specialization.

A resource local assigned different elements of one resource array
(tex = textures[a] in one branch, textures[b] in another) failed with
"assigning different resources to one variable". Such a local is now
kept as Function variables holding the indices: each assignment stores
them, each read loads them and re-creates the element. dxc emits an
OpPhi of images there, which spirv-val rejects, unless inlining folds
the branches away.
2026-11-01 20:16:21 -08:00
Peter Li 5f9543170d Parse the builtin pseudo-enum typedefs as type names
RAY_FLAG, RAYQUERY_FLAG, COMMITTED_STATUS, CANDIDATE_TYPE,
MEMORY_TYPE_FLAG and BARRIER_SEMANTIC_FLAG were declared as uint
typedefs in Sema but unknown to the parser, so `const RAY_FLAG f = ...`
failed with "unknown type name".
2026-11-01 20:16:21 -08:00
Peter Li 0d4837d5fb Static locals read from another static's initializer
A function-local static whose initializer reads another local static
(static const int n = min((order + 1) * (order + 1), 9)) failed with
"this variable is not supported yet": initializers are lowered in
functions of their own, where the other static is not a local. It is
its private global there, as a file-scope static is.
2026-11-01 20:16:21 -08:00
Peter Li 2716772d98 Accept "-opt value" passed as one argument
dxc's option parser skips spaces after an option name, so a separate
option given as "-HV 2021" in a single argument is "-HV" with value
2021 (programs calling IDxcCompiler3::Compile pass it that way).
zdxc rejected it as an unknown argument. "-HV2021" stays an error, as
in dxc.
2026-11-01 20:16:21 -08:00
Peter Li c6d58c0017 Add a DXC drop-in: dxc and a dxcompiler library with DXC's COM API
zig build dropin installs the command line as bin/dxc and builds
dxcompiler (libdxcompiler.so / .dylib, dxcompiler.dll) exporting
DxcCreateInstance and DxcCreateInstance2. It implements IDxcCompiler3,
IDxcVersionInfo and IDxcUtils over compile, with DXC's result shapes,
status codes and include-path spellings, so programs that load DXC's
library (SDL_shadercross, for one) run on zdxc unchanged.

compile.Request gains compat_notes, off for the drop-in: its clients
read any diagnostic text as a warning.
2026-11-01 17:59:17 -08:00
Peter Li 31f3293380 zdxc: C API and static libzdxc
include/zdxc.h: compile a dxc command line in memory and read the
outputs (object, diagnostics, -P, -Frs) from a result; an optional
callback serves the input and #include files. No global state, so any
number of threads can compile at once. zig build installs libzdxc.a
(-Dlinkage=dynamic for a shared library) with the compiler runtime
bundled and only the zdxc_* symbols visible. docs/c-api.md describes it.

The pipeline moves from main.zig into compile.zig, which returns its
outputs instead of writing files; the command line and the C API both
use it, and produce the same bytes. The executable's build step is now
zdxc-cli so that artifact("zdxc") names the library; it still installs
as bin/zdxc. Writing an output file now fails with a message instead of
an error trace.
2026-11-01 17:15:16 -08:00
Peter Li badcdd8593 zdxc: make the tree a clean public source drop
Move the oracle tests, the benchmark and the libzdxc investigation
notes to the zdxc-internal development repo, which builds
this tree as a path dependency. The public build keeps install, run and
test. build.zig.zon now lists tools/ (the build needs its generators)
and docs/.
2026-11-01 15:39:53 -08:00
Peter Li 265fd17fd8 removing the zdxc binary 2026-11-01 15:26:33 -08:00
Peter Li a7f86d1a88 zdxc: --job=<job.json> batch mode
Compile every shader a JSON job file lists in one process, on all cores.
Each job is a dxc command line; shared args come first. Outputs are
byte-identical to separate runs and each job's diagnostics print together
in job order. 1481 corpus shaders: 0.064 s, against 1.09 s for one zdxc
per shader on 10 cores and 1.68 s for dxc.

Also: an unreadable input exits 1 as in dxc (was 5), and stdout/stderr
write in streaming mode so `2>> log` appends instead of overwriting.
2026-11-01 09:46:47 -08:00
Peter Li 9aa5f83508 zdxc: number DXIL instructions once per function
The bitcode writer found an instruction's value ID by counting the
non-void instructions before it, for every operand: quadratic in the
function's size. Large functions (unrolled loops, -O0 hull shaders) took
up to 190 ms; the IDs are now computed once per function. Output is
byte-identical; SubD11_SubDToBezierHS4444 goes from 192 ms to 10 ms
(dxc: 64 ms).
2026-11-01 09:27:47 -08:00
Peter Li 3fbbd5c4b5 zdxc: partial stores to shared memory; one SPIR-V type per strided array
Writing some components of a vector or matrix in an RW structured
buffer or groupshared memory read the whole value and wrote it all
back, racing with other threads writing the other components. Those
stores now write only the named components, as dxc does. Matrix rows
and elements of buffer matrices (W[i][1][2] = x, B[i].m[r] = v, at
constant or dynamic rows) are stored element by element instead of
being rejected.

SPIR-V arrays with the same element, length and stride are now one
type, so buffers of the same element share their runtime array.
2026-11-01 09:12:38 -08:00
Peter Li 717a0a9fad zdxc: -Zpr / -Zpc and #pragma pack_matrix
-Zpr and #pragma pack_matrix were accepted but ignored, so row-major
matrices silently got the column-major layout. Now, as in dxc:

- #pragma pack_matrix sets the orientation of matrices declared after
  it and may come between any two tokens; typedefs keep theirs.
- -Zpr is the default for matrices with neither; -Zpc is accepted and
  the two together are an error.
- Entry parameters take an orientation written on them or the
  pragma's, not a typedef's (dxc's signatures lose that sugar).
- Structured buffer matrix elements follow -Zpr only in DXIL; in
  SPIR-V they take the template argument's orientation too.
2026-11-01 08:53:09 -08:00
Peter Li d33c3838e2 zdxc: nested types of template instances; typedef members as dxc
Types declared in structs, template ones included, are accepted as the
last part of a qualified type name (TO<float>::In), which the parser
lost with the template's scope. typedef members are reported in struct
templates too (at the definition, as dxc), while alias declarations
(using F = float;) are allowed in any struct, as in dxc. Each HLSL
struct gets a module type of its own: struct types are named, and
same-named structs (two instances' nested In, or a ConstantBuffer<S>
class type and S) shared one layout, which crashed dxv.
2026-11-01 00:58:07 -07:00
Peter Li 3c4372d2bc zdxc: mangle template instances, classes and scoped names as dxc
Structs and enums remember their enclosing namespaces and structs, and
struct template instances their name and arguments, so mangled names
spell them as dxc does: U/V for struct/class, ?$Name@<args>@ for
instances (type arguments, $0<n> and $0?<n> integral ones, with names
of their own), each enclosing scope after the name, with back-references.
Exported functions whose signature holds a resource or matrix handle get
dxc's error instead of an invalid module.
2026-11-01 00:39:38 -07:00
Peter Li 8a6698c925 zdxc: keep [noinline] functions in DXIL libraries
[noinline] plain functions in libraries become internal functions of
their own (noinline nounwind) instead of being inlined, passed values as
exported functions are: scalars and vectors by value, structs and out /
inout values by pointer (through temporaries at the call). RDAT lists
them, and each function's shader flags, minimum shader model and stage
mask merge in its callees' (dxc's ComputeShaderCompatInfo), as do the
LinAlg extended properties. Functions with resources, matrix handles,
arrays, matrices or groupshared parameters are still inlined (the
validator rejects resources, LinAlg matrices included, in signatures).
2026-11-01 00:28:56 -07:00
Peter Li 5f4d2dc8e4 zdxc: SM 6.10 LinAlg in libraries
Write each library function's RDAT ExtendedProperties the way dxc's
AddLinAlgFunctionProperties does: matrix constructions with their
operation shapes, thread mat-vec multiplies, wave and thread-group
matrix multiplies, outer products and accumulating stores, merged from
callees, in the extended property record tables (part types 13-20)
with record deduplication. Removes the library LinAlg gate.
2026-11-01 00:07:09 -07:00
Peter Li e88c8500d1 out / inout resource parameters
- Resource locals may be declared without an initializer (an alias of
  what is stored into them; reading one first is reported).
- DXIL: inlined calls write out resources into the caller's alias; a
  resource written back to the global it is is a no-op.
- SPIR-V: out / inout resource parameters leave the parameter list (an
  inout one's value comes in by value); the callee works on a local and
  what it holds at the end is traced to a parameter or global, which the
  caller stores into the argument after the call.
- An acceleration structure that is only declared gets the ray query
  capability its type needs.
2026-10-31 23:55:37 -07:00
Peter Li 56d0da0b92 Arrays of resources as function parameters
- DXIL: a local array of resources (a parameter's copy) aliases the
  resource array stored into it; elements index that array.
- SPIR-V: a whole resource array read to pass on stays its variable, so
  the callee is specialized on it; arrays read whole are not flattened
  (their bindings are still numbered per element), which also lets
  global structs holding resource arrays be passed to functions.
2026-10-31 22:10:48 -07:00
Peter Li e830120128 SPIR-V: resources in structs (locals, values, parameters, returns)
- An IR pass for SPIR-V splits structs holding resources: resource
  members of locals become resource locals, struct values carry their
  resources alongside (construct / extract / insert / load / store),
  parameters holding resources (by value or reference, including
  `this`) gain a resource parameter per member, and functions returning
  resources return the parameter or global they trace to.
- Struct values in SPIR-V leave resource members out.
- Arrays of global structs of resources: an element per resource
  variable named by flattened index (globals[5].t), and the whole struct
  reserves one consecutive binding range, as dxc numbers them.
2026-10-31 21:55:56 -07:00
Peter Li 45b4805a25 Resources in structs (DXIL), global structs of resources (both)
- DXIL: structs and arrays holding resources as values (data plus the
  resources, statically known) and as locals (data in memory, a
  resource slot per member): copies, nested structs, arrays, init lists,
  function arguments and returns, and functions returning resources.
- Global structs with resources: each resource is its own global named
  by its path (g.tex), bound like other unbound resources; data members
  stay in $Globals with resources taking no space in the layout.
- SPIR-V: struct types drop resource members (member indices remapped);
  a global struct of textures and samplers gets a binding per resource
  and turns on per-element array bindings, as dxc does; dxc's errors
  for structs with buffers or mixed members.
- LinAlg vectors of one element stay native vectors.
2026-10-31 21:12:07 -07:00
Peter Li 3c7fdb2ad2 SM 6.9 long vectors (DXIL)
- vector<T, N> with N up to 1024 from shader model 6.9 (vector lengths
  and shapes widen to u16); intrinsic layouts accept long vectors.
- DXIL keeps the scalarized form: buffers, groupshared memory, structs,
  intrinsics and LinAlg vector operands work for any length.
- dxc's diagnostics: no swizzles on long vectors, and none in cbuffers,
  tbuffers, $Globals, ConstantBuffer/TextureBuffer, patches, streams or
  entry point parameters / return types.
- SPIR-V reports long vectors as unsupported (Vulkan has none; dxc's
  output is invalid).
2026-10-31 20:49:41 -07:00
Peter Li 77f4fb539c SM 6.10 linear algebra (DXIL)
- __builtin_LinAlgMatrix [[__LinAlgMatrix_Attributes(c, m, n, use,
  scope)]] as a type; matrices live in locals, statics and structs as
  matrix-typed allocas (as dxc -Od); !dx.targetTypes.
- All 21 dx::__builtin_LinAlg_* builtins lowered to DXIL ops 322-342
  with dxc's overload names (matrix, native vector and scalar operands;
  results stored to the out / ref argument).
- The LinearAlgebra shader flag; PSV0 LinAlgRuntimeInfo (constructions,
  multiplies, outer products, accumulate stores), byte-identical to dxc
  where matrix loads are traceable.
- groupshared parameters alias the caller's variable (they were copied);
  constants forwarded through locals within a block (immediates through
  parameters); enum static consts folded.
- Linear algebra in libraries (RDAT properties) and long vectors are
  reported as not supported yet.
2026-10-31 20:25:57 -07:00
Peter Li 56adacfc4a Inline SPIR-V types (vk::SpirvType, vk::SpirvOpaqueType) and cooperative matrices
- A spirv type kind: opcode with type, constant and literal operands
  (vk::integral_constant, vk::Literal), sized (SpirvType) or opaque.
  Integer, float and pointer types map to zdxc's own; others are
  declared as spelled and deduplicated. Capabilities and extensions on
  aliases, fields and declarations travel with the type.
- vk::WorkgroupSpirvPointer and other inline pointers are values, never
  variables; passing one to a function adds VariablePointers (dxc
  inlines the call instead).
- __builtin_spv_CooperativeMatrixLengthKHR; template argument deduction
  through aliases of inline types and qualified patterns; function
  template instances keep their arguments.
- [[vk::ext_literal]] defaults, constants resolved where Sema saw them,
  static members through objects, enum-typed values in SPIR-V.
- [[vk::ext_decorate(_string)]] on struct members; capabilities from
  inline SPIR-V add the extensions they need; PhysicalStorageBuffer64
  addressing with physical storage buffer pointers.
- All vk::khr::CooperativeMatrix tests compile to valid SPIR-V.
2026-10-31 19:22:10 -07:00
Peter Li 478bb4faf6 Templates: S<T>::member, partial specialization, member templates, SFINAE, out-of-line members, ADL
- Qualified names through template instances (S<T>::x, S<T>::f(),
  typename S<T>::type).
- Partial specialization patterns matched structurally
  (matrix<T, N, M>, S<T>); the injected class name inside instances.
- Member function templates (obj.f<T>(), S::f<T>()), including calls
  from other members; S::f<1>(x) parsed as a call.
- SFINAE: candidates whose signature fails to substitute are dropped;
  a declared-then-defined template uses its definition.
- Out-of-line member definitions, for plain structs (keeping static),
  namespaces and class templates (given to every instance), including
  nested template<> template<> member templates.
- Deduction from resources (RWStructuredBuffer<T>), through alias
  templates and from the injected class name; argument-dependent lookup.
- static const members evaluated in their instance's scope; sizeof(T)
  in template arguments; ::template; instantiation depth limit.
2026-10-31 18:58:46 -07:00
Peter Li d05bf92af5 Vulkan memory model, ROV interlock, globallycoherent, legacy buffer matrix order
- -fspv-use-vulkan-memory-model: a port of spirv-opt's UpgradeMemoryModel
  (Coherent / Volatile become access flags, Device scope becomes
  QueueFamily); also used when ray tracing reads subgroup built-ins
  below Vulkan 1.3, as dxc does.
- Rasterizer-ordered views: SPIR-V fragment shader interlock around the
  entry; DXIL ROV metadata, properties, RDAT flag and shader flag.
- globallycoherent: SPIR-V Coherent; DXIL metadata, properties, RDAT.
- -fspv-use-legacy-buffer-matrix-order: row-major byte-address matrices.
- -fspv-preserve-interface accepted (zdxc keeps every interface variable).
2026-10-31 17:26:53 -07:00
Peter Li 9e0375fbc5 SubpassInput, vk::image_format and inline SPIR-V
SubpassInput / SubpassInputMS with [[vk::input_attachment_index]] (a
SubpassData image read at (0, 0), with the sample for MS). Explicit
[[vk::image_format]] on storage images and texel buffers, followed from
the variable to every load and element access.

Inline SPIR-V: calls of [[vk::ext_instruction(op[, set])]] functions emit
the instruction (OpExtInst for a set) with [[vk::ext_literal]] and
[[vk::ext_reference]] operands; vk::ext_result_id<T>; ext_capability /
ext_extension on functions, variables and entry points;
ext_builtin_input / ext_builtin_output variables; ext_storage_class;
ext_decorate, ext_decorate_id and ext_decorate_string on variables and
entry parameters; vk::ext_execution_mode(_id). The capabilities and
extensions instructions, builtins, decorations and execution modes need
come from a table generated from the SPIR-V grammar.
2026-10-31 17:08:44 -07:00
Peter Li 3f33ec209b SPIR-V reflection, extension and entry point options; vk::builtin
-fspv-reflect adds SPV_GOOGLE UserSemantic, UserTypeGOOGLE and
CounterBuffer decorations; -fspv-extension= restricts the extensions
used (KHR allows all KHR ones; the NV compute derivatives extension is
used when only it is allowed); -fspv-entrypoint-name= renames the entry
point; -fspv-enable-maximal-reconvergence; -fvk-support-nonzero-base-
instance / -vertex subtract the base instance / vertex as dxc does;
-fspv-use-unknown-image-format. [[vk::builtin(...)]] on parameters and
fields (PointSize, HelperInvocation, BaseVertex, BaseInstance, DrawIndex,
DeviceIndex). Constant buffer block types are named type.<buffer> only.
2026-10-31 16:55:14 -07:00
Peter Li 726d0016eb Vulkan layout and position options; packoffset; 64-bit buffer access
-fvk-use-gl-layout (strict std140 / std430), -fvk-use-dx-layout (FXC
cbuffer / structured buffer packing) and -fvk-use-scalar-layout pick the
constant buffer, tbuffer and structured buffer rules as dxc picks them;
[[vk::offset]] places members (and is checked against the rules).
-fvk-invert-y flips SV_Position.y in the last pre-raster stage;
-fvk-use-dx-position-w reciprocates SV_Position.w in pixel shaders.

Constant buffer members honor packoffset / register(cN) on both
backends, the rest following the last explicit member (as dxc; DXIL used
to ignore them). Packed structs round their size up to their widest
component, so structured buffers of {double; float3} have dxc's 24-byte
stride on both backends (was 20). 64-bit structured buffer loads and
stores before SM 6.3 go through i32 words (bufferLoad / rawBufferLoad
.i32 with makeDouble / splitDouble), as dxc; they used invalid 64-bit
overloads before.
2026-10-31 16:47:35 -07:00
Peter Li eff23d800e Vulkan bindings, locations, push constants and spec constants
SPIR-V descriptor bindings are numbered as dxc numbers them: Sema keeps
global and cbuffer declarations in order, lowering records every
descriptor declaration (used or not), and the backend assigns
[[vk::binding]] / [[vk::counter_binding]] first, then register() with the
-fvk-{b,t,s,u}-shift options, then the rest on the next free bindings in
declaration order (Append / Consume counters right after their buffer,
other counters last). Adds -fvk-bind-register, -fvk-bind-globals,
-auto-binding-space, -fvk-auto-shift-bindings, -fvk-stage-io-order and
-fspv-flatten-resource-arrays (one variable per element where indices
are constant), [[vk::push_constant]] buffers (std430, PushConstant),
[[vk::constant_id]] specialization constants, [[vk::location]] and
[[vk::index]], interface variables named after the semantic as written,
and location counts for 1xN / Nx1 matrices. -fcgl is accepted.

Against dxc on the corpus, bindings and locations now match on all 1234
comparable SPIR-V outputs (865 differed before). The SPIR-V checks now
compare bindings and locations with dxc for every test.
2026-10-31 16:38:16 -07:00
Peter Li 1c5d9bed09 Root signatures in shaders, libraries and rootsig targets
[RootSignature(...)] on an entry compiles (global mode, version 1.1 or
-force-rootsig-ver) into an RTS0 part after PSV0; errors are reported as
dxc reports them. Libraries' GlobalRootSignature / LocalRootSignature
subobjects carry their serialized root signature in RDAT's raw bytes.
-T rootsig_1_0 / rootsig_1_1 compile the macro -E names into a root
signature container; -rootsig-define, -Frs and -Qstrip_rootsignature
are supported. All 49 corpus shaders with root signatures match dxc's
RTS0; the DXIL checks now compare RTS0 as well as RDAT.
2026-10-31 16:09:26 -07:00