Skip to content

New VertexBuffer YAML definition using new Format enum#1087

Open
EmilioLaiso wants to merge 11 commits intollvm:mainfrom
Traverse-Research:render-backend-api-vertex-buffer
Open

New VertexBuffer YAML definition using new Format enum#1087
EmilioLaiso wants to merge 11 commits intollvm:mainfrom
Traverse-Research:render-backend-api-vertex-buffer

Conversation

@EmilioLaiso
Copy link
Copy Markdown
Contributor

@EmilioLaiso EmilioLaiso commented Apr 14, 2026

Summary

This PR introduces a new VertexBuffers YAML schema and vertex buffer support into the offload test suite, replacing the previous approach where vertex data was defined as a raw CPUBuffer entry under Buffers: and manually described via VertexAttributes: in Bindings:.

New YAML schema: VertexBuffers

A new VertexBuffers: section is added to test pipeline definitions.
Each vertex buffer declares named streams with a typed Format and inline Data:

VertexBuffers:
  - Name: VB
    Streams:
      - Name: POSITION
        Format: RGB32Float
        Data: [...]
Bindings:
  VertexBuffer: VB

This replaces the old pattern where vertex data lived in Buffers: and layout was specified separately in Bindings: > VertexAttributes:. Channels, Offsets and Stride are now inferred.

# Old (removed)
Buffers:
  - Name: VB
    Format: Float32
    Channels: 3
    Data: [...]
Bindings:
  VertexBuffer: VB
  VertexAttributes:
    - Format: Float32
      Channels: 3
      Offset: 0
      Name: POSITION

Parsed representation

  • ParsedVertexBuffer / VertexStreamData (include/Support/Pipeline.h) -- YAML-side parsed representation. Stream values are stored as double and then interleaved + type-converted during parsing into a single InterleavedData buffer ready for GPU upload. Provides helpers for computing stride, per-stream byte offsets, and vertex count.

BufferUsage enum and per-backend changes

A BufferUsage enum (Storage / VertexBuffer) is added to BufferCreateDesc so backends can set the correct usage flags. Each backend creates its vertex buffer directly via createBuffer with VertexBuffer usage, and derives the input layout from the parsed pipeline (ParsedVertexBuffer) at PSO/pipeline creation time:

  • Vulkan (lib/API/VK/Device.cpp): sets VK_BUFFER_USAGE_VERTEX_BUFFER_BIT for vertex buffers; eliminates the old host-staging + device-copy pair in favor of a single CpuToGpu mapped buffer (with a TODO to revisit for discrete GPUs).
  • DirectX 12 (lib/API/DX/Device.cpp): uses D3D12_HEAP_TYPE_UPLOAD for CpuToGpu vertex buffers; builds D3D12_INPUT_ELEMENT_DESC from ParsedVertexBuffer streams instead of VertexAttribute.
  • Metal (lib/API/MTL/MTLDevice.cpp): builds MTL::VertexDescriptor from ParsedVertexBuffer streams; copies interleaved data into a managed Metal buffer.

Buffer::getSizeInBytes()

A new pure virtual getSizeInBytes() is added to Buffer, implemented by DXBuffer, VulkanBuffer, and MTLBuffer.

Resources.h helpers

  • getComponentCount(Format) -- returns the number of components per element for a format.

Pipeline parser changes (lib/Support/Pipeline.cpp)

  • Parses the new VertexBuffers: section with VertexStreamData mapping (Name, Format, Data).
  • Validates format compatibility (isVertexCompatible), data-size-to-component-count alignment, and consistent vertex count across streams.
  • Interleaves per-stream double values into a packed byte buffer (InterleavedData) with format-specific type conversion via writeComponent().
  • Resolves Bindings::VertexBuffer against Pipeline::VertexBuffers instead of Pipeline::Buffers.
  • Removes VertexAttribute mapping and the VertexAttributes binding key.
  • Adds ScalarEnumerationTraits<Format> so that the new Format enum can be used directly in YAML fields.

Test migrations

All 22 graphics test files are migrated from the old schema to the new VertexBuffers: + Streams: format.

Comment thread include/API/VertexBuffer.h Outdated
@EmilioLaiso EmilioLaiso force-pushed the render-backend-api-vertex-buffer branch from dd8710c to c575aca Compare April 16, 2026 08:30
@EmilioLaiso
Copy link
Copy Markdown
Contributor Author

Use of shared_ptr will be replaced with unique_ptr after #1094 has gone in

@EmilioLaiso EmilioLaiso changed the title Add VertexBuffer abstraction with typed streams and per-backend support New VertexBuffer YAML definition using new Format enum Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants