Commit Graph

3 Commits

Author SHA1 Message Date
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