Commit Graph
3 Commits
Author SHA1 Message Date
西风逍遥游 128fd5c95e feat(graphics): complete classic rendering chain 2026-08-26 22:35:20 +08:00
西风逍遥游 eae8cfbc38 feat(graphics): stage 3 - VirtualGeometry hardware-raster integration
Virtual-geometry assets now render through the main GPU-driven frame instead of
the standalone software-raster experiment:

- Shared VG scene in vulkan::Graphics: pooled positions/triangles/clusters +
  per-cluster asset ids + per-slot visible list / indirect commands / asset
  models + materials. Meshes attach an asset via gpuDrivenVgAttachToMesh;
  GpuMeshRecord.vgAssetId routes them out of the instance chain.
- vg_main_cull.comp runs in the main frame's compute section (frustum + HZB
  against the per-asset model) and emits per-cluster VkDrawIndirectCommand
  (vertexCount = triCount*3, firstInstance = cluster id).
- Hardware raster: mesh3d_gbuffer_vgvis draws clusters with NO vertex input -
  gl_InstanceIndex = cluster, gl_VertexIndex = triangle corner, positions from
  the cluster stream; face normals computed from world edges; writes the same
  visID/visBary attachments (bit31 marks VG clusters).
- resolve_vis.frag decodes VG clusters: asset -> material, interpolates from
  the cluster stream, flat-tint shading via the shared PBR core, writes
  gl_FragDepth so later transparent draws depth-test correctly.
- gpu_emit.comp additionally writes non-indexed VkDrawIndirectCommand per
  bucket (the 20-byte indexed layout's firstInstance sits at offset 16, which
  vkCmdDrawIndirect (16-byte commands) ignores - this was the vis pass showing
  only instance 0). The vis pass now draws from that command stream.
- All per-frame bindless updates (vis samplers 15/16, VG bindings 26-29) moved
  BEFORE the set is bound to the recording command buffer (no UPDATE_AFTER_BIND;
  updating a bound set invalidates the CB - caught by validation).
- drawIndirectCount Vulkan 1.2 feature enabled at device creation; the VG
  count buffer carries VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT.
- RenderControl gains the "visResolve" feature flag (the stage-3 resolve path
  was previously enabled via an unknown flag that setFeature silently dropped).

Verified: GpuDriven.visResolveParity now genuinely exercises the resolve path
(maxDelta = 0.0 vs forward); GpuDriven.vgVisResolve renders a sphere's clusters
through the main frame (9 visible after frustum+HZB, tint-correct center,
frustum-culled to 0 behind the camera); 19 render tests + 3x suite repeat pass;
validation shows no new VUIDs.
2026-08-21 19:04:13 +08:00
西风逍遥游 d82d246465 gpu-driven stage 2: GPU frustum/HZB cull + GPU-written indirect draws
Add the stage-2 compute chain to the main frame:
- ComputePass wrapper + compile script for compute SPIR-V (hzb_build /
  gpu_cull / gpu_emit); bindless set extended with cull UBO, visible flags,
  compacted instances, indirect commands, HZB buffer and GBuffer depth.
- HZB: R32F max-downsampled mip chain per frame slot built from the
  GBuffer depth after the GBuffer pass (buffer-based; offsets header at slot
  start). Same-frame self-occlusion handled by testing the bounding sphere's
  FRONT depth, and near-zero depth (uninitialized/corner garbage) never
  occludes.
- Cull: per-instance Gribb-Hartmann frustum test + HZB occlusion test, flags
  written per instance; emit compacts visible instances per CPU-provided
  bucket layout and fills per-bucket indirect commands with atomic counters.
- Frame wiring: begin3DFrame defers opening the scene color pass when the
  cull chain is live, so the compute section records before the opaque
  draws; RenderSystem3D uploads sorted instances, runs cull+emit, opens the
  pass and draws with GPU-written commands (per-bucket, empty buckets no-op).
  Fallback to stage 1 when compute caps are missing. gpuDriven now forces
  the GBuffer pass (HZB source).
- Known limitation: HZB is built from the same-frame GBuffer, so objects
  already in the GBuffer cannot be occlusion-culled until the GBuffer itself
  is culled (stage 3 vis buffer); the chain is verified with frustum culling
  (2 of 5 instances culled) and pixel parity.

Tests: GpuDriven.opaqueForwardCullParity (5 spheres, 2 outside frustum ->
3 visible / 3 non-empty buckets, pixel parity < 0.03); all 6 GpuDriven
tests pass (integrated GPU; the AMD driver intermittently crashes at
vkCreateImage during init - environmental).
2026-08-21 15:09:39 +08:00