Commit Graph

11 Commits

Author SHA1 Message Date
96dcddb6fb Merge pull request #1911 from Jan Trencansky 2026-11-22 10:39:21 -05:00
6a16ac1436 FSPX lookup: a kind-0 state key next to the code key; ambiguous programs are refused (RT-99 review)
Review on #1911: two containers with the same kind-6 program and different kind-0 entries (32x1x1 and 64x1x1)
translate to different modules but got the same fspx_code_sha256, so both resolved to the same pipeline.

- tools/fspx_unpack.py writes the kind-0 entry as fspx/<name>.state; tools/shader_meta.py records its SHA-256 as
  fspx_state_sha256 next to fspx_code_sha256.
- make_game.py: entries with the same code and state keys must have identical modules, otherwise the FSPX step fails
  naming both programs and drops the index. The same code key with other state keys is allowed.
- runtime: a container or bare payload (kinds 0 and 6 present) matches the code key and then the state key; no match
  is E_INVALIDARG. A bare kind-6 program (slot 67, no kind 0) takes the code key's entries when their modules are
  identical, and is refused with E_INVALIDARG and an "ambiguous" log line when they differ.
- Tests: the review case in tests/test_fspx_shaders_stage.py, shader_library_test and d3d12_fspx_compute_test.
- docs/fspx.md: the two keys and the ambiguous case.

On 1.0.2.1 the 29 kind-6 programs are distinct, so nothing resolved wrongly before: 17 translated entries, 17
distinct code keys, 17 distinct (code, state) pairs, all 17 found from the container and from the bare program.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 10:28:07 -05:00
4de870250e SHADER-309: keep compute workgroup memory under the limit
--wave64-emulate adds %x_buf (2L + 6W + 7 dwords) on top of the LDS
array, so a 64 KiB LDS made modules over maxComputeSharedMemorySize,
which spirv-val accepts and RADV dies on (#1721).

Translator: a 64 KiB hard cap (MAX_SHARED_BYTES, --max-shared-memory).
Over it, the pow2-rounded LDS array shrinks to the room left when the
program's need fits (indices wrap with OpUMod); otherwise the shader is
refused (Unsupported, with the byte counts). lds_bytes in index.json is
now the whole Workgroup total.

Runtime: the D3D12 shim's create_compute compares lds_bytes with the
device's maxComputeSharedMemorySize (32768 on AMD Windows and Intel)
and refuses the pipeline with a log line instead of creating it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 15:49:23 +01:00
c7801ac6fb Merge upstream main
# Conflicts:
#	docs/d3d12_vulkan.md
#	runtime/README.md
2026-11-22 09:35:55 -05:00
088447e117 FSPX programs: translated by the shaders stage, found at run time by their kind-6 bytes (RT-99)
The FidelityFX DLL creates its compute pipelines from FSPX programs (docs/fspx.md): through slot 67 with the bare
kind-6 program, then through slot 62 with the DXBC container whose ACCC part holds the payload. Both ended in
E_INVALIDARG: the layer took only FSSM bytecode, the build never translated the DLL and the index had no key for it.

- make_game.py: the shaders stage unpacks the package's DLL with tools/fspx_unpack.py --disasm into
  <work>/shaders/fspx and translates it into <work>/shaders/spirv/fspx, with the same wave64 mode and fallback
  flags. The step is redone as a whole when the DLL, its tools, llvm-mc or the flags change (fspx_build.json,
  written last) and never makes the game's shaders run again.
- tools/shader_meta.py: an entry of a program without an FSSM blob gets fspx_code_sha256, the SHA-256 of
  fspx/<name>.code.
- runtime/src/shader_library.h: the library also loads <dir>/fspx/index.json and finds entries by
  fspx_code_sha256. compute_program() takes an FSSM program as before, the kind-6 bytes of an ACCC container or of a
  bare FSPX payload, and a bare kind-6 program recognized by its prologue; the directory is parsed with the DLL
  reader's rules and bounds-checked, so a malformed one is refused.
- create_compute: looks the program up by the key of its kind and uses those bytes as the code base.
- Tests: shader_library_test (parsing, malformed directories, lookup, the fspx folder), d3d12_fspx_compute_test
  (PSOs from both forms, a dispatch each, refused inputs) and tests/test_fspx_shaders_stage.py.
- Docs: the lookup in docs/fspx.md; slots 62 and 67 in d3d12_command_objects.md and d3d12_vulkan.md. The size the
  slot-67 description carries at +0x30 is kind 6's own size, read from the DLL's code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 09:22:54 -05:00
bb0ecfc089 Merge pull request #906 from AlxcBTW 2026-11-22 08:37:59 -05:00
e4de50abfd fix(shader_library): validate DXBC part-table bounds before iterating parts 2026-11-22 09:59:46 -03:00
7176d29679 Runtime: read subgroup_size and wave64_exchange from the shader index
ShaderEntry gains subgroup_size (0 when the entry says null or has none) and
wave64_exchange; emulated() is true for a shader translated with
--wave64-emulate, which is exact on any subgroup size. shader_library_test
checks an absent, a native and an emulated entry.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-22 13:05:09 +01:00
Ryx
8b711cc6b4 Runtime: fixes from CharlyRien's review of the compute and draw paths
Shader library
- fssm_program takes the last XDAT 0x0D payload, as tools/fssm_unpack.py does by default (195 of 26,503
  containers have two different ones, and fssm_sha256 is computed from the last).
- The JSON reader parses numbers with from_chars and \u escapes as exactly four hex digits, so a malformed
  index is refused instead of throwing into the shim. Integer fields outside 0..2^32-1 read as 0.
- Index entries that share a program are all kept; CreateGraphicsPipelineState takes the VS whose input
  signature the input layout feeds.

Command list
- Setting the root signature that is already bound keeps the root arguments, as D3D12 does.
- A draw with no viewport (never set, or RSSetViewports(0, ...)) or an empty one is not recorded: D3D12
  rasterizes nothing and Vulkan forbids a 0x0 viewport.
- More than eight render targets is an invalid call, in OMSetRenderTargets and in a PSO.

Device
- Buffers of 0 bytes, or with a size that wraps when aligned, are E_INVALIDARG. The arena refuses zero-size
  ranges, and its fit test cannot wrap.
- A shader-visible descriptor heap the arena cannot hold is E_OUTOFMEMORY instead of a host heap with GPU
  handle 0.
- A failed arena releases its buffer and memory, so other buffers do not get raw device addresses as VAs.
- Graphics PSOs that need independentBlend, fillModeNonSolid, depthBiasClamp or dualSrcBlend are refused
  unless VulkanDeviceInfo::features has them. The standalone device enables those the GPU supports.
- A draw that leaves a slot unbound where the PSO names a format uses a pipeline variant with that format
  undefined (built on first use, kept with the PSO), instead of breaking
  dynamicRenderingUnusedAttachments-08912.
- Instance step rate 0 reads element 0 for every instance (stride 0 at draw time).
- The Vulkan 1.0 graphics entry points are required; the 1.3 ones are checked before a graphics PSO is made.

Replay
- An unbound vertex slot, or an indexed draw with no index buffer, reads the arena's reserved first 64 KiB,
  which is kept zero, as D3D12 reads zeros. A view that runs past its buffer is cut at the buffer's end
  instead of failing the whole ExecuteCommandLists.
- The rendering layer count is the smallest layer count of the bound views.

Tests: shader_library_test covers two payloads, malformed JSON and duplicate programs. d3d12_draw_test
covers an unbound RT and DSV, a rebound root signature, step rate 0, an unbound vertex slot, a draw with no
viewport, the feature and count refusals, and bad buffer and heap sizes. Each of the rebind, step-rate and
variant fixes, undone on its own, makes the test fail.

Still open, documented: instance step rates above 1, read-only DSV layouts, and the index buffer's view size.
2026-11-22 05:01:36 +01:00
Ryx
1e7f5152ae Runtime: graphics pipelines and draws on Vulkan (milestone M1, D3D-4)
- CreateGraphicsPipelineState (PC slot 10): VS and PS found by the SHA-256
  of their FSSM programs in the translator's index. Input-layout elements are
  matched to the VS input signature by semantic name and index; location =
  the element's register (the translator's vertex-fetch rule); a layout that
  leaves an input unfed is refused, as D3D12 does. Rasterizer, blend and
  depth-stencil state map one to one; viewport, scissor, topology, vertex
  strides, stencil references and blend factor are dynamic; dynamic
  rendering takes the RTV/DSV formats. Hull/domain/geometry, stream output,
  MSAA, set-0 bindings and two code-base stages (question 14) are refused
  with a log.
