diff --git a/CMakeLists.txt b/CMakeLists.txt index 92728dc8..b20b7d6f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,7 @@ endif() # PROSPER_ALLOCATOR_DEBUG # Set up sub-builds and sources add_subdirectory(ext) add_subdirectory(src) +add_subdirectory(res/shader/shared) if(PROSPER_ALWAYS_O2_DEPENDENCIES) # Only optimize the dependencies that have a noticeable impact @@ -113,6 +114,7 @@ target_link_libraries(prosper meshoptimizer mikktspace shaderc + shared_shader_structs spirv_headers stb tomlcpp diff --git a/res/shader/deferred_shading.comp b/res/shader/deferred_shading.comp index ba15fbf1..d8656cf4 100644 --- a/res/shader/deferred_shading.comp +++ b/res/shader/deferred_shading.comp @@ -9,6 +9,7 @@ #include "scene/lighting.glsl" #include "scene/lights.glsl" #include "scene/skybox.glsl" +#include "shared/shader_structs/push_constants/deferred_shading.h" layout(set = STORAGE_SET, binding = 0) uniform readonly image2D inAlbedoRoughness; @@ -18,12 +19,7 @@ layout(set = STORAGE_SET, binding = 2) uniform texture2D inNonLinearDepth; layout(set = STORAGE_SET, binding = 3) uniform image2D outColor; layout(set = STORAGE_SET, binding = 4) uniform sampler depthSampler; -layout(push_constant) uniform DeferredShadingPC -{ - uint DrawType; - uint ibl; -} -PC; +layout(push_constant) uniform PushConstants { DeferredShadingPC PC; }; layout(local_size_x = GROUP_X, local_size_y = GROUP_Y) in; void main() @@ -63,15 +59,15 @@ void main() if (PC.ibl == 1) color += evalIBL(surface); - if (PC.DrawType != DrawType_Default) + if (PC.drawType != DrawType_Default) { - if (PC.DrawType == DrawType_Position) + if (PC.drawType == DrawType_Position) { DebugInputs di; di.position = surface.positionWS; imageStore( outColor, coord, - vec4(commonDebugDraw(PC.DrawType, di, surface.material), 1)); + vec4(commonDebugDraw(PC.drawType, di, surface.material), 1)); } else { diff --git a/res/shader/dof/dilate.comp b/res/shader/dof/dilate.comp index 50c7a3d3..1410e077 100644 --- a/res/shader/dof/dilate.comp +++ b/res/shader/dof/dilate.comp @@ -5,17 +5,13 @@ // Based on A Life of a Bokeh by Guillaume Abadie // https://advances.realtimerendering.com/s2018/index.htm +#include "../shared/shader_structs/push_constants/dof/dilate.h" + layout(set = 0, binding = 0) uniform texture2D inTileMinMaxCoC; layout(set = 0, binding = 1) uniform writeonly image2D outDilatedTileMinMaxCoC; layout(set = 0, binding = 2) uniform sampler nearestSampler; -layout(push_constant) uniform DilatePC -{ - ivec2 res; - vec2 invRes; - int gatherRadius; -} -PC; +layout(push_constant) uniform PushConstants { DilatePC PC; }; layout(local_size_x = GROUP_X, local_size_y = GROUP_Y) in; void main() diff --git a/res/shader/dof/gather.comp b/res/shader/dof/gather.comp index e02f95c8..3c8437f7 100644 --- a/res/shader/dof/gather.comp +++ b/res/shader/dof/gather.comp @@ -4,6 +4,7 @@ #include "../common/math.glsl" #include "../common/random.glsl" +#include "../shared/shader_structs/push_constants/dof/gather.h" // Based on A Life of a Bokeh by Guillaume Abadie // https://advances.realtimerendering.com/s2018/index.htm @@ -16,13 +17,7 @@ layout(set = 0, binding = 3) uniform writeonly image2D layout(set = 0, binding = 4) uniform sampler nearestSampler; layout(set = 0, binding = 5) uniform sampler trilinearSampler; -layout(push_constant) uniform GatherPC -{ - ivec2 halfResolution; - vec2 invHalfResolution; - uint frameIndex; -} -PC; +layout(push_constant) uniform PushConstants { GatherPC PC; }; int octawebRingSampleCount(int ring) { diff --git a/res/shader/dof/reduce.comp b/res/shader/dof/reduce.comp index 7ace10eb..09f38e4e 100644 --- a/res/shader/dof/reduce.comp +++ b/res/shader/dof/reduce.comp @@ -6,6 +6,8 @@ // https://advances.realtimerendering.com/s2018/index.htm // implemented using https://github.com/GPUOpen-Effects/FidelityFX-SPD +#include "../shared/shader_structs/push_constants/dof/reduce.h" + layout(set = 0, binding = 0) uniform image2D imgSrc; layout(set = 0, binding = 1) uniform coherent image2D imgDst[12]; layout(std430, set = 0, binding = 2) coherent buffer SpdGlobalAtomicBuffer @@ -14,13 +16,7 @@ layout(std430, set = 0, binding = 2) coherent buffer SpdGlobalAtomicBuffer } spdGlobalAtomic; -layout(push_constant) uniform ReducePC -{ - ivec2 topMipResolution; - uint numWorkGroupsPerSlice; - uint mips; -} -PC; +layout(push_constant) uniform PushConstants { ReducePC PC; }; #define A_GPU 1 #define A_GLSL 1 diff --git a/res/shader/dof/setup.comp b/res/shader/dof/setup.comp index 50692f3b..ffe7db6d 100644 --- a/res/shader/dof/setup.comp +++ b/res/shader/dof/setup.comp @@ -7,6 +7,7 @@ #include "../common/math.glsl" #include "../scene/camera.glsl" +#include "../shared/shader_structs/push_constants/dof/setup.h" #include "bilateral.glsl" layout(set = STORAGE_SET, binding = 0) uniform readonly image2D inIllumination; @@ -18,13 +19,7 @@ layout(set = STORAGE_SET, binding = 2) uniform image2D outIllumination; layout(set = STORAGE_SET, binding = 3) uniform image2D outCircleOfConfusion; layout(set = STORAGE_SET, binding = 4) uniform sampler depthSampler; -layout(push_constant) uniform SetupPC -{ - float focusDistance; - float maxBackgroundCoC; - float maxCoC; -} -PC; +layout(push_constant) uniform PushConstants { SetupPC PC; }; float circleOfConfusion(float viewDepth) { diff --git a/res/shader/draw_list_culler.comp b/res/shader/draw_list_culler.comp index 8daee1cc..f682e013 100644 --- a/res/shader/draw_list_culler.comp +++ b/res/shader/draw_list_culler.comp @@ -10,6 +10,7 @@ #include "scene/camera.glsl" #include "scene/geometry.glsl" #include "scene/instances.glsl" +#include "shared/shader_structs/push_constants/draw_list_culler.h" // TODO: Put in a header? struct DrawMeshletInstance @@ -51,19 +52,12 @@ layout(set = STORAGE_SET, binding = 4) uniform texture2D // This should clamp to 1 on/beyond edges layout(set = STORAGE_SET, binding = 5) uniform sampler depthSampler; -layout(push_constant) uniform DrawListCullerPC -{ - uvec2 hizResolution; - vec2 hizUvScale; - // 0 means no hiz bound - uint hizMipCount; - uint outputSecondPhaseInput; -} -PC; +layout(push_constant) uniform PushConstants { DrawListCullerPC PC; }; float signedDistance(vec4 plane, vec3 p) { return dot(plane, vec4(p, 1)); } -void transformBounds(inout MeshletBounds bounds, Transforms trfn, float scale) +void transformBounds( + inout MeshletBounds bounds, ModelInstanceTransforms trfn, float scale) { // Need full SRT for center as it's the cluster center in model space bounds.center = (vec4(bounds.center, 1.0) * trfn.modelToWorld).xyz; @@ -219,7 +213,7 @@ void main() MeshletInfo meshletInfo = loadMeshletInfo(metadata, meshletInstance.meshletIndex); - Transforms trfn = + ModelInstanceTransforms trfn = modelInstanceTransforms.instance[instance.modelInstanceIndex]; float scale = modelInstanceScales.instance[instance.modelInstanceIndex]; diff --git a/res/shader/draw_list_generator.comp b/res/shader/draw_list_generator.comp index df15fb6a..0098793c 100644 --- a/res/shader/draw_list_generator.comp +++ b/res/shader/draw_list_generator.comp @@ -10,6 +10,7 @@ #include "scene/geometry.glsl" #include "scene/instances.glsl" #include "scene/materials.glsl" +#include "shared/shader_structs/push_constants/draw_list_generator.h" // TODO: Put in a header? struct DrawMeshletInstance @@ -24,8 +25,7 @@ layout(std430, set = STORAGE_SET, binding = 0) writeonly buffer DrawList } outDrawList; -layout(push_constant) uniform DrawListGeneratorPC { uint matchTransparents; } -PC; +layout(push_constant) uniform PushConstants { DrawListGeneratorPC PC; }; layout(local_size_x = GROUP_X) in; void main() diff --git a/res/shader/forward.frag b/res/shader/forward.frag index de7e5955..44acba38 100644 --- a/res/shader/forward.frag +++ b/res/shader/forward.frag @@ -7,7 +7,6 @@ #include "brdf.glsl" #include "common/random.glsl" #include "debug.glsl" -#include "forward_pc.glsl" #include "scene/camera.glsl" #include "scene/instances.glsl" #include "scene/light_clusters.glsl" @@ -15,6 +14,9 @@ #include "scene/lights.glsl" #include "scene/materials.glsl" #include "scene/skybox.glsl" +#include "shared/shader_structs/push_constants/forward.h" + +layout(push_constant) uniform PushConstants { ForwardPC PC; }; layout(location = 0) in vec3 inPositionWorld; layout(location = 1) in float inZCam; @@ -90,9 +92,9 @@ void main() // Write before debug to not break TAA outVelocity = clamp(velocity, vec2(-1), vec2(1)); - if (PC.DrawType >= DrawType_PrimitiveID) + if (PC.drawType >= DrawType_PrimitiveID) { - if (PC.DrawType == DrawType_MeshletID) + if (PC.drawType == DrawType_MeshletID) { outColor = vec4(uintToColor(inMeshletIndex), 1); return; @@ -105,7 +107,7 @@ void main() di.position = surface.positionWS; di.shadingNormal = surface.normalWS; di.texCoord0 = inTexCoord0; - outColor = vec4(commonDebugDraw(PC.DrawType, di, surface.material), 1); + outColor = vec4(commonDebugDraw(PC.drawType, di, surface.material), 1); return; } diff --git a/res/shader/forward.mesh b/res/shader/forward.mesh index 1d85216b..3a09866d 100644 --- a/res/shader/forward.mesh +++ b/res/shader/forward.mesh @@ -7,9 +7,11 @@ #extension GL_EXT_shader_8bit_storage : require #ifdef USE_GBUFFER_PC -#include "gbuffer_pc.glsl" +#include "shared/shader_structs/push_constants/gbuffer.h" +layout(push_constant) uniform PushConstants { GBufferPC PC; }; #else // !USE_GBUFFER_PC -#include "forward_pc.glsl" +#include "shared/shader_structs/push_constants/forward.h" +layout(push_constant) uniform PushConstants { ForwardPC PC; }; #endif // USE_GBUFFER_PC #include "common/math.glsl" @@ -60,8 +62,8 @@ layout(location = 8) out flat uint outMeshletIndex[]; void writeTransformedVertex( DrawInstance instance, MeshletInstance meshletInstance, - GeometryMetadata metadata, Transforms trfn, uint globalVertexIndex, - uint meshletVertexIndex) + GeometryMetadata metadata, ModelInstanceTransforms trfn, + uint globalVertexIndex, uint meshletVertexIndex) { Vertex vertexModel = loadVertex(metadata, globalVertexIndex); Vertex vertexWorld = transform(vertexModel, trfn); @@ -75,7 +77,7 @@ void writeTransformedVertex( vec4 posNDC = camera.cameraToClip * posCam; outPositionNDC[meshletVertexIndex] = posNDC; - Transforms prevTrfn = trfn; + ModelInstanceTransforms prevTrfn = trfn; if (PC.previousTransformValid == 1) prevTrfn = previousModelInstanceTransforms .instance[instance.modelInstanceIndex]; @@ -106,7 +108,7 @@ void main() GeometryMetadata metadata = geometryMetadatas.data[instance.meshIndex]; MeshletInfo meshletInfo = loadMeshletInfo(metadata, meshletInstance.meshletIndex); - Transforms trfn = + ModelInstanceTransforms trfn = modelInstanceTransforms.instance[instance.modelInstanceIndex]; if (threadIndex == 0) diff --git a/res/shader/forward_pc.glsl b/res/shader/forward_pc.glsl deleted file mode 100644 index 2e7e07a4..00000000 --- a/res/shader/forward_pc.glsl +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef FORWARD_PC_GLSL -#define FORWARD_PC_GLSL - -layout(push_constant) uniform ForwardPC -{ - // Some of these are mirrored between this and GBufferPC - uint DrawType; - uint ibl; - uint previousTransformValid; -} -PC; - -#endif // FORWARD_PC_GLSL diff --git a/res/shader/gbuffer.frag b/res/shader/gbuffer.frag index 5f8f90d8..b2065f58 100644 --- a/res/shader/gbuffer.frag +++ b/res/shader/gbuffer.frag @@ -5,10 +5,12 @@ #include "common/math.glsl" #include "debug.glsl" -#include "gbuffer_pc.glsl" #include "scene/camera.glsl" #include "scene/instances.glsl" #include "scene/materials.glsl" +#include "shared/shader_structs/push_constants/gbuffer.h" + +layout(push_constant) uniform PushConstants { GBufferPC PC; }; layout(location = 0) in vec3 inPositionWorld; layout(location = 1) in float inZCam; diff --git a/res/shader/gbuffer_pc.glsl b/res/shader/gbuffer_pc.glsl deleted file mode 100644 index 6a60b1b0..00000000 --- a/res/shader/gbuffer_pc.glsl +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef GBUFFER_PC_GLSL -#define GBUFFER_PC_GLSL - -layout(push_constant) uniform GBufferPC -{ - // Some of these are mirrored between this and ForwardPC - uint previousTransformValid; - uint drawType; -} -PC; - -#endif // GBUFFER_PC_GLSL diff --git a/res/shader/hiz_downsampler.comp b/res/shader/hiz_downsampler.comp index 6294f70e..83a9bc37 100644 --- a/res/shader/hiz_downsampler.comp +++ b/res/shader/hiz_downsampler.comp @@ -6,6 +6,8 @@ // https://advances.realtimerendering.com/s2018/index.htm // implemented using https://github.com/GPUOpen-Effects/FidelityFX-SPD +#include "shared/shader_structs/push_constants/hiz_downsampler.h" + layout(set = 0, binding = 0) uniform texture2D depthSrc; layout(set = 0, binding = 1) uniform sampler depthSampler; layout(set = 0, binding = 2) uniform coherent image2D depthDst[12]; @@ -15,14 +17,7 @@ layout(std430, set = 0, binding = 3) coherent buffer SpdGlobalAtomicBuffer } spdGlobalAtomic; -layout(push_constant) uniform ReducePC -{ - ivec2 inputResolution; - ivec2 topMipResolution; - uint numWorkGroupsPerSlice; - uint mips; -} -PC; +layout(push_constant) uniform PushConstants { HizDownsamplerPC PC; }; #define A_GPU 1 #define A_GLSL 1 diff --git a/res/shader/ibl/prefilter_radiance.comp b/res/shader/ibl/prefilter_radiance.comp index 533b5814..7288a3f8 100644 --- a/res/shader/ibl/prefilter_radiance.comp +++ b/res/shader/ibl/prefilter_radiance.comp @@ -1,16 +1,16 @@ #pragma shader_stage(compute) -layout(push_constant) uniform PrefilterRadiancePC { uint mipCount; } -PC; - -layout(binding = 0) uniform samplerCube inEnvironment; -// 15 levels == 16k texture -layout(binding = 1, r11f_g11f_b10f) uniform writeonly imageCube outRadiance[15]; - #include "../brdf.glsl" #include "../common/math.glsl" #include "../common/random.glsl" #include "../common/sampling.glsl" +#include "../shared/shader_structs/push_constants/prefilter_radiance.h" + +layout(push_constant) uniform PushConstants { PrefilterRadiancePC PC; }; + +layout(binding = 0) uniform samplerCube inEnvironment; +// 15 levels == 16k texture +layout(binding = 1, r11f_g11f_b10f) uniform writeonly imageCube outRadiance[15]; // From Real Shading in Unreal Engine 4 // by Brian Karis diff --git a/res/shader/light_clustering.comp b/res/shader/light_clustering.comp index 003376a4..92f8dcb8 100644 --- a/res/shader/light_clustering.comp +++ b/res/shader/light_clustering.comp @@ -5,12 +5,12 @@ #include "common/math.glsl" #include "scene/camera.glsl" #include "scene/lights.glsl" +#include "shared/shader_structs/push_constants/light_clustering.h" #define WRITE_CULLING_BINDS #include "scene/light_clusters.glsl" -layout(push_constant) uniform ClusteringPC { uvec2 resolution; } -clusteringPC; +layout(push_constant) uniform PushConstants { LightClusteringPC clusteringPC; }; const uint maxPointIndices = 128; const uint maxSpotIndices = 128; diff --git a/res/shader/restir_di/initial_reservoirs.comp b/res/shader/restir_di/initial_reservoirs.comp index 03266a84..fba3514b 100644 --- a/res/shader/restir_di/initial_reservoirs.comp +++ b/res/shader/restir_di/initial_reservoirs.comp @@ -9,11 +9,11 @@ #include "../scene/camera.glsl" #include "../scene/lighting.glsl" #include "../scene/material.glsl" +#include "../shared/shader_structs/push_constants/restir_di/initial_reservoirs.h" #include "resampling_phat.glsl" #include "reservoir.glsl" -layout(push_constant) uniform RtDiInitialReservoirsPC { uint frameIndex; } -PC; +layout(push_constant) uniform PushConstants { InitialReservoirsPC PC; }; layout(set = STORAGE_SET, binding = 0) uniform readonly image2D inAlbedoRoughness; diff --git a/res/shader/restir_di/spatial_reuse.comp b/res/shader/restir_di/spatial_reuse.comp index e9e8047b..1f1f0b56 100644 --- a/res/shader/restir_di/spatial_reuse.comp +++ b/res/shader/restir_di/spatial_reuse.comp @@ -9,11 +9,11 @@ #include "../scene/camera.glsl" #include "../scene/lighting.glsl" #include "../scene/material.glsl" +#include "../shared/shader_structs/push_constants/restir_di/spatial_reuse.h" #include "resampling_phat.glsl" #include "reservoir.glsl" -layout(push_constant) uniform RtDiInitialReservoirsPC { uint frameIndex; } -PC; +layout(push_constant) uniform PushConstants { SpatialReusePC PC; }; layout(set = STORAGE_SET, binding = 0) uniform readonly image2D inAlbedoRoughness; diff --git a/res/shader/rt/direct_illumination/main.rgen b/res/shader/rt/direct_illumination/main.rgen index 15d64ba7..ec21b120 100644 --- a/res/shader/rt/direct_illumination/main.rgen +++ b/res/shader/rt/direct_illumination/main.rgen @@ -17,11 +17,15 @@ #include "../../scene/lighting.glsl" #include "../../scene/materials.glsl" #include "../../scene/skybox.glsl" +#include "../../shared/shader_structs/push_constants/restir_di/trace.h" +#include "../payload.glsl" #include "../ray.glsl" #include "../rt_data.glsl" -#include "../payload.glsl" -#include "pc.glsl" +layout(push_constant) uniform PushConstant { TracePC PC; }; + +bool flagSkipHistory() { return bitfieldExtract(PC.flags, 0, 1) == 1; } +bool flagAccumulate() { return bitfieldExtract(PC.flags, 1, 1) == 1; } layout(set = STORAGE_SET, binding = 0) uniform readonly image2D inAlbedoRoughness; diff --git a/res/shader/rt/direct_illumination/pc.glsl b/res/shader/rt/direct_illumination/pc.glsl deleted file mode 100644 index 5b82801a..00000000 --- a/res/shader/rt/direct_illumination/pc.glsl +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef RT_DIRECT_ILLUMINATION_PC_GLSL -#define RT_DIRECT_ILLUMINATION_PC_GLSL - -layout(push_constant) uniform RtDirectIlluminationPC -{ - uint drawType; - uint frameIndex; - uint flags; -} -PC; - -bool flagSkipHistory() { return bitfieldExtract(PC.flags, 0, 1) == 1; } -bool flagAccumulate() { return bitfieldExtract(PC.flags, 1, 1) == 1; } - -#endif // RT_DIRECT_ILLUMINATION_PC_GLSL diff --git a/res/shader/rt/reference/main.rgen b/res/shader/rt/reference/main.rgen index 8095cbd9..4070d729 100644 --- a/res/shader/rt/reference/main.rgen +++ b/res/shader/rt/reference/main.rgen @@ -16,10 +16,18 @@ #include "../../scene/lighting.glsl" #include "../../scene/materials.glsl" #include "../../scene/skybox.glsl" +#include "../../shared/shader_structs/push_constants/rt_reference.h" #include "../payload.glsl" #include "../ray.glsl" #include "../rt_data.glsl" -#include "rtpc.glsl" + +layout(push_constant) uniform PushConstant { ReferencePC PC; }; + +bool flagSkipHistory() { return bitfieldExtract(PC.flags, 0, 1) == 1; } +bool flagAccumulate() { return bitfieldExtract(PC.flags, 1, 1) == 1; } +bool flagIBL() { return bitfieldExtract(PC.flags, 2, 1) == 1; } +bool flagDepthOfField() { return bitfieldExtract(PC.flags, 3, 1) == 1; } +bool flagClampIndirect() { return bitfieldExtract(PC.flags, 4, 1) == 1; } layout(set = OUTPUT_SET, binding = 0) uniform image2D previousColor; layout(set = OUTPUT_SET, binding = 1) uniform image2D outColor; @@ -139,7 +147,7 @@ VisibleSurface evaluateSurface(Ray ray, RayPayload hit) { DrawInstance instance = drawInstances.instance[hit.drawInstanceIndex]; - Transforms trfn = + ModelInstanceTransforms trfn = modelInstanceTransforms.instance[instance.modelInstanceIndex]; GeometryMetadata metadata = geometryMetadatas.data[instance.meshIndex]; diff --git a/res/shader/rt/reference/rtpc.glsl b/res/shader/rt/reference/rtpc.glsl deleted file mode 100644 index 993c7f1c..00000000 --- a/res/shader/rt/reference/rtpc.glsl +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef RT_REFERENCE_RTPC_GLSL -#define RT_REFERENCE_RTPC_GLSL - -layout(push_constant) uniform ReferenceRtPC -{ - uint drawType; - uint flags; - uint frameIndex; - float apertureDiameter; - float focusDistance; - float focalLength; - uint rouletteStartBounce; - uint maxBounces; -} -PC; - -bool flagSkipHistory() { return bitfieldExtract(PC.flags, 0, 1) == 1; } -bool flagAccumulate() { return bitfieldExtract(PC.flags, 1, 1) == 1; } -bool flagIBL() { return bitfieldExtract(PC.flags, 2, 1) == 1; } -bool flagDepthOfField() { return bitfieldExtract(PC.flags, 3, 1) == 1; } -bool flagClampIndirect() { return bitfieldExtract(PC.flags, 4, 1) == 1; } - -#endif // RT_REFERENCE_RTPC_GLSL diff --git a/res/shader/scene/camera.glsl b/res/shader/scene/camera.glsl index acb17400..d885278f 100644 --- a/res/shader/scene/camera.glsl +++ b/res/shader/scene/camera.glsl @@ -1,31 +1,12 @@ #ifndef SCENE_CAMERA_GLSL #define SCENE_CAMERA_GLSL +#include "../shared/shader_structs/scene/camera.h" + layout(std430, set = CAMERA_SET, binding = 0) buffer CameraDSB { - mat4 worldToCamera; - mat4 cameraToWorld; - mat4 cameraToClip; - mat4 clipToWorld; - mat4 previousWorldToCamera; - mat4 previousCameraToClip; - vec4 eye; - // These are world space plane normal,distance and normals point into the - // frustum - vec4 nearPlane; - vec4 farPlane; - vec4 leftPlane; - vec4 rightPlane; - vec4 topPlane; - vec4 bottomPlane; - uvec2 resolution; - vec2 currentJitter; - vec2 previousJitter; - float near; - float far; - float maxViewScale; -} -camera; + CameraUniforms camera; +}; float linearizeDepth(float nonLinearDepth) { diff --git a/res/shader/scene/geometry.glsl b/res/shader/scene/geometry.glsl index 16800ac1..cb6b2c0d 100644 --- a/res/shader/scene/geometry.glsl +++ b/res/shader/scene/geometry.glsl @@ -1,33 +1,9 @@ #ifndef SCENE_GEOMETRY_GLSL #define SCENE_GEOMETRY_GLSL +#include "../shared/shader_structs/scene/geometry_metadata.h" #include "vertex.glsl" -struct MeshBuffer -{ - uint index; - uint offset; -}; - -struct GeometryMetadata -{ - uint bufferIndex; - // These offsets are into the geometry data buffers. Most are for U32/F32 - // and an offset of 0xFFFFFFFF signals an unused attribute. - // This addresses U16 if short indices are in use. - uint indicesOffset; - uint positionsOffset; - uint normalsOffset; - uint tangentsOffset; - uint texCoord0sOffset; - uint meshletsOffset; - uint meshletBoundsOffset; - // This addresses U16 if short indices are in use. - uint meshletVerticesOffset; - // This addresses U8. - uint meshletTrianglesByteOffset; - uint usesShortIndices; -}; layout(std430, set = GEOMETRY_SET, binding = 0) readonly buffer GeometryMetadatas { diff --git a/res/shader/scene/instances.glsl b/res/shader/scene/instances.glsl index 735c19fd..666b0ca7 100644 --- a/res/shader/scene/instances.glsl +++ b/res/shader/scene/instances.glsl @@ -1,24 +1,21 @@ #ifndef SCENE_INTSTANCES_GLSL #define SCENE_INTSTANCES_GLSL +#include "../shared/shader_structs/scene/draw_instance.h" +#include "../shared/shader_structs/scene/model_instance_transforms.h" #include "vertex.glsl" -struct Transforms -{ - mat3x4 modelToWorld; - mat3x4 normalToWorld; -}; layout(std430, set = SCENE_INSTANCES_SET, binding = 0) readonly buffer ModelInstanceTransformsDSB { - Transforms instance[]; + ModelInstanceTransforms instance[]; } modelInstanceTransforms; layout(std430, set = SCENE_INSTANCES_SET, binding = 1) readonly buffer PreviousModelInstanceTransformsDSB { - Transforms instance[]; + ModelInstanceTransforms instance[]; } previousModelInstanceTransforms; @@ -29,12 +26,6 @@ layout(std430, set = SCENE_INSTANCES_SET, binding = 2) readonly buffer } modelInstanceScales; -struct DrawInstance -{ - uint modelInstanceIndex; - uint meshIndex; - uint materialIndex; -}; layout(std430, set = SCENE_INSTANCES_SET, binding = 3) readonly buffer DrawInstances { @@ -42,7 +33,7 @@ layout(std430, set = SCENE_INSTANCES_SET, binding = 3) readonly buffer } drawInstances; -Vertex transform(Vertex v, Transforms t) +Vertex transform(Vertex v, ModelInstanceTransforms t) { Vertex ret; // 3x4 SRT multiplies from the right @@ -61,7 +52,7 @@ Vertex transform(Vertex v, Transforms t) return ret; } -vec3 worldPosition(Vertex v, Transforms t) +vec3 worldPosition(Vertex v, ModelInstanceTransforms t) { // 3x4 SRT multiplies from the right return (vec4(v.Position, 1.0) * t.modelToWorld).xyz; diff --git a/res/shader/scene/lights.glsl b/res/shader/scene/lights.glsl index d57775ce..6c7614c8 100644 --- a/res/shader/scene/lights.glsl +++ b/res/shader/scene/lights.glsl @@ -1,17 +1,11 @@ #ifndef SCENE_LIGHTS_GLSL #define SCENE_LIGHTS_GLSL -layout(set = LIGHTS_SET, binding = 0) buffer DirectionalLightDSB -{ - vec4 irradiance; - vec4 direction; -} -directionalLight; +#include "../shared/shader_structs/scene/lights.h" -struct PointLight +layout(set = LIGHTS_SET, binding = 0) buffer DirectionalLightDSB { - vec4 radianceAndRadius; - vec4 position; + DirectionalLightParameters directionalLight; }; layout(set = LIGHTS_SET, binding = 1) buffer PointLightsDSB @@ -21,13 +15,6 @@ layout(set = LIGHTS_SET, binding = 1) buffer PointLightsDSB } pointLights; -struct SpotLight -{ - vec4 radianceAndAngleScale; - vec4 positionAndAngleOffset; - vec4 direction; -}; - layout(set = LIGHTS_SET, binding = 2) buffer SpotLightsDSB { SpotLight lights[MAX_SPOT_LIGHT_COUNT]; diff --git a/res/shader/scene/materials.glsl b/res/shader/scene/materials.glsl index 4c25632c..3f4e7a61 100644 --- a/res/shader/scene/materials.glsl +++ b/res/shader/scene/materials.glsl @@ -1,25 +1,9 @@ #ifndef SCENE_MATERIALS_GLSL #define SCENE_MATERIALS_GLSL +#include "../shared/shader_structs/scene/material_data.h" #include "material.glsl" -const uint AlphaModeOpaque = 0; -const uint AlphaModeMask = 1; -const uint AlphaModeBlend = 2; - -struct MaterialData -{ - vec4 baseColorFactor; - float metallicFactor; - float roughnessFactor; - float alphaCutoff; - uint alphaMode; - uint baseColorTexture; - uint metallicRoughnessTexture; - uint normalTexture; - uint pad; -}; - layout(std430, set = MATERIAL_DATAS_SET, binding = 0) readonly buffer MaterialDatas { @@ -66,8 +50,8 @@ Material sampleMaterial(uint index, vec2 uv) Material ret; vec4 linearBaseColor; - uint baseColorTex = data.baseColorTexture & 0xFFFFFF; - uint baseColorSampler = data.baseColorTexture >> 24; + uint baseColorTex = data.baseColorTextureSampler & 0xFFFFFF; + uint baseColorSampler = data.baseColorTextureSampler >> 24; if (baseColorTex > 0) linearBaseColor = sRGBtoLinear(sampleMaterialTexture( sampler2D( @@ -94,8 +78,8 @@ Material sampleMaterial(uint index, vec2 uv) } ret.albedo = linearBaseColor.rgb; - uint metallicRoughnessTex = data.metallicRoughnessTexture & 0xFFFFFF; - uint metallicRoughnessSampler = data.metallicRoughnessTexture >> 24; + uint metallicRoughnessTex = data.metallicRoughnessTextureSampler & 0xFFFFFF; + uint metallicRoughnessSampler = data.metallicRoughnessTextureSampler >> 24; if (metallicRoughnessTex > 0) { vec3 mr = sampleMaterialTexture( @@ -115,8 +99,8 @@ Material sampleMaterial(uint index, vec2 uv) // Avoid losing specular at zero roughness ret.roughness = max(ret.roughness, 0.05); - uint normalTextureTex = data.normalTexture & 0xFFFFFF; - uint normalTextureSampler = data.normalTexture >> 24; + uint normalTextureTex = data.normalTextureSampler & 0xFFFFFF; + uint normalTextureSampler = data.normalTextureSampler >> 24; if (normalTextureTex > 0) { vec3 texture_normal = @@ -139,8 +123,8 @@ float sampleAlpha(uint index, vec2 uv) MaterialData data = materialDatas.materials[index]; float linearAlpha = 1; - uint baseColorTex = data.baseColorTexture & 0xFFFFFF; - uint baseColorSampler = data.baseColorTexture >> 24; + uint baseColorTex = data.baseColorTextureSampler & 0xFFFFFF; + uint baseColorSampler = data.baseColorTextureSampler >> 24; if (baseColorTex > 0) linearAlpha = sRGBtoLinear(sampleMaterialTexture( diff --git a/res/shader/shared/CMakeLists.txt b/res/shader/shared/CMakeLists.txt new file mode 100644 index 00000000..4b65c63c --- /dev/null +++ b/res/shader/shared/CMakeLists.txt @@ -0,0 +1,5 @@ +add_subdirectory(shader_structs) + +add_library(shared_shader_structs INTERFACE ${SHARED_SHADER_STRUCTS_INCLUDES}) +target_include_directories(shared_shader_structs SYSTEM INTERFACE ${CMAKE_CURRENT_LIST_DIR}) +target_link_libraries(shared_shader_structs INTERFACE glm wheels) diff --git a/res/shader/shared/shader_structs/CMakeLists.txt b/res/shader/shared/shader_structs/CMakeLists.txt new file mode 100644 index 00000000..021cbd4b --- /dev/null +++ b/res/shader/shared/shader_structs/CMakeLists.txt @@ -0,0 +1,10 @@ +add_subdirectory(push_constants) +add_subdirectory(scene) + +set(SHARED_SHADER_STRUCTS_INCLUDES + ${SHARED_SHADER_STRUCTS_PUSH_CONSTANTS_INCLUDES} + ${SHARED_SHADER_STRUCTS_SCENE_INCLUDES} + ${CMAKE_CURRENT_LIST_DIR}/fields.h + ${CMAKE_CURRENT_LIST_DIR}/fwd.hpp + PARENT_SCOPE +) diff --git a/res/shader/shared/shader_structs/fields.h b/res/shader/shared/shader_structs/fields.h new file mode 100644 index 00000000..cc3c3f41 --- /dev/null +++ b/res/shader/shared/shader_structs/fields.h @@ -0,0 +1,27 @@ +#ifndef SHARED_SHADER_STRUCTS_FIELDS_H +#define SHARED_SHADER_STRUCTS_FIELDS_H + +#ifdef __cplusplus + +#include + +#define STRUCT_FIELD_SEPARATE_TYPES(glsl_type, cpp_type, name, default_value) \ + cpp_type name { default_value } + +#define STRUCT_FIELD_GLM(type, name, default_value) \ + glm::type name { default_value } + +#define STRUCT_FIELD(type, name, default_value) \ + type name { default_value } + +#else // !__cplusplus + +#define STRUCT_FIELD_SEPARATE_TYPES(glsl_type, cpp_type, name, default_value) \ + glsl_type name + +#define STRUCT_FIELD_GLM(type, name, default) type name +#define STRUCT_FIELD(type, name, default) type name + +#endif // __cplusplus + +#endif // SHARED_SHADER_STRUCTS_FIELDS_H diff --git a/res/shader/shared/shader_structs/fwd.hpp b/res/shader/shared/shader_structs/fwd.hpp new file mode 100644 index 00000000..5d921bf8 --- /dev/null +++ b/res/shader/shared/shader_structs/fwd.hpp @@ -0,0 +1,10 @@ +#ifndef SHARED_SHADER_STRUCTS_FWD_HPP +#define SHARED_SHADER_STRUCTS_FWD_HPP + +#ifndef __cplusplus +#error "Forward declarations have no meaning in GLSL" +#endif // !__cplusplus + +#include "scene/fwd.hpp" + +#endif // SHARED_SHADER_STRUCTS_FWD_HPP diff --git a/res/shader/shared/shader_structs/push_constants/CMakeLists.txt b/res/shader/shared/shader_structs/push_constants/CMakeLists.txt new file mode 100644 index 00000000..e5301dd0 --- /dev/null +++ b/res/shader/shared/shader_structs/push_constants/CMakeLists.txt @@ -0,0 +1,23 @@ +add_subdirectory(dof) +add_subdirectory(restir_di) + +set(SHARED_SHADER_STRUCTS_PUSH_CONSTANTS_INCLUDES + ${SHARED_SHADER_STRUCTS_PUSH_CONSTANTS_IBL_INCLUDES} + ${SHARED_SHADER_STRUCTS_PUSH_CONSTANTS_DOF_INCLUDES} + ${SHARED_SHADER_STRUCTS_PUSH_CONSTANTS_RESTIR_DI_INCLUDES} + ${SHARED_SHADER_STRUCTS_PUSH_CONSTANTS_RT_INCLUDES} + ${CMAKE_CURRENT_LIST_DIR}/deferred_shading.h + ${CMAKE_CURRENT_LIST_DIR}/draw_list_culler.h + ${CMAKE_CURRENT_LIST_DIR}/draw_list_generator.h + ${CMAKE_CURRENT_LIST_DIR}/forward.h + ${CMAKE_CURRENT_LIST_DIR}/gbuffer.h + ${CMAKE_CURRENT_LIST_DIR}/hiz_downsampler.h + ${CMAKE_CURRENT_LIST_DIR}/light_clustering.h + ${CMAKE_CURRENT_LIST_DIR}/prefilter_radiance.h + ${CMAKE_CURRENT_LIST_DIR}/rt_reference.h + ${CMAKE_CURRENT_LIST_DIR}/taa_resolve.h + ${CMAKE_CURRENT_LIST_DIR}/texture_debug.h + ${CMAKE_CURRENT_LIST_DIR}/texture_readback.h + ${CMAKE_CURRENT_LIST_DIR}/tone_map.h + PARENT_SCOPE +) diff --git a/res/shader/shared/shader_structs/push_constants/deferred_shading.h b/res/shader/shared/shader_structs/push_constants/deferred_shading.h new file mode 100644 index 00000000..6dc9b04a --- /dev/null +++ b/res/shader/shared/shader_structs/push_constants/deferred_shading.h @@ -0,0 +1,12 @@ +#ifndef SHADER_STRUCTS_PUSH_CONSTANTS_DEFERRED_SHADING_H +#define SHADER_STRUCTS_PUSH_CONSTANTS_DEFERRED_SHADING_H + +#include "../fields.h" + +struct DeferredShadingPC +{ + STRUCT_FIELD_GLM(uint, drawType, 0); + STRUCT_FIELD_GLM(uint, ibl, 0); +}; + +#endif // SHADER_STRUCTS_PUSH_CONSTANTS_DEFERRED_SHADING_H diff --git a/res/shader/shared/shader_structs/push_constants/dof/CMakeLists.txt b/res/shader/shared/shader_structs/push_constants/dof/CMakeLists.txt new file mode 100644 index 00000000..deefbe53 --- /dev/null +++ b/res/shader/shared/shader_structs/push_constants/dof/CMakeLists.txt @@ -0,0 +1,7 @@ +set(SHARED_SHADER_STRUCTS_PUSH_CONSTANTS_DOF_INCLUDES + ${CMAKE_CURRENT_LIST_DIR}/dilate.h + ${CMAKE_CURRENT_LIST_DIR}/gather.h + ${CMAKE_CURRENT_LIST_DIR}/reduce.h + ${CMAKE_CURRENT_LIST_DIR}/setup.h + PARENT_SCOPE +) diff --git a/res/shader/shared/shader_structs/push_constants/dof/dilate.h b/res/shader/shared/shader_structs/push_constants/dof/dilate.h new file mode 100644 index 00000000..4723089b --- /dev/null +++ b/res/shader/shared/shader_structs/push_constants/dof/dilate.h @@ -0,0 +1,13 @@ +#ifndef SHADER_STRUCTS_PUSH_CONSTANTS_DOF_DILATE_H +#define SHADER_STRUCTS_PUSH_CONSTANTS_DOF_DILATE_H + +#include "../../fields.h" + +struct DilatePC +{ + STRUCT_FIELD_GLM(ivec2, res, {}); + STRUCT_FIELD_GLM(vec2, invRes, {}); + STRUCT_FIELD(int, gatherRadius, 1); +}; + +#endif // SHADER_STRUCTS_PUSH_CONSTANTS_DOF_DILATE_H diff --git a/res/shader/shared/shader_structs/push_constants/dof/gather.h b/res/shader/shared/shader_structs/push_constants/dof/gather.h new file mode 100644 index 00000000..a3bb2840 --- /dev/null +++ b/res/shader/shared/shader_structs/push_constants/dof/gather.h @@ -0,0 +1,13 @@ +#ifndef SHADER_STRUCTS_PUSH_CONSTANTS_DOF_GATHER_H +#define SHADER_STRUCTS_PUSH_CONSTANTS_DOF_GATHER_H + +#include "../../fields.h" + +struct GatherPC +{ + STRUCT_FIELD_GLM(ivec2, halfResolution, {}); + STRUCT_FIELD_GLM(vec2, invHalfResolution, {}); + STRUCT_FIELD_GLM(uint, frameIndex, 0); +}; + +#endif // SHADER_STRUCTS_PUSH_CONSTANTS_DOF_GATHER_H diff --git a/res/shader/shared/shader_structs/push_constants/dof/reduce.h b/res/shader/shared/shader_structs/push_constants/dof/reduce.h new file mode 100644 index 00000000..6e11f465 --- /dev/null +++ b/res/shader/shared/shader_structs/push_constants/dof/reduce.h @@ -0,0 +1,13 @@ +#ifndef SHADER_STRUCTS_PUSH_CONSTANTS_DOF_REDUCE_H +#define SHADER_STRUCTS_PUSH_CONSTANTS_DOF_REDUCE_H + +#include "../../fields.h" + +struct ReducePC +{ + STRUCT_FIELD_GLM(ivec2, topMipResolution, {}); + STRUCT_FIELD_GLM(uint, numWorkGroupsPerSlice, 0); + STRUCT_FIELD_GLM(uint, mips, 0); +}; + +#endif // SHADER_STRUCTS_PUSH_CONSTANTS_DOF_REDUCE_H diff --git a/res/shader/shared/shader_structs/push_constants/dof/setup.h b/res/shader/shared/shader_structs/push_constants/dof/setup.h new file mode 100644 index 00000000..ff89ff22 --- /dev/null +++ b/res/shader/shared/shader_structs/push_constants/dof/setup.h @@ -0,0 +1,13 @@ +#ifndef SHADER_STRUCTS_PUSH_CONSTANTS_DOF_SETUP_H +#define SHADER_STRUCTS_PUSH_CONSTANTS_DOF_SETUP_H + +#include "../../fields.h" + +struct SetupPC +{ + STRUCT_FIELD(float, focusDistance, 0.f); + STRUCT_FIELD(float, maxBackgroundCoC, 0.f); + STRUCT_FIELD(float, maxCoC, 0.f); +}; + +#endif // SHADER_STRUCTS_PUSH_CONSTANTS_DOF_SETUP_H diff --git a/res/shader/shared/shader_structs/push_constants/draw_list_culler.h b/res/shader/shared/shader_structs/push_constants/draw_list_culler.h new file mode 100644 index 00000000..408d8646 --- /dev/null +++ b/res/shader/shared/shader_structs/push_constants/draw_list_culler.h @@ -0,0 +1,15 @@ +#ifndef SHADER_STRUCTS_PUSH_CONSTANTS_DRAW_LIST_CULLER_H +#define SHADER_STRUCTS_PUSH_CONSTANTS_DRAW_LIST_CULLER_H + +#include "../fields.h" + +struct DrawListCullerPC +{ + STRUCT_FIELD_GLM(uvec2, hizResolution, {}); + STRUCT_FIELD_GLM(vec2, hizUvScale, 1.f); + // 0 means no hiz bound + STRUCT_FIELD_GLM(uint, hizMipCount, 0); + STRUCT_FIELD_GLM(uint, outputSecondPhaseInput, 0); +}; + +#endif // SHADER_STRUCTS_PUSH_CONSTANTS_DRAW_LIST_CULLER_H diff --git a/res/shader/shared/shader_structs/push_constants/draw_list_generator.h b/res/shader/shared/shader_structs/push_constants/draw_list_generator.h new file mode 100644 index 00000000..af1d9a25 --- /dev/null +++ b/res/shader/shared/shader_structs/push_constants/draw_list_generator.h @@ -0,0 +1,11 @@ +#ifndef SHADER_STRUCTS_PUSH_CONSTANTS_DRAW_LIST_GENERATOR_H +#define SHADER_STRUCTS_PUSH_CONSTANTS_DRAW_LIST_GENERATOR_H + +#include "../fields.h" + +struct DrawListGeneratorPC +{ + STRUCT_FIELD_GLM(uint, matchTransparents, 0); +}; + +#endif // SHADER_STRUCTS_PUSH_CONSTANTS_DRAW_LIST_GENERATOR_H diff --git a/res/shader/shared/shader_structs/push_constants/forward.h b/res/shader/shared/shader_structs/push_constants/forward.h new file mode 100644 index 00000000..638c6da3 --- /dev/null +++ b/res/shader/shared/shader_structs/push_constants/forward.h @@ -0,0 +1,14 @@ +#ifndef SHADER_STRUCTS_PUSH_CONSTANTS_FORWARD_H +#define SHADER_STRUCTS_PUSH_CONSTANTS_FORWARD_H + +#include "../fields.h" + +struct ForwardPC +{ + // Some of these are mirrored between this and GBufferPC + STRUCT_FIELD_GLM(uint, drawType, 0); + STRUCT_FIELD_GLM(uint, ibl, 0); + STRUCT_FIELD_GLM(uint, previousTransformValid, 0); +}; + +#endif // SHADER_STRUCTS_PUSH_CONSTANTS_FORWARD_H diff --git a/res/shader/shared/shader_structs/push_constants/gbuffer.h b/res/shader/shared/shader_structs/push_constants/gbuffer.h new file mode 100644 index 00000000..b02447a0 --- /dev/null +++ b/res/shader/shared/shader_structs/push_constants/gbuffer.h @@ -0,0 +1,13 @@ +#ifndef SHADER_STRUCTS_PUSH_CONSTANTS_GBUFFER_H +#define SHADER_STRUCTS_PUSH_CONSTANTS_GBUFFER_H + +#include "../fields.h" + +struct GBufferPC +{ + // Some of these are mirrored between this and ForwardPC + STRUCT_FIELD_GLM(uint, previousTransformValid, 0); + STRUCT_FIELD_GLM(uint, drawType, 0); +}; + +#endif // SHADER_STRUCTS_PUSH_CONSTANTS_GBUFFER_H diff --git a/res/shader/shared/shader_structs/push_constants/hiz_downsampler.h b/res/shader/shared/shader_structs/push_constants/hiz_downsampler.h new file mode 100644 index 00000000..2d060709 --- /dev/null +++ b/res/shader/shared/shader_structs/push_constants/hiz_downsampler.h @@ -0,0 +1,14 @@ +#ifndef SHADER_STRUCTS_PUSH_CONSTANTS_HIZ_DOWNSAMPLER_H +#define SHADER_STRUCTS_PUSH_CONSTANTS_HIZ_DOWNSAMPLER_H + +#include "../fields.h" + +struct HizDownsamplerPC +{ + STRUCT_FIELD_GLM(ivec2, inputResolution, {}); + STRUCT_FIELD_GLM(ivec2, topMipResolution, {}); + STRUCT_FIELD_GLM(uint, numWorkGroupsPerSlice, 0); + STRUCT_FIELD_GLM(uint, mips, 0); +}; + +#endif // SHADER_STRUCTS_PUSH_CONSTANTS_HIZ_DOWNSAMPLER_H diff --git a/res/shader/shared/shader_structs/push_constants/light_clustering.h b/res/shader/shared/shader_structs/push_constants/light_clustering.h new file mode 100644 index 00000000..453474b1 --- /dev/null +++ b/res/shader/shared/shader_structs/push_constants/light_clustering.h @@ -0,0 +1,11 @@ +#ifndef SHADER_STRUCTS_PUSH_CONSTANTS_LIGHT_CLUSTERING_H +#define SHADER_STRUCTS_PUSH_CONSTANTS_LIGHT_CLUSTERING_H + +#include "../fields.h" + +struct LightClusteringPC +{ + STRUCT_FIELD_GLM(uvec2, resolution, {}); +}; + +#endif // SHADER_STRUCTS_PUSH_CONSTANTS_LIGHT_CLUSTERING_H diff --git a/res/shader/shared/shader_structs/push_constants/prefilter_radiance.h b/res/shader/shared/shader_structs/push_constants/prefilter_radiance.h new file mode 100644 index 00000000..e8e32563 --- /dev/null +++ b/res/shader/shared/shader_structs/push_constants/prefilter_radiance.h @@ -0,0 +1,11 @@ +#ifndef SHADER_STRUCTS_PUSH_CONSTANTS_IBL_PREFILTER_RADIANCE_H +#define SHADER_STRUCTS_PUSH_CONSTANTS_IBL_PREFILTER_RADIANCE_H + +#include "../fields.h" + +struct PrefilterRadiancePC +{ + STRUCT_FIELD_GLM(uint, mipCount, 0); +}; + +#endif // SHADER_STRUCTS_PUSH_CONSTANTS_IBL_PREFILTER_RADIANCE_H diff --git a/res/shader/shared/shader_structs/push_constants/restir_di/CMakeLists.txt b/res/shader/shared/shader_structs/push_constants/restir_di/CMakeLists.txt new file mode 100644 index 00000000..f6f08667 --- /dev/null +++ b/res/shader/shared/shader_structs/push_constants/restir_di/CMakeLists.txt @@ -0,0 +1,6 @@ +set(SHARED_SHADER_STRUCTS_PUSH_CONSTANTS_RESTIR_DI_INCLUDES + ${CMAKE_CURRENT_LIST_DIR}/initial_reservoirs.h + ${CMAKE_CURRENT_LIST_DIR}/spatial_reuse.h + ${CMAKE_CURRENT_LIST_DIR}/trace.h + PARENT_SCOPE +) diff --git a/res/shader/shared/shader_structs/push_constants/restir_di/initial_reservoirs.h b/res/shader/shared/shader_structs/push_constants/restir_di/initial_reservoirs.h new file mode 100644 index 00000000..ab83f920 --- /dev/null +++ b/res/shader/shared/shader_structs/push_constants/restir_di/initial_reservoirs.h @@ -0,0 +1,11 @@ +#ifndef SHADER_STRUCTS_PUSH_CONSTANTS_RESTIR_DI_INITIAL_RESERVOIRS_H +#define SHADER_STRUCTS_PUSH_CONSTANTS_RESTIR_DI_INITIAL_RESERVOIRS_H + +#include "../../fields.h" + +struct InitialReservoirsPC +{ + STRUCT_FIELD_GLM(uint, frameIndex, 0); +}; + +#endif // SHADER_STRUCTS_PUSH_CONSTANTS_RESTIR_DI_INITIAL_RESERVOIRS_H diff --git a/res/shader/shared/shader_structs/push_constants/restir_di/spatial_reuse.h b/res/shader/shared/shader_structs/push_constants/restir_di/spatial_reuse.h new file mode 100644 index 00000000..8d71a804 --- /dev/null +++ b/res/shader/shared/shader_structs/push_constants/restir_di/spatial_reuse.h @@ -0,0 +1,11 @@ +#ifndef SHADER_STRUCTS_PUSH_CONSTANTS_RESTIR_DI_SPATIAL_REUSE_H +#define SHADER_STRUCTS_PUSH_CONSTANTS_RESTIR_DI_SPATIAL_REUSE_H + +#include "../../fields.h" + +struct SpatialReusePC +{ + STRUCT_FIELD_GLM(uint, frameIndex, 0); +}; + +#endif // SHADER_STRUCTS_PUSH_CONSTANTS_RESTIR_DI_SPATIAL_REUSE_H diff --git a/res/shader/shared/shader_structs/push_constants/restir_di/trace.h b/res/shader/shared/shader_structs/push_constants/restir_di/trace.h new file mode 100644 index 00000000..e59b99ca --- /dev/null +++ b/res/shader/shared/shader_structs/push_constants/restir_di/trace.h @@ -0,0 +1,13 @@ +#ifndef SHADER_STRUCTS_PUSH_CONSTANTS_RT_TRACE_H +#define SHADER_STRUCTS_PUSH_CONSTANTS_RT_TRACE_H + +#include "../../fields.h" + +struct TracePC +{ + STRUCT_FIELD_GLM(uint, drawType, 0); + STRUCT_FIELD_GLM(uint, frameIndex, 0); + STRUCT_FIELD_GLM(uint, flags, 0); +}; + +#endif // SHADER_STRUCTS_PUSH_CONSTANTS_RT_TRACE_H diff --git a/res/shader/shared/shader_structs/push_constants/rt_reference.h b/res/shader/shared/shader_structs/push_constants/rt_reference.h new file mode 100644 index 00000000..b317f14d --- /dev/null +++ b/res/shader/shared/shader_structs/push_constants/rt_reference.h @@ -0,0 +1,18 @@ +#ifndef SHADER_STRUCTS_PUSH_CONSTANTS_RT_REFERENCE_H +#define SHADER_STRUCTS_PUSH_CONSTANTS_RT_REFERENCE_H + +#include "../fields.h" + +struct ReferencePC +{ + STRUCT_FIELD_GLM(uint, drawType, 0); + STRUCT_FIELD_GLM(uint, flags, 0); + STRUCT_FIELD_GLM(uint, frameIndex, 0); + STRUCT_FIELD(float, apertureDiameter, 0.0001f); + STRUCT_FIELD(float, focusDistance, 1.f); + STRUCT_FIELD(float, focalLength, 0.f); + STRUCT_FIELD_GLM(uint, rouletteStartBounce, 3); + STRUCT_FIELD_GLM(uint, maxBounces, 3); +}; + +#endif // SHADER_STRUCTS_PUSH_CONSTANTS_RT_REFERENCE_H diff --git a/res/shader/shared/shader_structs/push_constants/taa_resolve.h b/res/shader/shared/shader_structs/push_constants/taa_resolve.h new file mode 100644 index 00000000..e6f8cb2d --- /dev/null +++ b/res/shader/shared/shader_structs/push_constants/taa_resolve.h @@ -0,0 +1,11 @@ +#ifndef SHADER_STRUCTS_PUSH_CONSTANTS_TAA_RESOLVE_H +#define SHADER_STRUCTS_PUSH_CONSTANTS_TAA_RESOLVE_H + +#include "../fields.h" + +struct TaaResolvePC +{ + STRUCT_FIELD_GLM(uint, flags, 0); +}; + +#endif // SHADER_STRUCTS_PUSH_CONSTANTS_TAA_RESOLVE_H diff --git a/res/shader/shared/shader_structs/push_constants/texture_debug.h b/res/shader/shared/shader_structs/push_constants/texture_debug.h new file mode 100644 index 00000000..2d7f3c5e --- /dev/null +++ b/res/shader/shared/shader_structs/push_constants/texture_debug.h @@ -0,0 +1,21 @@ +#ifndef SHADER_STRUCTS_PUSH_CONSTANTS_TEXTURE_DEBUG_H +#define SHADER_STRUCTS_PUSH_CONSTANTS_TEXTURE_DEBUG_H + +#include "../fields.h" + +#define TEXTURE_DEBUG_RANGE_DEFAULT \ + glm::vec2 { 0.f, 1.f } + +struct TextureDebugPC +{ + STRUCT_FIELD_GLM(ivec2, inRes, {}); + STRUCT_FIELD_GLM(ivec2, outRes, {}); + + STRUCT_FIELD_GLM(vec2, range, TEXTURE_DEBUG_RANGE_DEFAULT); + STRUCT_FIELD_GLM(uint, lod, 0); + STRUCT_FIELD_GLM(uint, flags, 0); + + STRUCT_FIELD_GLM(vec2, cursorUv, {}); +}; + +#endif // SHADER_STRUCTS_PUSH_CONSTANTS_TEXTURE_DEBUG_H diff --git a/res/shader/shared/shader_structs/push_constants/texture_readback.h b/res/shader/shared/shader_structs/push_constants/texture_readback.h new file mode 100644 index 00000000..6816054f --- /dev/null +++ b/res/shader/shared/shader_structs/push_constants/texture_readback.h @@ -0,0 +1,11 @@ +#ifndef SHADER_STRUCTS_PUSH_CONSTANTS_TEXTURE_READBACK_H +#define SHADER_STRUCTS_PUSH_CONSTANTS_TEXTURE_READBACK_H + +#include "../fields.h" + +struct TextureReadbackPC +{ + STRUCT_FIELD_GLM(vec2, uv, {}); +}; + +#endif // SHADER_STRUCTS_PUSH_CONSTANTS_TEXTURE_READBACK_H diff --git a/res/shader/shared/shader_structs/push_constants/tone_map.h b/res/shader/shared/shader_structs/push_constants/tone_map.h new file mode 100644 index 00000000..f83c7c4c --- /dev/null +++ b/res/shader/shared/shader_structs/push_constants/tone_map.h @@ -0,0 +1,12 @@ +#ifndef SHADER_STRUCTS_PUSH_CONSTANTS_TONE_MAP_H +#define SHADER_STRUCTS_PUSH_CONSTANTS_TONE_MAP_H + +#include "../fields.h" + +struct ToneMapPC +{ + STRUCT_FIELD(float, exposure, 1.f); + STRUCT_FIELD(float, contrast, 1.f); +}; + +#endif // SHADER_STRUCTS_PUSH_CONSTANTS_TONE_MAP_H diff --git a/res/shader/shared/shader_structs/scene/CMakeLists.txt b/res/shader/shared/shader_structs/scene/CMakeLists.txt new file mode 100644 index 00000000..4b189b1a --- /dev/null +++ b/res/shader/shared/shader_structs/scene/CMakeLists.txt @@ -0,0 +1,10 @@ +set(SHARED_SHADER_STRUCTS_SCENE_INCLUDES + ${CMAKE_CURRENT_LIST_DIR}/camera.h + ${CMAKE_CURRENT_LIST_DIR}/draw_instance.h + ${CMAKE_CURRENT_LIST_DIR}/fwd.hpp + ${CMAKE_CURRENT_LIST_DIR}/geometry_metadata.h + ${CMAKE_CURRENT_LIST_DIR}/lights.h + ${CMAKE_CURRENT_LIST_DIR}/material_data.h + ${CMAKE_CURRENT_LIST_DIR}/model_instance_transforms.h + PARENT_SCOPE +) diff --git a/res/shader/shared/shader_structs/scene/camera.h b/res/shader/shared/shader_structs/scene/camera.h new file mode 100644 index 00000000..a98efedf --- /dev/null +++ b/res/shader/shared/shader_structs/scene/camera.h @@ -0,0 +1,31 @@ +#ifndef SHARED_SHADER_STRUCTS_SCENE_CAMERA_H +#define SHARED_SHADER_STRUCTS_SCENE_CAMERA_H + +#include "../fields.h" + +struct CameraUniforms +{ + STRUCT_FIELD_GLM(mat4, worldToCamera, {}); + STRUCT_FIELD_GLM(mat4, cameraToWorld, {}); + STRUCT_FIELD_GLM(mat4, cameraToClip, {}); + STRUCT_FIELD_GLM(mat4, clipToWorld, {}); + STRUCT_FIELD_GLM(mat4, previousWorldToCamera, {}); + STRUCT_FIELD_GLM(mat4, previousCameraToClip, {}); + STRUCT_FIELD_GLM(vec4, eye, {}); + // These are world space plane normal,distance and normals point into the + // frustum + STRUCT_FIELD_GLM(vec4, nearPlane, {}); + STRUCT_FIELD_GLM(vec4, farPlane, {}); + STRUCT_FIELD_GLM(vec4, leftPlane, {}); + STRUCT_FIELD_GLM(vec4, rightPlane, {}); + STRUCT_FIELD_GLM(vec4, topPlane, {}); + STRUCT_FIELD_GLM(vec4, bottomPlane, {}); + STRUCT_FIELD_GLM(uvec2, resolution, {}); + STRUCT_FIELD_GLM(vec2, currentJitter, {}); + STRUCT_FIELD_GLM(vec2, previousJitter, {}); + STRUCT_FIELD(float, near, 0.f); + STRUCT_FIELD(float, far, 0.f); + STRUCT_FIELD(float, maxViewScale, 0.f); +}; + +#endif // SHARED_SHADER_STRUCTS_SCENE_CAMERA_H diff --git a/res/shader/shared/shader_structs/scene/draw_instance.h b/res/shader/shared/shader_structs/scene/draw_instance.h new file mode 100644 index 00000000..fb039c1c --- /dev/null +++ b/res/shader/shared/shader_structs/scene/draw_instance.h @@ -0,0 +1,20 @@ +#ifndef SHARED_SHADER_STRUCTS_SCENE_DRAW_INSTANCE_H +#define SHARED_SHADER_STRUCTS_SCENE_DRAW_INSTANCE_H + +#include "../fields.h" + +struct DrawInstance +{ + STRUCT_FIELD_GLM(uint, modelInstanceIndex, 0); + STRUCT_FIELD_GLM(uint, meshIndex, 0xFFFF'FFFF); + STRUCT_FIELD_GLM(uint, materialIndex, 0xFFFF'FFFF); +}; + +#ifdef __cplusplus + +// These are uploaded onto the gpu and tight packing is assumed +static_assert(alignof(DrawInstance) == sizeof(uint32_t)); + +#endif // __cplusplus + +#endif // SHARED_SHADER_STRUCTS_SCENE_DRAW_INSTANCE_H diff --git a/res/shader/shared/shader_structs/scene/fwd.hpp b/res/shader/shared/shader_structs/scene/fwd.hpp new file mode 100644 index 00000000..ae11a438 --- /dev/null +++ b/res/shader/shared/shader_structs/scene/fwd.hpp @@ -0,0 +1,18 @@ +#ifndef SHARED_SHADER_STRUCTS_SCENE_FWD_HPP +#define SHARED_SHADER_STRUCTS_SCENE_FWD_HPP + +#ifndef __cplusplus +#error "Forward declarations have no meaning in GLSL" +#endif // !__cplusplus + +struct CameraUniforms; +struct DrawInstance; +struct GeometryMetadata; +struct DirectionalLightParameters; +struct PointLight; +struct SpotLight; +struct Texture2DSampler; +struct MaterialData; +struct ModelInstanceTransforms; + +#endif // SHARED_SHADER_STRUCTS_SCENE_FWD_HPP diff --git a/res/shader/shared/shader_structs/scene/geometry_metadata.h b/res/shader/shared/shader_structs/scene/geometry_metadata.h new file mode 100644 index 00000000..7c00ca3a --- /dev/null +++ b/res/shader/shared/shader_structs/scene/geometry_metadata.h @@ -0,0 +1,33 @@ +#ifndef SHARED_SHADER_STRUCTS_SCENE_GEOMETRY_METADATA_H +#define SHARED_SHADER_STRUCTS_SCENE_GEOMETRY_METADATA_H + +#include "../fields.h" + +struct GeometryMetadata +{ + STRUCT_FIELD_GLM(uint, bufferIndex, 0xFFFF'FFFF); + // These offsets are into the geometry data buffers. Most are for U32/F32 + // and an offset of 0xFFFF'FFFF signals an unused attribute. + // This addresses U16 if short indices are in use. + STRUCT_FIELD_GLM(uint, indicesOffset, 0xFFFF'FFFF); + STRUCT_FIELD_GLM(uint, positionsOffset, 0xFFFF'FFFF); + STRUCT_FIELD_GLM(uint, normalsOffset, 0xFFFF'FFFF); + STRUCT_FIELD_GLM(uint, tangentsOffset, 0xFFFF'FFFF); + STRUCT_FIELD_GLM(uint, texCoord0sOffset, 0xFFFF'FFFF); + STRUCT_FIELD_GLM(uint, meshletsOffset, 0xFFFF'FFFF); + STRUCT_FIELD_GLM(uint, meshletBoundsOffset, 0xFFFF'FFFF); + // This addresses U16 if short indices are in use. + STRUCT_FIELD_GLM(uint, meshletVerticesOffset, 0xFFFF'FFFF); + // This addresses U8. + STRUCT_FIELD_GLM(uint, meshletTrianglesByteOffset, 0xFFFF'FFFF); + STRUCT_FIELD_GLM(uint, usesShortIndices, 0); +}; + +#ifdef __cplusplus + +// These are uploaded onto the gpu and tight packing is assumed +static_assert(alignof(GeometryMetadata) == sizeof(uint32_t)); + +#endif // __cplusplus + +#endif // SHARED_SHADER_STRUCTS_SCENE_GEOMETRY_METADATA_H diff --git a/res/shader/shared/shader_structs/scene/lights.h b/res/shader/shared/shader_structs/scene/lights.h new file mode 100644 index 00000000..017aa9ed --- /dev/null +++ b/res/shader/shared/shader_structs/scene/lights.h @@ -0,0 +1,36 @@ +#ifndef SHARED_SHADER_STRUCTS_SCENE_LIGHTS_H +#define SHARED_SHADER_STRUCTS_SCENE_LIGHTS_H + +#include "../fields.h" + +#ifdef __cplusplus + +// Cant do {}s in macro arguments +#define DIRECTIONAL_LIGHT_DEFAULT_DIRECTION \ + glm::vec4 \ + { \ + -1.f, -1.f, -1.f, 1.f \ + } + +#endif // __cplusplus + +struct DirectionalLightParameters +{ + STRUCT_FIELD_GLM(vec4, irradiance, 2.f); + STRUCT_FIELD_GLM(vec4, direction, DIRECTIONAL_LIGHT_DEFAULT_DIRECTION); +}; + +struct PointLight +{ + STRUCT_FIELD_GLM(vec4, radianceAndRadius, 0.f); + STRUCT_FIELD_GLM(vec4, position, 0.f); +}; + +struct SpotLight +{ + STRUCT_FIELD_GLM(vec4, radianceAndAngleScale, 0.f); + STRUCT_FIELD_GLM(vec4, positionAndAngleOffset, 0.f); + STRUCT_FIELD_GLM(vec4, direction, 0.f); +}; + +#endif // SHARED_SHADER_STRUCTS_SCENE_LIGHTS_H diff --git a/res/shader/shared/shader_structs/scene/material_data.h b/res/shader/shared/shader_structs/scene/material_data.h new file mode 100644 index 00000000..bed977f0 --- /dev/null +++ b/res/shader/shared/shader_structs/scene/material_data.h @@ -0,0 +1,64 @@ +#ifndef SHARED_SHADER_STRUCTS_SCENE_MATERIAL_DATA_H +#define SHARED_SHADER_STRUCTS_SCENE_MATERIAL_DATA_H + +#include "../fields.h" + +#ifdef __cplusplus + +#include +#include + +class Texture; + +struct Texture2DSampler +{ + static constexpr uint32_t sMaxTextureIndex = 0xFF'FFFF; + static constexpr uint32_t sMaxSamplerIndex = 0xFF; + + uint32_t packed{0}; + + Texture2DSampler() noexcept = default; + Texture2DSampler(uint32_t texture, uint32_t sampler) + : packed{(sampler << 24) | texture} + { + WHEELS_ASSERT(texture < sMaxTextureIndex); + WHEELS_ASSERT(sampler < sMaxSamplerIndex); + }; + + [[nodiscard]] uint32_t texture() const { return packed & sMaxTextureIndex; } +}; +static_assert(sizeof(Texture2DSampler) == sizeof(uint32_t)); + +enum AlphaMode : uint32_t +{ + AlphaMode_Opaque, + AlphaMode_Mask, + AlphaMode_Blend, +}; + +#else // !__cplusplus + +const uint AlphaModeOpaque = 0; +const uint AlphaModeMask = 1; +const uint AlphaModeBlend = 2; + +#endif // __cplusplus + +struct MaterialData +{ + STRUCT_FIELD_GLM(vec4, baseColorFactor, 1.f); + STRUCT_FIELD(float, metallicFactor, 1.f); + STRUCT_FIELD(float, roughnessFactor, 1.f); + STRUCT_FIELD(float, alphaCutoff, 0.5f); + STRUCT_FIELD_SEPARATE_TYPES(uint, AlphaMode, alphaMode, AlphaMode_Opaque); + STRUCT_FIELD_SEPARATE_TYPES( + uint, Texture2DSampler, baseColorTextureSampler, Texture2DSampler{}); + STRUCT_FIELD_SEPARATE_TYPES( + uint, Texture2DSampler, metallicRoughnessTextureSampler, + Texture2DSampler{}); + STRUCT_FIELD_SEPARATE_TYPES( + uint, Texture2DSampler, normalTextureSampler, Texture2DSampler{}); + STRUCT_FIELD_GLM(uint, pad, 0); +}; + +#endif // SHARED_SHADER_STRUCTS_SCENE_MATERIAL_DATA_H diff --git a/res/shader/shared/shader_structs/scene/model_instance_transforms.h b/res/shader/shared/shader_structs/scene/model_instance_transforms.h new file mode 100644 index 00000000..2ae68f84 --- /dev/null +++ b/res/shader/shared/shader_structs/scene/model_instance_transforms.h @@ -0,0 +1,12 @@ +#ifndef SHARED_SHADER_STRUCTS_SCENE_MODEL_INSTANCE_TRANSFORMS_H +#define SHARED_SHADER_STRUCTS_SCENE_MODEL_INSTANCE_TRANSFORMS_H + +#include "../fields.h" + +struct ModelInstanceTransforms +{ + STRUCT_FIELD_GLM(mat3x4, modelToWorld, 1.f); + STRUCT_FIELD_GLM(mat3x4, normalToWorld, 1.f); +}; + +#endif // SHARED_SHADER_STRUCTS_SCENE_MODEL_INSTANCE_TRANSFORMS_H diff --git a/res/shader/taa_resolve.comp b/res/shader/taa_resolve.comp index c8567f2e..288b908c 100644 --- a/res/shader/taa_resolve.comp +++ b/res/shader/taa_resolve.comp @@ -9,9 +9,9 @@ #include "common/math.glsl" #include "scene/camera.glsl" +#include "shared/shader_structs/push_constants/taa_resolve.h" -layout(push_constant) uniform TaaResolvePC { uint flags; } -PC; +layout(push_constant) uniform PushConstants { TaaResolvePC PC; }; bool flagIgnoreHistory() { return bitfieldExtract(PC.flags, 0, 1) == 1; } bool flagCatmullRom() { return bitfieldExtract(PC.flags, 1, 1) == 1; } diff --git a/res/shader/texture_debug.comp b/res/shader/texture_debug.comp index d748483e..97c302be 100644 --- a/res/shader/texture_debug.comp +++ b/res/shader/texture_debug.comp @@ -4,6 +4,7 @@ #extension GL_EXT_shader_image_load_formatted : require #include "common/math.glsl" +#include "shared/shader_structs/push_constants/texture_debug.h" layout(binding = 0) uniform texture2D inColor; layout(binding = 1) uniform writeonly image2D outColor; @@ -12,18 +13,7 @@ layout(binding = 3) uniform sampler nearestSampler; layout(std430, binding = 4) buffer Color { vec4 color; } outPeekColor; -layout(push_constant) uniform TextureDebugPC -{ - ivec2 inRes; - ivec2 outRes; - - vec2 range; - uint lod; - uint flags; - - vec2 cursorUv; -} -PC; +layout(push_constant) uniform PushConstants { TextureDebugPC PC; }; uint flagChannelType() { return bitfieldExtract(PC.flags, 0, 3); } bool flagAbsBeforeRange() { return bitfieldExtract(PC.flags, 3, 1) == 1; } diff --git a/res/shader/texture_readback.comp b/res/shader/texture_readback.comp index 7db0279a..6ee40183 100644 --- a/res/shader/texture_readback.comp +++ b/res/shader/texture_readback.comp @@ -1,7 +1,8 @@ #pragma shader_stage(compute) -layout(push_constant) uniform TextureReadbackPC { vec2 uv; } -PC; +#include "shared/shader_structs/push_constants/texture_readback.h" + +layout(push_constant) uniform PushConstants { TextureReadbackPC PC; }; layout(binding = 0) uniform texture2D inTexture; layout(binding = 1) uniform sampler nearestSampler; diff --git a/res/shader/tone_map.comp b/res/shader/tone_map.comp index 10c8a1cc..05011be9 100644 --- a/res/shader/tone_map.comp +++ b/res/shader/tone_map.comp @@ -3,13 +3,9 @@ #extension GL_EXT_shader_image_load_formatted : require #include "common/math.glsl" +#include "shared/shader_structs/push_constants/tone_map.h" -layout(push_constant) uniform ToneMapPC -{ - float exposure; - float contrast; -} -PC; +layout(push_constant) uniform PushConstants { ToneMapPC PC; }; layout(binding = 0) uniform readonly image2D inColor; layout(binding = 1) uniform texture3D inLut; diff --git a/src/render/DeferredShading.cpp b/src/render/DeferredShading.cpp index a90bff01..e4df9b9b 100644 --- a/src/render/DeferredShading.cpp +++ b/src/render/DeferredShading.cpp @@ -13,6 +13,7 @@ #include "utils/Utils.hpp" #include +#include using namespace glm; using namespace wheels; @@ -32,12 +33,6 @@ enum BindingSet : uint32_t BindingSetCount, }; -struct PCBlock -{ - uint drawType{0}; - uint ibl{0}; -}; - ComputePass::Shader shaderDefinitionCallback( Allocator &alloc, const WorldDSLayouts &worldDSLayouts) { @@ -186,7 +181,7 @@ DeferredShading::Output DeferredShading::record( PROFILER_GPU_SCOPE(cb, "DeferredShading"); - const PCBlock pcBlock{ + const DeferredShadingPC pcBlock{ .drawType = static_cast(drawType), .ibl = static_cast(applyIbl), }; diff --git a/src/render/ForwardRenderer.cpp b/src/render/ForwardRenderer.cpp index dff4ad93..4ffe8533 100644 --- a/src/render/ForwardRenderer.cpp +++ b/src/render/ForwardRenderer.cpp @@ -20,6 +20,7 @@ #include "utils/Utils.hpp" #include +#include using namespace glm; using namespace wheels; @@ -41,13 +42,6 @@ enum BindingSet : uint32_t BindingSetCount, }; -struct PCBlock -{ - uint32_t drawType{0}; - uint32_t ibl{0}; - uint32_t previousTransformValid{0}; -}; - struct Attachments { InlineArray color; @@ -328,11 +322,11 @@ bool ForwardRenderer::compileShaders( m_meshReflection = WHEELS_MOV(meshResult->reflection); WHEELS_ASSERT( - sizeof(PCBlock) == m_meshReflection->pushConstantsBytesize()); + sizeof(ForwardPC) == m_meshReflection->pushConstantsBytesize()); m_fragReflection = WHEELS_MOV(fragResult->reflection); WHEELS_ASSERT( - sizeof(PCBlock) == m_fragReflection->pushConstantsBytesize()); + sizeof(ForwardPC) == m_fragReflection->pushConstantsBytesize()); m_shaderStages = {{ vk::PipelineShaderStageCreateInfo{ @@ -424,7 +418,7 @@ void ForwardRenderer::createGraphicsPipelines(const InputDSLayouts &dsLayouts) .stageFlags = vk::ShaderStageFlagBits::eMeshEXT | vk::ShaderStageFlagBits::eFragment, .offset = 0, - .size = sizeof(PCBlock), + .size = sizeof(ForwardPC), }; m_pipelineLayout = gDevice.logical().createPipelineLayout(vk::PipelineLayoutCreateInfo{ @@ -612,7 +606,7 @@ void ForwardRenderer::recordDraw( setViewportScissor(cb, renderArea); - const PCBlock pcBlock{ + const ForwardPC pcBlock{ .drawType = static_cast(options.drawType), .ibl = static_cast(options.ibl), .previousTransformValid = scene.previousTransformsValid ? 1u : 0u, @@ -621,7 +615,7 @@ void ForwardRenderer::recordDraw( m_pipelineLayout, vk::ShaderStageFlagBits::eMeshEXT | vk::ShaderStageFlagBits::eFragment, 0, // offset - sizeof(PCBlock), &pcBlock); + sizeof(pcBlock), &pcBlock); const vk::Buffer argumentHandle = gRenderResources.buffers->nativeHandle(inputsOutputs.inArgumentBuffer); diff --git a/src/render/GBufferRenderer.cpp b/src/render/GBufferRenderer.cpp index 831c0d3f..06b2c5ab 100644 --- a/src/render/GBufferRenderer.cpp +++ b/src/render/GBufferRenderer.cpp @@ -17,6 +17,7 @@ #include "wheels/assert.hpp" #include +#include using namespace glm; using namespace wheels; @@ -38,12 +39,6 @@ enum BindingSet : uint32_t BindingSetCount, }; -struct PCBlock -{ - uint32_t previousTransformValid{0}; - uint32_t drawType{0}; -}; - struct Attachments { wheels::StaticArray color; @@ -305,7 +300,7 @@ bool GBufferRenderer::compileShaders( m_meshReflection = WHEELS_MOV(meshResult->reflection); WHEELS_ASSERT( - sizeof(PCBlock) == m_meshReflection->pushConstantsBytesize()); + sizeof(GBufferPC) == m_meshReflection->pushConstantsBytesize()); m_fragReflection = WHEELS_MOV(fragResult->reflection); @@ -397,7 +392,7 @@ void GBufferRenderer::createGraphicsPipelines( .stageFlags = vk::ShaderStageFlagBits::eMeshEXT | vk::ShaderStageFlagBits::eFragment, .offset = 0, - .size = sizeof(PCBlock), + .size = sizeof(GBufferPC), }; m_pipelineLayout = gDevice.logical().createPipelineLayout(vk::PipelineLayoutCreateInfo{ @@ -560,7 +555,7 @@ void GBufferRenderer::recordDraw( setViewportScissor(cb, renderArea); - const PCBlock pcBlock{ + const GBufferPC pcBlock{ .previousTransformValid = scene.previousTransformsValid ? 1u : 0u, .drawType = static_cast(drawType), }; @@ -568,7 +563,7 @@ void GBufferRenderer::recordDraw( m_pipelineLayout, vk::ShaderStageFlagBits::eMeshEXT | vk::ShaderStageFlagBits::eFragment, 0, // offset - sizeof(PCBlock), &pcBlock); + sizeof(pcBlock), &pcBlock); const vk::Buffer argumentHandle = gRenderResources.buffers->nativeHandle(inputsOutputs.inArgumentBuffer); diff --git a/src/render/HierarchicalDepthDownsampler.cpp b/src/render/HierarchicalDepthDownsampler.cpp index 89e57348..e7914b1e 100644 --- a/src/render/HierarchicalDepthDownsampler.cpp +++ b/src/render/HierarchicalDepthDownsampler.cpp @@ -7,6 +7,7 @@ #include "utils/Utils.hpp" #include +#include using namespace glm; using namespace wheels; @@ -36,14 +37,6 @@ void SpdSetup( (dispatchThreadGroupCountXY[0]) * (dispatchThreadGroupCountXY[1]); } -struct PCBlock -{ - ivec2 inputResolution; - ivec2 topMipResolution; - uint32_t numWorkGroupsPerSlice; - uint32_t mips; -}; - ComputePass::Shader shaderDefinitionCallback(Allocator &alloc) { return ComputePass::Shader{ @@ -124,7 +117,7 @@ ImageHandle HierarchicalDepthDownsampler::record( WHEELS_ASSERT(hizMipCount <= sMaxMips); uvec2 dispatchThreadGroupCountXY{}; - PCBlock pcBlock{ + HizDownsamplerPC pcBlock{ .inputResolution = ivec2{ asserted_cast(inDepth.extent.width), diff --git a/src/render/ImageBasedLighting.cpp b/src/render/ImageBasedLighting.cpp index d5e6132d..7e2104c3 100644 --- a/src/render/ImageBasedLighting.cpp +++ b/src/render/ImageBasedLighting.cpp @@ -5,6 +5,7 @@ #include "utils/Profiler.hpp" #include +#include using namespace wheels; using namespace glm; @@ -44,11 +45,6 @@ ComputePass::Shader integrateSpecularBrdfShaderDefinitionCallback( }; } -struct PrefilterRadiancePC -{ - uint mipCount{0}; -}; - ComputePass::Shader prefilterRadianceShaderDefinitionCallback(Allocator &alloc) { const size_t len = 32; diff --git a/src/render/LightClustering.cpp b/src/render/LightClustering.cpp index 0bd21d80..0e8e3838 100644 --- a/src/render/LightClustering.cpp +++ b/src/render/LightClustering.cpp @@ -8,6 +8,7 @@ #include "utils/Profiler.hpp" #include "utils/Utils.hpp" +#include #include #include @@ -29,11 +30,6 @@ enum BindingSet : uint32_t BindingSetCount, }; -struct ClusteringPCBlock -{ - uvec2 resolution; -}; - ComputePass::Shader shaderDefinitionCallback(Allocator &alloc) { const size_t len = 256; @@ -215,7 +211,7 @@ LightClusteringOutput LightClustering::record( } { // Main dispatch - const ClusteringPCBlock pcBlock{ + const LightClusteringPC pcBlock{ .resolution = uvec2(renderExtent.width, renderExtent.height), }; diff --git a/src/render/MeshletCuller.cpp b/src/render/MeshletCuller.cpp index fc31d603..eeb5ec14 100644 --- a/src/render/MeshletCuller.cpp +++ b/src/render/MeshletCuller.cpp @@ -13,6 +13,9 @@ #include "scene/WorldRenderStructs.hpp" #include "utils/Profiler.hpp" +#include +#include + using namespace glm; using namespace wheels; @@ -39,20 +42,6 @@ enum GeneratorBindingSet : uint32_t GeneratorBindingSetCount, }; -struct GeneratorPCBlock -{ - uint32_t matchTransparents; -}; - -struct CullerPCBlock -{ - uvec2 hizResolution{0}; - vec2 hizUvScale{1.f}; - // 0 means no hiz bound - uint hizMipCount{0}; - uint32_t outputSecondPhaseInput{0}; -}; - enum CullerBindingSet : uint32_t { CullerCameraBindingSet, @@ -296,7 +285,7 @@ BufferHandle MeshletCuller::recordGenerateList( { const Scene &scene = world.currentScene(); const Span models = world.models(); - const Span materials = world.materials(); + const Span materials = world.materials(); const Span meshInfos = world.meshInfos(); for (const ModelInstance &instance : scene.modelInstances) @@ -305,15 +294,16 @@ BufferHandle MeshletCuller::recordGenerateList( const Model &model = models[instance.modelIndex]; for (const Model::SubModel &subModel : model.subModels) { - const Material &material = materials[subModel.materialIndex]; + const MaterialData &material = + materials[subModel.materialIndex]; const MeshInfo &info = meshInfos[subModel.meshIndex]; // 0 means invalid or not yet loaded if (info.indexCount > 0) { const bool shouldDraw = mode == Mode::Opaque - ? material.alphaMode != Material::AlphaMode::Blend - : material.alphaMode == Material::AlphaMode::Blend; + ? material.alphaMode != AlphaMode_Blend + : material.alphaMode == AlphaMode_Blend; if (shouldDraw) { @@ -373,7 +363,7 @@ BufferHandle MeshletCuller::recordGenerateList( gRenderResources.buffers->transition( cb, ret, BufferState::ComputeShaderReadWrite); - const GeneratorPCBlock pcBlock{ + const DrawListGeneratorPC pcBlock{ .matchTransparents = mode == Mode::Transparent ? 1u : 0u, }; @@ -672,7 +662,7 @@ MeshletCuller::CullOutput MeshletCuller::recordCullList( worldByteOffsets.modelInstanceScales, }}; - CullerPCBlock pcBlock{ + DrawListCullerPC pcBlock{ .outputSecondPhaseInput = outputSecondPhaseInput ? 1u : 0u, }; if (input.hierarchicalDepth.has_value()) diff --git a/src/render/RtReference.cpp b/src/render/RtReference.cpp index 88ccdfeb..297179e5 100644 --- a/src/render/RtReference.cpp +++ b/src/render/RtReference.cpp @@ -16,6 +16,7 @@ #include "utils/Utils.hpp" #include +#include using namespace wheels; @@ -61,28 +62,16 @@ enum class GroupIndex : uint32_t Miss, }; -struct PCBlock +struct ReferencePCFlags { - uint32_t drawType{0}; - uint32_t flags{0}; - uint32_t frameIndex{0}; - float apertureDiameter{0.00001f}; - float focusDistance{1.f}; - float focalLength{0.f}; - uint32_t rouletteStartBounce{3}; - uint32_t maxBounces{RtReference::sMaxBounces}; - - struct Flags - { - bool skipHistory{false}; - bool accumulate{false}; - bool ibl{false}; - bool depthOfField{false}; - bool clampIndirect{false}; - }; + bool skipHistory{false}; + bool accumulate{false}; + bool ibl{false}; + bool depthOfField{false}; + bool clampIndirect{false}; }; -uint32_t pcFlags(PCBlock::Flags flags) +uint32_t pcFlags(ReferencePCFlags flags) { uint32_t ret = 0; @@ -284,9 +273,9 @@ RtReference::Output RtReference::record( const CameraParameters &camParams = cam.parameters(); - const PCBlock pcBlock{ + const ReferencePC pcBlock{ .drawType = static_cast(options.drawType), - .flags = pcFlags(PCBlock::Flags{ + .flags = pcFlags(ReferencePCFlags{ .skipHistory = cam.changedThisFrame() || options.colorDirty || m_accumulationDirty, .accumulate = m_accumulate, @@ -302,7 +291,7 @@ RtReference::Output RtReference::record( .maxBounces = m_maxBounces, }; cb.pushConstants( - m_pipelineLayout, sVkShaderStageFlagsAllRt, 0, sizeof(PCBlock), + m_pipelineLayout, sVkShaderStageFlagsAllRt, 0, sizeof(pcBlock), &pcBlock); WHEELS_ASSERT(m_shaderBindingTable.deviceAddress != 0); @@ -490,22 +479,24 @@ bool RtReference::compileShaders( m_raygenReflection = WHEELS_MOV(raygenResult->reflection); WHEELS_ASSERT( - sizeof(PCBlock) == m_raygenReflection->pushConstantsBytesize()); + sizeof(ReferencePC) == m_raygenReflection->pushConstantsBytesize()); m_rayMissReflection = WHEELS_MOV(rayMissResult->reflection); WHEELS_ASSERT( m_rayMissReflection->pushConstantsBytesize() == 0 || - sizeof(PCBlock) == m_rayMissReflection->pushConstantsBytesize()); + sizeof(ReferencePC) == + m_rayMissReflection->pushConstantsBytesize()); m_closestHitReflection = WHEELS_MOV(closestHitResult->reflection); WHEELS_ASSERT( m_closestHitReflection->pushConstantsBytesize() == 0 || - sizeof(PCBlock) == m_closestHitReflection->pushConstantsBytesize()); + sizeof(ReferencePC) == + m_closestHitReflection->pushConstantsBytesize()); m_anyHitReflection = WHEELS_MOV(anyHitResult->reflection); WHEELS_ASSERT( m_anyHitReflection->pushConstantsBytesize() == 0 || - sizeof(PCBlock) == m_anyHitReflection->pushConstantsBytesize()); + sizeof(ReferencePC) == m_anyHitReflection->pushConstantsBytesize()); m_shaderStages[static_cast(StageIndex::RayGen)] = { .stage = vk::ShaderStageFlagBits::eRaygenKHR, @@ -628,7 +619,7 @@ void RtReference::createPipeline( const vk::PushConstantRange pcRange{ .stageFlags = sVkShaderStageFlagsAllRt, .offset = 0, - .size = sizeof(PCBlock), + .size = sizeof(ReferencePC), }; m_pipelineLayout = gDevice.logical().createPipelineLayout(vk::PipelineLayoutCreateInfo{ diff --git a/src/render/TemporalAntiAliasing.cpp b/src/render/TemporalAntiAliasing.cpp index 017ce6c7..34456cda 100644 --- a/src/render/TemporalAntiAliasing.cpp +++ b/src/render/TemporalAntiAliasing.cpp @@ -10,6 +10,7 @@ #include #include +#include using namespace glm; using namespace wheels; @@ -33,23 +34,18 @@ enum BindingSet : uint32_t BindingSetCount, }; -struct PCBlock +struct TaaResolveFlags { - uint32_t flags{0}; - - struct Flags - { - bool ignoreHistory{false}; - bool catmullRom{false}; - TemporalAntiAliasing::ColorClippingType colorClipping{ - TemporalAntiAliasing::ColorClippingType::None}; - TemporalAntiAliasing::VelocitySamplingType velocitySampling{ - TemporalAntiAliasing::VelocitySamplingType::Center}; - bool luminanceWeighting{false}; - }; + bool ignoreHistory{false}; + bool catmullRom{false}; + TemporalAntiAliasing::ColorClippingType colorClipping{ + TemporalAntiAliasing::ColorClippingType::None}; + TemporalAntiAliasing::VelocitySamplingType velocitySampling{ + TemporalAntiAliasing::VelocitySamplingType::Center}; + bool luminanceWeighting{false}; }; -uint32_t pcFlags(PCBlock::Flags flags) +uint32_t pcFlags(TaaResolveFlags flags) { uint32_t ret = 0; @@ -239,8 +235,8 @@ TemporalAntiAliasing::Output TemporalAntiAliasing::record( m_computePass.record( cb, - PCBlock{ - .flags = pcFlags(PCBlock::Flags{ + TaaResolvePC{ + .flags = pcFlags(TaaResolveFlags{ .ignoreHistory = ignoreHistory, .catmullRom = m_catmullRom, .colorClipping = m_colorClipping, diff --git a/src/render/TextureDebug.cpp b/src/render/TextureDebug.cpp index 41d0f135..95b200d2 100644 --- a/src/render/TextureDebug.cpp +++ b/src/render/TextureDebug.cpp @@ -9,6 +9,7 @@ #include #include +#include using namespace glm; using namespace wheels; @@ -18,27 +19,15 @@ namespace const Hash sStrSpanHash = Hash{}; -struct PCBlock +struct TextureDebugPCFlags { - ivec2 inRes{}; - ivec2 outRes{}; - - vec2 range{0.f, 1.f}; - uint32_t lod{0}; - uint32_t flags{0}; - - vec2 cursorUv{}; - - struct Flags - { - TextureDebug::ChannelType channelType{TextureDebug::ChannelType::RGB}; - bool absBeforeRange{false}; - bool zoom{false}; - bool magnifier{false}; - }; + TextureDebug::ChannelType channelType{TextureDebug::ChannelType::RGB}; + bool absBeforeRange{false}; + bool zoom{false}; + bool magnifier{false}; }; -uint32_t pcFlags(PCBlock::Flags flags) +uint32_t pcFlags(TextureDebugPCFlags flags) { uint32_t ret = 0; @@ -356,7 +345,7 @@ ImageHandle TextureDebug::record( ? (vec2(*cursorCoord) + 0.5f) / vec2(outExtent.width, outExtent.height) : vec2{}; - const PCBlock pcBlock{ + const TextureDebugPC pcBlock{ .inRes = uvec2{ asserted_cast(inExtent.width), @@ -369,7 +358,7 @@ ImageHandle TextureDebug::record( }, .range = settings.range, .lod = asserted_cast(settings.lod), - .flags = pcFlags(PCBlock::Flags{ + .flags = pcFlags(TextureDebugPCFlags{ .channelType = settings.channelType, .absBeforeRange = settings.absBeforeRange, .zoom = m_zoom, diff --git a/src/render/TextureReadback.cpp b/src/render/TextureReadback.cpp index d9cf3f70..4894ca5f 100644 --- a/src/render/TextureReadback.cpp +++ b/src/render/TextureReadback.cpp @@ -4,17 +4,14 @@ #include "render/RenderResources.hpp" #include "utils/Profiler.hpp" +#include + using namespace glm; using namespace wheels; namespace { -struct PCBlock -{ - vec2 uv{}; -}; - ComputePass::Shader shaderDefinitionCallback(Allocator &alloc) { return ComputePass::Shader{ @@ -127,7 +124,7 @@ void TextureReadback::record( const vk::Extent3D inRes = gRenderResources.images->resource(inTexture).extent; - const PCBlock pcBlock{ + const TextureReadbackPC pcBlock{ .uv = px / vec2(inRes.width, inRes.height), }; diff --git a/src/render/ToneMap.cpp b/src/render/ToneMap.cpp index 4674beef..0bbd6d16 100644 --- a/src/render/ToneMap.cpp +++ b/src/render/ToneMap.cpp @@ -7,6 +7,7 @@ #include #include +#include using namespace glm; using namespace wheels; @@ -14,12 +15,6 @@ using namespace wheels; namespace { -struct PCBlock -{ - float exposure{1.f}; - float contrast{1.f}; -}; - ComputePass::Shader shaderDefinitionCallback(Allocator &alloc) { return ComputePass::Shader{ @@ -125,7 +120,7 @@ ToneMap::Output ToneMap::record( m_computePass.storageSet(nextFrame); m_computePass.record( cb, - PCBlock{ + ToneMapPC{ .exposure = m_exposure, .contrast = m_contrast, }, diff --git a/src/render/dof/DepthOfFieldDilate.cpp b/src/render/dof/DepthOfFieldDilate.cpp index 925712e3..f8c632fc 100644 --- a/src/render/dof/DepthOfFieldDilate.cpp +++ b/src/render/dof/DepthOfFieldDilate.cpp @@ -9,6 +9,7 @@ #include #include +#include using namespace glm; using namespace wheels; @@ -24,13 +25,6 @@ ComputePass::Shader shaderDefinitionCallback(Allocator &alloc) }; } -struct PcBlock -{ - ivec2 res{}; - vec2 invRes{}; - int32_t gatherRadius{1}; -}; - } // namespace void DepthOfFieldDilate::init(ScopedScratch scopeAlloc) @@ -122,7 +116,7 @@ DepthOfFieldDilate::Output DepthOfFieldDilate::record( std::ceil(DepthOfField::sMaxFgCoCFactor)), 1); - const PcBlock pcBlock{ + const DilatePC pcBlock{ .res = ivec2(inputExtent.width, inputExtent.height), .invRes = 1.f / vec2(inputExtent.width, inputExtent.height), .gatherRadius = gatherRadius, diff --git a/src/render/dof/DepthOfFieldGather.cpp b/src/render/dof/DepthOfFieldGather.cpp index d4190708..121fb714 100644 --- a/src/render/dof/DepthOfFieldGather.cpp +++ b/src/render/dof/DepthOfFieldGather.cpp @@ -6,6 +6,7 @@ #include "utils/Utils.hpp" #include +#include using namespace glm; using namespace wheels; @@ -13,13 +14,6 @@ using namespace wheels; namespace { -struct PCBlock -{ - ivec2 halfResolution{}; - vec2 invHalfResolution{}; - uint frameIndex{0}; -}; - ComputePass::Shader backgroundDefinitionCallback(Allocator &alloc) { const size_t len = 32; @@ -152,7 +146,7 @@ DepthOfFieldGather::Output DepthOfFieldGather::record( PROFILER_GPU_SCOPE(cb, debugString); - const PCBlock pcBlock{ + const GatherPC pcBlock{ .halfResolution = ivec2{ asserted_cast(renderExtent.width), diff --git a/src/render/dof/DepthOfFieldReduce.cpp b/src/render/dof/DepthOfFieldReduce.cpp index 6ff62c86..52549964 100644 --- a/src/render/dof/DepthOfFieldReduce.cpp +++ b/src/render/dof/DepthOfFieldReduce.cpp @@ -6,6 +6,7 @@ #include "utils/Utils.hpp" #include +#include using namespace glm; using namespace wheels; @@ -33,13 +34,6 @@ void SpdSetup( (dispatchThreadGroupCountXY[0]) * (dispatchThreadGroupCountXY[1]); } -struct PCBlock -{ - ivec2 topMipResolution; - uint32_t numWorkGroupsPerSlice; - uint32_t mips; -}; - ComputePass::Shader shaderDefinitionCallback(Allocator &alloc) { return ComputePass::Shader{ @@ -103,7 +97,7 @@ void DepthOfFieldReduce::record( WHEELS_ASSERT(inOutRes.mipCount <= sMaxMips + 1); uvec2 dispatchThreadGroupCountXY{}; - PCBlock pcBlock{ + ReducePC pcBlock{ .topMipResolution = ivec2{ asserted_cast(inOutRes.extent.width), diff --git a/src/render/dof/DepthOfFieldSetup.cpp b/src/render/dof/DepthOfFieldSetup.cpp index da3db498..00d1ced2 100644 --- a/src/render/dof/DepthOfFieldSetup.cpp +++ b/src/render/dof/DepthOfFieldSetup.cpp @@ -9,6 +9,7 @@ #include "utils/Utils.hpp" #include +#include using namespace glm; using namespace wheels; @@ -23,13 +24,6 @@ enum BindingSet : uint32_t BindingSetCount, }; -struct PCBlock -{ - float focusDistance{0.f}; - float maxBackgroundCoC{0.f}; - float maxCoC{0.f}; -}; - ComputePass::Shader shaderDefinitionCallback(Allocator &alloc) { const size_t len = 48; @@ -173,7 +167,7 @@ DepthOfFieldSetup::Output DepthOfFieldSetup::record( (maxBgCoCInUnits / cam.sensorWidth()) * static_cast(renderExtent.width); - const PCBlock pcBlock{ + const SetupPC pcBlock{ .focusDistance = camParams.focusDistance, .maxBackgroundCoC = maxBgCoCInHalfResPixels, .maxCoC = maxBgCoCInHalfResPixels * DepthOfField::sMaxFgCoCFactor, diff --git a/src/render/rtdi/RtDiInitialReservoirs.cpp b/src/render/rtdi/RtDiInitialReservoirs.cpp index 824ed4ef..8d12ec05 100644 --- a/src/render/rtdi/RtDiInitialReservoirs.cpp +++ b/src/render/rtdi/RtDiInitialReservoirs.cpp @@ -10,6 +10,8 @@ #include "utils/Profiler.hpp" #include "utils/Utils.hpp" +#include + using namespace glm; using namespace wheels; @@ -26,11 +28,6 @@ enum BindingSet : uint32_t BindingSetCount, }; -struct PCBlock -{ - uint32_t frameIndex{0}; -}; - ComputePass::Shader shaderDefinitionCallback( Allocator &alloc, const WorldDSLayouts &worldDSLayouts) { @@ -182,7 +179,7 @@ RtDiInitialReservoirs::Output RtDiInitialReservoirs::record( const uvec3 groupCount = m_computePass.groupCount( glm::uvec3{renderExtent.width, renderExtent.height, 1u}); - const PCBlock pcBlock{ + const InitialReservoirsPC pcBlock{ .frameIndex = m_frameIndex, }; diff --git a/src/render/rtdi/RtDiSpatialReuse.cpp b/src/render/rtdi/RtDiSpatialReuse.cpp index 6ea71cf7..490d1065 100644 --- a/src/render/rtdi/RtDiSpatialReuse.cpp +++ b/src/render/rtdi/RtDiSpatialReuse.cpp @@ -10,6 +10,8 @@ #include "utils/Profiler.hpp" #include "utils/Utils.hpp" +#include + using namespace glm; using namespace wheels; @@ -26,11 +28,6 @@ enum BindingSet : uint32_t BindingSetCount, }; -struct PCBlock -{ - uint32_t frameIndex{0}; -}; - ComputePass::Shader shaderDefinitionCallback( Allocator &alloc, const WorldDSLayouts &worldDSLayouts) { @@ -192,7 +189,7 @@ RtDiSpatialReuse::Output RtDiSpatialReuse::record( const uvec3 groupCount = m_computePass.groupCount( glm::uvec3{renderExtent.width, renderExtent.height, 1u}); - const PCBlock pcBlock{ + const SpatialReusePC pcBlock{ .frameIndex = m_frameIndex, }; diff --git a/src/render/rtdi/RtDiTrace.cpp b/src/render/rtdi/RtDiTrace.cpp index 1873dc10..4ee05d7e 100644 --- a/src/render/rtdi/RtDiTrace.cpp +++ b/src/render/rtdi/RtDiTrace.cpp @@ -16,6 +16,7 @@ #include "utils/Utils.hpp" #include +#include using namespace wheels; @@ -61,20 +62,13 @@ enum class GroupIndex : uint32_t Miss, }; -struct PCBlock +struct TracePCFlags { - uint32_t drawType{0}; - uint32_t frameIndex{0}; - uint32_t flags{0}; - - struct Flags - { - bool skipHistory{false}; - bool accumulate{false}; - }; + bool skipHistory{false}; + bool accumulate{false}; }; -uint32_t pcFlags(PCBlock::Flags flags) +inline uint32_t pcFlags(TracePCFlags flags) { uint32_t ret = 0; @@ -252,17 +246,17 @@ RtDiTrace::Output RtDiTrace::record( asserted_cast(dynamicOffsets.size()), dynamicOffsets.data()); - const PCBlock pcBlock{ + const TracePC pcBlock{ .drawType = static_cast(drawType), .frameIndex = m_frameIndex, - .flags = pcFlags(PCBlock::Flags{ + .flags = pcFlags(TracePCFlags{ .skipHistory = cam.changedThisFrame() || resetAccumulation || m_accumulationDirty, .accumulate = m_accumulate, }), }; cb.pushConstants( - m_pipelineLayout, sVkShaderStageFlagsAllRt, 0, sizeof(PCBlock), + m_pipelineLayout, sVkShaderStageFlagsAllRt, 0, sizeof(pcBlock), &pcBlock); WHEELS_ASSERT(m_shaderBindingTable.deviceAddress != 0); @@ -444,22 +438,22 @@ bool RtDiTrace::compileShaders( m_raygenReflection = WHEELS_MOV(raygenResult->reflection); WHEELS_ASSERT( - sizeof(PCBlock) == m_raygenReflection->pushConstantsBytesize()); + sizeof(TracePC) == m_raygenReflection->pushConstantsBytesize()); m_rayMissReflection = WHEELS_MOV(rayMissResult->reflection); WHEELS_ASSERT( m_rayMissReflection->pushConstantsBytesize() == 0 || - sizeof(PCBlock) == m_rayMissReflection->pushConstantsBytesize()); + sizeof(TracePC) == m_rayMissReflection->pushConstantsBytesize()); m_closestHitReflection = WHEELS_MOV(closestHitResult->reflection); WHEELS_ASSERT( m_closestHitReflection->pushConstantsBytesize() == 0 || - sizeof(PCBlock) == m_closestHitReflection->pushConstantsBytesize()); + sizeof(TracePC) == m_closestHitReflection->pushConstantsBytesize()); m_anyHitReflection = WHEELS_MOV(anyHitResult->reflection); WHEELS_ASSERT( m_anyHitReflection->pushConstantsBytesize() == 0 || - sizeof(PCBlock) == m_anyHitReflection->pushConstantsBytesize()); + sizeof(TracePC) == m_anyHitReflection->pushConstantsBytesize()); m_shaderStages[static_cast(StageIndex::RayGen)] = { .stage = vk::ShaderStageFlagBits::eRaygenKHR, @@ -608,7 +602,7 @@ void RtDiTrace::createPipeline( const vk::PushConstantRange pcRange{ .stageFlags = sVkShaderStageFlagsAllRt, .offset = 0, - .size = sizeof(PCBlock), + .size = sizeof(TracePC), }; m_pipelineLayout = gDevice.logical().createPipelineLayout(vk::PipelineLayoutCreateInfo{ diff --git a/src/scene/Camera.hpp b/src/scene/Camera.hpp index cb28223a..2bc15d6c 100644 --- a/src/scene/Camera.hpp +++ b/src/scene/Camera.hpp @@ -5,6 +5,7 @@ #include "gfx/ShaderReflection.hpp" #include +#include #include #include @@ -43,29 +44,6 @@ struct CameraParameters float focalLength{0.f}; }; -struct CameraUniforms -{ - glm::mat4 worldToCamera; - glm::mat4 cameraToWorld; - glm::mat4 cameraToClip; - glm::mat4 clipToWorld; - glm::mat4 previousWorldToCamera; - glm::mat4 previousCameraToClip; - glm::vec4 eye; - glm::vec4 nearPlane; - glm::vec4 farPlane; - glm::vec4 leftPlane; - glm::vec4 rightPlane; - glm::vec4 topPlane; - glm::vec4 bottomPlane; - glm::uvec2 resolution; - glm::vec2 currentJitter; - glm::vec2 previousJitter; - float near; - float far; - float maxViewScale; -}; - struct FrustumCorners { glm::vec3 bottomLeftNear{0.f}; diff --git a/src/scene/DeferredLoadingContext.hpp b/src/scene/DeferredLoadingContext.hpp index 4cea47df..4c822829 100644 --- a/src/scene/DeferredLoadingContext.hpp +++ b/src/scene/DeferredLoadingContext.hpp @@ -148,7 +148,7 @@ class DeferredLoadingContext uint32_t loadedMeshCount{0}; uint32_t loadedImageCount{0}; uint32_t loadedMaterialCount{0}; - wheels::Array materials{gAllocators.loadingWorker}; + wheels::Array materials{gAllocators.loadingWorker}; Buffer stagingBuffer; private: diff --git a/src/scene/Fwd.hpp b/src/scene/Fwd.hpp index 326933a1..223e4568 100644 --- a/src/scene/Fwd.hpp +++ b/src/scene/Fwd.hpp @@ -13,7 +13,6 @@ class Camera; struct CameraOffset; struct CameraParameters; struct CameraTransform; -struct CameraUniforms; struct PerspectiveParameters; // DebugGeometry.hpp @@ -29,12 +28,7 @@ struct PointLights; struct SpotLight; struct SpotLights; -// Material.hpp -struct Material; -struct Texture2DSampler; - // Mesh.hpp -struct GeometryMetadata; struct MeshInfo; // Model.hpp diff --git a/src/scene/Light.hpp b/src/scene/Light.hpp index 978685e3..f9b91484 100644 --- a/src/scene/Light.hpp +++ b/src/scene/Light.hpp @@ -5,29 +5,19 @@ #include "utils/Utils.hpp" #include +#include #include #include struct DirectionalLight { - struct Parameters - { - // Use vec4 because vec3 alignment is no fun between glsl, c++ - glm::vec4 irradiance{2.f}; - glm::vec4 direction{-1.f, -1.f, -1.f, 1.f}; - } parameters; + DirectionalLightParameters parameters; - static const uint32_t sBufferByteSize = sizeof(Parameters); + static const uint32_t sBufferByteSize = sizeof(DirectionalLightParameters); [[nodiscard]] uint32_t write(RingBuffer &buffer) const; }; -struct PointLight -{ - glm::vec4 radianceAndRadius{0.f}; - glm::vec4 position{0.f}; -}; - struct PointLights { static const uint32_t sMaxCount = 1024; @@ -46,13 +36,6 @@ struct PointLights [[nodiscard]] uint32_t write(RingBuffer &buffer) const; }; -struct SpotLight -{ - glm::vec4 radianceAndAngleScale{0.f}; - glm::vec4 positionAndAngleOffset{0.f}; - glm::vec4 direction{0.f}; -}; - struct SpotLights { static const uint32_t sMaxCount = 1024; diff --git a/src/scene/Material.hpp b/src/scene/Material.hpp index 7b871421..579d706a 100644 --- a/src/scene/Material.hpp +++ b/src/scene/Material.hpp @@ -1,49 +1,6 @@ #ifndef PROSPER_SCENE_MATERIAL_HPP #define PROSPER_SCENE_MATERIAL_HPP -#include -#include - -class Texture; - -struct Texture2DSampler -{ - static constexpr uint32_t sMaxTextureIndex = 0xFF'FFFF; - static constexpr uint32_t sMaxSamplerIndex = 0xFF; - - uint32_t packed{0}; - - Texture2DSampler() noexcept = default; - Texture2DSampler(uint32_t texture, uint32_t sampler) - : packed{(sampler << 24) | texture} - { - WHEELS_ASSERT(texture < sMaxTextureIndex); - WHEELS_ASSERT(sampler < sMaxSamplerIndex); - }; - - [[nodiscard]] uint32_t texture() const { return packed & sMaxTextureIndex; } -}; -static_assert(sizeof(Texture2DSampler) == sizeof(uint32_t)); - -struct Material -{ - enum class AlphaMode : uint32_t - { - Opaque, - Mask, - Blend, - }; - - // Needs to match shader - glm::vec4 baseColorFactor{1.f}; - float metallicFactor{1.f}; - float roughnessFactor{1.f}; - float alphaCutoff{0.5f}; - AlphaMode alphaMode{AlphaMode::Opaque}; - Texture2DSampler baseColor; - Texture2DSampler metallicRoughness; - Texture2DSampler normal; - uint32_t pad{0}; -}; +#include #endif // PROSPER_SCENE_MATERIAL_HPP diff --git a/src/scene/Mesh.hpp b/src/scene/Mesh.hpp index eee3fb85..78ea76cb 100644 --- a/src/scene/Mesh.hpp +++ b/src/scene/Mesh.hpp @@ -10,27 +10,7 @@ constexpr vk::Format sVertexNormalFormat = vk::Format::eA2B10G10R10SnormPack32; constexpr vk::Format sVertexTangentFormat = vk::Format::eA2B10G10R10SnormPack32; constexpr vk::Format sVertexTexCoord0Format = vk::Format::eR16G16Sfloat; -struct GeometryMetadata -{ - uint32_t bufferIndex{0xFFFF'FFFF}; - // These offsets are into the geometry data buffers. Most are for U32/F32 - // and an offset of 0xFFFF'FFFF signals an unused attribute. - // This addresses U16 if short indices are in use. - uint32_t indicesOffset{0xFFFF'FFFF}; - uint32_t positionsOffset{0xFFFF'FFFF}; - uint32_t normalsOffset{0xFFFF'FFFF}; - uint32_t tangentsOffset{0xFFFF'FFFF}; - uint32_t texCoord0sOffset{0xFFFF'FFFF}; - uint32_t meshletsOffset{0xFFFF'FFFF}; - uint32_t meshletBoundsOffset{0xFFFF'FFFF}; - // This addresses U16 if short indices are in use. - uint32_t meshletVerticesOffset{0xFFFF'FFFF}; - // This addresses U8. - uint32_t meshletTrianglesByteOffset{0xFFFF'FFFF}; - uint32_t usesShortIndices{0}; -}; -// These are uploaded onto the gpu and tight packing is assumed -static_assert(alignof(GeometryMetadata) == sizeof(uint32_t)); +#include struct MeshInfo { diff --git a/src/scene/Model.hpp b/src/scene/Model.hpp index 592a00dd..5c49ff76 100644 --- a/src/scene/Model.hpp +++ b/src/scene/Model.hpp @@ -3,7 +3,7 @@ #include "Allocators.hpp" -#include +#include #include #include @@ -20,15 +20,9 @@ struct Model struct ModelInstance { - struct Transforms - { - glm::mat3x4 modelToWorld{1.f}; - glm::mat3x4 normalToWorld{1.f}; - }; - uint32_t id{0}; uint32_t modelIndex{0xFFFF'FFFF}; - Transforms transforms; + ModelInstanceTransforms transforms; wheels::StrSpan fullName; }; diff --git a/src/scene/Scene.hpp b/src/scene/Scene.hpp index f403622e..b840cdac 100644 --- a/src/scene/Scene.hpp +++ b/src/scene/Scene.hpp @@ -54,12 +54,6 @@ struct Scene wheels::Array modelInstances{gAllocators.world}; bool previousTransformsValid{false}; - struct DrawInstance - { - uint32_t modelInstanceIndex{0}; - uint32_t meshIndex{0xFFFF'FFFF}; - uint32_t materialIndex{0xFFFF'FFFF}; - }; uint32_t drawInstanceCount{0}; Buffer drawInstancesBuffer; vk::DescriptorSet sceneInstancesDescriptorSet; diff --git a/src/scene/World.cpp b/src/scene/World.cpp index e5bed5ad..9cc73456 100644 --- a/src/scene/World.cpp +++ b/src/scene/World.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -401,7 +402,7 @@ void World::Impl::updateScene( if (node.modelInstance.has_value()) scene.modelInstances[*node.modelInstance].transforms = - ModelInstance::Transforms{ + ModelInstanceTransforms{ .modelToWorld = modelToWorld, .normalToWorld = normalToWorld, }; @@ -463,9 +464,8 @@ void World::Impl::updateBuffers(ScopedScratch scopeAlloc) const auto &scene = currentScene(); { - Array drawInstances{ - scopeAlloc, scene.drawInstanceCount}; - Array transforms{ + Array drawInstances{scopeAlloc, scene.drawInstanceCount}; + Array transforms{ scopeAlloc, scene.modelInstances.size()}; Array scales{scopeAlloc, scene.modelInstances.size()}; @@ -498,7 +498,7 @@ void World::Impl::updateBuffers(ScopedScratch scopeAlloc) for (const auto &model : m_data.m_models[instance.modelIndex].subModels) { - drawInstances.push_back(Scene::DrawInstance{ + drawInstances.push_back(DrawInstance{ .modelInstanceIndex = mi, .meshIndex = model.meshIndex, .materialIndex = model.materialIndex, @@ -517,7 +517,7 @@ void World::Impl::updateBuffers(ScopedScratch scopeAlloc) memcpy( scene.drawInstancesBuffer.mapped, drawInstances.data(), - sizeof(Scene::DrawInstance) * drawInstances.size()); + sizeof(DrawInstance) * drawInstances.size()); } updateTlasInstances(scopeAlloc.child_scope(), scene); @@ -636,9 +636,9 @@ bool World::Impl::buildNextBlas(ScopedScratch scopeAlloc, vk::CommandBuffer cb) .indexData = dataBuffer.deviceAddress + indicesOffset, }; - const Material &material = m_data.m_materials[info.materialIndex]; + const MaterialData &material = m_data.m_materials[info.materialIndex]; const vk::GeometryFlagsKHR geomFlags = - material.alphaMode == Material::AlphaMode::Opaque + material.alphaMode == AlphaMode_Opaque ? vk::GeometryFlagBitsKHR::eOpaque : vk::GeometryFlagsKHR{}; geometries.push_back(vk::AccelerationStructureGeometryKHR{ @@ -1100,7 +1100,7 @@ Span World::models() const return m_impl->m_data.m_models; } -Span World::materials() const +Span World::materials() const { WHEELS_ASSERT(m_initialized); return m_impl->m_data.m_materials; diff --git a/src/scene/World.hpp b/src/scene/World.hpp index b8ca4084..ed66902b 100644 --- a/src/scene/World.hpp +++ b/src/scene/World.hpp @@ -6,6 +6,7 @@ #include "utils/Fwd.hpp" #include +#include #include #include #include @@ -65,7 +66,7 @@ class World [[nodiscard]] const WorldDescriptorSets &descriptorSets() const; [[nodiscard]] const WorldByteOffsets &byteOffsets() const; [[nodiscard]] wheels::Span models() const; - [[nodiscard]] wheels::Span materials() const; + [[nodiscard]] wheels::Span materials() const; [[nodiscard]] wheels::Span meshInfos() const; [[nodiscard]] SkyboxResources &skyboxResources(); diff --git a/src/scene/WorldData.cpp b/src/scene/WorldData.cpp index 86fb0da4..a037119f 100644 --- a/src/scene/WorldData.cpp +++ b/src/scene/WorldData.cpp @@ -8,6 +8,7 @@ #include #include #include +#include using namespace glm; using namespace wheels; @@ -561,8 +562,8 @@ void WorldData::uploadMaterialDatas(uint32_t nextFrame) m_deferredLoadingContext->materialsGeneration) return; - Material *mapped = - static_cast(m_materialsBuffers[nextFrame].mapped); + MaterialData *mapped = + static_cast(m_materialsBuffers[nextFrame].mapped); memcpy( mapped, m_materials.data(), m_materials.size() * sizeof(m_materials[0])); @@ -743,12 +744,12 @@ void WorldData::loadMaterials( const cgltf_data &gltfData, const Array &texture2DSamplers) { - m_materials.push_back(Material{}); + m_materials.push_back(MaterialData{}); for (const cgltf_material &material : Span{gltfData.materials, gltfData.materials_count}) { - Material mat; + MaterialData mat; if (material.has_pbr_metallic_roughness == 0) { LOG_WARN( @@ -783,18 +784,19 @@ void WorldData::loadMaterials( const cgltf_pbr_metallic_roughness &pbrParams = material.pbr_metallic_roughness; - mat.baseColor = + mat.baseColorTextureSampler = getTexture2dSampler(pbrParams.base_color_texture, "base color"); mat.baseColorFactor = make_vec4(&pbrParams.base_color_factor[0]); - mat.metallicRoughness = getTexture2dSampler( + mat.metallicRoughnessTextureSampler = getTexture2dSampler( pbrParams.metallic_roughness_texture, "metallic roughness"); mat.metallicFactor = pbrParams.metallic_factor; mat.roughnessFactor = pbrParams.roughness_factor; - mat.normal = getTexture2dSampler(material.normal_texture, "normal"); + mat.normalTextureSampler = + getTexture2dSampler(material.normal_texture, "normal"); if (material.alpha_mode == cgltf_alpha_mode_mask) - mat.alphaMode = Material::AlphaMode::Mask; + mat.alphaMode = AlphaMode_Mask; else if (material.alpha_mode == cgltf_alpha_mode_blend) - mat.alphaMode = Material::AlphaMode::Blend; + mat.alphaMode = AlphaMode_Blend; else if (material.alpha_mode != cgltf_alpha_mode_opaque) LOG_ERR( "%s: Unsupported alpha mode '%s'", material.name, @@ -803,7 +805,7 @@ void WorldData::loadMaterials( // Copy the alpha mode of the real material because that's used to // set opaque flag in rt - m_materials.push_back(Material{ + m_materials.push_back(MaterialData{ .alphaMode = mat.alphaMode, }); WHEELS_ASSERT(m_deferredLoadingContext.has_value()); @@ -1548,8 +1550,8 @@ void WorldData::createBuffers() scene.drawInstancesBuffer = gDevice.createBuffer(BufferCreateInfo{ .desc = BufferDescription{ - .byteSize = sizeof(Scene::DrawInstance) * - scene.drawInstanceCount, + .byteSize = + sizeof(DrawInstance) * scene.drawInstanceCount, .usage = vk::BufferUsageFlagBits::eStorageBuffer, .properties = vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent, @@ -1561,7 +1563,7 @@ void WorldData::createBuffers() // Make room for one extra frame because the previous frame's transforms // are read for motion const uint32_t bufferSize = asserted_cast( - ((maxModelInstanceTransforms * sizeof(ModelInstance::Transforms) + + ((maxModelInstanceTransforms * sizeof(ModelInstanceTransforms) + static_cast(RingBuffer::sAlignment)) + (maxModelInstanceTransforms * sizeof(float) + static_cast(RingBuffer::sAlignment))) * @@ -1874,7 +1876,7 @@ void WorldData::createDescriptorSets( DescriptorInfo{vk::DescriptorBufferInfo{ .buffer = ringBuffers.lightDataRing->buffer(), .offset = 0, - .range = sizeof(DirectionalLight::Parameters), + .range = sizeof(DirectionalLightParameters), }}, DescriptorInfo{vk::DescriptorBufferInfo{ .buffer = ringBuffers.lightDataRing->buffer(), @@ -1911,12 +1913,12 @@ void WorldData::createDescriptorSets( DescriptorInfo{vk::DescriptorBufferInfo{ .buffer = m_modelInstanceTransformsRing.buffer(), .range = scene.modelInstances.size() * - sizeof(ModelInstance::Transforms), + sizeof(ModelInstanceTransforms), }}, DescriptorInfo{vk::DescriptorBufferInfo{ .buffer = m_modelInstanceTransformsRing.buffer(), .range = scene.modelInstances.size() * - sizeof(ModelInstance::Transforms), + sizeof(ModelInstanceTransforms), }}, DescriptorInfo{vk::DescriptorBufferInfo{ .buffer = m_modelInstanceTransformsRing.buffer(), @@ -2186,11 +2188,12 @@ bool WorldData::updateMaterials() bool materialsUpdated = false; for (size_t i = ctx.loadedMaterialCount; i < ctx.materials.size(); ++i) { - const Material &material = ctx.materials[i]; - const uint32_t baseColorIndex = material.baseColor.texture(); - const uint32_t normalIndex = material.normal.texture(); + const MaterialData &material = ctx.materials[i]; + const uint32_t baseColorIndex = + material.baseColorTextureSampler.texture(); + const uint32_t normalIndex = material.normalTextureSampler.texture(); const uint32_t metallicRoughnessIndex = - material.metallicRoughness.texture(); + material.metallicRoughnessTextureSampler.texture(); // Inclusive as 0 is our default, starting gltf indices from 1 if (baseColorIndex <= ctx.loadedImageCount && normalIndex <= ctx.loadedImageCount && diff --git a/src/scene/WorldData.hpp b/src/scene/WorldData.hpp index c512dfe1..bc576ac0 100644 --- a/src/scene/WorldData.hpp +++ b/src/scene/WorldData.hpp @@ -93,7 +93,7 @@ class WorldData wheels::Array m_cameras{gAllocators.general}; // True if any instance of the camera is dynamic wheels::Array m_cameraDynamic{gAllocators.general}; - wheels::Array m_materials{gAllocators.general}; + wheels::Array m_materials{gAllocators.general}; wheels::Array m_geometryBuffers{gAllocators.general}; wheels::Array m_geometryMetadatas{gAllocators.general}; wheels::Array m_meshInfos{gAllocators.general};