From 19c3e559b15af3a59e5c464ff535972ef16316e1 Mon Sep 17 00:00:00 2001 From: Dynamitos Date: Wed, 8 Nov 2023 23:27:21 +0100 Subject: [PATCH] Progress i guess --- CMakeSettings.json | 1 + Seele.natvis | 12 +- res/shaders/BasePass.slang | 16 +-- res/shaders/ComputeFrustums.slang | 35 +---- res/shaders/DepthPrepass.slang | 24 ---- res/shaders/LegacyBasePass.slang | 9 +- res/shaders/LightCulling.slang | 22 +-- res/shaders/MeshletBasePass.slang | 34 ++--- res/shaders/Skybox.slang | 16 +-- res/shaders/TextPass.slang | 12 +- res/shaders/UIPass.slang | 12 +- res/shaders/lib/Common.slang | 5 +- res/shaders/lib/LightEnv.slang | 10 +- res/shaders/lib/Material.slang | 2 +- res/shaders/lib/MaterialParameter.slang | 15 +- res/shaders/lib/Meshlet.slang | 2 +- res/shaders/lib/StaticMeshVertexData.slang | 45 +++--- res/shaders/lib/VertexData.slang | 17 +-- src/Editor/Asset/AssetImporter.cpp | 4 +- src/Editor/Asset/AssetImporter.h | 2 +- src/Editor/Asset/MaterialLoader.cpp | 1 - src/Editor/Asset/MeshLoader.cpp | 6 +- src/Editor/main.cpp | 4 +- src/Engine/Actor/CameraActor.cpp | 2 +- .../Graphics/RenderPass/DepthPrepass.cpp | 11 +- src/Engine/Graphics/RenderPass/DepthPrepass.h | 4 +- .../Graphics/RenderPass/LightCullingPass.cpp | 2 +- .../Graphics/RenderPass/LightCullingPass.h | 1 + src/Engine/Graphics/RenderPass/RenderPass.h | 2 +- .../Graphics/RenderPass/SkyboxRenderPass.cpp | 9 +- .../Graphics/RenderPass/SkyboxRenderPass.h | 3 + src/Engine/Graphics/RenderPass/UIPass.cpp | 4 +- src/Engine/Graphics/Shader.cpp | 28 ++-- src/Engine/Graphics/Shader.h | 4 + src/Engine/Graphics/VertexData.cpp | 11 +- src/Engine/Graphics/VertexData.h | 2 + src/Engine/Graphics/Vulkan/Allocator.cpp | 132 ++++++------------ src/Engine/Graphics/Vulkan/Allocator.h | 11 +- src/Engine/Graphics/Vulkan/DescriptorSets.h | 14 +- src/Engine/Graphics/Vulkan/Graphics.h | 2 +- src/Engine/Graphics/Vulkan/RenderPass.cpp | 8 +- src/Engine/Graphics/Vulkan/RenderTarget.cpp | 20 +-- src/Engine/Graphics/Vulkan/Shader.cpp | 13 +- src/Engine/Scene/LightEnvironment.cpp | 5 +- src/Engine/Window/GameView.cpp | 14 +- src/Engine/Window/GameView.h | 10 +- src/Engine/Window/Window.cpp | 4 +- src/Engine/Window/Window.h | 4 +- src/Engine/Window/WindowManager.cpp | 3 +- 49 files changed, 268 insertions(+), 361 deletions(-) delete mode 100644 res/shaders/DepthPrepass.slang diff --git a/CMakeSettings.json b/CMakeSettings.json index 7a80985..8d62c21 100644 --- a/CMakeSettings.json +++ b/CMakeSettings.json @@ -6,6 +6,7 @@ "ctestCommandArgs": "", "configurationType": "Debug", "generator": "Visual Studio 17 2022 Win64", + "addressSanitizerEnabled": true, "intelliSenseMode": "windows-msvc-x64", "inheritEnvironments": [ "msvc_x64" ], "cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64", diff --git a/Seele.natvis b/Seele.natvis index 7b956ce..6921e5f 100644 --- a/Seele.natvis +++ b/Seele.natvis @@ -41,6 +41,14 @@ + + [{pair}] + + pair + leftChild + rightChild + + empty [{nodeContainer._data[node].pair}] @@ -50,9 +58,9 @@ empty - RefPtr {*object->handle} {object->refCount} references + RefPtr {*object} - object->handle + object diff --git a/res/shaders/BasePass.slang b/res/shaders/BasePass.slang index 56e14cd..edc87c4 100644 --- a/res/shaders/BasePass.slang +++ b/res/shaders/BasePass.slang @@ -11,21 +11,21 @@ struct LightCullingData RWTexture2D oLightGrid; RWTexture2D tLightGrid; }; -ParameterBuffer gLightCullingData; +ParameterBlock pLightCullingData; [shader("pixel")] void pixelMain(in VertexAttributes attribs, out float4 baseColor) { - MaterialParameter params = MaterialParameter.create(attribs); - BRDF brdf = gMaterial.prepare(params); + MaterialParameter params = attribs.create(); + BRDF brdf = pMaterial.prepare(params); float3 result = float3(0, 0, 0); - for(int i = 0; i < gLightEnv.numDirectionalLights; ++i) + for(int i = 0; i < pLightEnv.numDirectionalLights; ++i) { - result += gLightEnv.directionalLights[i].illuminate(params, brdf); + result += pLightEnv.directionalLights[i].illuminate(params, brdf); } - for(int i = 0; i < gLightEnv.numPointLights; ++i) + for(int i = 0; i < pLightEnv.numPointLights; ++i) { - result += gLightEnv.pointLights[i].illuminate(params, brdf); + result += pLightEnv.pointLights[i].illuminate(params, brdf); } - return float4(result, 1.0f); + return float4(1, 1, 0, 1.0f); } diff --git a/res/shaders/ComputeFrustums.slang b/res/shaders/ComputeFrustums.slang index 12a4f2e..624d9c5 100644 --- a/res/shaders/ComputeFrustums.slang +++ b/res/shaders/ComputeFrustums.slang @@ -14,43 +14,18 @@ struct DispatchParams uint pad0; uint3 numThreads; uint pad1; - RWShaderBuffer frustums; + RWStructuredBuffer frustums; } -ParameterBuffer dispatchParams; +ParameterBlock pDispatchParams; [numthreads(BLOCK_SIZE, BLOCK_SIZE, 1)] [shader("compute")] void computeFrustums(ComputeShaderInput in) { - const float3 eyePos = float3(0,0,0); - - float4 screenSpace[4]; - - screenSpace[0] = float4(in.dispatchThreadID.xy * BLOCK_SIZE, -1.0f, 1.0f); - screenSpace[1] = float4(float2(in.dispatchThreadID.x + 1, in.dispatchThreadID.y) * BLOCK_SIZE, -1.0f, 1.0f); - screenSpace[2] = float4(float2(in.dispatchThreadID.x, in.dispatchThreadID.y + 1) * BLOCK_SIZE, -1.0f, 1.0f); - screenSpace[3] = float4(float2(in.dispatchThreadID.x + 1, in.dispatchThreadID.y + 1) * BLOCK_SIZE, -1.0f, 1.0f); - - //Convert to viewSpace - float3 viewSpace[4]; - - for(int i = 0; i < 4; i++) + if(in.dispatchThreadID.x < pDispatchParams.numThreads.x && in.dispatchThreadID.y < pDispatchParams.numThreads.y) { - viewSpace[i] = screenToClip(screenSpace[i]).xyz; - } - - //Compute frustum - Frustum frustum; - - frustum.planes[0] = computePlane(eyePos, viewSpace[2], viewSpace[0]); - frustum.planes[1] = computePlane(eyePos, viewSpace[1], viewSpace[3]); - frustum.planes[2] = computePlane(eyePos, viewSpace[0], viewSpace[1]); - frustum.planes[3] = computePlane(eyePos, viewSpace[3], viewSpace[2]); - - if(in.dispatchThreadID.x < dispatchParams.numThreads.x && in.dispatchThreadID.y < dispatchParams.numThreads.y) - { - uint index = in.dispatchThreadID.x + (in.dispatchThreadID.y * numThreads.x); - dispatchParams.frustums[index] = frustum; + uint index = in.dispatchThreadID.x + (in.dispatchThreadID.y * pDispatchParams.numThreads.x); + //pDispatchParams.frustums[index] = frustum; } } diff --git a/res/shaders/DepthPrepass.slang b/res/shaders/DepthPrepass.slang deleted file mode 100644 index 1728996..0000000 --- a/res/shaders/DepthPrepass.slang +++ /dev/null @@ -1,24 +0,0 @@ -import Common; -import Material; -import PrimitiveSceneData; -import StaticMeshVertexInput; - - -struct VertexStageOutput -{ - float4 position : SV_Position; -} -[shader("vertex")] -VertexStageOutput vertexMain(PositionOnlyVertexShaderInput input) -{ - VertexStageOutput output; - - float3 worldPosition = input.getWorldPosition(); - //worldPosition += gMaterial.getWorldOffset(); - float4 clipSpacePosition; - - float4 viewSpacePosition = mul(gViewParams.viewMatrix, float4(worldPosition, 1)); - clipSpacePosition = mul(gViewParams.projectionMatrix, viewSpacePosition); - output.position = clipSpacePosition; - return output; -} diff --git a/res/shaders/LegacyBasePass.slang b/res/shaders/LegacyBasePass.slang index 31f85ae..e2a562e 100644 --- a/res/shaders/LegacyBasePass.slang +++ b/res/shaders/LegacyBasePass.slang @@ -1,5 +1,4 @@ import VertexData; -import StaticMeshVertexData; struct InstanceData { @@ -11,14 +10,14 @@ struct Scene StructuredBuffer instances; } -ParameterBlock scene; +ParameterBlock pScene; [shader("vertex")] -StaticMeshVertexAttributes vertexMain( +IVertexAttributes vertexMain( uint vertexId: SV_VertexID, uint instanceId: SV_InstanceID, ){ - InstanceData inst = scene.instances[instanceId]; - StaticMeshVertexAttributes attr = vertexData.getAttributes(vertexId, inst.transformMatrix); + InstanceData inst = pScene.instances[instanceId]; + IVertexAttributes attr = pVertexData.getAttributes(vertexId, inst.transformMatrix); return attr; } \ No newline at end of file diff --git a/res/shaders/LightCulling.slang b/res/shaders/LightCulling.slang index 29e2c47..1349e99 100644 --- a/res/shaders/LightCulling.slang +++ b/res/shaders/LightCulling.slang @@ -28,7 +28,7 @@ struct CullingParams StructuredBuffer frustums; }; -ParameterBlock gCullingParams; +ParameterBlock pCullingParams; // Debug //Texture2D lightCountHeatMap; //RWTexture2D debugTexture; @@ -72,7 +72,7 @@ void tAppendLight(uint lightIndex) void cullLights(ComputeShaderInput in) { int2 texCoord = int2(in.dispatchThreadID.xy); - float fDepth = gCullingParams.depthTextureVS.Load(int3(texCoord, 0)).r; + float fDepth = pCullingParams.depthTextureVS.Load(int3(texCoord, 0)).r; uint uDepth = asuint(fDepth); if(in.groupIndex == 0) @@ -81,7 +81,7 @@ void cullLights(ComputeShaderInput in) uMaxDepth = 0x0; oLightCount = 0; tLightCount = 0; - groupFrustum = gCullingParams.frustums[in.groupID.x + (in.groupID.y * gCullingParams.numThreadGroups.x)]; + groupFrustum = pCullingParams.frustums[in.groupID.x + (in.groupID.y * pCullingParams.numThreadGroups.x)]; } GroupMemoryBarrierWithGroupSync(); @@ -100,9 +100,9 @@ void cullLights(ComputeShaderInput in) Plane minPlane = {float3(0, 0, -1), -minDepthVS}; - for ( uint i = in.groupIndex; i < gLightEnv.numPointLights; i += BLOCK_SIZE * BLOCK_SIZE ) + for ( uint i = in.groupIndex; i < pLightEnv.numPointLights; i += BLOCK_SIZE * BLOCK_SIZE ) { - PointLight light = gLightEnv.pointLights[i]; + PointLight light = pLightEnv.pointLights[i]; //TODO: why doesn't this check go through? //if(light.insideFrustum(groupFrustum, nearClipVS, maxDepthVS)) { @@ -118,23 +118,23 @@ void cullLights(ComputeShaderInput in) if(in.groupIndex == 0) { - InterlockedAdd(gCullingParams.oLightIndexCounter[0], oLightCount, oLightIndexStartOffset); - gCullingParams.oLightGrid[in.groupID.xy] = uint2(oLightIndexStartOffset, oLightCount); + InterlockedAdd(pCullingParams.oLightIndexCounter[0], oLightCount, oLightIndexStartOffset); + pCullingParams.oLightGrid[in.groupID.xy] = uint2(oLightIndexStartOffset, oLightCount); - InterlockedAdd(gCullingParams.tLightIndexCounter[0], tLightCount, tLightIndexStartOffset); - gCullingParams.tLightGrid[in.groupID.xy] = uint2(tLightIndexStartOffset, tLightCount); + InterlockedAdd(pCullingParams.tLightIndexCounter[0], tLightCount, tLightIndexStartOffset); + pCullingParams.tLightGrid[in.groupID.xy] = uint2(tLightIndexStartOffset, tLightCount); } GroupMemoryBarrierWithGroupSync(); for (uint j = in.groupIndex; j < oLightCount; j += BLOCK_SIZE * BLOCK_SIZE) { - gCullingParams.oLightIndexList[oLightIndexStartOffset + j] = oLightList[j]; + pCullingParams.oLightIndexList[oLightIndexStartOffset + j] = oLightList[j]; } // For transparent geometry. for ( uint k = in.groupIndex; k < tLightCount; k += BLOCK_SIZE * BLOCK_SIZE ) { - gCullingParams.tLightIndexList[tLightIndexStartOffset + k] = tLightList[k]; + pCullingParams.tLightIndexList[tLightIndexStartOffset + k] = tLightList[k]; } diff --git a/res/shaders/MeshletBasePass.slang b/res/shaders/MeshletBasePass.slang index 2eaabc1..6a1bd88 100644 --- a/res/shaders/MeshletBasePass.slang +++ b/res/shaders/MeshletBasePass.slang @@ -22,11 +22,11 @@ void taskMain( uint threadID: SV_GroupIndex, uint groupID: SV_GroupID ){ - InstanceData instance = scene.instances[groupID]; + InstanceData instance = pScene.instances[groupID]; if(threadID == 0) { head = 0; - localToClip = mul(viewParams.projectionMatrix, mul(viewParams.viewMatrix, instance.transformMatrix)); + localToClip = mul(pViewParams.projectionMatrix, mul(pViewParams.viewMatrix, instance.transformMatrix)); // Left viewFrustum.sides[0].n = float3(1, 0, 0); viewFrustum.sides[0].d = -1; @@ -44,11 +44,11 @@ void taskMain( viewFrustum.basePlane.d = 0; } GroupMemoryBarrierWithGroupSync(); - MeshData mesh = scene.meshData[groupID]; + MeshData mesh = pScene.meshData[groupID]; for(uint i = threadID; i < MAX_MESHLETS_PER_MESH; i += TASK_GROUP_SIZE) { uint m = mesh.meshletOffset + min(mesh.numMeshlets, i); - MeshletDescription meshlet = scene.meshlets.meshletInfos[m]; + MeshletDescription meshlet = pScene.meshlets.meshletInfos[m]; //if(meshlet.boundingBox.insideFrustum(localToClip, viewFrustum)) { uint index; @@ -61,7 +61,7 @@ void taskMain( DispatchMesh(head, 1, 1, p); } -groupshared VertexAttributes gs_vertices[MAX_VERTICES]; +groupshared IVertexAttributes gs_vertices[MAX_VERTICES]; groupshared uint3 gs_indices[MAX_PRIMITIVES]; groupshared uint gs_numVertices; groupshared uint gs_numPrimitives; @@ -78,12 +78,12 @@ void meshMain( in uint threadID: SV_GroupIndex, in uint groupID: SV_GroupID, in payload MeshPayload meshPayload, - out Vertices vertices, + out Vertices vertices, out Indices indices ){ - InstanceData inst = scene.instances[meshPayload.instanceId[groupID]]; - MeshData md = scene.meshData[meshPayload.instanceId[groupID]]; - MeshletDescription m = meshlets.meshletInfos[meshPayload.meshletId[groupID]]; + InstanceData inst = pScene.instances[meshPayload.instanceId[groupID]]; + MeshData md = pScene.meshData[meshPayload.instanceId[groupID]]; + MeshletDescription m = pScene.meshletInfos[meshPayload.meshletId[groupID]]; const uint vertexLoops = (MAX_VERTICES + MESH_GROUP_SIZE - 1) / MESH_GROUP_SIZE; for(uint loop = 0; loop < vertexLoops; ++loop) { @@ -91,8 +91,8 @@ void meshMain( v = min(v, m.vertexCount - 1); InterlockedMax(gs_numVertices, v + 1); { - int vertexIndex = meshlets.vertexIndices[m.vertexOffset + v]; - gs_vertices[v] = vertexData.getAttributes(md.indexOffset + vertexIndex, inst); + int vertexIndex = pScene.vertexIndices[m.vertexOffset + v]; + gs_vertices[v] = pVertexData.getAttributes(md.indexOffset + vertexIndex, inst); } } @@ -103,12 +103,12 @@ void meshMain( p = min(p, m.primitiveCount - 1); InterlockedMax(gs_numPrimitives, p + 1); { - uint8_t local_idx0 = meshlets.primitiveIndices[m.primitiveOffset + (p * 3) + 0]; - uint8_t local_idx1 = meshlets.primitiveIndices[m.primitiveOffset + (p * 3) + 1]; - uint8_t local_idx2 = meshlets.primitiveIndices[m.primitiveOffset + (p * 3) + 2]; - uint32_t idx0 = meshlets.vertexIndices[m.vertexOffset + local_idx0]; - uint32_t idx1 = meshlets.vertexIndices[m.vertexOffset + local_idx1]; - uint32_t idx2 = meshlets.vertexIndices[m.vertexOffset + local_idx2]; + uint8_t local_idx0 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 0]; + uint8_t local_idx1 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 1]; + uint8_t local_idx2 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 2]; + uint32_t idx0 = pScene.vertexIndices[m.vertexOffset + local_idx0]; + uint32_t idx1 = pScene.vertexIndices[m.vertexOffset + local_idx1]; + uint32_t idx2 = pScene.vertexIndices[m.vertexOffset + local_idx2]; gs_indices[p * 3 + 0] = idx0; gs_indices[p * 3 + 1] = idx1; gs_indices[p * 3 + 2] = idx2; diff --git a/res/shaders/Skybox.slang b/res/shaders/Skybox.slang index c06e43f..92997d1 100644 --- a/res/shaders/Skybox.slang +++ b/res/shaders/Skybox.slang @@ -15,17 +15,17 @@ struct SkyboxData float4x4 transformMatrix; float4 fogBlend; }; -ParameterBuffer gSkyboxData; +ParameterBlock pSkyboxData; [shader("vertex")] VertexShaderOutput vertexMain( VertexShaderInput input) { VertexShaderOutput output; - float3x3 cameraRotation = float3x3(gViewParams.viewMatrix); + float3x3 cameraRotation = float3x3(pViewParams.viewMatrix); float4 worldPos = float4(mul(cameraRotation, input.position), 1.0f); //clip(dot(worldPos, clipPlane)); - output.clipPos = mul(gViewParams.projectionMatrix, worldPos); + output.clipPos = mul(pViewParams.projectionMatrix, worldPos); output.texCoords = normalize(input.position); return output; } @@ -36,7 +36,7 @@ struct TextureData TextureCube cubeMap2; SamplerState sampler; }; -ParameterBuffer textures; +ParameterBlock pTextures; static const float lowerLimit = 0.0; static const float upperLimit = 0.1; @@ -44,11 +44,11 @@ static const float upperLimit = 0.1; float4 fragmentMain( VertexShaderOutput output) : SV_Target { - float4 texture1 = textures.cubeMap.Sample(textures.sampler, output.texCoords); - float4 texture2 = textures.cubeMap2.Sample(textures.sampler, output.texCoords); - float4 finalColor = lerp(texture1, texture2, gSkyboxData.fogBlend.w); + float4 texture1 = pTextures.cubeMap.Sample(pTextures.sampler, output.texCoords); + float4 texture2 = pTextures.cubeMap2.Sample(pTextures.sampler, output.texCoords); + float4 finalColor = lerp(texture1, texture2, pSkyboxData.fogBlend.w); float factor = (output.texCoords.y - lowerLimit) / (upperLimit - lowerLimit); factor = clamp(factor, 0.0, 1.0); - return lerp(float4(gSkyboxData.fogBlend.xyz, 1), finalColor, factor); + return lerp(float4(pSkyboxData.fogBlend.xyz, 1), finalColor, factor); } \ No newline at end of file diff --git a/res/shaders/TextPass.slang b/res/shaders/TextPass.slang index cc7988a..9575ca0 100644 --- a/res/shaders/TextPass.slang +++ b/res/shaders/TextPass.slang @@ -9,14 +9,14 @@ struct TextData float4 textColor; float scale; } -ParameterBuffer glyphSampler; +ParameterBlock glyphSampler; //layout(set = 1) //ShaderBuffer glyphData; -ParameterBuffer[]> glyphTextures; +ParameterBuffer[]> pGlyphTextures; [[vk::push_constant]] ConstantBuffer textData; -struct VertexStageInput +struct VertexInput { float2 position; float2 widthHeight; @@ -24,7 +24,7 @@ struct VertexStageInput uint vertexId : SV_VertexID; }; -struct VertexStageOutput +struct VertexOutput { float4 position : SV_Position; float2 texCoords : TEXCOORD; @@ -32,7 +32,7 @@ struct VertexStageOutput }; [shader("vertex")] -VertexStageOutput vertexMain(VertexStageInput input) +VertexOutput vertexMain(VertexInput input) { float xpos = input.position.x; float ypos = input.position.y; @@ -61,5 +61,5 @@ float4 fragmentMain( uint glyphIndex : GLYPHINDEX ) : SV_Target { - return textData.textColor * glyphTextures[glyphIndex].Sample(glyphSampler, texCoords); + return textData.textColor * pGlyphTextures[glyphIndex].Sample(glyphSampler, texCoords); } \ No newline at end of file diff --git a/res/shaders/UIPass.slang b/res/shaders/UIPass.slang index 221dbda..4d65646 100644 --- a/res/shaders/UIPass.slang +++ b/res/shaders/UIPass.slang @@ -24,9 +24,9 @@ struct UIParameter Texture2D backgroundTextures[]; } -ParameterBuffer params; +ParameterBlock pParams; -struct VertexStageOutput +struct VertexOutput { float4 position : SV_Position; float2 texCoords : TEXCOORD; @@ -34,7 +34,7 @@ struct VertexStageOutput }; [shader("vertex")] -VertexStageOutput vertexMain(uint vertexId : SV_VertexID, RenderElementStyle style) +VertexOutput vertexMain(uint vertexId : SV_VertexID, RenderElementStyle style) { float xMin = style.position.x; float xMax = xMin + style.dimensions.x; @@ -46,8 +46,8 @@ VertexStageOutput vertexMain(uint vertexId : SV_VertexID, RenderElementStyle sty float4(xMax, yMin, 1, 0), float4(xMax, yMax, 1, 1) }; - VertexStageOutput output; - output.position = mul(viewData.projectionMatrix, float4(coordinates[vertexId].xy, style.position.z, 1)); + VertexOutput output; + output.position = mul(pViewData.projectionMatrix, float4(coordinates[vertexId].xy, style.position.z, 1)); output.texCoords = coordinates[vertexId].zw; output.style = style; return output; @@ -64,7 +64,7 @@ float4 fragmentMain( uint imageIndex = style.backgroundImageIndex; if(imageIndex < numBackgroundTextures) { - bgTextureColor = backgroundTextures[imageIndex].Sample(backgroundSampler, texCoords); + bgTextureColor = pParams.backgroundTextures[imageIndex].Sample(pParams.backgroundSampler, texCoords); } return float4(style.backgroundColor, style.opacity) * bgTextureColor; } \ No newline at end of file diff --git a/res/shaders/lib/Common.slang b/res/shaders/lib/Common.slang index 4a06fb3..d709156 100644 --- a/res/shaders/lib/Common.slang +++ b/res/shaders/lib/Common.slang @@ -9,15 +9,14 @@ struct ViewParameter float4 cameraPos_WS; float2 screenDimensions; } -layout(set = INDEX_VIEW_PARAMS) -ParameterBlock viewParams; +ParameterBlock pViewParams; // Convert screen space coordinates to view space. float4 screenToClip( float4 screen ) { // Convert to normalized texture coordinates - float2 texCoord = screen.xy / viewParams.screenDimensions; + float2 texCoord = screen.xy / pViewParams.screenDimensions; // Convert to clip space return float4( float2( texCoord.x, 1.0f-texCoord.y ) * 2.0f - 1.0f, screen.z, screen.w ); diff --git a/res/shaders/lib/LightEnv.slang b/res/shaders/lib/LightEnv.slang index 36834e2..f505322 100644 --- a/res/shaders/lib/LightEnv.slang +++ b/res/shaders/lib/LightEnv.slang @@ -1,6 +1,6 @@ -import MaterialParameter; -import BRDF; import Common; +import BRDF; +import MaterialParameter; interface ILightEnv { @@ -15,7 +15,7 @@ struct DirectionalLight : ILightEnv float3 illuminate(MaterialParameter input, B brdf) { float3 lightDir_TS = normalize(direction.xyz); - return brdf.evaluate(input.viewDir_TS, -lightDir_TS, color.xyz); + return brdf.evaluate(input.viewDir_TS, -lightDir_TS, color.xyz); } }; @@ -57,7 +57,7 @@ struct PointLight : ILightEnv } float3 getViewPos() { - return mul(viewParams.viewMatrix, position_WS).xyz; + return mul(pViewParams.viewMatrix, position_WS).xyz; } }; @@ -69,4 +69,4 @@ struct LightEnv uint numPointLights; }; -ParameterBlock gLightEnv; +ParameterBlock pLightEnv; diff --git a/res/shaders/lib/Material.slang b/res/shaders/lib/Material.slang index 86c7275..da0c53c 100644 --- a/res/shaders/lib/Material.slang +++ b/res/shaders/lib/Material.slang @@ -8,4 +8,4 @@ interface IMaterial BRDF prepare(MaterialParameter input); }; -ParameterBlock gMaterial; +ParameterBlock pMaterial; diff --git a/res/shaders/lib/MaterialParameter.slang b/res/shaders/lib/MaterialParameter.slang index 4e09c13..88b2bdd 100644 --- a/res/shaders/lib/MaterialParameter.slang +++ b/res/shaders/lib/MaterialParameter.slang @@ -1,24 +1,11 @@ -import VertexData; - struct MaterialParameter { -float3 position_TS; + float3 position_TS; float3 worldPosition; float2 texCoords; float3 normal; float3 tangent; float3 biTangent; float3 viewDir_TS; - - static MaterialParameter create(VertexAttributes attrib) - { - MaterialParameter result; - result.worldPosition = attrib.getWorldPosition().xyz; - result.texCoords = attrib.getTexCoords(); - result.normal = attrib.getNormal(); - result.tangent = attrib.getTangent(); - result.biTangent = attrib.getBiTangent(); - return result; - } } diff --git a/res/shaders/lib/Meshlet.slang b/res/shaders/lib/Meshlet.slang index 14814e3..ea0e8ba 100644 --- a/res/shaders/lib/Meshlet.slang +++ b/res/shaders/lib/Meshlet.slang @@ -37,5 +37,5 @@ struct Scene StructuredBuffer vertexIndices; }; -ParameterBlock scene; +ParameterBlock pScene; diff --git a/res/shaders/lib/StaticMeshVertexData.slang b/res/shaders/lib/StaticMeshVertexData.slang index 599737b..fa32105 100644 --- a/res/shaders/lib/StaticMeshVertexData.slang +++ b/res/shaders/lib/StaticMeshVertexData.slang @@ -1,8 +1,8 @@ -import VertexData; import Common; -import Scene; +import VertexData; +import MaterialParameter; -struct StaticMeshVertexAttributes : VertexAttributes +struct StaticMeshVertexAttributes : IVertexAttributes { float4 clipPosition: SV_Position; float3 worldPosition: POSITION0; @@ -10,37 +10,30 @@ struct StaticMeshVertexAttributes : VertexAttributes float3 normal: NORMAL0; float3 tangent: TANGENT0; float3 biTangent: BITANGENT0; - float3 getWorldPosition() + + MaterialParameter create() { - return worldPosition; + MaterialParameter result; + result.worldPosition = worldPosition; + result.texCoords = texCoords; + result.normal = normal; + result.tangent = tangent; + result.biTangent = biTangent; + return result; } - float2 getTexCoords() - { - return texCoords; - } - float3 getNormal() - { - return normal; - } - float3 getTangent() - { - return tangent; - } - float3 getBiTangent() - { - return biTangent; - } -} -struct StaticMeshVertexData : VertexData +}; + +struct StaticMeshVertexData : IVertexData { + typedef StaticMeshVertexAttributes VertexAttributes; StaticMeshVertexAttributes getAttributes(uint index, float4x4 transform) { StaticMeshVertexAttributes attr; float4 localPos = float4(positions[index], 1); float4 worldPos = mul(transform, localPos); - float4 viewPos = mul(viewParams.viewMatrix, worldPos); - float4 clipPos = mul(viewParams.projectionMatrix, viewPos); + float4 viewPos = mul(pViewParams.viewMatrix, worldPos); + float4 clipPos = mul(pViewParams.projectionMatrix, viewPos); attr.clipPosition = clipPos; attr.worldPosition = worldPos.xyz; attr.texCoords = texCoords[index]; @@ -54,4 +47,4 @@ struct StaticMeshVertexData : VertexData StructuredBuffer normals; StructuredBuffer tangents; StructuredBuffer biTangents; -} \ No newline at end of file +}; diff --git a/res/shaders/lib/VertexData.slang b/res/shaders/lib/VertexData.slang index eb73292..06fdacc 100644 --- a/res/shaders/lib/VertexData.slang +++ b/res/shaders/lib/VertexData.slang @@ -1,16 +1,13 @@ -import Scene; +import MaterialParameter; -interface VertexAttributes +interface IVertexAttributes { - float3 getWorldPosition(); - float2 getTexCoords(); - float3 getNormal(); - float3 getTangent(); - float3 getBiTangent(); -} + MaterialParameter create(); +}; -interface VertexData +interface IVertexData { + associatedtype VertexAttributes : IVertexAttributes; VertexAttributes getAttributes(uint index, float4x4 transform); }; -ParameterBlock vertexData; \ No newline at end of file +ParameterBlock pVertexData; \ No newline at end of file diff --git a/src/Editor/Asset/AssetImporter.cpp b/src/Editor/Asset/AssetImporter.cpp index 5075d3b..420f052 100644 --- a/src/Editor/Asset/AssetImporter.cpp +++ b/src/Editor/Asset/AssetImporter.cpp @@ -47,9 +47,9 @@ void AssetImporter::importMaterial(MaterialImportArgs args) get().materialLoader->importAsset(args); } -void AssetImporter::init(Gfx::PGraphics graphics, AssetRegistry* registry) +void AssetImporter::init(Gfx::PGraphics graphics) { - get().registry = registry; + get().registry = AssetRegistry::getInstance(); get().meshLoader = new MeshLoader(graphics); get().textureLoader = new TextureLoader(graphics); get().materialLoader = new MaterialLoader(graphics); diff --git a/src/Editor/Asset/AssetImporter.h b/src/Editor/Asset/AssetImporter.h index 5c60218..52e8429 100644 --- a/src/Editor/Asset/AssetImporter.h +++ b/src/Editor/Asset/AssetImporter.h @@ -15,7 +15,7 @@ public: static void importTexture(struct TextureImportArgs args); static void importFont(struct FontImportArgs args); static void importMaterial(struct MaterialImportArgs args); - static void init(Gfx::PGraphics graphics, AssetRegistry* registry); + static void init(Gfx::PGraphics graphics); private: static AssetImporter& get(); UPTextureLoader textureLoader; diff --git a/src/Editor/Asset/MaterialLoader.cpp b/src/Editor/Asset/MaterialLoader.cpp index f738a44..0fc8483 100644 --- a/src/Editor/Asset/MaterialLoader.cpp +++ b/src/Editor/Asset/MaterialLoader.cpp @@ -47,7 +47,6 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset) Gfx::ODescriptorLayout layout = graphics->createDescriptorLayout(materialName + "Layout"); //Shader file needs to conform to the slang standard, which prohibits _ materialName.erase(std::remove(materialName.begin(), materialName.end(), '_'), materialName.end()); - materialName.erase(std::remove(materialName.begin(), materialName.end(), '.'), materialName.end()); uint32 uniformBufferOffset = 0; uint32 bindingCounter = 0; // Uniform buffers are always binding 0 diff --git a/src/Editor/Asset/MeshLoader.cpp b/src/Editor/Asset/MeshLoader.cpp index 00e7b0a..4e4f69c 100644 --- a/src/Editor/Asset/MeshLoader.cpp +++ b/src/Editor/Asset/MeshLoader.cpp @@ -48,7 +48,9 @@ void MeshLoader::loadMaterials(const aiScene* scene, const std::string& baseName { aiMaterial* material = scene->mMaterials[i]; json matCode; - matCode["name"] = baseName + material->GetName().C_Str(); + std::string materialName = std::format("{0}{1}", baseName, material->GetName().C_Str()); + materialName.erase(std::remove(materialName.begin(), materialName.end(), '.'), materialName.end()); // dots break adding the .asset extension later + matCode["name"] = materialName; matCode["profile"] = "BlinnPhong"; //TODO: other shading models aiString texPath; //TODO make samplers based on used textures @@ -58,7 +60,7 @@ void MeshLoader::loadMaterials(const aiScene* scene, const std::string& baseName }; if(material->GetTexture(aiTextureType_DIFFUSE, 0, &texPath) == AI_SUCCESS) { - std::string texFilename = std::filesystem::path(texPath.C_Str()).replace_extension("asset").stem().string(); + std::string texFilename = std::filesystem::path(texPath.C_Str()).stem().string(); matCode["params"]["diffuseTexture"] = { {"type", "Texture2D"}, diff --git a/src/Editor/main.cpp b/src/Editor/main.cpp index a78093a..a630ea7 100644 --- a/src/Editor/main.cpp +++ b/src/Editor/main.cpp @@ -17,8 +17,6 @@ using namespace Seele; using namespace Seele::Editor; -extern AssetRegistry* instance; - int main() { #ifdef WIN32 @@ -41,7 +39,7 @@ int main() vd->init(graphics); PWindowManager windowManager = new WindowManager(); AssetRegistry::init(sourcePath / "Assets", graphics); - AssetImporter::init(graphics, AssetRegistry::getInstance()); + AssetImporter::init(graphics); AssetImporter::importFont(FontImportArgs{ .filePath = "./fonts/Calibri.ttf", }); diff --git a/src/Engine/Actor/CameraActor.cpp b/src/Engine/Actor/CameraActor.cpp index 1da543d..79b6e4d 100644 --- a/src/Engine/Actor/CameraActor.cpp +++ b/src/Engine/Actor/CameraActor.cpp @@ -7,7 +7,7 @@ CameraActor::CameraActor(PScene scene) : Actor(scene) { attachComponent(); - attachComponent().setRelativeLocation(Vector(10, 5, 14)); + accessComponent().setRelativeLocation(Vector(10, 5, 14)); } CameraActor::~CameraActor() diff --git a/src/Engine/Graphics/RenderPass/DepthPrepass.cpp b/src/Engine/Graphics/RenderPass/DepthPrepass.cpp index 140ccc3..936a45f 100644 --- a/src/Engine/Graphics/RenderPass/DepthPrepass.cpp +++ b/src/Engine/Graphics/RenderPass/DepthPrepass.cpp @@ -19,6 +19,7 @@ DepthPrepass::DepthPrepass(Gfx::PGraphics graphics, PScene scene) depthPrepassLayout = graphics->createPipelineLayout(); depthPrepassLayout->addDescriptorLayout(INDEX_VIEW_PARAMS, viewParamsLayout); + graphics->getShaderCompiler()->registerRenderPass("DepthPass", "LegacyBasePass"); } DepthPrepass::~DepthPrepass() @@ -43,18 +44,18 @@ void DepthPrepass::render() { permutation.useMeshShading = true; permutation.hasTaskShader = true; - std::memcpy(permutation.taskFile, "MeshletBasePass", sizeof("MeshletBasePass")); - std::memcpy(permutation.vertexMeshFile, "MeshletBasePass", sizeof("MeshletBasePass")); + std::strncpy(permutation.taskFile, "MeshletBasePass", sizeof("MeshletBasePass")); + std::strncpy(permutation.vertexMeshFile, "MeshletBasePass", sizeof("MeshletBasePass")); } else { permutation.useMeshShading = false; - std::memcpy(permutation.vertexMeshFile, "LegacyBasePass", sizeof("LegacyBasePass")); + std::strncpy(permutation.vertexMeshFile, "LegacyBasePass", sizeof("LegacyBasePass")); } graphics->beginRenderPass(renderPass); for (VertexData* vertexData : VertexData::getList()) { - std::memcpy(permutation.vertexDataName, vertexData->getTypeName().c_str(), std::strlen(vertexData->getTypeName().c_str())); + std::strncpy(permutation.vertexDataName, vertexData->getTypeName().c_str(), sizeof(permutation.vertexDataName)); const auto& materials = vertexData->getMaterialData(); for (const auto& [_, materialData] : materials) { @@ -64,7 +65,7 @@ void DepthPrepass::render() // Material => per material // VertexData => per meshtype // SceneData => per material instance - std::memcpy(permutation.materialName, materialData.material->getName().c_str(), std::strlen(materialData.material->getName().c_str())); + std::strncpy(permutation.materialName, materialData.material->getName().c_str(), sizeof(permutation.materialName)); Gfx::PermutationId id(permutation); Gfx::PRenderCommand command = graphics->createRenderCommand("DepthRender"); diff --git a/src/Engine/Graphics/RenderPass/DepthPrepass.h b/src/Engine/Graphics/RenderPass/DepthPrepass.h index 9ce581f..033e628 100644 --- a/src/Engine/Graphics/RenderPass/DepthPrepass.h +++ b/src/Engine/Graphics/RenderPass/DepthPrepass.h @@ -18,8 +18,8 @@ public: virtual void createRenderPass() override; static void modifyRenderPassMacros(Map& defines); private: - Gfx::PRenderTargetAttachment depthAttachment; - Gfx::PTexture2D depthBuffer; + Gfx::ORenderTargetAttachment depthAttachment; + Gfx::OTexture2D depthBuffer; Array descriptorSets; diff --git a/src/Engine/Graphics/RenderPass/LightCullingPass.cpp b/src/Engine/Graphics/RenderPass/LightCullingPass.cpp index a46ba2f..277fd11 100644 --- a/src/Engine/Graphics/RenderPass/LightCullingPass.cpp +++ b/src/Engine/Graphics/RenderPass/LightCullingPass.cpp @@ -200,7 +200,7 @@ void LightCullingPass::setupFrustums() dispatchParams.numThreads = numThreads; dispatchParams.numThreadGroups = numThreadGroups; - Gfx::ODescriptorLayout frustumDescriptorLayout = graphics->createDescriptorLayout("FrustumLayout"); + frustumDescriptorLayout = graphics->createDescriptorLayout("FrustumLayout"); frustumDescriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER); frustumDescriptorLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER); frustumLayout = graphics->createPipelineLayout(); diff --git a/src/Engine/Graphics/RenderPass/LightCullingPass.h b/src/Engine/Graphics/RenderPass/LightCullingPass.h index ce0b174..34cedc2 100644 --- a/src/Engine/Graphics/RenderPass/LightCullingPass.h +++ b/src/Engine/Graphics/RenderPass/LightCullingPass.h @@ -45,6 +45,7 @@ private: Gfx::OShaderBuffer frustumBuffer; Gfx::OUniformBuffer dispatchParamsBuffer; Gfx::OUniformBuffer viewParamsBuffer; + Gfx::ODescriptorLayout frustumDescriptorLayout; Gfx::PDescriptorSet frustumDescriptorSet; Gfx::OComputeShader frustumShader; Gfx::OPipelineLayout frustumLayout; diff --git a/src/Engine/Graphics/RenderPass/RenderPass.h b/src/Engine/Graphics/RenderPass/RenderPass.h index 4f2b398..b921d28 100644 --- a/src/Engine/Graphics/RenderPass/RenderPass.h +++ b/src/Engine/Graphics/RenderPass/RenderPass.h @@ -38,7 +38,7 @@ protected: PRenderGraphResources resources; static constexpr uint32 INDEX_VIEW_PARAMS = 0; Gfx::ODescriptorLayout viewParamsLayout; - Gfx::OShaderBuffer viewParamsBuffer; + Gfx::OUniformBuffer viewParamsBuffer; Gfx::PDescriptorSet viewParamsSet; Gfx::ORenderPass renderPass; Gfx::PGraphics graphics; diff --git a/src/Engine/Graphics/RenderPass/SkyboxRenderPass.cpp b/src/Engine/Graphics/RenderPass/SkyboxRenderPass.cpp index 1802fa6..022a5a2 100644 --- a/src/Engine/Graphics/RenderPass/SkyboxRenderPass.cpp +++ b/src/Engine/Graphics/RenderPass/SkyboxRenderPass.cpp @@ -169,14 +169,13 @@ void SkyboxRenderPass::createRenderPass() createInfo.name = "SkyboxVertex"; createInfo.mainModule = "Skybox"; createInfo.entryPoint = "vertexMain"; - createInfo.defines["INDEX_VIEW_PARAMS"] = "0"; - Gfx::PVertexShader vertexShader = graphics->createVertexShader(createInfo); + vertexShader = graphics->createVertexShader(createInfo); createInfo.name = "SkyboxFragment"; createInfo.entryPoint = "fragmentMain"; - Gfx::PFragmentShader fragmentShader = graphics->createFragmentShader(createInfo); + fragmentShader = graphics->createFragmentShader(createInfo); - Gfx::PVertexDeclaration vertexDecl = graphics->createVertexDeclaration({ + declaration = graphics->createVertexDeclaration({ Gfx::VertexElement { .binding = 0, .offset = 0, @@ -187,7 +186,7 @@ void SkyboxRenderPass::createRenderPass() }); Gfx::LegacyPipelineCreateInfo gfxInfo; - gfxInfo.vertexDeclaration = vertexDecl; + gfxInfo.vertexDeclaration = declaration; gfxInfo.vertexShader = vertexShader; gfxInfo.fragmentShader = fragmentShader; gfxInfo.rasterizationState.polygonMode = Gfx::SE_POLYGON_MODE_FILL; diff --git a/src/Engine/Graphics/RenderPass/SkyboxRenderPass.h b/src/Engine/Graphics/RenderPass/SkyboxRenderPass.h index 822696c..5252d4c 100644 --- a/src/Engine/Graphics/RenderPass/SkyboxRenderPass.h +++ b/src/Engine/Graphics/RenderPass/SkyboxRenderPass.h @@ -26,6 +26,9 @@ private: Gfx::ODescriptorLayout descriptorLayout; Gfx::PDescriptorSet descriptorSet; Gfx::OPipelineLayout pipelineLayout; + Gfx::OVertexDeclaration declaration; + Gfx::OVertexShader vertexShader; + Gfx::OFragmentShader fragmentShader; Gfx::OGraphicsPipeline pipeline; Gfx::OSamplerState skyboxSampler; Component::Skybox skybox; diff --git a/src/Engine/Graphics/RenderPass/UIPass.cpp b/src/Engine/Graphics/RenderPass/UIPass.cpp index a5cf8d0..41594fe 100644 --- a/src/Engine/Graphics/RenderPass/UIPass.cpp +++ b/src/Engine/Graphics/RenderPass/UIPass.cpp @@ -155,8 +155,8 @@ void UIPass::createRenderPass() }, .dynamic = false, }; - Gfx::PUniformBuffer uniformBuffer = graphics->createUniformBuffer(info); - Gfx::PSamplerState backgroundSampler = graphics->createSamplerState({}); + Gfx::OUniformBuffer uniformBuffer = graphics->createUniformBuffer(info); + Gfx::OSamplerState backgroundSampler = graphics->createSamplerState({}); info = { .sourceData = { diff --git a/src/Engine/Graphics/Shader.cpp b/src/Engine/Graphics/Shader.cpp index 059f9ad..a6e8d0e 100644 --- a/src/Engine/Graphics/Shader.cpp +++ b/src/Engine/Graphics/Shader.cpp @@ -53,27 +53,26 @@ void ShaderCompiler::compile() ShaderPermutation permutation; for (const auto& [name, pass] : passes) { - std::memset(&permutation, 0, sizeof(ShaderPermutation)); permutation.hasFragment = pass.hasFragmentShader; permutation.useMeshShading = pass.useMeshShading; permutation.hasTaskShader = pass.hasTaskShader; - std::memcpy(permutation.vertexMeshFile, pass.mainFile.c_str(), sizeof(permutation.vertexMeshFile)); + std::strncpy(permutation.vertexMeshFile, pass.mainFile.c_str(), sizeof(permutation.vertexMeshFile)); if (pass.hasFragmentShader) { - std::memcpy(permutation.fragmentFile, pass.fragmentFile.c_str(), sizeof(permutation.fragmentFile)); + std::strncpy(permutation.fragmentFile, pass.fragmentFile.c_str(), sizeof(permutation.fragmentFile)); } if (pass.hasTaskShader) { - std::memcpy(permutation.taskFile, pass.taskFile.c_str(), sizeof(permutation.taskFile)); + std::strncpy(permutation.taskFile, pass.taskFile.c_str(), sizeof(permutation.taskFile)); } for (const auto& [vdName, vd] : vertexData) { - std::memcpy(permutation.vertexDataName, vd->getTypeName().c_str(), sizeof(permutation.vertexDataName)); + std::strncpy(permutation.vertexDataName, vd->getTypeName().c_str(), sizeof(permutation.vertexDataName)); if (pass.useMaterial) { for (const auto& [matName, mat] : materials) { - std::memcpy(permutation.materialName, matName.c_str(), sizeof(permutation.materialName)); + std::strncpy(permutation.materialName, matName.c_str(), sizeof(permutation.materialName)); createShaders(permutation); } } @@ -92,10 +91,23 @@ ShaderCollection& ShaderCompiler::createShaders(ShaderPermutation permutation) ShaderCollection collection; ShaderCreateInfo createInfo; - createInfo.typeParameter = { permutation.materialName, permutation.vertexDataName }; + createInfo.typeParameter = { permutation.vertexDataName }; createInfo.name = std::format("Material {0}", permutation.materialName); - createInfo.additionalModules.add(permutation.materialName); + if (std::strlen(permutation.materialName) > 0) + { + createInfo.additionalModules.add(permutation.materialName); + createInfo.typeParameter.add(permutation.materialName); + } createInfo.additionalModules.add(permutation.vertexDataName); + createInfo.additionalModules.add(permutation.vertexMeshFile); + if (permutation.hasFragment) + { + createInfo.additionalModules.add(permutation.fragmentFile); + } + if (permutation.hasTaskShader) + { + createInfo.additionalModules.add(permutation.taskFile); + } if (permutation.useMeshShading) { diff --git a/src/Engine/Graphics/Shader.h b/src/Engine/Graphics/Shader.h index 2f765b4..a8543be 100644 --- a/src/Engine/Graphics/Shader.h +++ b/src/Engine/Graphics/Shader.h @@ -62,6 +62,10 @@ struct ShaderPermutation uint8 useMeshShading : 1; uint8 hasTaskShader : 1; //TODO: lightmapping etc + ShaderPermutation() + { + std::memset(this, 0, sizeof(ShaderPermutation)); + } }; //Hashed ShaderPermutation for fast lookup struct PermutationId diff --git a/src/Engine/Graphics/VertexData.cpp b/src/Engine/Graphics/VertexData.cpp index 9c74895..c18c4d8 100644 --- a/src/Engine/Graphics/VertexData.cpp +++ b/src/Engine/Graphics/VertexData.cpp @@ -16,6 +16,7 @@ void VertexData::resetMeshData() if (dirty) { updateBuffers(); + dirty = false; } } @@ -23,6 +24,7 @@ void VertexData::updateMesh(const Component::Transform& transform, PMesh mesh) { PMaterial mat = mesh->referencedMaterial->getHandle()->getBaseMaterial(); MaterialData& matData = materialData[mat->getName()]; + matData.material = mat; MaterialInstanceData& matInstanceData = matData.instances[mesh->referencedMaterial->getHandle()->getId()]; matInstanceData.meshes.add(MeshInstanceData{ .id = mesh->id, @@ -89,7 +91,6 @@ void VertexData::loadMesh(MeshId id, Array loadedMeshlets) .stride = sizeof(uint8), .dynamic = true, }); - } void VertexData::createDescriptors() @@ -108,7 +109,7 @@ void VertexData::createDescriptors() meshes.add(mesh); } } - Gfx::PShaderBuffer instanceBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{ + matInst.instanceBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{ .sourceData = { .size = sizeof(InstanceData) * instanceData.size(), .data = (uint8*)instanceData.data(), @@ -117,17 +118,17 @@ void VertexData::createDescriptors() }); instanceDataLayout->reset(); matInst.descriptorSet = instanceDataLayout->allocateDescriptorSet(); - matInst.descriptorSet->updateBuffer(0, instanceBuffer); + matInst.descriptorSet->updateBuffer(0, matInst.instanceBuffer); if (graphics->supportMeshShading()) { - Gfx::PShaderBuffer meshDataBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{ + matInst.meshDataBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{ .sourceData = { .size = sizeof(MeshData) * meshes.size(), .data = (uint8*)meshes.data(), }, .stride = sizeof(MeshData) }); - matInst.descriptorSet->updateBuffer(1, meshDataBuffer); + matInst.descriptorSet->updateBuffer(1, matInst.meshDataBuffer); matInst.descriptorSet->updateBuffer(2, meshletBuffer); matInst.descriptorSet->updateBuffer(3, primitiveIndicesBuffer); matInst.descriptorSet->updateBuffer(4, vertexIndicesBuffer); diff --git a/src/Engine/Graphics/VertexData.h b/src/Engine/Graphics/VertexData.h index 34b3045..907f5c9 100644 --- a/src/Engine/Graphics/VertexData.h +++ b/src/Engine/Graphics/VertexData.h @@ -43,6 +43,8 @@ public: struct MaterialInstanceData { PMaterialInstance materialInstance; + Gfx::OShaderBuffer instanceBuffer; + Gfx::OShaderBuffer meshDataBuffer; Gfx::PDescriptorSet descriptorSet; uint32 numMeshes; // not necessarily equal to meshes.size() if a MeshId has multiple meshes Array meshes; diff --git a/src/Engine/Graphics/Vulkan/Allocator.cpp b/src/Engine/Graphics/Vulkan/Allocator.cpp index 723ab83..c6c60c1 100644 --- a/src/Engine/Graphics/Vulkan/Allocator.cpp +++ b/src/Engine/Graphics/Vulkan/Allocator.cpp @@ -4,12 +4,12 @@ using namespace Seele::Vulkan; -SubAllocation::SubAllocation(PAllocation owner, VkDeviceSize allocatedOffset, VkDeviceSize size, VkDeviceSize alignedOffset, VkDeviceSize allocatedSize) +SubAllocation::SubAllocation(PAllocation owner, VkDeviceSize requestedSize, VkDeviceSize allocatedOffset, VkDeviceSize allocatedSize, VkDeviceSize alignedOffset) : owner(owner) - , size(size) + , requestedSize(requestedSize) , allocatedOffset(allocatedOffset) - , alignedOffset(alignedOffset) , allocatedSize(allocatedSize) + , alignedOffset(alignedOffset) { } @@ -61,7 +61,7 @@ Allocation::Allocation(PGraphics graphics, PAllocator allocator, VkDeviceSize si allocInfo.pNext = dedicatedInfo; VK_CHECK(vkAllocateMemory(device, &allocInfo, nullptr, &allocatedMemory)); bytesAllocated = size; - freeRanges[0] = new SubAllocation(this, 0, size, 0, size); + freeRanges[0] = size; canMap = (properties & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; isMapped = false; @@ -69,16 +69,16 @@ Allocation::Allocation(PGraphics graphics, PAllocator allocator, VkDeviceSize si Allocation::~Allocation() { + assert(bytesUsed == 0); } OSubAllocation Allocation::getSuballocation(VkDeviceSize requestedSize, VkDeviceSize alignment) { - std::scoped_lock lck(lock); if (isDedicated) { if (activeAllocations.empty() && requestedSize == bytesAllocated) { - OSubAllocation suballoc = std::move(freeRanges[0]); + OSubAllocation suballoc = new SubAllocation(this, requestedSize, 0, requestedSize, 0); activeAllocations.add(suballoc); freeRanges.clear(); bytesUsed += requestedSize; @@ -89,32 +89,30 @@ OSubAllocation Allocation::getSuballocation(VkDeviceSize requestedSize, VkDevice return nullptr; } } - for (auto& [allocatedOffset, freeAllocation] : freeRanges) + for (const auto& [lower, size] : freeRanges) { - assert(allocatedOffset == freeAllocation->allocatedOffset); - VkDeviceSize alignedOffset = allocatedOffset + alignment - 1; + VkDeviceSize alignedOffset = lower + alignment - 1; alignedOffset /= alignment; alignedOffset *= alignment; - VkDeviceSize allocatedSize = requestedSize + (alignedOffset - allocatedOffset); - if (freeAllocation->size == allocatedSize) + VkDeviceSize allocatedSize = requestedSize + (alignedOffset - lower); + if (size == allocatedSize) { - activeAllocations.add(freeAllocation); - freeRanges.erase(allocatedOffset); + OSubAllocation alloc = new SubAllocation(this, requestedSize, lower, allocatedSize, alignedOffset); + activeAllocations.add(alloc); + freeRanges.erase(lower); bytesUsed += allocatedSize; - return std::move(freeAllocation); + return std::move(alloc); } - else if (allocatedSize < freeAllocation->allocatedSize) + else if (allocatedSize < size) { - freeAllocation->size -= allocatedSize; - freeAllocation->allocatedSize -= allocatedSize; - freeAllocation->allocatedOffset += allocatedSize; - freeAllocation->alignedOffset += allocatedSize; - OSubAllocation subAlloc = new SubAllocation(this, allocatedOffset, allocatedSize, alignedOffset, allocatedSize); + VkDeviceSize newSize = size - allocatedSize; + VkDeviceSize newLower = lower + allocatedSize; + OSubAllocation subAlloc = new SubAllocation(this, requestedSize, lower, allocatedSize, alignedOffset); activeAllocations.add(subAlloc); - freeRanges[freeAllocation->allocatedOffset] = std::move(freeAllocation); - freeRanges.erase(allocatedOffset); + freeRanges.erase(lower); + freeRanges[newLower] = newSize; bytesUsed += allocatedSize; - return subAlloc; + return std::move(subAlloc); } } return nullptr; @@ -122,70 +120,28 @@ OSubAllocation Allocation::getSuballocation(VkDeviceSize requestedSize, VkDevice void Allocation::markFree(PSubAllocation allocation) { - // Dont free if it is already a free allocation, since they also mark themselves on deletion - if (freeRanges.find(allocation->allocatedOffset) != freeRanges.end()) - { - return; - } + assert(activeAllocations.find(allocation) != activeAllocations.end()); VkDeviceSize lowerBound = allocation->allocatedOffset; VkDeviceSize upperBound = allocation->allocatedOffset + allocation->allocatedSize; - PSubAllocation allocHandle; - PSubAllocation freeRangeToDelete; - + freeRanges[lowerBound] = allocation->allocatedSize; + for (const auto& [lower, size] : freeRanges) { - std::scoped_lock lck(lock); - //Join lower bound - for (auto& [allocatedOffset, freeAlloc] : freeRanges) + if (lower + size == lowerBound) { - if (freeAlloc->allocatedOffset <= lowerBound - && freeAlloc->allocatedOffset + freeAlloc->allocatedSize >= upperBound) - { - // allocation is already in a free region - assert(false); - } - if (freeAlloc->allocatedOffset + freeAlloc->allocatedSize == lowerBound) - { - //extend freeAlloc by the allocatedSize - freeAlloc->allocatedSize += allocation->allocatedSize; - allocHandle = freeAlloc; - break; - } + freeRanges[lower] = upperBound; + freeRanges.erase(lowerBound); + lowerBound = lower; + break; } - //Join upper bound - auto foundAlloc = freeRanges.find(upperBound); - if (foundAlloc != freeRanges.end()) - { - // There is a free allocation ending where the new free one ends - freeRangeToDelete = foundAlloc->value; - if (allocHandle != nullptr) - { - // extend allocHandle by another foundAlloc->allocatedSize bytes - allocHandle->allocatedSize += foundAlloc->value->allocatedSize; - freeRanges.erase(foundAlloc->key); - } - else - { - // set foundAlloc back by size amount - allocHandle = foundAlloc->value; - allocHandle->allocatedOffset -= allocation->allocatedSize; - allocHandle->alignedOffset -= allocation->allocatedSize; - allocHandle->size += allocation->allocatedSize; - allocHandle->allocatedSize += allocation->allocatedSize; - // place back at correct offset, move original owning pointer - freeRanges[allocHandle->allocatedOffset] = std::move(foundAlloc->value); - // remove from offset map since key changes - freeRanges.erase(foundAlloc->key); - } - } - - if (allocHandle == nullptr) - { - freeRanges[allocation->allocatedOffset] = new SubAllocation(this, allocation->allocatedOffset, allocation->size, allocation->alignedOffset, allocation->allocatedSize); - } - activeAllocations.remove_if([&](const PSubAllocation& a) {return a.getHandle() == allocation.getHandle(); }); } + if (freeRanges.find(upperBound) != freeRanges.end()) + { + freeRanges[lowerBound] += freeRanges[upperBound]; + freeRanges.erase(upperBound); + } + activeAllocations.remove(allocation, false); bytesUsed -= allocation->allocatedSize; - if(bytesUsed == 0) + if (bytesUsed == 0) { allocator->free(this); } @@ -231,7 +187,6 @@ Allocator::Allocator(PGraphics graphics) Allocator::~Allocator() { - std::scoped_lock lck(lock); for (auto& heap : heaps) { for (auto& alloc : heap.allocations) @@ -246,7 +201,6 @@ Allocator::~Allocator() OSubAllocation Allocator::allocate(const VkMemoryRequirements2 &memRequirements2, VkMemoryPropertyFlags properties, VkMemoryDedicatedAllocateInfo *dedicatedInfo) { - std::scoped_lock lck(lock); const VkMemoryRequirements &requirements = memRequirements2.memoryRequirements; uint32 memoryTypeIndex = findMemoryType(requirements.memoryTypeBits, properties); uint32 heapIndex = memProperties.memoryTypes[memoryTypeIndex].heapIndex; @@ -270,7 +224,7 @@ OSubAllocation Allocator::allocate(const VkMemoryRequirements2 &memRequirements2 OSubAllocation suballoc = alloc->getSuballocation(requirements.size, requirements.alignment); if (suballoc != nullptr) { - return suballoc; + return std::move(suballoc); } } } @@ -284,7 +238,6 @@ OSubAllocation Allocator::allocate(const VkMemoryRequirements2 &memRequirements2 void Allocator::free(PAllocation allocation) { - std::scoped_lock lck(lock); for (uint32 heapIndex = 0; heapIndex < heaps.size(); ++heapIndex) { for (uint32 alloc = 0; alloc < heaps[heapIndex].allocations.size(); ++alloc) @@ -293,7 +246,7 @@ void Allocator::free(PAllocation allocation) { heaps[heapIndex].inUse -= allocation->bytesAllocated; std::cout << "Heap " << heapIndex << " -" <bytesAllocated << ": " << (float)heaps[heapIndex].inUse / heaps[heapIndex].maxSize << "%" << std::endl; - heaps[heapIndex].allocations.removeAt(heapIndex, false); + heaps[heapIndex].allocations.removeAt(alloc, false); return; } } @@ -371,7 +324,6 @@ void StagingManager::clearPending() OStagingBuffer StagingManager::allocateStagingBuffer(uint64 size, VkBufferUsageFlags usage, bool readable) { - std::scoped_lock l(lock); for (auto it = freeBuffers.begin(); it != freeBuffers.end(); ++it) { auto& freeBuffer = *it; @@ -381,7 +333,7 @@ OStagingBuffer StagingManager::allocateStagingBuffer(uint64 size, VkBufferUsageF activeBuffers.add(freeBuffer); OStagingBuffer owner = std::move(freeBuffer); freeBuffers.remove(it, false); - return owner; + return std::move(owner); } } //std::cout << "Creating new stagingbuffer" << std::endl; @@ -421,11 +373,9 @@ OStagingBuffer StagingManager::allocateStagingBuffer(uint64 size, VkBufferUsageF ); vkBindBufferMemory(graphics->getDevice(), buffer, stagingBuffer->getMemoryHandle(), stagingBuffer->getOffset()); - std::cout << "Creating new stagingbuffer size " << stagingBuffer->getSize() << std::endl; - activeBuffers.add(stagingBuffer); - return stagingBuffer; + return std::move(stagingBuffer); } void StagingManager::releaseStagingBuffer(OStagingBuffer buffer) @@ -434,8 +384,6 @@ void StagingManager::releaseStagingBuffer(OStagingBuffer buffer) { return; } - std::scoped_lock l(lock); activeBuffers.remove(buffer); - std::cout << "Releasing stagingbuffer size " << buffer->getSize() << std::endl; freeBuffers.add(std::move(buffer)); } \ No newline at end of file diff --git a/src/Engine/Graphics/Vulkan/Allocator.h b/src/Engine/Graphics/Vulkan/Allocator.h index 1c86b69..4fce498 100644 --- a/src/Engine/Graphics/Vulkan/Allocator.h +++ b/src/Engine/Graphics/Vulkan/Allocator.h @@ -15,13 +15,13 @@ DECLARE_REF(Allocation) class SubAllocation { public: - SubAllocation(PAllocation owner, VkDeviceSize allocatedOffset, VkDeviceSize size, VkDeviceSize alignedOffset, VkDeviceSize allocatedSize); + SubAllocation(PAllocation owner, VkDeviceSize requestedSize, VkDeviceSize allocatedOffset, VkDeviceSize allocatedSize, VkDeviceSize alignedOffset); ~SubAllocation(); VkDeviceMemory getHandle() const; constexpr VkDeviceSize getSize() const { - return size; + return requestedSize; } constexpr VkDeviceSize getOffset() const @@ -37,7 +37,7 @@ public: private: PAllocation owner; - VkDeviceSize size; + VkDeviceSize requestedSize; VkDeviceSize allocatedOffset; VkDeviceSize alignedOffset; VkDeviceSize allocatedSize; @@ -87,8 +87,7 @@ private: VkDeviceSize bytesUsed; VkDeviceMemory allocatedMemory; Array activeAllocations; - Map freeRanges; - std::mutex lock; + Map freeRanges; void *mappedPointer; uint8 isDedicated : 1; uint8 canMap : 1; @@ -147,7 +146,6 @@ private: }; Array heaps; uint32 findMemoryType(uint32 typeBits, VkMemoryPropertyFlags properties); - std::mutex lock; PGraphics graphics; VkPhysicalDeviceMemoryProperties memProperties; }; @@ -200,7 +198,6 @@ private: PAllocator allocator; Array freeBuffers; Array activeBuffers; - std::mutex lock; }; DEFINE_REF(StagingManager) } // namespace Vulkan diff --git a/src/Engine/Graphics/Vulkan/DescriptorSets.h b/src/Engine/Graphics/Vulkan/DescriptorSets.h index e5dd7f6..f2b0b58 100644 --- a/src/Engine/Graphics/Vulkan/DescriptorSets.h +++ b/src/Engine/Graphics/Vulkan/DescriptorSets.h @@ -76,31 +76,31 @@ public: virtual void updateTextureArray(uint32_t binding, Array texture); virtual bool operator<(Gfx::PDescriptorSet other); - inline bool isCurrentlyBound() const + constexpr bool isCurrentlyBound() const { return currentlyBound; } - inline bool isCurrentlyInUse() const + constexpr bool isCurrentlyInUse() const { return currentlyInUse; } - void bind() + constexpr void bind() { currentlyBound = true; } - void unbind() + constexpr void unbind() { currentlyBound = false; } - void allocate() + constexpr void allocate() { currentlyInUse = true; } - void free() + constexpr void free() { currentlyInUse = false; } - inline VkDescriptorSet getHandle() const + constexpr VkDescriptorSet getHandle() const { return setHandle; } diff --git a/src/Engine/Graphics/Vulkan/Graphics.h b/src/Engine/Graphics/Vulkan/Graphics.h index db8912b..8181ed3 100644 --- a/src/Engine/Graphics/Vulkan/Graphics.h +++ b/src/Engine/Graphics/Vulkan/Graphics.h @@ -104,7 +104,7 @@ protected: std::mutex viewportLock; Array viewports; std::mutex allocatedFrameBufferLock; - Map allocatedFramebuffers; + Map allocatedFramebuffers; OAllocator allocator; OStagingManager stagingManager; diff --git a/src/Engine/Graphics/Vulkan/RenderPass.cpp b/src/Engine/Graphics/Vulkan/RenderPass.cpp index 82c1d11..cdd8aa1 100644 --- a/src/Engine/Graphics/Vulkan/RenderPass.cpp +++ b/src/Engine/Graphics/Vulkan/RenderPass.cpp @@ -8,8 +8,8 @@ using namespace Seele; using namespace Seele::Vulkan; -RenderPass::RenderPass(PGraphics graphics, Gfx::ORenderTargetLayout layout, Gfx::PViewport viewport) - : Gfx::RenderPass(std::move(layout)) +RenderPass::RenderPass(PGraphics graphics, Gfx::ORenderTargetLayout _layout, Gfx::PViewport viewport) + : Gfx::RenderPass(std::move(_layout)) , graphics(graphics) { renderArea.extent.width = viewport->getSizeX(); @@ -22,7 +22,7 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::ORenderTargetLayout layout, Gfx: Array colorRefs; VkAttachmentReference depthRef; uint32 attachmentCounter = 0; - for (auto& inputAttachment : this->layout->inputAttachments) + for (auto& inputAttachment : layout->inputAttachments) { PTexture2D image = inputAttachment->getTexture().cast(); VkAttachmentDescription& desc = attachments.add(); @@ -40,7 +40,7 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::ORenderTargetLayout layout, Gfx: ref.attachment = attachmentCounter; attachmentCounter++; } - for (auto& colorAttachment : this->layout->colorAttachments) + for (auto& colorAttachment : layout->colorAttachments) { VkAttachmentDescription& desc = attachments.add(); desc.flags = 0; diff --git a/src/Engine/Graphics/Vulkan/RenderTarget.cpp b/src/Engine/Graphics/Vulkan/RenderTarget.cpp index 7c19c35..628e45e 100644 --- a/src/Engine/Graphics/Vulkan/RenderTarget.cpp +++ b/src/Engine/Graphics/Vulkan/RenderTarget.cpp @@ -223,16 +223,16 @@ void Window::present() backBufferImages[currentImageIndex]->changeLayout(Gfx::SE_IMAGE_LAYOUT_PRESENT_SRC_KHR); graphics->getGraphicsCommands()->submitCommands(renderFinished[currentImageIndex]); VkSemaphore renderFinishedHandle = renderFinished[currentImageIndex]->getHandle(); - VkPresentInfoKHR info; - info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; - info.pNext = nullptr; - info.swapchainCount = 1; - info.pSwapchains = &swapchain; - info.pImageIndices = (uint32 *)¤tImageIndex; - info.pResults = 0; - info.waitSemaphoreCount = 1; - info.pWaitSemaphores = &renderFinishedHandle; - + VkPresentInfoKHR info = { + .sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, + .pNext = nullptr, + .waitSemaphoreCount = 1, + .pWaitSemaphores = &renderFinishedHandle, + .swapchainCount = 1, + .pSwapchains = &swapchain, + .pImageIndices = (uint32*)¤tImageIndex, + .pResults = 0, + }; VkResult presentResult = VK_ERROR_OUT_OF_DATE_KHR; // Trial and error while (presentResult != VK_SUCCESS) diff --git a/src/Engine/Graphics/Vulkan/Shader.cpp b/src/Engine/Graphics/Vulkan/Shader.cpp index f11da5f..d37b159 100644 --- a/src/Engine/Graphics/Vulkan/Shader.cpp +++ b/src/Engine/Graphics/Vulkan/Shader.cpp @@ -39,11 +39,11 @@ void Shader::create(const ShaderCreateInfo& createInfo) sessionDesc.flags = 0; sessionDesc.defaultMatrixLayoutMode = SLANG_MATRIX_LAYOUT_COLUMN_MAJOR; Array macros; - for(auto define : createInfo.defines) + for(const auto& [key, val] : createInfo.defines) { macros.add(slang::PreprocessorMacroDesc{ - .name = define.key, - .value = define.value + .name = key, + .value = val, }); } sessionDesc.preprocessorMacroCount = macros.size(); @@ -91,10 +91,11 @@ void Shader::create(const ShaderCreateInfo& createInfo) std::cout << (const char*)diagnostics->getBufferPointer() << std::endl; } - /*for(auto typeParam : createInfo.typeParameter) + /*slang::ProgramLayout* layout = moduleComposition->getLayout(); + for(auto typeParam : createInfo.typeParameter) { Slang::ComPtr typeConformance; - session->createTypeConformanceComponentType(moduleComposition->getLayout()->findTypeByName(typeParam), moduleComposition->getLayout()->findTypeByName("IMaterial"), typeConformance.writeRef(), -1, diagnostics.writeRef()); + session->createTypeConformanceComponentType(layout->findTypeByName(typeParam), layout->findTypeByName("IMaterial"), typeConformance.writeRef(), -1, diagnostics.writeRef()); modules.add(typeConformance); if(diagnostics) { @@ -104,7 +105,7 @@ void Shader::create(const ShaderCreateInfo& createInfo) Slang::ComPtr conformingModule; session->createCompositeComponentType(modules.data(), modules.size(), conformingModule.writeRef(), diagnostics.writeRef()); -*/ + */ Slang::ComPtr linkedProgram; moduleComposition->link(linkedProgram.writeRef(), diagnostics.writeRef()); if(diagnostics) diff --git a/src/Engine/Scene/LightEnvironment.cpp b/src/Engine/Scene/LightEnvironment.cpp index 07e8d3b..f62c656 100644 --- a/src/Engine/Scene/LightEnvironment.cpp +++ b/src/Engine/Scene/LightEnvironment.cpp @@ -21,7 +21,7 @@ LightEnvironment::LightEnvironment(Gfx::PGraphics graphics) directionalLights = graphics->createShaderBuffer(ShaderBufferCreateInfo{ .sourceData = { .size = sizeof(Component::DirectionalLight) * MAX_DIRECTIONAL_LIGHTS, - .data = (uint8*)dirs.data(), + .data = nullptr, }, .stride = sizeof(Component::DirectionalLight), .dynamic = true, @@ -29,7 +29,7 @@ LightEnvironment::LightEnvironment(Gfx::PGraphics graphics) pointLights = graphics->createShaderBuffer(ShaderBufferCreateInfo{ .sourceData = { .size = sizeof(Component::PointLight) * MAX_POINT_LIGHTS, - .data = (uint8*)dirs.data(), + .data = nullptr, }, .stride = sizeof(Component::PointLight), .dynamic = true, @@ -77,6 +77,7 @@ void LightEnvironment::commit() set->updateBuffer(0, lightEnvBuffer); set->updateBuffer(1, directionalLights); set->updateBuffer(2, pointLights); + set->writeChanges(); } const Gfx::PDescriptorLayout Seele::LightEnvironment::getDescriptorLayout() const diff --git a/src/Engine/Window/GameView.cpp b/src/Engine/Window/GameView.cpp index 57d391c..db10ac6 100644 --- a/src/Engine/Window/GameView.cpp +++ b/src/Engine/Window/GameView.cpp @@ -4,6 +4,8 @@ #include "Component/KeyboardInput.h" #include "Actor/CameraActor.h" #include "Asset/AssetRegistry.h" +#include "System/LightGather.h" +#include "System/MeshUpdater.h" using namespace Seele; @@ -12,12 +14,13 @@ GameView::GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreate , scene(new Scene(graphics)) , gameInterface(dllPath) , renderGraph(RenderGraphBuilder::build( - DepthPrepass(graphics, scene), - LightCullingPass(graphics, scene), - BasePass(graphics, scene), - SkyboxRenderPass(graphics, scene) + DepthPrepass(graphics, scene) + //LightCullingPass(graphics, scene), + //BasePass(graphics, scene), + //SkyboxRenderPass(graphics, scene) )) { + camera = new CameraActor(scene); reloadGame(); renderGraph.updateViewport(viewport); } @@ -67,11 +70,12 @@ void GameView::render() void GameView::reloadGame() { - scene = new Scene(graphics); gameInterface.reload(AssetRegistry::getInstance()); systemGraph = new SystemGraph(); gameInterface.getGame()->setupScene(scene, systemGraph); + systemGraph->addSystem(new System::LightGather(scene)); + systemGraph->addSystem(new System::MeshUpdater(scene)); } void GameView::keyCallback(KeyCode code, InputAction action, KeyModifier) diff --git a/src/Engine/Window/GameView.h b/src/Engine/Window/GameView.h index ea60ef8..9afba9e 100644 --- a/src/Engine/Window/GameView.h +++ b/src/Engine/Window/GameView.h @@ -28,13 +28,13 @@ public: void reloadGame(); private: OScene scene; - PEntity camera; + OEntity camera; GameInterface gameInterface; RenderGraph< - DepthPrepass, - LightCullingPass, - BasePass, - SkyboxRenderPass + DepthPrepass + //LightCullingPass, + //BasePass, + //SkyboxRenderPass > renderGraph; PSystemGraph systemGraph; diff --git a/src/Engine/Window/Window.cpp b/src/Engine/Window/Window.cpp index 3ba03d1..bf01e3d 100644 --- a/src/Engine/Window/Window.cpp +++ b/src/Engine/Window/Window.cpp @@ -4,9 +4,9 @@ using namespace Seele; -Window::Window(PWindowManager owner, Gfx::PWindow handle) +Window::Window(PWindowManager owner, Gfx::OWindow handle) : owner(owner) - , gfxHandle(handle) + , gfxHandle(std::move(handle)) { } diff --git a/src/Engine/Window/Window.h b/src/Engine/Window/Window.h index 9deca16..cd8db50 100644 --- a/src/Engine/Window/Window.h +++ b/src/Engine/Window/Window.h @@ -9,7 +9,7 @@ DECLARE_REF(WindowManager) class Window { public: - Window(PWindowManager owner, Gfx::PWindow handle); + Window(PWindowManager owner, Gfx::OWindow handle); ~Window(); void addView(PView view); void render(); @@ -19,7 +19,7 @@ public: protected: PWindowManager owner; Array views; - Gfx::PWindow gfxHandle; + Gfx::OWindow gfxHandle; //void viewWorker(size_t viewIndex); }; diff --git a/src/Engine/Window/WindowManager.cpp b/src/Engine/Window/WindowManager.cpp index 98f32e5..c7ce8e4 100644 --- a/src/Engine/Window/WindowManager.cpp +++ b/src/Engine/Window/WindowManager.cpp @@ -13,8 +13,7 @@ WindowManager::~WindowManager() PWindow WindowManager::addWindow(Gfx::PGraphics graphics, const WindowCreateInfo &createInfo) { - Gfx::OWindow handle = graphics->createWindow(createInfo); - OWindow window = new Window(this, handle); + OWindow window = new Window(this, graphics->createWindow(createInfo)); PWindow ref = window; windows.add(std::move(window)); return ref;