- Command list: IASetPrimitiveTopology / VertexBuffers / IndexBuffer,
  RSSetViewports / ScissorRects (first of each), OMSetRenderTargets (views
  read at the call, single-range handles too), OMSetBlendFactor,
  OMSetStencilRef and CommandList8's front/back references (now applied),
  DrawInstanced / DrawIndexedInstanced recording a copy of that state.
  CreateCommandList's initial pipeline state is applied. Reset and
  ClearState share one state reset.
- Replay: vertex/index views resolve to buffers by VA (arena or upload),
  attachments move to attachment layouts through the tracker (first use
  zero-fills), the draw runs in a dynamic-rendering scope with a flipped
  viewport (translated VS write D3D clip coordinates), stencil references
  per face, then vkCmdDraw / vkCmdDrawIndexed. Render-target views take the
  pipeline's formats (the view cache keys on format).
- shader_library.h reads the index's input_signature and PS outputs.

Test: d3d12_draw_test (through the proxy) builds a VS+PS PSO whose input
layout order differs from the VS registers, uploads a vertex buffer into the
arena, reads indices from an upload heap, and draws two indexed quads with
different root constants and root CBVs plus a back-facing triangle: all 4096
read-back pixels match (which also checks the viewport flip and winding).
Shaders are GLSL written to the translator's contract. d3d12_com_test now
uses SetMarker as its unimplemented-method example, since DrawInstanced is
implemented. 13/13 ctest; all six GPU tests clean under the Khronos
validation layer.
2026-11-22 05:01:36 +01:00
Ryx
998368adbf Runtime: compute groundwork (FSSM shader lookup, Dispatch in the IR)
First pieces of D3D-3 (compute path), no pipelines wired up yet:
- shader_library.h: FSSM extraction from the DXBC container (DXIL, XDAT
  0x0D, XBCH, zlib), SHA-256, a minimal JSON reader and the
  spirv/index.json lookup by fssm_sha256. Self-contained inflate, no
  dependencies.
- IR Dispatch with user data captured at record time; replay binds the
  pipeline, pushes the 144-byte block (s0..s31, heap base, code base) and
  dispatches. Arena buffers get a buffer_offset that copies honour.
- Root signatures use main's model (runtime/src/root_signature.h); the docs
  say so.

Tests: shader_library_test (FIPS 180-4 vectors; stored, fixed and dynamic
deflate blocks; corrupt and truncated streams; FSSM from a synthetic
container) joins ctest; command_list_test covers dispatch recording.
2026-11-22 04:58:00 +01:00