From 6417ab940d53343efa4d7d3b6f36cf65ab876b10 Mon Sep 17 00:00:00 2001 From: Dynamitos Date: Mon, 16 Sep 2024 13:00:53 +0200 Subject: [PATCH] Descriptors now work in metal hopefully --- .vscode/settings.json | 2 +- external/vcpkg | 2 +- res/shaders/ComputeFrustums.slang | 4 +- res/shaders/Debug.slang | 2 +- res/shaders/DepthCullingTask.slang | 10 +- res/shaders/DepthMipGen.slang | 4 +- res/shaders/LightCulling.slang | 2 +- res/shaders/Skybox.slang | 4 +- res/shaders/TextPass.slang | 2 +- res/shaders/WaterMesh.slang | 4 +- res/shaders/WaterPass.slang | 2 +- res/shaders/WaterTask.slang | 2 +- res/shaders/lib/Bounding.slang | 2 +- res/shaders/lib/Common.slang | 18 +- res/shaders/lib/DispatchParams.slang | 9 +- res/shaders/lib/MaterialParameter.slang | 9 +- res/shaders/lib/Scene.slang | 20 +- res/shaders/raytracing/RayGen.slang | 6 +- src/Editor/main.cpp | 20 +- src/Engine/Graphics/Command.h | 8 +- src/Engine/Graphics/Descriptor.h | 5 +- src/Engine/Graphics/Enums.h | 4 +- src/Engine/Graphics/Initializer.h | 3 +- src/Engine/Graphics/Metal/Buffer.mm | 15 +- src/Engine/Graphics/Metal/Command.h | 13 +- src/Engine/Graphics/Metal/Command.mm | 53 ++- src/Engine/Graphics/Metal/Descriptor.h | 9 +- src/Engine/Graphics/Metal/Descriptor.mm | 104 ++++-- src/Engine/Graphics/Metal/Graphics.mm | 8 +- src/Engine/Graphics/Metal/PipelineCache.mm | 324 ++++++++---------- src/Engine/Graphics/Metal/Query.h | 8 +- src/Engine/Graphics/Metal/Query.mm | 42 +-- src/Engine/Graphics/Metal/Shader.mm | 6 +- src/Engine/Graphics/Metal/Texture.mm | 5 +- src/Engine/Graphics/Metal/Window.mm | 4 + .../Graphics/RenderPass/WaterRenderer.cpp | 14 +- src/Engine/Graphics/StaticMeshVertexData.cpp | 15 +- src/Engine/Graphics/VertexData.cpp | 2 +- src/Engine/Graphics/Vulkan/Command.h | 8 +- src/Engine/Graphics/Vulkan/Descriptor.cpp | 106 +----- src/Engine/Graphics/Vulkan/Descriptor.h | 5 +- src/Engine/Graphics/slang-compile.cpp | 13 +- src/Engine/Material/Material.cpp | 7 +- src/Engine/System/ComponentSystem.h | 4 +- src/Engine/Window/GameView.cpp | 2 +- 45 files changed, 435 insertions(+), 476 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 38e5436..1263a01 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -23,6 +23,6 @@ "lldb.showDisassembly": "auto", "lldb.dereferencePointers": true, "lldb.consoleMode": "commands", - "cmake.generator": "Ninja", + "cmake.generator": "Xcode", "editor.tabSize": 4 } \ No newline at end of file diff --git a/external/vcpkg b/external/vcpkg index 4002e5f..509f71e 160000 --- a/external/vcpkg +++ b/external/vcpkg @@ -1 +1 @@ -Subproject commit 4002e5f3598cc0d216c395bc0db3de44a2d2ec9b +Subproject commit 509f71e53f45e46c13fa7935d2f6a45803580c07 diff --git a/res/shaders/ComputeFrustums.slang b/res/shaders/ComputeFrustums.slang index e6ad1f3..45272f0 100644 --- a/res/shaders/ComputeFrustums.slang +++ b/res/shaders/ComputeFrustums.slang @@ -25,9 +25,9 @@ void computeFrustums(ComputeShaderInput in) frustum.sides[1] = computePlane(origin, corners[1], corners[3]); frustum.sides[2] = computePlane(origin, corners[0], corners[1]); frustum.sides[3] = computePlane(origin, corners[3], corners[2]); - if(in.dispatchThreadID.x < pDispatchParams.numThreads.x && in.dispatchThreadID.y < pDispatchParams.numThreads.y) + if(in.dispatchThreadID.x < pDispatchParams.p.numThreads.x && in.dispatchThreadID.y < pDispatchParams.p.numThreads.y) { - uint index = in.dispatchThreadID.x + (in.dispatchThreadID.y * pDispatchParams.numThreads.x); + uint index = in.dispatchThreadID.x + (in.dispatchThreadID.y * pDispatchParams.p.numThreads.x); pDispatchParams.frustums[index] = frustum; } } diff --git a/res/shaders/Debug.slang b/res/shaders/Debug.slang index ddf6581..a391df9 100644 --- a/res/shaders/Debug.slang +++ b/res/shaders/Debug.slang @@ -17,7 +17,7 @@ Params vertexMain( DebugVertex vert ){ Params result; - result.pos = mul(pViewParams.projectionMatrix, mul(pViewParams.viewMatrix, float4(vert.position, 1))); + result.pos = mul(pViewParams.c.projectionMatrix, mul(pViewParams.c.viewMatrix, float4(vert.position, 1))); result.color = vert.color; return result; } diff --git a/res/shaders/DepthCullingTask.slang b/res/shaders/DepthCullingTask.slang index eadb0b3..f2dbd02 100644 --- a/res/shaders/DepthCullingTask.slang +++ b/res/shaders/DepthCullingTask.slang @@ -30,7 +30,7 @@ groupshared bool meshVisible; ParameterBlock pDepthAttachment; bool isBoxVisible(AABB bounding) { - int2 mipDimensions = int2(int(pViewParams.screenDimensions.x), int(pViewParams.screenDimensions.y)); + int2 mipDimensions = int2(int(pViewParams.c.screenDimensions.x), int(pViewParams.c.screenDimensions.y)); // now we calculate what mip level we need to only sample up to 4 texels covering the entire meshlet int2 screenCornerMin = mipDimensions; int2 screenCornerMax = int2(0, 0); @@ -91,14 +91,14 @@ void taskMain( p.instanceId = pOffsets.instanceOffset + groupID; p.meshletOffset = mesh.meshletOffset; p.cullingOffset = pScene.cullingOffsets[p.instanceId]; - modelViewProjection = mul(mul(pViewParams.projectionMatrix, pViewParams.viewMatrix), instance.transformMatrix); + modelViewProjection = mul(mul(pViewParams.c.projectionMatrix, pViewParams.c.viewMatrix), instance.transformMatrix); float3 origin = viewToModel(instance.inverseTransformMatrix, float4(0, 0, 0, 1)).xyz; const float offset = 0.0f; float3 corners[4] = { screenToModel(instance.inverseTransformMatrix, float4(offset, offset, -1.0f, 1.0f)).xyz, - screenToModel(instance.inverseTransformMatrix, float4(pViewParams.screenDimensions.x - offset, offset, -1.0f, 1.0f)).xyz, - screenToModel(instance.inverseTransformMatrix, float4(offset, pViewParams.screenDimensions.y - offset, -1.0f, 1.0f)).xyz, - screenToModel(instance.inverseTransformMatrix, float4(pViewParams.screenDimensions - float2(offset, offset), -1.0f, 1.0f)).xyz + screenToModel(instance.inverseTransformMatrix, float4(pViewParams.c.screenDimensions.x - offset, offset, -1.0f, 1.0f)).xyz, + screenToModel(instance.inverseTransformMatrix, float4(offset, pViewParams.c.screenDimensions.y - offset, -1.0f, 1.0f)).xyz, + screenToModel(instance.inverseTransformMatrix, float4(pViewParams.c.screenDimensions - float2(offset, offset), -1.0f, 1.0f)).xyz }; viewFrustum.sides[0] = computePlane(origin, corners[2], corners[0]); viewFrustum.sides[1] = computePlane(origin, corners[1], corners[3]); diff --git a/res/shaders/DepthMipGen.slang b/res/shaders/DepthMipGen.slang index 15bd015..a5d09a8 100644 --- a/res/shaders/DepthMipGen.slang +++ b/res/shaders/DepthMipGen.slang @@ -47,9 +47,9 @@ void reduceLevel( void sourceCopy( uint2 dispatchID: SV_DispatchThreadID ) { - if(dispatchID.x >= pViewParams.screenDimensions.x || dispatchID.y >= pViewParams.screenDimensions.y) + if(dispatchID.x >= pViewParams.c.screenDimensions.x || dispatchID.y >= pViewParams.c.screenDimensions.y) { return; } - pDepthAttachment.buffer[dispatchID.x + (dispatchID.y * uint(pViewParams.screenDimensions.x))] = pDepthAttachment.texture[uint2(dispatchID)]; + pDepthAttachment.buffer[dispatchID.x + (dispatchID.y * uint(pViewParams.c.screenDimensions.x))] = pDepthAttachment.texture[uint2(dispatchID)]; } diff --git a/res/shaders/LightCulling.slang b/res/shaders/LightCulling.slang index 541847d..cd17db0 100644 --- a/res/shaders/LightCulling.slang +++ b/res/shaders/LightCulling.slang @@ -72,7 +72,7 @@ void cullLights(ComputeShaderInput in) uMaxDepth = 0x0; oLightCount = 0; tLightCount = 0; - groupFrustum = pDispatchParams.frustums[in.groupID.x + (in.groupID.y * pDispatchParams.numThreadGroups.x)]; + groupFrustum = pDispatchParams.frustums[in.groupID.x + (in.groupID.y * pDispatchParams.p.numThreadGroups.x)]; } GroupMemoryBarrierWithGroupSync(); diff --git a/res/shaders/Skybox.slang b/res/shaders/Skybox.slang index f0e2aea..892831a 100644 --- a/res/shaders/Skybox.slang +++ b/res/shaders/Skybox.slang @@ -73,10 +73,10 @@ VertexShaderOutput vertexMain( }; VertexShaderOutput output; - float3x3 cameraRotation = float3x3(pViewParams.viewMatrix); + float3x3 cameraRotation = float3x3(pViewParams.c.viewMatrix); float4 worldPos = float4(mul(cameraRotation, vertices[vertexIndex]), 1.0f); //clip(dot(worldPos, clipPlane)); - output.clipPos = mul(pViewParams.projectionMatrix, worldPos); + output.clipPos = mul(pViewParams.c.projectionMatrix, worldPos); output.texCoords = normalize(vertices[vertexIndex]); return output; } diff --git a/res/shaders/TextPass.slang b/res/shaders/TextPass.slang index 17463b0..30ab8dc 100644 --- a/res/shaders/TextPass.slang +++ b/res/shaders/TextPass.slang @@ -66,7 +66,7 @@ VertexOutput vertexMain(VertexInput input) float4 vertex = coordinates[input.vertexId]; VertexOutput output; output.texCoords = vertex.zw; - output.position = mul(pViewParams.projectionMatrix, float4(vertex.xy, 0, 1)); + output.position = mul(pViewParams.c.projectionMatrix, float4(vertex.xy, 0, 1)); output.glyphIndex = pRender.instances[input.instanceId].glyphIndex; return output; } diff --git a/res/shaders/WaterMesh.slang b/res/shaders/WaterMesh.slang index d9ccb93..69fda0b 100644 --- a/res/shaders/WaterMesh.slang +++ b/res/shaders/WaterMesh.slang @@ -34,7 +34,7 @@ void meshMain( out vertices WaterVertex vertices[TILE_VERTS], out indices uint3 indices[TILE_PRIMS], ) { - float4x4 vp = mul(pViewParams.projectionMatrix, pViewParams.viewMatrix); + float4x4 vp = mul(pViewParams.c.projectionMatrix, pViewParams.c.viewMatrix); SetMeshOutputCounts(TILE_VERTS, TILE_PRIMS); for(uint i = threadID; i < TILE_PRIMS; i += MESH_GROUP_SIZE) @@ -48,7 +48,7 @@ void meshMain( float3 worldPos = params.offset + objectPos * params.extent + float3(groupID.x * params.extent, 0, groupID.y * params.extent); float lodDisplacement = 0; - float3 camPos = pViewParams.cameraPos_WS.xyz; + float3 camPos = pViewParams.c.cameraPos_WS.xyz; float cameraDistance = distance(worldPos, camPos); float threshold = 0; if(params.numMeshes == 3) diff --git a/res/shaders/WaterPass.slang b/res/shaders/WaterPass.slang index 2057498..549de04 100644 --- a/res/shaders/WaterPass.slang +++ b/res/shaders/WaterPass.slang @@ -23,7 +23,7 @@ float Beckmann(float ndoth, float roughness) { [shader("pixel")] float4 fragmentMain(WaterVertex vert) : SV_TARGET { float3 lightDir = -normalize(pWaterMaterial.sunDirection); - float3 viewDir = normalize(pViewParams.cameraPos_WS.xyz - vert.position_WS); + float3 viewDir = normalize(pViewParams.c.cameraPos_WS.xyz - vert.position_WS); float3 halfwayDir = normalize(lightDir + viewDir); float depth = vert.depth; float LdotH = clamp(dot(lightDir, halfwayDir), 0, 1); diff --git a/res/shaders/WaterTask.slang b/res/shaders/WaterTask.slang index f8d85a0..6726bb4 100644 --- a/res/shaders/WaterTask.slang +++ b/res/shaders/WaterTask.slang @@ -15,7 +15,7 @@ void taskMain( bounding.minCorner = float3(tile.location.x, tile.height, tile.location.y) * tile.extent; bounding.maxCorner = float3(tile.location.x + 1, tile.height, tile.location.y + 1) * tile.extent; float3 median = (bounding.minCorner + bounding.maxCorner) / 2; - float distance = distance(median, pViewParams.cameraPos_WS.xyz); + float distance = distance(median, pViewParams.c.cameraPos_WS.xyz); float tileDistance = distance / tile.extent; uint numMeshes = groupID.y + 1; diff --git a/res/shaders/lib/Bounding.slang b/res/shaders/lib/Bounding.slang index b849cc3..0d831b8 100644 --- a/res/shaders/lib/Bounding.slang +++ b/res/shaders/lib/Bounding.slang @@ -67,7 +67,7 @@ struct AABB { float4 clipCorner = mul(mvp, corners[i]); float4 screenCorner = clipToScreen(clipCorner); - int2 screenCoords = int2(clamp(int(screenCorner.x), 0, int(pViewParams.screenDimensions.x)), clamp(int(screenCorner.y), 0, int(pViewParams.screenDimensions.y))); + int2 screenCoords = int2(clamp(int(screenCorner.x), 0, int(pViewParams.c.screenDimensions.x)), clamp(int(screenCorner.y), 0, int(pViewParams.c.screenDimensions.y))); screenCornerMin = int2(min(screenCornerMin.x, screenCoords.x), min(screenCornerMin.y, screenCoords.y)); screenCornerMax = int2(max(screenCornerMax.x, screenCoords.x), max(screenCornerMax.y, screenCoords.y)); maxDepth = max(maxDepth, screenCorner.z); diff --git a/res/shaders/lib/Common.slang b/res/shaders/lib/Common.slang index 2b046e5..4994e6a 100644 --- a/res/shaders/lib/Common.slang +++ b/res/shaders/lib/Common.slang @@ -12,9 +12,13 @@ struct ViewParameter float4x4 inverseProjection; float4 cameraPos_WS; float2 screenDimensions; -} -layout(set=0) -ParameterBlock pViewParams; +}; +struct ViewParamWrapper +{ + ParameterBlock c; +}; +layout(set = 0) +ParameterBlock pViewParams; float4 worldToModel(float4x4 inverseTransform, float4 world) { @@ -27,7 +31,7 @@ float4 worldToModel(float4x4 inverseTransform, float4 world) float4 viewToWorld(float4 view) { - float4 world = mul(pViewParams.inverseViewMatrix, view); + float4 world = mul(pViewParams.c.inverseViewMatrix, view); world = world / world.w; @@ -43,7 +47,7 @@ float4 viewToModel(float4x4 inverseTransform, float4 view) float4 clipToView(float4 clip) { - float4 view = mul(pViewParams.inverseProjection, clip); + float4 view = mul(pViewParams.c.inverseProjection, clip); view = view / view.w; @@ -59,7 +63,7 @@ float4 clipToWorld(float4 clip) float4 screenToView(float4 screen) { - float2 texCoord = screen.xy / pViewParams.screenDimensions; + float2 texCoord = screen.xy / pViewParams.c.screenDimensions; // Convert to clip space float4 clip = float4( float2( texCoord.x, 1.0f-texCoord.y ) * 2.0f - 1.0f, screen.z, screen.w); @@ -88,7 +92,7 @@ float4 clipToScreen(float4 clip) float oz = 1; float pz = 0 - 1; float zf = pz * ndc.z + oz; - return float4(float2(texCoords.x, 1 - texCoords.y) * pViewParams.screenDimensions, zf, 1.0f); + return float4(float2(texCoords.x, 1 - texCoords.y) * pViewParams.c.screenDimensions, zf, 1.0f); } struct Plane diff --git a/res/shaders/lib/DispatchParams.slang b/res/shaders/lib/DispatchParams.slang index e3a00a0..66923ea 100644 --- a/res/shaders/lib/DispatchParams.slang +++ b/res/shaders/lib/DispatchParams.slang @@ -6,6 +6,11 @@ struct DispatchParams uint pad0; uint3 numThreads; uint pad1; - RWStructuredBuffer frustums; +}; + +struct DispatchParamWrapper +{ + ParameterBlock p; + RWStructuredBuffer frustums; } -ParameterBlock pDispatchParams; \ No newline at end of file +ParameterBlock pDispatchParams; \ No newline at end of file diff --git a/res/shaders/lib/MaterialParameter.slang b/res/shaders/lib/MaterialParameter.slang index 658cdec..ff2e79d 100644 --- a/res/shaders/lib/MaterialParameter.slang +++ b/res/shaders/lib/MaterialParameter.slang @@ -21,7 +21,6 @@ struct FragmentParameter { float4 position_CS : SV_Position; #ifndef POS_ONLY - float3 cameraPos_WS: POSITION0; float3 normal_WS : NORMAL0; float3 tangent_WS : TANGENT0; float3 biTangent_WS : TANGENT1; @@ -52,7 +51,7 @@ struct FragmentParameter float3x3 tbn = float3x3(normalize(tangent_WS), normalize(biTangent_WS), normalize(normal_WS)); result.tbn = tbn; result.position_TS = mul(tbn, position_WS); - result.viewDir_TS = mul(tbn, normalize(cameraPos_WS - position_WS)); + result.viewDir_TS = mul(tbn, normalize(pViewParams.c.cameraPos_WS.xyz - position_WS)); result.normal_TS = mul(tbn, normal_WS); return result; } @@ -67,7 +66,6 @@ struct FragmentParameter FragmentParameter result; result.position_CS = f0.position_CS * barycentricCoords.x + f1.position_CS * barycentricCoords.y + f2.position_CS * barycentricCoords.z; #ifndef POS_ONLY - result.cameraPos_WS = f0.cameraPos_WS * barycentricCoords.x + f1.cameraPos_WS * barycentricCoords.y + f2.cameraPos_WS * barycentricCoords.z; result.normal_WS = f0.normal_WS * barycentricCoords.x + f1.normal_WS * barycentricCoords.y + f2.normal_WS * barycentricCoords.z; result.tangent_WS = f0.tangent_WS * barycentricCoords.x + f1.tangent_WS * barycentricCoords.y + f2.tangent_WS * barycentricCoords.z; result.biTangent_WS = f0.biTangent_WS * barycentricCoords.x + f1.biTangent_WS * barycentricCoords.y + f2.biTangent_WS * barycentricCoords.z; @@ -104,8 +102,8 @@ struct VertexAttributes { float4 modelPos = float4(position_MS, 1); float4 worldPos = mul(transformMatrix, modelPos); - float4 viewPos = mul(pViewParams.viewMatrix, worldPos); - float4 clipPos = mul(pViewParams.projectionMatrix, viewPos); + float4 viewPos = mul(pViewParams.c.viewMatrix, worldPos); + float4 clipPos = mul(pViewParams.c.projectionMatrix, viewPos); FragmentParameter result; result.position_CS = clipPos; #ifndef POS_ONLY @@ -113,7 +111,6 @@ struct VertexAttributes float3 T = mul(normalMatrix, tangent_MS); float3 N = mul(normalMatrix, normal_MS); float3 B = mul(normalMatrix, biTangent_MS); - result.cameraPos_WS = pViewParams.cameraPos_WS.xyz; result.normal_WS = N; result.tangent_WS = T; result.biTangent_WS = B; diff --git a/res/shaders/lib/Scene.slang b/res/shaders/lib/Scene.slang index 4eefe2a..09bb9de 100644 --- a/res/shaders/lib/Scene.slang +++ b/res/shaders/lib/Scene.slang @@ -20,8 +20,8 @@ struct MeshData uint32_t numIndices; }; -static const uint32_t MAX_VERTICES = 256; -static const uint32_t MAX_PRIMITIVES = 256; +static const uint32_t MAX_VERTICES = 64; +static const uint32_t MAX_PRIMITIVES = 126; static const uint32_t MAX_MESHLETS_PER_INSTANCE = 2048; struct InstanceData @@ -39,19 +39,19 @@ struct MeshletCullingInfo } }; -struct DrawCallOffsets +cbuffer DrawCallOffsets { uint instanceOffset; uint textureOffset; uint samplerOffset; uint floatOffset; -}; -#ifdef RAY_TRACING -layout(shaderRecordEXT) -#else -layout(push_constant) -#endif -ConstantBuffer pOffsets; +} pOffsets; +//#ifdef RAY_TRACING +//layout(shaderRecordEXT) +//#else +//layout(push_constant) +//#endif +//ConstantBuffer pOffsets; struct Scene { diff --git a/res/shaders/raytracing/RayGen.slang b/res/shaders/raytracing/RayGen.slang index ea07ab6..b570e97 100644 --- a/res/shaders/raytracing/RayGen.slang +++ b/res/shaders/raytracing/RayGen.slang @@ -10,11 +10,11 @@ void raygen() const float2 pixelCenter = float2(LaunchID.xy) + float2(0.5, 0.5); const float2 inUV = pixelCenter / float2(LaunchSize.xy); float2 d = float2(inUV.x, 1 - inUV.y) * 2.0 - 1.0; - float4 target = mul(pViewParams.inverseProjection, float4(d.x, d.y, 1, 1)); + float4 target = mul(pViewParams.c.inverseProjection, float4(d.x, d.y, 1, 1)); RayDesc rayDesc; - rayDesc.Origin = mul(pViewParams.inverseViewMatrix, float4(0, 0, 0, 1)).xyz; - rayDesc.Direction = mul(pViewParams.inverseViewMatrix, float4(normalize(target.xyz), 0)).xyz; + rayDesc.Origin = mul(pViewParams.c.inverseViewMatrix, float4(0, 0, 0, 1)).xyz; + rayDesc.Direction = mul(pViewParams.c.inverseViewMatrix, float4(normalize(target.xyz), 0)).xyz; rayDesc.TMin = 0.001; rayDesc.TMax = 10000.0; diff --git a/src/Editor/main.cpp b/src/Editor/main.cpp index b3a676e..d5c1b8a 100644 --- a/src/Editor/main.cpp +++ b/src/Editor/main.cpp @@ -11,8 +11,6 @@ #include "Graphics/Vulkan/Graphics.h" #endif #include "Graphics/StaticMeshVertexData.h" -#include "Graphics/Vulkan/Buffer.h" -#include "Graphics/Vulkan/Graphics.h" #include "Window/PlayView.h" #include "Window/WindowManager.h" #include @@ -60,22 +58,22 @@ int main() { //AssetImporter::importMesh(MeshImportArgs{ // .filePath = sourcePath / "import/models/cube.fbx", //}); - AssetImporter::importMesh(MeshImportArgs{ - .filePath = sourcePath / "import/models/culling.fbx", - }); + //AssetImporter::importMesh(MeshImportArgs{ + // .filePath = sourcePath / "import/models/culling.fbx", + //}); AssetImporter::importTexture(TextureImportArgs{ .filePath = sourcePath / "import/textures/skyboxsun5deg_tn.jpg", .type = TextureImportType::TEXTURE_CUBEMAP, }); - //AssetImporter::importMesh(MeshImportArgs{ - // .filePath = sourcePath / "import/models/ship.fbx", - // .importPath = "ship", - //}); AssetImporter::importMesh(MeshImportArgs{ - .filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.glb", - .importPath = "Whitechapel", + .filePath = sourcePath / "import/models/ship.fbx", + .importPath = "ship", }); //AssetImporter::importMesh(MeshImportArgs{ + // .filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.glb", + // .importPath = "Whitechapel", + //}); + //AssetImporter::importMesh(MeshImportArgs{ // .filePath = sourcePath / "import/models/city-suburbs/source/city-suburbs.obj", // .importPath = "suburbs", //}); diff --git a/src/Engine/Graphics/Command.h b/src/Engine/Graphics/Command.h index 693012f..631a77d 100644 --- a/src/Engine/Graphics/Command.h +++ b/src/Engine/Graphics/Command.h @@ -13,8 +13,8 @@ class RenderCommand { virtual void setViewport(Gfx::PViewport viewport) = 0; virtual void bindPipeline(Gfx::PGraphicsPipeline pipeline) = 0; virtual void bindPipeline(Gfx::PRayTracingPipeline pipeline) = 0; - virtual void bindDescriptor(Gfx::PDescriptorSet set, Array dynamicOffsets = {}) = 0; - virtual void bindDescriptor(const Array& sets, Array dynamicOffsets = {}) = 0; + virtual void bindDescriptor(Gfx::PDescriptorSet set) = 0; + virtual void bindDescriptor(const Array& sets) = 0; virtual void bindVertexBuffer(const Array& buffer) = 0; virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) = 0; virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) = 0; @@ -31,8 +31,8 @@ class ComputeCommand { ComputeCommand(); virtual ~ComputeCommand(); virtual void bindPipeline(Gfx::PComputePipeline pipeline) = 0; - virtual void bindDescriptor(Gfx::PDescriptorSet set, Array dynamicOffsets = {}) = 0; - virtual void bindDescriptor(const Array& sets, Array dynamicOffsets = {}) = 0; + virtual void bindDescriptor(Gfx::PDescriptorSet set) = 0; + virtual void bindDescriptor(const Array& sets) = 0; virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) = 0; virtual void dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) = 0; std::string name; diff --git a/src/Engine/Graphics/Descriptor.h b/src/Engine/Graphics/Descriptor.h index e7d0289..bf704ab 100644 --- a/src/Engine/Graphics/Descriptor.h +++ b/src/Engine/Graphics/Descriptor.h @@ -64,11 +64,8 @@ class DescriptorSet { virtual void updateBuffer(uint32 binding, PUniformBuffer uniformBuffer) = 0; virtual void updateBuffer(uint32 binding, PIndexBuffer indexBuffer) = 0; virtual void updateBuffer(uint32 binding, PShaderBuffer shaderBuffer) = 0; - virtual void updateBuffer(uint32_t binding, uint32 index, Gfx::PShaderBuffer uniformBuffer) = 0; virtual void updateSampler(uint32 binding, PSampler sampler) = 0; - virtual void updateSampler(uint32_t binding, uint32 dstArrayIndex, Gfx::PSampler samplerState) = 0; virtual void updateTexture(uint32 binding, PTexture texture, PSampler samplerState = nullptr) = 0; - virtual void updateTexture(uint32 binding, uint32 dstArrayIndex, PTexture texture) = 0; virtual void updateTextureArray(uint32_t binding, Array texture) = 0; virtual void updateSamplerArray(uint32_t binding, Array samplers) = 0; virtual void updateAccelerationStructure(uint32 binding, PTopLevelAS as) = 0; @@ -96,6 +93,8 @@ class PipelineLayout { constexpr uint32 findParameter(const std::string& param) const { return parameterMapping[param]; } void addMapping(std::string name, uint32 index); constexpr std::string getName() const { return name; }; + constexpr bool hasPushConstants() const { return !pushConstants.empty(); } + constexpr uint64 getPushConstantsSize() const { return pushConstants[0].size; } protected: uint32 layoutHash = 0; diff --git a/src/Engine/Graphics/Enums.h b/src/Engine/Graphics/Enums.h index b900614..7b3e5ad 100644 --- a/src/Engine/Graphics/Enums.h +++ b/src/Engine/Graphics/Enums.h @@ -159,8 +159,8 @@ static constexpr bool useAsyncCompute = false; static constexpr bool useMeshShading = true; static constexpr uint32 numFramesBuffered = 3; -static constexpr uint32 numVerticesPerMeshlet = 256; -static constexpr uint32 numPrimitivesPerMeshlet = 256; +static constexpr uint32 numVerticesPerMeshlet = 64; +static constexpr uint32 numPrimitivesPerMeshlet = 126; double getCurrentFrameDelta(); double getCurrentFrameTime(); uint32 getCurrentFrameIndex(); diff --git a/src/Engine/Graphics/Initializer.h b/src/Engine/Graphics/Initializer.h index 4277b8e..12cb13c 100644 --- a/src/Engine/Graphics/Initializer.h +++ b/src/Engine/Graphics/Initializer.h @@ -68,7 +68,7 @@ struct SamplerCreateInfo { Gfx::SeSamplerAddressMode addressModeW = Gfx::SE_SAMPLER_ADDRESS_MODE_REPEAT; float mipLodBias = 0.0f; uint32 anisotropyEnable = 0; - float maxAnisotropy = 0.0f; + float maxAnisotropy = 1.0f; uint32 compareEnable = 0; Gfx::SeCompareOp compareOp = Gfx::SE_COMPARE_OP_NEVER; float minLod = 0.0f; @@ -138,6 +138,7 @@ struct SePushConstantRange { SeShaderStageFlags stageFlags; uint32 offset; uint32 size; + std::string name; }; struct RasterizationState { uint32 depthClampEnable = 0; diff --git a/src/Engine/Graphics/Metal/Buffer.mm b/src/Engine/Graphics/Metal/Buffer.mm index 5af3bc8..012ce0f 100644 --- a/src/Engine/Graphics/Metal/Buffer.mm +++ b/src/Engine/Graphics/Metal/Buffer.mm @@ -42,8 +42,11 @@ void BufferAllocation::unmap() {} Buffer::Buffer(PGraphics graphics, uint64 size, Gfx::SeBufferUsageFlags usage, Gfx::QueueType queueType, bool dynamic, std::string name, bool createCleared, uint32 clearValue) : graphics(graphics), currentBuffer(0), dynamic(dynamic), createCleared(createCleared), name(name), clearValue(clearValue) { - buffers.add(nullptr); - createBuffer(size, 0); + if(size > 0) + { + buffers.add(nullptr); + createBuffer(size, 0); + } } Buffer::~Buffer() { @@ -101,10 +104,16 @@ void Buffer::copyBuffer(uint64 src, uint64 dest) { std::memcpy(buffers[dest]->map(), buffers[src]->map(), buffers[src]->size); } -void Buffer::transferOwnership(Gfx::QueueType newOwner) { getAlloc()->transferOwnership(newOwner); } +void Buffer::transferOwnership(Gfx::QueueType newOwner) { + if(buffers.size() == 0) + return; + getAlloc()->transferOwnership(newOwner); +} void Buffer::pipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) { + if(buffers.size() == 0) + return; getAlloc()->pipelineBarrier(srcAccess, srcStage, dstAccess, dstStage); } diff --git a/src/Engine/Graphics/Metal/Command.h b/src/Engine/Graphics/Metal/Command.h index 5e62f56..80a57b9 100644 --- a/src/Engine/Graphics/Metal/Command.h +++ b/src/Engine/Graphics/Metal/Command.h @@ -57,8 +57,8 @@ class RenderCommand : public Gfx::RenderCommand { virtual void setViewport(Gfx::PViewport viewport) override; virtual void bindPipeline(Gfx::PGraphicsPipeline pipeline) override; virtual void bindPipeline(Gfx::PRayTracingPipeline pipeline) override; - virtual void bindDescriptor(Gfx::PDescriptorSet descriptorSet, Array dynamicOffsets) override; - virtual void bindDescriptor(const Array& descriptorSets, Array dynamicOffsets) override; + virtual void bindDescriptor(Gfx::PDescriptorSet descriptorSet) override; + virtual void bindDescriptor(const Array& descriptorSets) override; virtual void bindVertexBuffer(const Array& buffers) override; virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) override; virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) override; @@ -71,9 +71,8 @@ class RenderCommand : public Gfx::RenderCommand { private: PGraphicsPipeline boundPipeline; PIndexBuffer boundIndexBuffer; - MTL::ArgumentEncoder* argumentEncoder; - MTL::Buffer* argumentBuffer; MTL::RenderCommandEncoder* encoder; + MTL::Buffer* constantsBuffer; std::string name; }; DEFINE_REF(RenderCommand) @@ -83,8 +82,8 @@ class ComputeCommand : public Gfx::ComputeCommand { virtual ~ComputeCommand(); void end(); virtual void bindPipeline(Gfx::PComputePipeline pipeline) override; - virtual void bindDescriptor(Gfx::PDescriptorSet set, Array dynamicOffsets) override; - virtual void bindDescriptor(const Array& sets, Array dynamicOffsets) override; + virtual void bindDescriptor(Gfx::PDescriptorSet set) override; + virtual void bindDescriptor(const Array& sets) override; virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) override; virtual void dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) override; @@ -92,7 +91,7 @@ class ComputeCommand : public Gfx::ComputeCommand { PComputePipeline boundPipeline; MTL::CommandBuffer* commandBuffer; MTL::ComputeCommandEncoder* encoder; - MTL::Buffer* argumentBuffer; + MTL::Buffer* constantsBuffer; std::string name; }; DEFINE_REF(ComputeCommand) diff --git a/src/Engine/Graphics/Metal/Command.mm b/src/Engine/Graphics/Metal/Command.mm index 80fcd08..562dc09 100644 --- a/src/Engine/Graphics/Metal/Command.mm +++ b/src/Engine/Graphics/Metal/Command.mm @@ -3,6 +3,7 @@ #include "Containers/Array.h" #include "Descriptor.h" #include "Enums.h" +#include "Graphics/Graphics.h" #include "Graphics/Command.h" #include "Graphics/Enums.h" #include "Graphics/Graphics.h" @@ -74,35 +75,51 @@ void RenderCommand::setViewport(Gfx::PViewport viewport) { void RenderCommand::bindPipeline(Gfx::PGraphicsPipeline pipeline) { boundPipeline = pipeline.cast(); encoder->setRenderPipelineState(boundPipeline->getHandle()); + if(boundPipeline->getPipelineLayout()->hasPushConstants()) { + constantsBuffer = boundPipeline->graphics->getDevice()->newBuffer(boundPipeline->getPipelineLayout()->getPushConstantsSize(), 0); + } } void RenderCommand::bindPipeline(Gfx::PRayTracingPipeline pipeline) {} -void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet, Array offsets) { +void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet) { auto metalSet = descriptorSet.cast(); metalSet->bind(); + uint32 descriptorIndex = boundPipeline->getPipelineLayout()->findParameter(metalSet->getLayout()->getName()); + encoder->setVertexBuffer(metalSet->getArgumentBuffer(), 0, descriptorIndex); + encoder->setFragmentBuffer(metalSet->getArgumentBuffer(), 0, descriptorIndex); + encoder->setObjectBuffer(metalSet->getArgumentBuffer(), 0, descriptorIndex); + encoder->setMeshBuffer(metalSet->getArgumentBuffer(), 0, descriptorIndex); } -void RenderCommand::bindDescriptor(const Array& descriptorSets, Array offsets) { +void RenderCommand::bindDescriptor(const Array& descriptorSets) { for (auto set : descriptorSets) { - bindDescriptor(set, offsets); + bindDescriptor(set); } } void RenderCommand::bindVertexBuffer(const Array& buffers) { uint32 i = 0; for (auto buffer : buffers) { - encoder->setVertexBuffer(buffer.cast()->getHandle(), 0, METAL_VERTEXBUFFER_OFFSET + i++); + encoder->setVertexBuffer(buffer.cast()->getHandle(), 0, buffer.cast()->getVertexSize(), i++); } } void RenderCommand::bindIndexBuffer(Gfx::PIndexBuffer gfxIndexBuffer) { boundIndexBuffer = gfxIndexBuffer.cast(); } void RenderCommand::pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) { + std::memcpy(constantsBuffer->contents(), data, size); + uint pushIndex = boundPipeline->getPipelineLayout()->findParameter("pOffsets"); if (stage & Gfx::SE_SHADER_STAGE_VERTEX_BIT) { - encoder->setVertexBytes((char*)data + offset, size, 0); + encoder->setVertexBuffer(constantsBuffer, 0, pushIndex); // TODO: hardcoded } if (stage & Gfx::SE_SHADER_STAGE_FRAGMENT_BIT) { - encoder->setFragmentBytes((char*)data + offset, size, 0); + encoder->setFragmentBuffer(constantsBuffer, 0, pushIndex); // TODO: hardcoded + } + if (stage & Gfx::SE_SHADER_STAGE_TASK_BIT_EXT) { + encoder->setObjectBuffer(constantsBuffer, 0, pushIndex); // TODO: hardcoded + } + if (stage & Gfx::SE_SHADER_STAGE_MESH_BIT_EXT) { + encoder->setMeshBuffer(constantsBuffer, 0, pushIndex); // TODO: hardcoded } } @@ -116,11 +133,6 @@ void RenderCommand::drawIndexed(uint32 indexCount, uint32 instanceCount, int32 f } void RenderCommand::drawMesh(uint32 groupX, uint32 groupY, uint32 groupZ) { - // TODO: - std::cout << "Draw" << std::endl; - encoder->setFragmentBuffer(argumentBuffer, 0, 2); - encoder->setMeshBuffer(argumentBuffer, 0, 2); - encoder->setObjectBuffer(argumentBuffer, 0, 2); encoder->drawMeshThreadgroups(MTL::Size(groupX, groupY, groupZ), MTL::Size(128, 1, 1), MTL::Size(32, 1, 1)); } @@ -143,29 +155,32 @@ void ComputeCommand::end() { void ComputeCommand::bindPipeline(Gfx::PComputePipeline pipeline) { boundPipeline = pipeline.cast(); encoder->setComputePipelineState(boundPipeline->getHandle()); - argumentBuffer = boundPipeline->graphics->getDevice()->newBuffer( - sizeof(uint64) * (boundPipeline->getPipelineLayout()->getLayouts().size() + 1), MTL::ResourceStorageModeShared); - argumentBuffer->setLabel(NS::String::string(pipeline->getPipelineLayout()->getName().c_str(), NS::ASCIIStringEncoding)); + if(boundPipeline->getPipelineLayout()->hasPushConstants()) { + constantsBuffer = boundPipeline->graphics->getDevice()->newBuffer(boundPipeline->getPipelineLayout()->getPushConstantsSize(), 0); + } } -void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet set, Array offsets) { +void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet set) { auto metalSet = set.cast(); metalSet->bind(); + uint32 descriptorIndex = boundPipeline->getPipelineLayout()->findParameter(metalSet->getLayout()->getName()); + encoder->setBuffer(metalSet->getArgumentBuffer(), 0, descriptorIndex); } -void ComputeCommand::bindDescriptor(const Array& sets, Array offsets) { +void ComputeCommand::bindDescriptor(const Array& sets) { for (auto& set : sets) { - bindDescriptor(set, offsets); + bindDescriptor(set); } } void ComputeCommand::pushConstants(Gfx::SeShaderStageFlags, uint32 offset, uint32 size, const void* data) { - encoder->setBytes((char*)data + offset, size, 0); + std::memcpy(constantsBuffer->contents(), data, size); + uint pushIndex = boundPipeline->getPipelineLayout()->findParameter("pMipParam"); + encoder->setBuffer(constantsBuffer, 0, pushIndex); // TODO: hardcoded } void ComputeCommand::dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) { // TODO - encoder->setBuffer(argumentBuffer, 0, 2); encoder->dispatchThreadgroups(MTL::Size(threadX, threadY, threadZ), MTL::Size(32, 32, 1)); } diff --git a/src/Engine/Graphics/Metal/Descriptor.h b/src/Engine/Graphics/Metal/Descriptor.h index 0cf4b1f..7bae82b 100644 --- a/src/Engine/Graphics/Metal/Descriptor.h +++ b/src/Engine/Graphics/Metal/Descriptor.h @@ -50,21 +50,20 @@ class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource { virtual void updateBuffer(uint32 binding, Gfx::PUniformBuffer uniformBuffer) override; virtual void updateBuffer(uint32 binding, Gfx::PShaderBuffer uniformBuffer) override; virtual void updateBuffer(uint32 binding, Gfx::PIndexBuffer uniformBuffer) override; - virtual void updateBuffer(uint32 binding, uint32 index, Gfx::PShaderBuffer uniformBuffer) override; virtual void updateSampler(uint32 binding, Gfx::PSampler samplerState) override; - virtual void updateSampler(uint32 binding, uint32 dstArrayIndex, Gfx::PSampler samplerState) override; virtual void updateTexture(uint32 binding, Gfx::PTexture texture, Gfx::PSampler sampler = nullptr) override; - virtual void updateTexture(uint32 binding, uint32 dstArrayIndex, Gfx::PTexture texture) override; virtual void updateTextureArray(uint32 binding, Array texture) override; virtual void updateSamplerArray(uint32 binding, Array samplers) override; virtual void updateAccelerationStructure(uint32 binding, Gfx::PTopLevelAS as) override; - constexpr const Array>& getBoundResources() const { return boundResources; } + constexpr const Array& getBoundResources() const { return boundResources; } + + MTL::Buffer* getArgumentBuffer() const { return argumentBuffer; } private: PGraphics graphics; PDescriptorPool owner; - Array> boundResources; + Array boundResources; MTL::ArgumentEncoder* encoder; MTL::Buffer* argumentBuffer = nullptr; }; diff --git a/src/Engine/Graphics/Metal/Descriptor.mm b/src/Engine/Graphics/Metal/Descriptor.mm index 4a8a358..114339e 100644 --- a/src/Engine/Graphics/Metal/Descriptor.mm +++ b/src/Engine/Graphics/Metal/Descriptor.mm @@ -4,6 +4,7 @@ #include "Foundation/NSArray.hpp" #include "Foundation/NSObject.hpp" #include "Graphics/Descriptor.h" +#include "Graphics/Enums.h" #include "Graphics/Initializer.h" #include "Graphics/Metal/Resources.h" #include "Graphics/Metal/Shader.h" @@ -15,8 +16,10 @@ #include "Metal/MTLTexture.hpp" #include "Texture.h" #include +#include #include #include +#include using namespace Seele; using namespace Seele::Metal; @@ -29,19 +32,68 @@ void DescriptorLayout::create() { pool = new DescriptorPool(graphics, this); hash = CRC::Calculate(descriptorBindings.data(), sizeof(Gfx::DescriptorBinding) * descriptorBindings.size(), CRC::CRC_32()); MTL::ArgumentDescriptor** objects = new MTL::ArgumentDescriptor*[descriptorBindings.size()]; - for(uint32 i = 0; i < descriptorBindings.size(); ++i) { + for (uint32 i = 0; i < descriptorBindings.size(); ++i) { objects[i] = MTL::ArgumentDescriptor::alloc()->init(); objects[i]->setIndex(i); objects[i]->setAccess(cast(descriptorBindings[i].access)); objects[i]->setArrayLength(descriptorBindings[i].descriptorCount); - objects[i]->setDataType(MTL::DataTypeStruct); + MTL::DataType dataType; + switch (descriptorBindings[i].descriptorType) { + case Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE: + case Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE: + case Gfx::SE_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: + case Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: + case Gfx::SE_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: + case Gfx::SE_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: + dataType = MTL::DataTypeTexture; + break; + case Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER: + case Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER: + case Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: + case Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: + case Gfx::SE_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK: + dataType = MTL::DataTypePointer; + break; + case Gfx::SE_DESCRIPTOR_TYPE_SAMPLER: + dataType = MTL::DataTypeSampler; + break; + case Gfx::SE_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR: + dataType = MTL::DataTypeInstanceAccelerationStructure; + break; + default: + throw new std::logic_error("unknown descriptor type"); + } + objects[i]->setDataType(dataType); + MTL::TextureType textureType; + switch (descriptorBindings[i].textureType) { + case Gfx::SE_IMAGE_VIEW_TYPE_1D: + textureType = MTL::TextureType1D; + break; + case Gfx::SE_IMAGE_VIEW_TYPE_2D: + textureType = MTL::TextureType2D; + break; + case Gfx::SE_IMAGE_VIEW_TYPE_3D: + textureType = MTL::TextureType3D; + break; + case Gfx::SE_IMAGE_VIEW_TYPE_CUBE: + textureType = MTL::TextureTypeCube; + break; + case Gfx::SE_IMAGE_VIEW_TYPE_1D_ARRAY: + textureType = MTL::TextureType1DArray; + break; + case Gfx::SE_IMAGE_VIEW_TYPE_2D_ARRAY: + textureType = MTL::TextureType2DArray; + break; + case Gfx::SE_IMAGE_VIEW_TYPE_CUBE_ARRAY: + textureType = MTL::TextureTypeCubeArray; + break; + } + objects[i]->setTextureType(textureType); } arguments = NS::Array::array((NS::Object**)objects, descriptorBindings.size()); } -MTL::ArgumentEncoder* DescriptorLayout::createEncoder() { - return graphics->getDevice()->newArgumentEncoder(arguments); -} +MTL::ArgumentEncoder* DescriptorLayout::createEncoder() { return graphics->getDevice()->newArgumentEncoder(arguments); } DescriptorPool::DescriptorPool(PGraphics graphics, PDescriptorLayout layout) : graphics(graphics), layout(layout) {} @@ -65,10 +117,10 @@ void DescriptorPool::reset() {} DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner) : Gfx::DescriptorSet(owner->getLayout()), CommandBoundResource(graphics), graphics(graphics), owner(owner) { + encoder = owner->getLayout()->createEncoder(); + argumentBuffer = graphics->getDevice()->newBuffer(encoder->encodedLength(), 0); + encoder->setArgumentBuffer(argumentBuffer, 0); boundResources.resize(owner->getLayout()->getBindings().size()); - for (uint32 i = 0; i < boundResources.size(); ++i) { - boundResources[i].resize(owner->getLayout()->getBindings()[i].descriptorCount); - } } DescriptorSet::~DescriptorSet() {} @@ -76,38 +128,40 @@ DescriptorSet::~DescriptorSet() {} void DescriptorSet::writeChanges() {} void DescriptorSet::updateBuffer(uint32 binding, Gfx::PUniformBuffer uniformBuffer) { - boundResources[binding][0] = uniformBuffer.cast()->getHandle(); + PUniformBuffer buffer = uniformBuffer.cast(); + encoder->setBuffer(buffer->getHandle(), 0, binding); + boundResources[binding] = buffer->getHandle(); } void DescriptorSet::updateBuffer(uint32 binding, Gfx::PShaderBuffer uniformBuffer) { - boundResources[binding][0] = uniformBuffer.cast()->getHandle(); + PShaderBuffer buffer = uniformBuffer.cast(); + encoder->setBuffer(buffer->getHandle(), 0, binding); + boundResources[binding] = buffer->getHandle(); } void DescriptorSet::updateBuffer(uint32 binding, Gfx::PIndexBuffer uniformBuffer) { - boundResources[binding][0] = uniformBuffer.cast()->getHandle(); -} - -void DescriptorSet::updateBuffer(uint32 binding, uint32 index, Gfx::PShaderBuffer uniformBuffer) { - boundResources[binding][0] = uniformBuffer.cast()->getHandle(); + PIndexBuffer buffer = uniformBuffer.cast(); + encoder->setBuffer(buffer->getHandle(), 0, binding); + boundResources[binding] = buffer->getHandle(); } void DescriptorSet::updateSampler(uint32 binding, Gfx::PSampler samplerState) { - boundResources[binding][0] = nullptr; // Samplers are not resources?????? + PSampler sampler = samplerState.cast(); + encoder->setSamplerState(sampler->getHandle(), binding); + boundResources[binding] = nullptr; // Samplers are not resources?????? } -void DescriptorSet::updateSampler(uint32 binding, uint32 dstArrayIndex, Gfx::PSampler samplerState) { - boundResources[binding][dstArrayIndex] = nullptr; +void DescriptorSet::updateTexture(uint32 binding, Gfx::PTexture texture, Gfx::PSampler sampler) { + PTextureBase base = texture.cast(); + encoder->setTexture(base->getHandle()->texture, binding); + boundResources[binding] = base->getHandle()->texture; } -void DescriptorSet::updateTexture(uint32 binding, Gfx::PTexture texture, Gfx::PSampler sampler) {} +void DescriptorSet::updateTextureArray(uint32 binding, Array texture) { assert(false && "TODO"); } -void DescriptorSet::updateTexture(uint32 binding, uint32 dstArrayIndex, Gfx::PTexture texture) {} +void DescriptorSet::updateSamplerArray(uint32 binding, Array samplers) { assert(false && "TODO"); } -void DescriptorSet::updateTextureArray(uint32 binding, Array texture) {} - -void DescriptorSet::updateSamplerArray(uint32 binding, Array samplers) {} - -void DescriptorSet::updateAccelerationStructure(uint32 binding, Gfx::PTopLevelAS as) {} +void DescriptorSet::updateAccelerationStructure(uint32 binding, Gfx::PTopLevelAS as) { assert(false && "TODO"); } PipelineLayout::PipelineLayout(PGraphics graphics, const std::string& name, Gfx::PPipelineLayout baseLayout) : Gfx::PipelineLayout(name, baseLayout), graphics(graphics) {} diff --git a/src/Engine/Graphics/Metal/Graphics.mm b/src/Engine/Graphics/Metal/Graphics.mm index e2bff65..d664204 100644 --- a/src/Engine/Graphics/Metal/Graphics.mm +++ b/src/Engine/Graphics/Metal/Graphics.mm @@ -121,7 +121,7 @@ Gfx::PGraphicsPipeline Graphics::createGraphicsPipeline(Gfx::MeshPipelineCreateI Gfx::PComputePipeline Graphics::createComputePipeline(Gfx::ComputePipelineCreateInfo createInfo) { return cache->createPipeline(std::move(createInfo)); } -Gfx::PRayTracingPipeline Graphics::createRayTracingPipeline(Gfx::RayTracingPipelineCreateInfo createInfo) { return nullptr; } +Gfx::PRayTracingPipeline Graphics::createRayTracingPipeline(Gfx::RayTracingPipelineCreateInfo) { return nullptr; } Gfx::OSampler Graphics::createSampler(const SamplerCreateInfo& createInfo) { return new Sampler(this, createInfo); } @@ -143,16 +143,16 @@ Gfx::OTimestampQuery Graphics::createTimestampQuery(uint64 numTimestamps, const return new TimestampQuery(this, name, numTimestamps); } -void Graphics::resolveTexture(Gfx::PTexture source, Gfx::PTexture destination) {} +void Graphics::resolveTexture(Gfx::PTexture, Gfx::PTexture) {} -void Graphics::copyTexture(Gfx::PTexture src, Gfx::PTexture dst) {} +void Graphics::copyTexture(Gfx::PTexture, Gfx::PTexture) {} // Ray Tracing Gfx::OBottomLevelAS Graphics::createBottomLevelAccelerationStructure(const Gfx::BottomLevelASCreateInfo& createInfo) { return nullptr; } Gfx::OTopLevelAS Graphics::createTopLevelAccelerationStructure(const Gfx::TopLevelASCreateInfo& createInfo) { return nullptr; } -void Graphics::buildBottomLevelAccelerationStructures(Array data) {} +void Graphics::buildBottomLevelAccelerationStructures(Array) {} Gfx::ORayGenShader Graphics::createRayGenShader(const ShaderCreateInfo& createInfo) { ORayGenShader shader = new RayGenShader(this); diff --git a/src/Engine/Graphics/Metal/PipelineCache.mm b/src/Engine/Graphics/Metal/PipelineCache.mm index 10505c2..7bdc3d2 100644 --- a/src/Engine/Graphics/Metal/PipelineCache.mm +++ b/src/Engine/Graphics/Metal/PipelineCache.mm @@ -14,205 +14,171 @@ #include "Metal/MTLVertexDescriptor.hpp" #include "Shader.h" #include "Texture.h" +#include #include using namespace Seele; using namespace Seele::Metal; -PipelineCache::PipelineCache(PGraphics graphics, const std::string &name) - : graphics(graphics), cacheFile(name) {} +PipelineCache::PipelineCache(PGraphics graphics, const std::string& name) : graphics(graphics), cacheFile(name) {} PipelineCache::~PipelineCache() {} -PGraphicsPipeline -PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo createInfo) { - PPipelineLayout layout = - Gfx::PPipelineLayout(createInfo.pipelineLayout).cast(); +PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo createInfo) { + PPipelineLayout layout = Gfx::PPipelineLayout(createInfo.pipelineLayout).cast(); - MTL::RenderPipelineDescriptor *pipelineDescriptor = - MTL::RenderPipelineDescriptor::alloc()->init(); + MTL::RenderPipelineDescriptor* pipelineDescriptor = MTL::RenderPipelineDescriptor::alloc()->init(); - MTL::VertexDescriptor *vertexDescriptor = - pipelineDescriptor->vertexDescriptor()->init(); - MTL::VertexAttributeDescriptorArray *attributes = - vertexDescriptor->attributes()->init(); - if (createInfo.vertexInput != nullptr) { - const auto &vertexInfo = createInfo.vertexInput->getInfo(); - for (size_t attr = 0; attr < vertexInfo.attributes.size(); ++attr) { - MTL::VertexAttributeDescriptor *attribute = - attributes->object(attr + METAL_VERTEXATTRIBUTE_OFFSET)->init(); - attribute->setBufferIndex(vertexInfo.attributes[attr].binding + - METAL_VERTEXBUFFER_OFFSET); - switch (vertexInfo.attributes[attr].format) { - case Gfx::SE_FORMAT_R32G32B32_SFLOAT: - attribute->setFormat(MTL::VertexFormatFloat3); + MTL::VertexDescriptor* vertexDescriptor = pipelineDescriptor->vertexDescriptor()->init(); + MTL::VertexAttributeDescriptorArray* attributes = vertexDescriptor->attributes()->init(); + if (createInfo.vertexInput != nullptr) { + const auto& vertexInfo = createInfo.vertexInput->getInfo(); + for (size_t attr = 0; attr < vertexInfo.attributes.size(); ++attr) { + MTL::VertexAttributeDescriptor* attribute = attributes->object(attr)->init(); + attribute->setBufferIndex(vertexInfo.attributes[attr].binding); + switch (vertexInfo.attributes[attr].format) { + case Gfx::SE_FORMAT_R32G32B32_SFLOAT: + attribute->setFormat(MTL::VertexFormatFloat3); + break; + default: + throw std::logic_error("TODO"); + } + attribute->setOffset(vertexInfo.attributes[attr].offset); + } + + MTL::VertexBufferLayoutDescriptorArray* bufferLayout = vertexDescriptor->layouts()->init(); + for (size_t binding = 0; binding < vertexInfo.bindings.size(); ++binding) { + MTL::VertexBufferLayoutDescriptor* buffer = bufferLayout->object(binding)->init(); + buffer->setStride(vertexInfo.bindings[binding].stride); + buffer->setStepRate(1); + switch (vertexInfo.bindings[binding].inputRate) { + case Gfx::SE_VERTEX_INPUT_RATE_VERTEX: + buffer->setStepFunction(MTL::VertexStepFunctionPerVertex); + break; + case Gfx::SE_VERTEX_INPUT_RATE_INSTANCE: + buffer->setStepFunction(MTL::VertexStepFunctionPerInstance); + break; + } + } + } + pipelineDescriptor->setVertexDescriptor(vertexDescriptor); + + pipelineDescriptor->setVertexFunction(createInfo.vertexShader.cast()->getFunction()); + if (createInfo.fragmentShader != nullptr) { + pipelineDescriptor->setFragmentFunction(createInfo.fragmentShader.cast()->getFunction()); + } + pipelineDescriptor->setInputPrimitiveTopology(cast(createInfo.topology)); + if (createInfo.renderPass->getLayout().depthAttachment.getTexture() != nullptr) { + pipelineDescriptor->setDepthAttachmentPixelFormat( + cast(createInfo.renderPass->getLayout().depthAttachment.getTexture().cast()->getFormat())); + } + pipelineDescriptor->setAlphaToCoverageEnabled(createInfo.multisampleState.alphaCoverageEnable); + pipelineDescriptor->setAlphaToOneEnabled(createInfo.multisampleState.alphaToOneEnable); + pipelineDescriptor->setRasterSampleCount(createInfo.multisampleState.samples); + pipelineDescriptor->setRasterizationEnabled(!createInfo.rasterizationState.rasterizerDiscardEnable); + + uint32 hash = pipelineDescriptor->hash(); + + if (graphicsPipelines.contains(hash)) { + return graphicsPipelines[hash]; + } + MTL::PrimitiveType type = MTL::PrimitiveTypeTriangle; + switch (createInfo.topology) { + case Gfx::SE_PRIMITIVE_TOPOLOGY_POINT_LIST: + type = MTL::PrimitiveTypePoint; break; - default: - throw std::logic_error("TODO"); - } - attribute->setOffset(vertexInfo.attributes[attr].offset); + case Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_LIST: + type = MTL::PrimitiveTypeLine; + break; + case Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_STRIP: + type = MTL::PrimitiveTypeLineStrip; + break; + case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST: + type = MTL::PrimitiveTypeTriangle; + break; + case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP: + type = MTL::PrimitiveTypeTriangleStrip; + break; + case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN: + type = MTL::PrimitiveTypeTriangle; + break; + case Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY: + type = MTL::PrimitiveTypeLine; + break; + case Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY: + type = MTL::PrimitiveTypeLineStrip; + break; + case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY: + type = MTL::PrimitiveTypeTriangle; + break; + case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY: + type = MTL::PrimitiveTypeTriangleStrip; + break; + case Gfx::SE_PRIMITIVE_TOPOLOGY_PATCH_LIST: + type = MTL::PrimitiveTypeTriangle; + break; + } + NS::Error* error; + graphicsPipelines[hash] = new GraphicsPipeline( + graphics, type, graphics->getDevice()->newRenderPipelineState(pipelineDescriptor, &error), std::move(createInfo.pipelineLayout)); + if (error) { + std::cout << error->localizedDescription()->cString(NS::ASCIIStringEncoding) << std::endl; + assert(false); } - MTL::VertexBufferLayoutDescriptorArray *bufferLayout = - vertexDescriptor->layouts()->init(); - for (size_t binding = 0; binding < vertexInfo.bindings.size(); ++binding) { - MTL::VertexBufferLayoutDescriptor *buffer = - bufferLayout->object(binding + METAL_VERTEXBUFFER_OFFSET)->init(); - buffer->setStride(vertexInfo.bindings[binding].stride); - buffer->setStepRate(1); - switch (vertexInfo.bindings[binding].inputRate) { - case Gfx::SE_VERTEX_INPUT_RATE_VERTEX: - buffer->setStepFunction(MTL::VertexStepFunctionPerVertex); - break; - case Gfx::SE_VERTEX_INPUT_RATE_INSTANCE: - buffer->setStepFunction(MTL::VertexStepFunctionPerInstance); - break; - } + pipelineDescriptor->release(); + return graphicsPipelines[hash]; +} + +PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo createInfo) { + MTL::MeshRenderPipelineDescriptor* pipelineDescriptor = MTL::MeshRenderPipelineDescriptor::alloc()->init(); + + pipelineDescriptor->setMeshFunction(createInfo.meshShader.cast()->getFunction()); + if (createInfo.taskShader != nullptr) { + pipelineDescriptor->setObjectFunction(createInfo.taskShader.cast()->getFunction()); } - } - pipelineDescriptor->setVertexDescriptor(vertexDescriptor); + if (createInfo.fragmentShader != nullptr) { + pipelineDescriptor->setFragmentFunction(createInfo.fragmentShader.cast()->getFunction()); + } + if (createInfo.renderPass->getLayout().depthAttachment.getTexture() != nullptr) { + pipelineDescriptor->setDepthAttachmentPixelFormat( + cast(createInfo.renderPass->getLayout().depthAttachment.getTexture().cast()->getFormat())); + } + pipelineDescriptor->setAlphaToCoverageEnabled(createInfo.multisampleState.alphaCoverageEnable); + pipelineDescriptor->setAlphaToOneEnabled(createInfo.multisampleState.alphaToOneEnable); + pipelineDescriptor->setRasterSampleCount(createInfo.multisampleState.samples); + pipelineDescriptor->setRasterizationEnabled(!createInfo.rasterizationState.rasterizerDiscardEnable); - pipelineDescriptor->setVertexFunction( - createInfo.vertexShader.cast()->getFunction()); - if (createInfo.fragmentShader != nullptr) { - pipelineDescriptor->setFragmentFunction( - createInfo.fragmentShader.cast()->getFunction()); - } - pipelineDescriptor->setInputPrimitiveTopology(cast(createInfo.topology)); - if (createInfo.renderPass->getLayout().depthAttachment.getTexture() != - nullptr) { - pipelineDescriptor->setDepthAttachmentPixelFormat( - cast(createInfo.renderPass->getLayout() - .depthAttachment.getTexture() - .cast() - ->getFormat())); - } - pipelineDescriptor->setAlphaToCoverageEnabled( - createInfo.multisampleState.alphaCoverageEnable); - pipelineDescriptor->setAlphaToOneEnabled( - createInfo.multisampleState.alphaToOneEnable); - pipelineDescriptor->setRasterSampleCount(createInfo.multisampleState.samples); - pipelineDescriptor->setRasterizationEnabled( - !createInfo.rasterizationState.rasterizerDiscardEnable); + uint32 hash = pipelineDescriptor->hash(); - uint32 hash = pipelineDescriptor->hash(); + if (graphicsPipelines.contains(hash)) { + return graphicsPipelines[hash]; + } + NS::Error* error = nullptr; + MTL::AutoreleasedRenderPipelineReflection reflection; + graphicsPipelines[hash] = new GraphicsPipeline( + graphics, MTL::PrimitiveTypeTriangle, + graphics->getDevice()->newRenderPipelineState(pipelineDescriptor, MTL::PipelineOptionNone, &reflection, &error), + std::move(createInfo.pipelineLayout)); - if (graphicsPipelines.contains(hash)) { + if (error) { + std::cout << error->debugDescription()->utf8String() << std::endl; + } + + pipelineDescriptor->release(); return graphicsPipelines[hash]; - } - MTL::PrimitiveType type = MTL::PrimitiveTypeTriangle; - switch (createInfo.topology) { - case Gfx::SE_PRIMITIVE_TOPOLOGY_POINT_LIST: - type = MTL::PrimitiveTypePoint; - break; - case Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_LIST: - type = MTL::PrimitiveTypeLine; - break; - case Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_STRIP: - type = MTL::PrimitiveTypeLineStrip; - break; - case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST: - type = MTL::PrimitiveTypeTriangle; - break; - case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP: - type = MTL::PrimitiveTypeTriangleStrip; - break; - case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN: - type = MTL::PrimitiveTypeTriangle; - break; - case Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY: - type = MTL::PrimitiveTypeLine; - break; - case Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY: - type = MTL::PrimitiveTypeLineStrip; - break; - case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY: - type = MTL::PrimitiveTypeTriangle; - break; - case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY: - type = MTL::PrimitiveTypeTriangleStrip; - break; - case Gfx::SE_PRIMITIVE_TOPOLOGY_PATCH_LIST: - type = MTL::PrimitiveTypeTriangle; - break; - } - NS::Error *error; - graphicsPipelines[hash] = new GraphicsPipeline( - graphics, type, - graphics->getDevice()->newRenderPipelineState(pipelineDescriptor, &error), - std::move(createInfo.pipelineLayout)); - if (error) { - std::cout << error->localizedDescription()->cString(NS::ASCIIStringEncoding) - << std::endl; - assert(false); - } - - pipelineDescriptor->release(); - return graphicsPipelines[hash]; } -PGraphicsPipeline -PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo createInfo) { - MTL::MeshRenderPipelineDescriptor *pipelineDescriptor = - MTL::MeshRenderPipelineDescriptor::alloc()->init(); +PComputePipeline PipelineCache::createPipeline(Gfx::ComputePipelineCreateInfo createInfo) { + PComputeShader shader = createInfo.computeShader.cast(); + uint32 hash = shader->getShaderHash(); + if (computePipelines.contains(hash)) { + return computePipelines[hash]; + } - pipelineDescriptor->setMeshFunction( - createInfo.meshShader.cast()->getFunction()); - if (createInfo.taskShader != nullptr) { - pipelineDescriptor->setObjectFunction( - createInfo.taskShader.cast()->getFunction()); - } - if (createInfo.fragmentShader != nullptr) { - pipelineDescriptor->setFragmentFunction( - createInfo.fragmentShader.cast()->getFunction()); - } - if (createInfo.renderPass->getLayout().depthAttachment.getTexture() != - nullptr) { - pipelineDescriptor->setDepthAttachmentPixelFormat( - cast(createInfo.renderPass->getLayout() - .depthAttachment.getTexture() - .cast() - ->getFormat())); - } - pipelineDescriptor->setAlphaToCoverageEnabled( - createInfo.multisampleState.alphaCoverageEnable); - pipelineDescriptor->setAlphaToOneEnabled( - createInfo.multisampleState.alphaToOneEnable); - pipelineDescriptor->setRasterSampleCount(createInfo.multisampleState.samples); - pipelineDescriptor->setRasterizationEnabled( - !createInfo.rasterizationState.rasterizerDiscardEnable); - - uint32 hash = pipelineDescriptor->hash(); - - if (graphicsPipelines.contains(hash)) { - return graphicsPipelines[hash]; - } - NS::Error *error = nullptr; - MTL::AutoreleasedRenderPipelineReflection reflection; - graphicsPipelines[hash] = new GraphicsPipeline( - graphics, MTL::PrimitiveTypeTriangle, - graphics->getDevice()->newRenderPipelineState( - pipelineDescriptor, MTL::PipelineOptionNone, &reflection, &error), - std::move(createInfo.pipelineLayout)); - - pipelineDescriptor->release(); - return graphicsPipelines[hash]; -} - -PComputePipeline -PipelineCache::createPipeline(Gfx::ComputePipelineCreateInfo createInfo) { - PComputeShader shader = createInfo.computeShader.cast(); - uint32 hash = shader->getShaderHash(); - if (computePipelines.contains(hash)) { + NS::Error* error; + computePipelines[hash] = new ComputePipeline(graphics, graphics->getDevice()->newComputePipelineState(shader->getFunction(), &error), + std::move(createInfo.pipelineLayout)); + assert(!error); return computePipelines[hash]; - } - - NS::Error *error; - computePipelines[hash] = - new ComputePipeline(graphics, - graphics->getDevice()->newComputePipelineState( - shader->getFunction(), &error), - std::move(createInfo.pipelineLayout)); - assert(!error); - return computePipelines[hash]; } diff --git a/src/Engine/Graphics/Metal/Query.h b/src/Engine/Graphics/Metal/Query.h index f6c2f07..152aa1e 100644 --- a/src/Engine/Graphics/Metal/Query.h +++ b/src/Engine/Graphics/Metal/Query.h @@ -40,16 +40,10 @@ class TimestampQuery : public Gfx::TimestampQuery, public QueryPool { public: TimestampQuery(PGraphics graphics, const std::string& name, uint32 numTimestamps); virtual ~TimestampQuery(); - virtual void begin() override; virtual void write(Gfx::SePipelineStageFlagBits stage, const std::string& name = "") override; - virtual void end() override; - virtual Array getResults() override; + virtual Gfx::Timestamp getResult() override; private: - uint64 wrapping = 0; - uint64 lastMeasure = 0; - uint32 numTimestamps = 0; - uint32 currentTimestamp = 0; Array pendingTimestamps; }; DEFINE_REF(TimestampQuery) diff --git a/src/Engine/Graphics/Metal/Query.mm b/src/Engine/Graphics/Metal/Query.mm index 32a0fd2..a79ea1f 100644 --- a/src/Engine/Graphics/Metal/Query.mm +++ b/src/Engine/Graphics/Metal/Query.mm @@ -4,28 +4,23 @@ #include "Containers/Array.h" #include "Enums.h" #include "Graphics.h" +#include "Graphics/Query.h" #include using namespace Seele; using namespace Seele::Metal; -QueryPool::QueryPool(PGraphics graphics, const std::string& name) - : graphics(graphics) { -} +QueryPool::QueryPool(PGraphics graphics, const std::string&) : graphics(graphics) {} -QueryPool::~QueryPool() { } +QueryPool::~QueryPool() {} -void QueryPool::begin() { -} +void QueryPool::begin() {} -void QueryPool::end() { -} +void QueryPool::end() {} -void QueryPool::getQueryResults(Array& results) { -} +void QueryPool::getQueryResults(Array&) {} -OcclusionQuery::OcclusionQuery(PGraphics graphics, const std::string& name) - : QueryPool(graphics, name) {} +OcclusionQuery::OcclusionQuery(PGraphics graphics, const std::string& name) : QueryPool(graphics, name) {} OcclusionQuery::~OcclusionQuery() {} @@ -41,8 +36,7 @@ Gfx::OcclusionResult OcclusionQuery::getResults() { }; } -PipelineStatisticsQuery::PipelineStatisticsQuery(PGraphics graphics, const std::string& name) - : QueryPool(graphics, name) {} +PipelineStatisticsQuery::PipelineStatisticsQuery(PGraphics graphics, const std::string& name) : QueryPool(graphics, name) {} PipelineStatisticsQuery::~PipelineStatisticsQuery() {} @@ -66,21 +60,15 @@ Gfx::PipelineStatisticsResult PipelineStatisticsQuery::getResults() { }; } -TimestampQuery::TimestampQuery(PGraphics graphics, const std::string& name, uint32 numTimestamps) - : QueryPool(graphics, name), numTimestamps(numTimestamps) { -} +TimestampQuery::TimestampQuery(PGraphics graphics, const std::string& name, uint32) : QueryPool(graphics, name) {} TimestampQuery::~TimestampQuery() {} -void TimestampQuery::begin() { - currentTimestamp = 0; -} +void TimestampQuery::write(Gfx::SePipelineStageFlagBits, const std::string&) {} -void TimestampQuery::write(Gfx::SePipelineStageFlagBits stage, const std::string& name) { -} - -void TimestampQuery::end() { -} - -Array TimestampQuery::getResults() { +Gfx::Timestamp TimestampQuery::getResult() { + return Gfx::Timestamp{ + .name = "Test", + .time = 0, + }; } \ No newline at end of file diff --git a/src/Engine/Graphics/Metal/Shader.mm b/src/Engine/Graphics/Metal/Shader.mm index 5f989a0..37353b6 100644 --- a/src/Engine/Graphics/Metal/Shader.mm +++ b/src/Engine/Graphics/Metal/Shader.mm @@ -25,10 +25,10 @@ Shader::~Shader() { void Shader::create(const ShaderCreateInfo& createInfo) { auto [kernelBlob, entryPoint] = generateShader(createInfo); - std::ofstream test("test.metal"); - test.write((char*)kernelBlob->getBufferPointer(), kernelBlob->getBufferSize()); - test.close(); hash = CRC::Calculate(kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(), CRC::CRC_32()); + std::ofstream test("test.metal"); + test.write((const char*)kernelBlob->getBufferPointer(), kernelBlob->getBufferSize()); + test.close(); NS::Error* error; MTL::CompileOptions* options = MTL::CompileOptions::alloc()->init(); library = graphics->getDevice()->newLibrary(NS::String::string((char*)kernelBlob->getBufferPointer(), NS::ASCIIStringEncoding), options, diff --git a/src/Engine/Graphics/Metal/Texture.mm b/src/Engine/Graphics/Metal/Texture.mm index f61dd2d..1ebf4e9 100644 --- a/src/Engine/Graphics/Metal/Texture.mm +++ b/src/Engine/Graphics/Metal/Texture.mm @@ -88,7 +88,10 @@ void TextureBase::generateMipmaps() { handle->generateMipmaps(); } Texture2D::Texture2D(PGraphics graphics, const TextureCreateInfo& createInfo, MTL::Texture* existingImage) : Gfx::Texture2D(graphics->getFamilyMapping()), - TextureBase(graphics, createInfo.elements > 1 ? MTL::TextureType2DArray : MTL::TextureType2D, createInfo, existingImage) {} + TextureBase(graphics, + createInfo.elements > 1 ? (createInfo.samples > 1 ? MTL::TextureType2DMultisampleArray : MTL::TextureType2DArray) + : (createInfo.samples > 1 ? MTL::TextureType2DMultisample : MTL::TextureType2D), + createInfo, existingImage) {} Texture2D::~Texture2D() {} diff --git a/src/Engine/Graphics/Metal/Window.mm b/src/Engine/Graphics/Metal/Window.mm index 97d1bd9..269f72f 100644 --- a/src/Engine/Graphics/Metal/Window.mm +++ b/src/Engine/Graphics/Metal/Window.mm @@ -90,6 +90,10 @@ Window::Window(PGraphics graphics, const WindowCreateInfo& createInfo) : graphic metalLayer.drawableSize = CGSizeMake(createInfo.width, createInfo.height); metalWindow.contentView.layer = metalLayer; metalWindow.contentView.wantsLayer = YES; + framebufferFormat = Gfx::SE_FORMAT_R8G8B8A8_UNORM; + + drawable = (__bridge CA::MetalDrawable*)[metalLayer nextDrawable]; + createBackBuffer(); } Window::~Window() { glfwDestroyWindow(static_cast(windowHandle)); } diff --git a/src/Engine/Graphics/RenderPass/WaterRenderer.cpp b/src/Engine/Graphics/RenderPass/WaterRenderer.cpp index d89233e..6e8f33c 100644 --- a/src/Engine/Graphics/RenderPass/WaterRenderer.cpp +++ b/src/Engine/Graphics/RenderPass/WaterRenderer.cpp @@ -533,13 +533,13 @@ void WaterRenderer::updateFFTDescriptor() { computeSet = computeLayout->allocateDescriptorSet(); computeSet->updateBuffer(0, paramsBuffer); - computeSet->updateTexture(1, 0, Gfx::PTexture2D(spectrumTextures)); - computeSet->updateTexture(2, 0, Gfx::PTexture2D(initialSpectrumTextures)); - computeSet->updateTexture(3, 0, Gfx::PTexture2D(displacementTextures)); - computeSet->updateTexture(4, 0, Gfx::PTexture2D(slopeTextures)); - computeSet->updateTexture(5, 0, Gfx::PTexture2D(boyancyData)); - computeSet->updateBuffer(6, 0, spectrumBuffer); - computeSet->updateSampler(7, 0, linearRepeatSampler); + computeSet->updateTexture(1, Gfx::PTexture2D(spectrumTextures)); + computeSet->updateTexture(2, Gfx::PTexture2D(initialSpectrumTextures)); + computeSet->updateTexture(3, Gfx::PTexture2D(displacementTextures)); + computeSet->updateTexture(4, Gfx::PTexture2D(slopeTextures)); + computeSet->updateTexture(5, Gfx::PTexture2D(boyancyData)); + computeSet->updateBuffer(6, spectrumBuffer); + computeSet->updateSampler(7, linearRepeatSampler); computeSet->writeChanges(); } diff --git a/src/Engine/Graphics/StaticMeshVertexData.cpp b/src/Engine/Graphics/StaticMeshVertexData.cpp index 6538e30..3a64300 100644 --- a/src/Engine/Graphics/StaticMeshVertexData.cpp +++ b/src/Engine/Graphics/StaticMeshVertexData.cpp @@ -1,6 +1,7 @@ #include "StaticMeshVertexData.h" #include "Graphics.h" #include "Graphics/Enums.h" +#include "Graphics/VertexData.h" #include "Mesh.h" #include @@ -133,11 +134,13 @@ void StaticMeshVertexData::init(Gfx::PGraphics _graphics) { descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 2, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER}); descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 3, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER}); descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 4, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER}); - descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{ - .binding = 5, - .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, - .descriptorCount = MAX_TEXCOORDS, - }); + for(uint i = 0; i < MAX_TEXCOORDS; ++i) + { + descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{ + .binding = 5 + i, + .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, + }); + } descriptorLayout->create(); descriptorSet = descriptorLayout->allocateDescriptorSet(); } @@ -223,7 +226,7 @@ void StaticMeshVertexData::updateBuffers() { descriptorSet->updateBuffer(3, biTangents); descriptorSet->updateBuffer(4, colors); for (size_t i = 0; i < MAX_TEXCOORDS; ++i) { - descriptorSet->updateBuffer(5, i, texCoords[i]); + descriptorSet->updateBuffer(5 + i, texCoords[i]); } descriptorSet->writeChanges(); } diff --git a/src/Engine/Graphics/VertexData.cpp b/src/Engine/Graphics/VertexData.cpp index b58bbbe..8e0b254 100644 --- a/src/Engine/Graphics/VertexData.cpp +++ b/src/Engine/Graphics/VertexData.cpp @@ -274,7 +274,7 @@ MeshId VertexData::allocateVertexData(uint64 numVertices) { return res; } -void VertexData::serializeMesh(MeshId id, uint64 numVertices, ArchiveBuffer& buffer) { +void VertexData::serializeMesh(MeshId id, uint64, ArchiveBuffer& buffer) { std::unique_lock l(vertexDataLock); Array out; MeshData data = meshData[id]; diff --git a/src/Engine/Graphics/Vulkan/Command.h b/src/Engine/Graphics/Vulkan/Command.h index 100ca17..472b9dc 100644 --- a/src/Engine/Graphics/Vulkan/Command.h +++ b/src/Engine/Graphics/Vulkan/Command.h @@ -78,8 +78,8 @@ class RenderCommand : public Gfx::RenderCommand { virtual void setViewport(Gfx::PViewport viewport) override; virtual void bindPipeline(Gfx::PGraphicsPipeline pipeline) override; virtual void bindPipeline(Gfx::PRayTracingPipeline pipeline) override; - virtual void bindDescriptor(Gfx::PDescriptorSet descriptorSet, Array dynamicOffsets) override; - virtual void bindDescriptor(const Array& descriptorSets, Array dynamicOffsets) override; + virtual void bindDescriptor(Gfx::PDescriptorSet descriptorSet) override; + virtual void bindDescriptor(const Array& descriptorSets) override; virtual void bindVertexBuffer(const Array& buffers) override; virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) override; virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) override; @@ -114,8 +114,8 @@ class ComputeCommand : public Gfx::ComputeCommand { void reset(); bool isReady(); virtual void bindPipeline(Gfx::PComputePipeline pipeline) override; - virtual void bindDescriptor(Gfx::PDescriptorSet set, Array dynamicOffsets) override; - virtual void bindDescriptor(const Array& sets, Array dynamicOffsets) override; + virtual void bindDescriptor(Gfx::PDescriptorSet set) override; + virtual void bindDescriptor(const Array& sets) override; virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) override; virtual void dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) override; diff --git a/src/Engine/Graphics/Vulkan/Descriptor.cpp b/src/Engine/Graphics/Vulkan/Descriptor.cpp index f552467..f7c37a0 100644 --- a/src/Engine/Graphics/Vulkan/Descriptor.cpp +++ b/src/Engine/Graphics/Vulkan/Descriptor.cpp @@ -163,7 +163,7 @@ DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner) graphics(graphics), owner(owner) { boundResources.resize(owner->getLayout()->getBindings().size()); for (uint32 i = 0; i < boundResources.size(); ++i) { - boundResources[i].resize(owner->getLayout()->getBindings()[i].descriptorCount); + if(owner->getLayout()->getBindings()[i].descriptorCount > 1) std::abort(); } } @@ -171,7 +171,7 @@ DescriptorSet::~DescriptorSet() {} void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBuffer) { PUniformBuffer vulkanBuffer = uniformBuffer.cast(); - if (boundResources[binding][0] == vulkanBuffer->getAlloc()) { + if (boundResources[binding] == vulkanBuffer->getAlloc()) { return; } @@ -192,12 +192,12 @@ void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBu .pBufferInfo = &bufferInfos.back(), }); - boundResources[binding][0] = vulkanBuffer->getAlloc(); + boundResources[binding] = vulkanBuffer->getAlloc(); } void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PShaderBuffer shaderBuffer) { PShaderBuffer vulkanBuffer = shaderBuffer.cast(); - if (boundResources[binding][0] == vulkanBuffer->getAlloc()) { + if (boundResources[binding] == vulkanBuffer->getAlloc()) { return; } @@ -217,12 +217,12 @@ void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PShaderBuffer shaderBuff .pBufferInfo = &bufferInfos.back(), }); - boundResources[binding][0] = vulkanBuffer->getAlloc(); + boundResources[binding] = vulkanBuffer->getAlloc(); } void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PIndexBuffer indexBuffer) { PIndexBuffer vulkanBuffer = indexBuffer.cast(); - if (boundResources[binding][0] == vulkanBuffer->getAlloc()) { + if (boundResources[binding] == vulkanBuffer->getAlloc()) { return; } @@ -242,38 +242,12 @@ void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PIndexBuffer indexBuffer .pBufferInfo = &bufferInfos.back(), }); - boundResources[binding][0] = vulkanBuffer->getAlloc(); -} - -void DescriptorSet::updateBuffer(uint32_t binding, uint32 index, Gfx::PShaderBuffer shaderBuffer) { - PShaderBuffer vulkanBuffer = shaderBuffer.cast(); - if (boundResources[binding][index] == vulkanBuffer->getAlloc()) { - return; - } - - bufferInfos.add(VkDescriptorBufferInfo{ - .buffer = vulkanBuffer->getHandle(), - .offset = 0, - .range = vulkanBuffer->getSize(), - }); - - writeDescriptors.add(VkWriteDescriptorSet{ - .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, - .pNext = nullptr, - .dstSet = setHandle, - .dstBinding = binding, - .dstArrayElement = index, - .descriptorCount = 1, - .descriptorType = cast(layout->getBindings()[binding].descriptorType), - .pBufferInfo = &bufferInfos.back(), - }); - - boundResources[binding][index] = vulkanBuffer->getAlloc(); + boundResources[binding] = vulkanBuffer->getAlloc(); } void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSampler samplerState) { PSampler vulkanSampler = samplerState.cast(); - if (boundResources[binding][0] == vulkanSampler->getHandle()) { + if (boundResources[binding] == vulkanSampler->getHandle()) { return; } @@ -294,38 +268,12 @@ void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSampler samplerState) .pImageInfo = &imageInfos.back(), }); - boundResources[binding][0] = vulkanSampler->getHandle(); -} - -void DescriptorSet::updateSampler(uint32_t binding, uint32 dstArrayIndex, Gfx::PSampler samplerState) { - PSampler vulkanSampler = samplerState.cast(); - if (boundResources[binding][dstArrayIndex] == vulkanSampler->getHandle()) { - return; - } - - imageInfos.add(VkDescriptorImageInfo{ - .sampler = vulkanSampler->getSampler(), - .imageView = VK_NULL_HANDLE, - .imageLayout = VK_IMAGE_LAYOUT_UNDEFINED, - }); - - writeDescriptors.add(VkWriteDescriptorSet{ - .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, - .pNext = nullptr, - .dstSet = setHandle, - .dstBinding = binding, - .dstArrayElement = dstArrayIndex, - .descriptorCount = 1, - .descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER, - .pImageInfo = &imageInfos.back(), - }); - - boundResources[binding][dstArrayIndex] = vulkanSampler->getHandle(); + boundResources[binding] = vulkanSampler->getHandle(); } void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSampler samplerState) { TextureBase* vulkanTexture = texture.cast().getHandle(); - if (boundResources[binding][0] == vulkanTexture->getHandle()) { + if (boundResources[binding] == vulkanTexture->getHandle()) { return; } @@ -346,33 +294,7 @@ void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx:: .pImageInfo = &imageInfos.back(), }); - boundResources[binding][0] = vulkanTexture->getHandle(); -} - -void DescriptorSet::updateTexture(uint32 binding, uint32 dstArrayIndex, Gfx::PTexture texture) { - TextureBase* vulkanTexture = texture.cast().getHandle(); - if (boundResources[binding][dstArrayIndex] == vulkanTexture->getHandle()) { - return; - } - - // It is assumed that the image is in the correct layout - imageInfos.add(VkDescriptorImageInfo{ - .sampler = VK_NULL_HANDLE, - .imageView = vulkanTexture->getView(), - .imageLayout = cast(vulkanTexture->getLayout()), - }); - writeDescriptors.add(VkWriteDescriptorSet{ - .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, - .pNext = nullptr, - .dstSet = setHandle, - .dstBinding = binding, - .dstArrayElement = dstArrayIndex, - .descriptorCount = 1, - .descriptorType = cast(layout->getBindings()[binding].descriptorType), - .pImageInfo = &imageInfos.back(), - }); - - boundResources[binding][dstArrayIndex] = vulkanTexture->getHandle(); + boundResources[binding] = vulkanTexture->getHandle(); } void DescriptorSet::updateTextureArray(uint32_t binding, Array textures) { @@ -380,7 +302,7 @@ void DescriptorSet::updateTextureArray(uint32_t binding, Array uint32 arrayElement = 0; for (auto& gfxTexture : textures) { TextureBase* vulkanTexture = gfxTexture.cast().getHandle(); - if (boundResources[binding][arrayElement] == vulkanTexture->getHandle()) { + if (boundResources[binding+arrayElement] == vulkanTexture->getHandle()) { continue; } imageInfos.add(VkDescriptorImageInfo{ @@ -389,7 +311,7 @@ void DescriptorSet::updateTextureArray(uint32_t binding, Array .imageLayout = cast(vulkanTexture->getLayout()), }); - boundResources[binding][arrayElement] = vulkanTexture->getHandle(); + boundResources[binding+arrayElement] = vulkanTexture->getHandle(); writeDescriptors.add(VkWriteDescriptorSet{ .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, .pNext = nullptr, @@ -408,7 +330,7 @@ void DescriptorSet::updateSamplerArray(uint32_t binding, Array sa uint32 arrayElement = 0; for (auto& gfxSampler : samplers) { PSampler vulkanSampler = gfxSampler.cast(); - if (boundResources[binding][arrayElement] == vulkanSampler->getHandle()) { + if (boundResources[binding+arrayElement] == vulkanSampler->getHandle()) { continue; } imageInfos.add(VkDescriptorImageInfo{ diff --git a/src/Engine/Graphics/Vulkan/Descriptor.h b/src/Engine/Graphics/Vulkan/Descriptor.h index 4226ad0..14833d9 100644 --- a/src/Engine/Graphics/Vulkan/Descriptor.h +++ b/src/Engine/Graphics/Vulkan/Descriptor.h @@ -51,11 +51,8 @@ class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource { virtual void updateBuffer(uint32 binding, Gfx::PUniformBuffer uniformBuffer) override; virtual void updateBuffer(uint32 binding, Gfx::PShaderBuffer uniformBuffer) override; virtual void updateBuffer(uint32 binding, Gfx::PIndexBuffer uniformBuffer) override; - virtual void updateBuffer(uint32 binding, uint32 index, Gfx::PShaderBuffer uniformBuffer) override; virtual void updateSampler(uint32 binding, Gfx::PSampler samplerState) override; - virtual void updateSampler(uint32 binding, uint32 dstArrayIndex, Gfx::PSampler samplerState) override; virtual void updateTexture(uint32 binding, Gfx::PTexture texture, Gfx::PSampler sampler = nullptr) override; - virtual void updateTexture(uint32 binding, uint32 dstArrayIndex, Gfx::PTexture texture) override; virtual void updateTextureArray(uint32 binding, Array texture) override; virtual void updateSamplerArray(uint32 binding, Array samplers) override; virtual void updateAccelerationStructure(uint32 binding, Gfx::PTopLevelAS as) override; @@ -71,7 +68,7 @@ class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource { // since the layout is fixed, trying to bind a texture to a buffer // would not work anyways, so casts should be safe // Array cachedData; - Array> boundResources; + Array boundResources; VkDescriptorSet setHandle; PGraphics graphics; PDescriptorPool owner; diff --git a/src/Engine/Graphics/slang-compile.cpp b/src/Engine/Graphics/slang-compile.cpp index e863653..495b29d 100644 --- a/src/Engine/Graphics/slang-compile.cpp +++ b/src/Engine/Graphics/slang-compile.cpp @@ -116,15 +116,16 @@ void Seele::beginCompilation(const ShaderCompilationInfo& info, SlangCompileTarg for (size_t i = 0; i < signature->getParameterCount(); ++i) { auto param = signature->getParameterByIndex(i); layout->addMapping(param->getName(), param->getBindingIndex()); + std::cout << param->getName() << ": " << param->getBindingIndex() << std::endl; } // workaround - layout->addMapping("pVertexData", 1); - layout->addMapping("pMaterial", 4); - layout->addMapping("pLightEnv", 3); - layout->addMapping("pRayTracingParams", 5); - layout->addMapping("pScene", 2); - layout->addMapping("pWaterMaterial", 1); + //layout->addMapping("pVertexData", 1); + //layout->addMapping("pMaterial", 4); + //layout->addMapping("pLightEnv", 3); + //layout->addMapping("pRayTracingParams", 5); + //layout->addMapping("pScene", 2); + //layout->addMapping("pWaterMaterial", 1); } Pair, std::string> Seele::generateShader(const ShaderCreateInfo& createInfo) { diff --git a/src/Engine/Material/Material.cpp b/src/Engine/Material/Material.cpp index 2c6d39d..c1b753d 100644 --- a/src/Engine/Material/Material.cpp +++ b/src/Engine/Material/Material.cpp @@ -76,15 +76,16 @@ void Material::updateDescriptor() { Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT); layout->reset(); set = layout->allocateDescriptorSet(); - set->updateBuffer(0, floatBuffer); + uint32 binding = 0; + set->updateBuffer(binding++, floatBuffer); for (uint32 i = 0; i < textures.size(); ++i) { if (textures[i] != nullptr) { - set->updateTexture(1, i, textures[i]); + set->updateTexture(binding++, textures[i]); } } for (uint32 i = 0; i < samplers.size(); ++i) { if (samplers[i] != nullptr) { - set->updateSampler(2, i, samplers[i]); + set->updateSampler(binding++, samplers[i]); } } set->writeChanges(); diff --git a/src/Engine/System/ComponentSystem.h b/src/Engine/System/ComponentSystem.h index 266d0f5..e4c8604 100644 --- a/src/Engine/System/ComponentSystem.h +++ b/src/Engine/System/ComponentSystem.h @@ -27,8 +27,8 @@ template class ComponentSystem : public SystemBase { setupView((getDependencies() | ...)); } virtual void update() override {} - virtual void update(Components&... components) {} - virtual void update(entt::entity id, Components&... components) {} + virtual void update(Components&...) {} + virtual void update(entt::entity, Components&...) {} }; } // namespace System } // namespace Seele diff --git a/src/Engine/Window/GameView.cpp b/src/Engine/Window/GameView.cpp index e40c96b..ab3d983 100644 --- a/src/Engine/Window/GameView.cpp +++ b/src/Engine/Window/GameView.cpp @@ -28,7 +28,7 @@ GameView::GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreate renderGraph.addPass(new VisibilityPass(graphics, scene)); renderGraph.addPass(new LightCullingPass(graphics, scene)); renderGraph.addPass(new BasePass(graphics, scene)); - //renderGraph.addPass(new RayTracingPass(graphics, scene)); + renderGraph.addPass(new RayTracingPass(graphics, scene)); renderGraph.setViewport(viewport); renderGraph.createRenderPass(); }