Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
RenderData.h
Go to the documentation of this file.
1#pragma once
2#include <array>
3#include <cstddef> // for offsetof
4#include <glm/mat4x4.hpp>
5#include <vector>
6
7#include "GpuDataLayouts.hpp"
8
9namespace EngineCore
10{
18 {
19 // culling data
22
23 // Meshlet Info
24 uint32_t meshletOffset; // where the meshlet data for this primitive starts
25 uint32_t meshletCount;
26
28 };
29
37 {
38 glm::mat4 modelMatrix;
39 std::vector<CpuPrimitiveData> primitives;
40 };
41
42
43
51 {
52 uint32_t meshletCount = 0u;
53 uint32_t offset = 0u;
54 };
55
62 struct Dispatch
63 {
64 uint32_t groupSizeX = 0u;
65 uint32_t groupSizeY = 0u;
66 uint32_t groupSizeZ = 0u;
67 };
68
76 {
77 uint32_t vertexCount; // Number of vertices in this meshlet
78 uint32_t triangleCount; // Number of triangles in this meshlet (primitive count)
82 uint32_t pipelineIndex;
83 };
84
92 {
93 glm::vec4 worldPositionAndRadius; // xyz = world position, w = radius
94 uint32_t meshletIndex = 0;
95 uint32_t pipelineIndex = 0;
96 };
97
99 {
101 uint32_t materialId;
102 };
103
105 {
106 std::vector<UnifiedMeshlet> meshletData;
107 uint32_t textureIndex = 0u;
108 std::vector<uint32_t> vertices;
109 std::vector<uint8_t> tris;
110 };
111
123 struct alignas( 16 ) [[deprecated("Use mat4 directly via RenderingDataManager::getPerObjectDataBuffer()")]] PerObjectData
124 {
125 glm::mat4 worldMatrix;
127 uint32_t meshletCount;
128 uint32_t indexCount;
129 uint32_t meshOffset;
131 };
132
144 {
148 uint32_t objectIndex;
149 uint32_t _padding[3]; // Pad to 32 bytes for std430 struct alignment
150 };
151
164 {
166 };
167
172 {
174 uint32_t meshletCount;
175 uint32_t pipelineID;
176 };
177
182 {
183 uint32_t meshStartIndex; // start index of the meshlets of this mesh
184 uint32_t meshletCount; // amount of meshlets of which this meshlet is made of
185 uint32_t objectIndex; // index which links back to the main SSBO
186 };
187
195 {
196 std::array<glm::vec4, 6> planes[2]; // [eyeIndex][planeIndex] left, right, top, bottom, near, far
197 };
198
209 {
210 glm::mat4 viewProjection[2]; // [eyeIndex] - 2 x 64 bytes = 128 bytes
211 glm::vec2 screenSize; // 8 bytes
212 uint32_t hiZMipLevels; // 4 bytes
213 uint32_t _padding; // 4 bytes for alignment
214 }; // Total: 144 bytes
215
224 {
225 uint32_t objectID;
226 uint32_t meshletIndex;
228 uint32_t _padding;
229 };
230
232 {
233 uint32_t objectIndex; // Index into the allObjects array
234 uint32_t startMeshletId; // First thread ID assigned to this object's meshlets
235 uint32_t meshletCount; // How many meshlets this object has
236 uint32_t _padding; // Optional: for 16-byte alignment (GPU preference)
237 };
238
240 {
241 uint32_t objectCount;
243 };
244
245 // ============================================================================
246 // Instancing Data Structures (for geometry deduplication)
247 // ============================================================================
248
261 {
263 uint32_t meshletCount;
264 uint32_t pipelineIndex;
266 // LOD extension (Phase 1)
268 uint32_t clusterCount;
270 uint32_t groupCount;
271 };
272 static_assert(sizeof(MeshGeometryData) == 32, "MeshGeometryData size mismatch");
273
282 {
283 glm::mat4 worldMatrix;
284 uint32_t meshGeometryId;
285 uint32_t materialId;
286 uint32_t colorTextureId;
287 uint32_t _padding;
288 }; // Total: 80 bytes
289
298 {
300 uint32_t instanceId;
301 uint32_t meshGeometryId;
302 uint32_t _padding[2];
303 };
304
313 {
314 uint32_t meshGeometryId;
316 uint32_t meshletCount;
319 // Vertex shader path data (for single-meshlet geometry)
320 uint32_t vsIndexOffset;
321 uint32_t vsIndexCount;
323 // Cached material lookup (avoids redundant asset manager queries)
324 uint32_t pipelineIndex;
327 };
328
338 {
339 uint32_t indexCount;
340 uint32_t firstIndex;
341 int32_t vertexOffset;
342 uint32_t pipelineIndex;
343 };
344
345 // ============================================================================
346 // GPU Material Data Structures (must match GLSL std430 layout)
347 // ============================================================================
348
356 {
357 glm::vec3 color;
358 float _padding; // Align to 16 bytes for std430
359 };
360 static_assert(sizeof(GpuDiffuseFlatColorMaterial) == 16, "GpuDiffuseFlatColorMaterial size mismatch");
361
368 struct alignas(16) GpuDiffuseShaderMaterial
369 {
371 float _padding1[3];
373 };
374 static_assert(sizeof(GpuDiffuseShaderMaterial) == 32, "GpuDiffuseShaderMaterial size mismatch");
375 static_assert(offsetof(GpuDiffuseShaderMaterial, baseColorFactor) == 16, "baseColorFactor must be at offset 16");
376
391 struct alignas(16) GpuPbrMaterial
392 {
393 // Texture indices (0xFFFFFFFF = not present)
398
399 // Material factors - vec4 must be 16-byte aligned
401
402 // vec3 in std430 has 16-byte alignment; offset 32 is 16-byte aligned
403 glm::vec3 emissiveFactor;
405
408 float sh_scale;
410
411 uint32_t debug_mode;
412 uint32_t tone_mapping;
413 uint32_t lightmapTextureIndex; // Lightmap texture index (0xFFFFFFFF = not present)
414 uint32_t hasLightmap; // 1 if lightmap is present, 0 otherwise
415 };
416 static_assert(sizeof(GpuPbrMaterial) == 80, "GpuPbrMaterial size mismatch with GLSL std430 layout");
417 static_assert(offsetof(GpuPbrMaterial, baseColorFactor) == 16, "baseColorFactor must be at offset 16");
418 static_assert(offsetof(GpuPbrMaterial, emissiveFactor) == 32, "emissiveFactor must be at offset 32 (16-byte aligned for std430 vec3)");
419
425 struct alignas(16) GpuNormalsMaterial
426 {
427 uint32_t debug;
428 uint32_t _padding[3];
429 };
430 static_assert(sizeof(GpuNormalsMaterial) == 16, "GpuNormalsMaterial size mismatch");
431
438 struct alignas(16) SHProbeData
439 {
440 glm::vec4 coefficients[9]; // L0-L2 RGB coefficients (9 bands)
441 float scale;
443 uint32_t _padding[2];
444 };
445 static_assert(sizeof(SHProbeData) == 160, "SHProbeData size mismatch");
446
447 // ============================================================================
448 // LOD (Level of Detail) Data Structures
449 // ============================================================================
450
461 {
463 float error;
465 uint32_t meshletIndex;
466 uint32_t _padding;
467 };
468 static_assert(sizeof(ClusterLodData) == 32, "ClusterLodData size mismatch");
469
480 {
483 int32_t depth;
484 uint32_t _padding[2];
485 };
486 static_assert(sizeof(ClusterGroupData) == 32, "ClusterGroupData size mismatch");
487
498 {
502 uint32_t ditherEnabled;
503 glm::vec4 cameraPosition;
504 glm::vec2 screenSize;
505 glm::vec2 _padding;
506 };
507 static_assert(sizeof(LodConfigUBO) == 48, "LodConfigUBO size mismatch");
508
519 {
520 uint32_t primitiveID;
521 uint32_t clusterIndex;
523 uint32_t _padding;
524 };
525 static_assert(sizeof(ClusterSurvivor) == 16, "ClusterSurvivor size mismatch");
526
527} // namespace EngineCore
Log category system implementation.
Per-group LOD data representing a simplified version of child clusters. Groups are created by merging...
Definition RenderData.h:480
int32_t depth
DAG depth (0 = coarsest level)
Definition RenderData.h:483
float simplifiedError
Error threshold for this group.
Definition RenderData.h:482
glm::vec4 simplifiedBoundsPositionAndRadius
xyz = local center, w = radius
Definition RenderData.h:481
Per-cluster LOD data for GPU-driven LOD selection. Each cluster maps to exactly one meshlet and conta...
Definition RenderData.h:461
glm::vec4 boundsPositionAndRadius
xyz = local center, w = radius
Definition RenderData.h:462
float error
Simplification error (mesh-local units)
Definition RenderData.h:463
uint32_t meshletIndex
Index into UnifiedMeshlet buffer.
Definition RenderData.h:465
int32_t refinedGroupId
Parent group index (-1 for base/finest geometry)
Definition RenderData.h:464
Cluster survivor data passed from culling to binning shaders. Contains the LOD selection result inclu...
Definition RenderData.h:519
uint32_t primitiveID
For transform/material lookup.
Definition RenderData.h:520
uint32_t clusterIndex
Global cluster index → maps to meshlet.
Definition RenderData.h:521
float ditherFactor
0.0-1.0 for transition blending
Definition RenderData.h:522
CPU side data for per object data. This will get divided up into multiple gpu buffers.
Definition RenderData.h:37
std::vector< CpuPrimitiveData > primitives
Definition RenderData.h:39
Cpu primitive data. Stores data which corresponds to a primitive.
Definition RenderData.h:18
glm::vec3 boundingSphereWorldPosition
Definition RenderData.h:20
Alignment at 4 bytes.
Definition RenderData.h:63
Frustum planes for frustum culling in the first compute shader stage.
Definition RenderData.h:195
std::array< glm::vec4, 6 > planes[2]
Definition RenderData.h:196
GPU-side layout for flat color material Matches GLSL struct in triangle_flat.frag.
Definition RenderData.h:356
GPU-side layout for diffuse shader material Used for basic textured materials.
Definition RenderData.h:369
Describes a mesh on the gpu. Where it is in the memory and how many meshlets it consists of.
Definition RenderData.h:51
GPU-side layout for normals debug material.
Definition RenderData.h:426
GPU-side layout for PBR material with spherical harmonics Used by MovableDiffuseShader,...
Definition RenderData.h:392
uint32_t roughnessMetallicTextureIndex
Definition RenderData.h:396
View-projection data for Hi-Z occlusion culling Contains matrices and screen info needed to project b...
Definition RenderData.h:209
Instance culling data - replaces ObjectCullingData for instancing. Contains world-space bounding sphe...
Definition RenderData.h:298
uint32_t meshGeometryId
Index into MeshGeometryData buffer.
Definition RenderData.h:301
uint32_t _padding[2]
Padding for 32-byte alignment.
Definition RenderData.h:302
uint32_t instanceId
Index into InstanceData buffer.
Definition RenderData.h:300
glm::vec4 worldPositionAndRadius
xyz = world position, w = radius
Definition RenderData.h:299
Per-instance data - one per visible MeshComponent. References shared geometry via meshGeometryId.
Definition RenderData.h:282
uint32_t materialId
Material instance ID (for material variations)
Definition RenderData.h:285
uint32_t colorTextureId
Texture array index.
Definition RenderData.h:286
glm::mat4 worldMatrix
64 bytes - world transform
Definition RenderData.h:283
uint32_t meshGeometryId
Index into MeshGeometryData buffer.
Definition RenderData.h:284
uint32_t _padding
Padding for 16-byte alignment.
Definition RenderData.h:287
Local-space bounding sphere data - uploaded once, never changes.
Definition RenderData.h:164
glm::vec4 localCenterAndRadius
xyz = local center, w = local radius
Definition RenderData.h:165
LOD configuration for GPU shader selection. Updated per-frame with camera and screen information.
Definition RenderData.h:498
glm::vec4 cameraPosition
World-space camera position.
Definition RenderData.h:503
glm::vec2 _padding
Pad to 48 bytes (std140 alignment)
Definition RenderData.h:505
float cameraProj11
projection[1][1] = cot(fov/2)
Definition RenderData.h:500
float errorThresholdPixels
Target pixel error (default 1.0)
Definition RenderData.h:499
uint32_t ditherEnabled
1 = dither transitions, 0 = hard cut
Definition RenderData.h:502
float cameraNear
Positive near plane distance.
Definition RenderData.h:501
glm::vec2 screenSize
Render target dimensions.
Definition RenderData.h:504
Shared geometry metadata - one per unique MeshAsset primitive. Allows multiple instances to reference...
Definition RenderData.h:261
uint32_t clusterCount
Total clusters (all LOD levels)
Definition RenderData.h:268
uint32_t meshletStartIndex
First meshlet in shared meshlet buffer.
Definition RenderData.h:262
uint32_t meshletCount
Number of meshlets for this geometry.
Definition RenderData.h:263
uint32_t pipelineIndex
Material pipeline index.
Definition RenderData.h:264
uint32_t groupCount
Total groups in LOD hierarchy.
Definition RenderData.h:270
uint32_t clusterStartIndex
First ClusterLodData (0xFFFFFFFF if no LOD)
Definition RenderData.h:267
uint32_t groupStartIndex
First ClusterGroupData.
Definition RenderData.h:269
uint32_t singleMeshletGeoIndex
Index into SingleMeshletGeometryData (0xFFFFFFFF if multi-meshlet)
Definition RenderData.h:265
Mapping from MeshAsset primitive to shared geometry buffer location. Used by RenderingDataManager to ...
Definition RenderData.h:313
bool isSingleMeshlet
True if meshletCount == 1 (use vertex shader path)
Definition RenderData.h:322
uint32_t vsIndexOffset
Offset into VS index buffer (contiguous uint32_t)
Definition RenderData.h:320
float localBoundsRadius
Cached local bounding sphere radius.
Definition RenderData.h:326
uint32_t meshGeometryId
Index into MeshGeometryData buffer.
Definition RenderData.h:314
glm::vec3 localBoundsCenter
Cached local bounding sphere center.
Definition RenderData.h:325
uint32_t pipelineIndex
Cached pipeline index from material.
Definition RenderData.h:324
uint32_t meshletStartIndex
First meshlet in shared buffer.
Definition RenderData.h:315
uint32_t triangleBaseOffset
Offset into triangle buffer.
Definition RenderData.h:318
uint32_t meshletCount
Number of meshlets.
Definition RenderData.h:316
uint32_t vertexBaseOffset
Offset into vertex buffer.
Definition RenderData.h:317
uint32_t vsIndexCount
Number of indices (triangleCount * 3)
Definition RenderData.h:321
Data for the metadata buffer which handles the unpacking of meshes into their meshlets.
Definition RenderData.h:182
Used in meshlet culling.
Definition RenderData.h:92
glm::vec4 worldPositionAndRadius
Definition RenderData.h:93
Data for object culling.
Definition RenderData.h:144
glm::vec4 worldPositionAndRadius
The center point of the bounding sphere (w component stores radius)
Definition RenderData.h:146
uint32_t objectIndex
Object index linking back to the Object Data.
Definition RenderData.h:148
Stores all data which is unique to each object.
Definition RenderData.h:124
std::vector< uint8_t > tris
Definition RenderData.h:109
std::vector< UnifiedMeshlet > meshletData
Definition RenderData.h:106
std::vector< uint32_t > vertices
Definition RenderData.h:108
Data for the primitive culling shader to assemble and pass on to the unpacking shader.
Definition RenderData.h:172
SH Probe data structure for dynamic lighting Contains L0-L2 RGB spherical harmonic coefficients.
Definition RenderData.h:439
glm::vec4 coefficients[9]
Definition RenderData.h:440
GPU data for single-meshlet geometry using vertex shader path. One entry per unique single-meshlet ge...
Definition RenderData.h:338
uint32_t firstIndex
Offset into index buffer.
Definition RenderData.h:340
uint32_t pipelineIndex
Material pipeline index.
Definition RenderData.h:342
int32_t vertexOffset
Added to each index value.
Definition RenderData.h:341
uint32_t indexCount
Number of indices to draw.
Definition RenderData.h:339
Information about the wereabouts of a meshlet in memory on the gpu.
Definition RenderData.h:76
Struct for the result buffer of the culling operation. Stores which objects have passed the culling t...
Definition RenderData.h:224
float ditherFactor
LOD transition dither factor (0.0-1.0)
Definition RenderData.h:227