diff --git a/.vscode/settings.json b/.vscode/settings.json index eb2460b..044b7e0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -135,5 +135,5 @@ }, "git.ignoreSubmodules": true, "cmake.configureOnOpen": true, - "cmake.parallelJobs": 15 + "cmake.parallelJobs": 0 } \ No newline at end of file diff --git a/res/shaders/LightCulling.slang b/res/shaders/LightCulling.slang index 08131c3..93af0e6 100644 --- a/res/shaders/LightCulling.slang +++ b/res/shaders/LightCulling.slang @@ -19,24 +19,25 @@ cbuffer DispatchParams layout(set = INDEX_VIEW_PARAMS, binding = 2) Texture2D depthTextureVS; -layout(set = INDEX_VIEW_PARAMS, binding = 3) -StructuredBuffer frustums; -layout(set = INDEX_VIEW_PARAMS, binding = 4) +layout(set = INDEX_VIEW_PARAMS, binding = 3) globallycoherent RWStructuredBuffer oLightIndexCounter; -layout(set = INDEX_VIEW_PARAMS, binding = 5) +layout(set = INDEX_VIEW_PARAMS, binding = 4) globallycoherent RWStructuredBuffer tLightIndexCounter; -layout(set = INDEX_VIEW_PARAMS, binding = 6) +layout(set = INDEX_VIEW_PARAMS, binding = 5) RWStructuredBuffer oLightIndexList; -layout(set = INDEX_VIEW_PARAMS, binding = 7) +layout(set = INDEX_VIEW_PARAMS, binding = 6) RWStructuredBuffer tLightIndexList; -layout(set = INDEX_VIEW_PARAMS, binding = 8) +layout(set = INDEX_VIEW_PARAMS, binding = 7) RWTexture2D oLightGrid; -layout(set = INDEX_VIEW_PARAMS, binding = 9) +layout(set = INDEX_VIEW_PARAMS, binding = 8) RWTexture2D tLightGrid; +layout(set = INDEX_VIEW_PARAMS, binding = 9) +StructuredBuffer frustums; + // Debug //layout(set = INDEX_VIEW_PARAMS, binding = 10) //Texture2D lightCountHeatMap; diff --git a/res/shaders/TextPass.slang b/res/shaders/TextPass.slang index 6c67faf..72eb9f0 100644 --- a/res/shaders/TextPass.slang +++ b/res/shaders/TextPass.slang @@ -12,12 +12,12 @@ layout(set = 0, binding = 0) ConstantBuffer viewData; layout(set = 0, binding = 1) SamplerState glyphSampler; -layout(set = 0, binding = 2) -StructuredBuffer glyphData; layout(set = 1) -Texture2D glyphTextures[]; +RWStructuredBuffer glyphData; +layout(set = 2) +Texture2D glyphTextures[]; layout(push_constant) -float scale; +ConstantBuffer scale; struct VertexStageInput { @@ -45,10 +45,10 @@ VertexStageOutput vertexMain(VertexStageInput input) float h = glyph.size.y * scale; float4 coordinates[4] = { - float4(xpos, ypos + h, 0, 0), float4(xpos, ypos, 0, 1), - float4(xpos + w, ypos, 1, 0), - float4(xpos + w, ypos + h, 1, 1) + float4(xpos, ypos + h, 0, 0), + float4(xpos + w, ypos, 1, 1), + float4(xpos + w, ypos + h, 1, 0) }; float4 vertex = coordinates[input.vertexId]; VertexStageOutput output; diff --git a/res/shaders/culling.glsl b/res/shaders/culling.glsl new file mode 100644 index 0000000..9da1c55 --- /dev/null +++ b/res/shaders/culling.glsl @@ -0,0 +1,424 @@ +#version 450 +#extension GL_EXT_samplerless_texture_functions : require +layout(row_major) uniform; +layout(row_major) buffer; + +#line 21 0 +layout(binding = 2) +uniform texture2D depthTextureVS_0; + + +#line 46 +shared uint uMinDepth_0; + + +#line 47 +shared uint uMaxDepth_0; + + + +shared uint oLightCount_0; + + + +shared uint tLightCount_0; + + +#line 12 +struct SLANG_ParameterGroup_DispatchParams_0 +{ + uvec3 numThreadGroups_0; + uint pad0_0; + uvec3 numThreads_0; + uint pad1_0; +}; + + +#line 12 +layout(binding = 1) +layout(std140) uniform _S1 +{ + SLANG_ParameterGroup_DispatchParams_0 _data; +} DispatchParams_0; + +#line 39 1 +struct Plane_0 +{ + vec3 n_0; + float d_0; +}; + +struct Frustum_0 +{ + Plane_0 planes_0[4]; +}; + + +#line 23 0 +layout(std430, binding = 3) readonly buffer _S2 { + Frustum_0 _data[]; +} frustums_0; + +#line 49 +shared Frustum_0 groupFrustum_0; + + +#line 5 1 +struct ViewParameter_0 +{ + mat4x4 viewMatrix_0; + mat4x4 projectionMatrix_0; + mat4x4 inverseProjection_0; + vec4 cameraPos_WS_0; + vec2 screenDimensions_0; +}; + +layout(binding = 0) +layout(std140) uniform _S3 +{ + ViewParameter_0 _data; +} gViewParams_0; + +#line 17 +vec4 clipToView_0(vec4 clip_0) +{ + + vec4 view_0 = (((clip_0) * (gViewParams_0._data.inverseProjection_0))); + + vec4 view_1 = view_0 / view_0.w; + + return view_1; +} + + +#line 71 2 +layout(binding = 3, set = 1) +layout(std140) uniform _S4 +{ + uint _data; +} numPointLights_0; + +#line 22 +struct PointLight_0 +{ + vec4 positionWS_0; + vec4 colorRange_0; +}; + + +#line 69 +layout(std430, binding = 2, set = 1) readonly buffer _S5 { + PointLight_0 _data[]; +} pointLights_0; + +#line 57 0 +shared uint tLightList_0[1024]; + + +#line 70 +void tAppendLight_0(uint lightIndex_0) +{ + uint index_0; + ((index_0) = atomicAdd((tLightCount_0), (uint(1)))); + if(index_0 < uint(1024)) + { + tLightList_0[index_0] = lightIndex_0; + +#line 74 + } + else + { + +#line 74 + } + + + + return; +} + + +#line 58 2 +vec3 PointLight_getViewPos_0(PointLight_0 this_0) +{ + vec4 _S6 = (((this_0.positionWS_0) * (gViewParams_0._data.viewMatrix_0))); + +#line 60 + return _S6.xyz; +} + + +#line 36 +bool PointLight_insidePlane_0(PointLight_0 this_1, Plane_0 plane_0) +{ + +#line 36 + vec3 _S7 = plane_0.n_0; + + vec3 _S8 = PointLight_getViewPos_0(this_1); + +#line 38 + float _S9 = dot(_S7, _S8.xyz); + +#line 38 + return _S9 - plane_0.d_0 < - this_1.colorRange_0.w; +} + + +#line 53 0 +shared uint oLightList_0[1024]; + + +#line 60 +void oAppendLight_0(uint lightIndex_1) +{ + uint index_1; + ((index_1) = atomicAdd((oLightCount_0), (uint(1)))); + if(index_1 < uint(1024)) + { + oLightList_0[index_1] = lightIndex_1; + +#line 64 + } + else + { + +#line 64 + } + + + + return; +} + + +#line 26 +layout(std430, binding = 4) buffer _S10 { + uint _data[]; +} oLightIndexCounter_0; + +#line 52 +shared uint oLightIndexStartOffset_0; + + +#line 36 +layout(rg32ui) +layout(binding = 8) +uniform uimage2D oLightGrid_0; + + +#line 28 +layout(std430, binding = 5) buffer _S11 { + uint _data[]; +} tLightIndexCounter_0; + +#line 56 +shared uint tLightIndexStartOffset_0; + + +#line 38 +layout(rg32ui) +layout(binding = 9) +uniform uimage2D tLightGrid_0; + + +#line 31 +layout(std430, binding = 6) buffer _S12 { + uint _data[]; +} oLightIndexList_0; + +#line 33 +layout(std430, binding = 7) buffer _S13 { + uint _data[]; +} tLightIndexList_0; + +#line 4 +struct ComputeShaderInput_0 +{ + uvec3 groupID_0; + uvec3 groupThreadID_0; + uvec3 dispatchThreadID_0; + uint groupIndex_0; +}; + + +#line 82 +layout(local_size_x = 32, local_size_y = 32, local_size_z = 1) in; +void main() +{ + uint i_0; + uint j_0; + uint k_0; + +#line 82 + ComputeShaderInput_0 _S14 = ComputeShaderInput_0(gl_WorkGroupID, gl_LocalInvocationID, gl_GlobalInvocationID, gl_LocalInvocationIndex); + + + ivec3 _S15 = ivec3(ivec2(_S14.dispatchThreadID_0.xy), 0); + +#line 85 + vec4 _S16 = (texelFetch((depthTextureVS_0), ((_S15)).xy, ((_S15)).z)); + + uint uDepth_0 = floatBitsToUint(_S16.x); + if(_S14.groupIndex_0 == uint(0)) + { + uMinDepth_0 = uint(-1); + uMaxDepth_0 = uint(0); + oLightCount_0 = uint(0); + tLightCount_0 = uint(0); + Frustum_0 _S17 = ((frustums_0)._data[(_S14.groupID_0.x + _S14.groupID_0.y * DispatchParams_0._data.numThreadGroups_0.x)]); + +#line 94 + groupFrustum_0 = _S17; + +#line 88 + } + else + { + +#line 88 + } + +#line 97 + groupMemoryBarrier(), barrier(); + + atomicMin((uMinDepth_0), (uDepth_0)); + atomicMax((uMaxDepth_0), (uDepth_0)); + + groupMemoryBarrier(), barrier(); + + float fMinDepth_0 = uintBitsToFloat(uMinDepth_0); + float fMaxDepth_0 = uintBitsToFloat(uMaxDepth_0); + + vec4 _S18 = clipToView_0(vec4(float(0), float(0), fMinDepth_0, float(1))); + +#line 107 + float minDepthVS_0 = _S18.z; + vec4 _S19 = clipToView_0(vec4(float(0), float(0), fMaxDepth_0, float(1))); + vec4 _S20 = clipToView_0(vec4(float(0), float(0), float(0), 1.00000000000000000000)); + + Plane_0 _S21 = { vec3(float(0), float(0), float(-1)), - minDepthVS_0 }; + +#line 111 + uint _S22 = _S14.groupIndex_0; + + i_0 = _S22; + for(;;) + { + +#line 113 + if(i_0 < numPointLights_0._data) + { + } + else + { + break; + } + +#line 115 + PointLight_0 light_0 = ((pointLights_0)._data[(i_0)]); + + + + tAppendLight_0(i_0); + bool _S23 = PointLight_insidePlane_0(light_0, _S21); + +#line 120 + if(!_S23) + { + oAppendLight_0(i_0); + +#line 120 + } + else + { + +#line 120 + } + +#line 113 + uint i_1 = i_0 + uint(32) * uint(32); + +#line 113 + i_0 = i_1; + } + +#line 127 + groupMemoryBarrier(), barrier(); + + if(_S14.groupIndex_0 == uint(0)) + { + ((oLightIndexStartOffset_0) = atomicAdd((((oLightIndexCounter_0)._data[(uint(0))])), (oLightCount_0))); + imageStore((oLightGrid_0), ivec2((_S14.groupID_0.xy)), uvec4(uvec2(oLightIndexStartOffset_0, oLightCount_0), uint(0), uint(0))); + + ((tLightIndexStartOffset_0) = atomicAdd((((tLightIndexCounter_0)._data[(uint(0))])), (tLightCount_0))); + imageStore((tLightGrid_0), ivec2((_S14.groupID_0.xy)), uvec4(uvec2(tLightIndexStartOffset_0, tLightCount_0), uint(0), uint(0))); + +#line 129 + } + else + { + +#line 129 + } + +#line 137 + groupMemoryBarrier(), barrier(); + +#line 137 + uint _S24 = _S14.groupIndex_0; + + j_0 = _S24; + for(;;) + { + +#line 139 + if(j_0 < oLightCount_0) + { + } + else + { + break; + } + +#line 141 + ((oLightIndexList_0)._data[(oLightIndexStartOffset_0 + j_0)]) = oLightList_0[j_0]; + +#line 139 + uint j_1 = j_0 + uint(32) * uint(32); + +#line 139 + j_0 = j_1; + } + +#line 139 + uint _S25 = _S14.groupIndex_0; + +#line 145 + k_0 = _S25; + for(;;) + { + +#line 145 + if(k_0 < tLightCount_0) + { + } + else + { + break; + } + +#line 147 + ((tLightIndexList_0)._data[(tLightIndexStartOffset_0 + k_0)]) = tLightList_0[k_0]; + +#line 145 + uint k_1 = k_0 + uint(32) * uint(32); + +#line 145 + k_0 = k_1; + } + +#line 151 + return; +} + diff --git a/res/shaders/fragment.glsl b/res/shaders/fragment.glsl index d710148..6a2caae 100644 --- a/res/shaders/fragment.glsl +++ b/res/shaders/fragment.glsl @@ -1,20 +1,44 @@ #version 450 +#extension GL_EXT_nonuniform_qualifier : require layout(row_major) uniform; layout(row_major) buffer; -#line 61 0 +#line 18 0 +layout(binding = 1, set = 1) +uniform texture2D glyphTextures_0[]; + + +#line 14 +layout(binding = 1) +uniform sampler glyphSampler_0; + + +#line 14 layout(location = 0) out vec4 _S1; -#line 61 +#line 62 +layout(location = 0) +in vec2 _S2; + + +#line 62 +flat layout(location = 1) +in uint _S3; + + +#line 62 void main() { -#line 61 - _S1 = vec4(float(0), float(1), float(0), float(1)); +#line 68 + vec4 _S4 = (texture(sampler2D(glyphTextures_0[_S3],glyphSampler_0), (_S2))); -#line 61 +#line 68 + _S1 = _S4; + +#line 68 return; } diff --git a/res/shaders/frustums.glsl b/res/shaders/frustums.glsl new file mode 100644 index 0000000..fa30189 --- /dev/null +++ b/res/shaders/frustums.glsl @@ -0,0 +1,197 @@ +#version 450 +layout(row_major) uniform; +layout(row_major) buffer; + +#line 5 0 +struct ViewParameter_0 +{ + mat4x4 viewMatrix_0; + mat4x4 projectionMatrix_0; + mat4x4 inverseProjection_0; + vec4 cameraPos_WS_0; + vec2 screenDimensions_0; +}; + +layout(binding = 0) +layout(std140) uniform _S1 +{ + ViewParameter_0 _data; +} gViewParams_0; + +#line 17 +vec4 clipToView_0(vec4 clip_0) +{ + + vec4 view_0 = (((clip_0) * (gViewParams_0._data.inverseProjection_0))); + + vec4 view_1 = view_0 / view_0.w; + + return view_1; +} + + +vec4 screenToView_0(vec4 screen_0) +{ + + vec2 texCoord_0 = screen_0.xy / gViewParams_0._data.screenDimensions_0; + +#line 36 + vec4 _S2 = clipToView_0(vec4(vec2(texCoord_0.x, 1.00000000000000000000 - texCoord_0.y) * 2.00000000000000000000 - 1.00000000000000000000, screen_0.z, screen_0.w)); + +#line 36 + return _S2; +} + +struct Plane_0 +{ + vec3 n_0; + float d_0; +}; + + +#line 49 +Plane_0 computePlane_0(vec3 p0_0, vec3 p1_0, vec3 p2_0) +{ + Plane_0 plane_0; + +#line 56 + vec3 _S3 = cross(p1_0 - p0_0, p2_0 - p0_0); + +#line 56 + vec3 _S4 = normalize(_S3); + +#line 56 + plane_0.n_0 = _S4; + + float _S5 = dot(plane_0.n_0, p0_0); + +#line 58 + plane_0.d_0 = _S5; + + return plane_0; +} + + +#line 12 1 +struct SLANG_ParameterGroup_DispatchParams_0 +{ + uvec3 numThreadGroups_0; + uint pad0_0; + uvec3 numThreads_0; + uint pad1_0; +}; + + +#line 12 +layout(binding = 1) +layout(std140) uniform _S6 +{ + SLANG_ParameterGroup_DispatchParams_0 _data; +} DispatchParams_0; + +#line 45 0 +struct Frustum_0 +{ + Plane_0 planes_0[4]; +}; + + +#line 20 1 +layout(std430, binding = 2) buffer _S7 { + Frustum_0 _data[]; +} out_Frustums_0; + +#line 3 +struct ComputeShaderInput_0 +{ + uvec3 groupID_0; + uvec3 groupThreadID_0; + uvec3 dispatchThreadID_0; + uint groupIndex_0; +}; + + +#line 25 +layout(local_size_x = 32, local_size_y = 32, local_size_z = 1) in; +void main() +{ + int i_0; + +#line 25 + ComputeShaderInput_0 _S8 = ComputeShaderInput_0(gl_WorkGroupID, gl_LocalInvocationID, gl_GlobalInvocationID, gl_LocalInvocationIndex); + + const vec3 eyePos_0 = vec3(float(0), float(0), float(0)); + + vec4 screenSpace_0[4]; + + screenSpace_0[0] = vec4(vec2(_S8.dispatchThreadID_0.xy * uint(32)), -1.00000000000000000000, 1.00000000000000000000); + screenSpace_0[1] = vec4(vec2(float(_S8.dispatchThreadID_0.x + uint(1)), float(_S8.dispatchThreadID_0.y)) * float(uint(32)), -1.00000000000000000000, 1.00000000000000000000); + screenSpace_0[2] = vec4(vec2(float(_S8.dispatchThreadID_0.x), float(_S8.dispatchThreadID_0.y + uint(1))) * float(uint(32)), -1.00000000000000000000, 1.00000000000000000000); + screenSpace_0[3] = vec4(vec2(float(_S8.dispatchThreadID_0.x + uint(1)), float(_S8.dispatchThreadID_0.y + uint(1))) * float(uint(32)), -1.00000000000000000000, 1.00000000000000000000); + + + vec3 viewSpace_0[4]; + + i_0 = 0; + for(;;) + { + +#line 39 + if(i_0 < 4) + { + } + else + { + break; + } + +#line 41 + vec4 _S9 = screenToView_0(screenSpace_0[i_0]); + +#line 41 + viewSpace_0[i_0] = _S9.xyz; + +#line 39 + int _S10 = i_0 + int(1); + +#line 39 + i_0 = _S10; + } + +#line 45 + Frustum_0 frustum_0; + + Plane_0 _S11 = computePlane_0(eyePos_0, viewSpace_0[2], viewSpace_0[0]); + +#line 47 + frustum_0.planes_0[0] = _S11; + Plane_0 _S12 = computePlane_0(eyePos_0, viewSpace_0[1], viewSpace_0[3]); + +#line 48 + frustum_0.planes_0[1] = _S12; + Plane_0 _S13 = computePlane_0(eyePos_0, viewSpace_0[0], viewSpace_0[1]); + +#line 49 + frustum_0.planes_0[2] = _S13; + Plane_0 _S14 = computePlane_0(eyePos_0, viewSpace_0[3], viewSpace_0[2]); + +#line 50 + frustum_0.planes_0[3] = _S14; + + if(_S8.dispatchThreadID_0.x < DispatchParams_0._data.numThreads_0.x && _S8.dispatchThreadID_0.y < DispatchParams_0._data.numThreads_0.y) + { + + ((out_Frustums_0)._data[(_S8.dispatchThreadID_0.x + _S8.dispatchThreadID_0.y * DispatchParams_0._data.numThreads_0.x)]) = frustum_0; + +#line 52 + } + else + { + +#line 52 + } + +#line 57 + return; +} + diff --git a/res/shaders/vertex.glsl b/res/shaders/vertex.glsl index 6fbe6ae..cf15c35 100644 --- a/res/shaders/vertex.glsl +++ b/res/shaders/vertex.glsl @@ -2,7 +2,7 @@ layout(row_major) uniform; layout(row_major) buffer; -#line 7 0 +#line 2 0 struct GlyphData_0 { vec2 bearing_0; @@ -10,55 +10,54 @@ struct GlyphData_0 }; -layout(std430, binding = 1) readonly buffer _S1 { +#line 16 +layout(std430, binding = 0, set = 1) readonly buffer _S1 { GlyphData_0 _data[]; } glyphData_0; -#line 1 -struct ViewParameter_0 +layout(push_constant) +layout(std140) uniform _S2 +{ + float _data; +} scale_0; + +#line 7 +struct ViewData_0 { mat4x4 projectionMatrix_0; }; - -#line 5 layout(binding = 0) -layout(std140) uniform _S2 +layout(std140) uniform _S3 { - ViewParameter_0 _data; -} gViewParams_0; + ViewData_0 _data; +} viewData_0; -#line 5 +#line 12 layout(location = 0) -out vec2 _S3; +out vec2 _S4; -#line 5 +#line 12 layout(location = 1) -out uint _S4; +out uint _S5; -#line 5 +#line 12 layout(location = 0) -in uint _S5; +in uint _S6; -#line 5 +#line 12 layout(location = 1) -in vec2 _S6; +in vec2 _S7; -#line 5 -layout(location = 2) -in float _S7; - - -#line 20 +#line 22 struct VertexStageInput_0 { uint glyphIndex_0; vec2 position_0; - float scale_0; uint vertexId_0; }; @@ -73,42 +72,42 @@ struct VertexStageOutput_0 void main() { -#line 36 - VertexStageInput_0 _S8 = VertexStageInput_0(_S5, _S6, _S7, uint(gl_VertexIndex)); +#line 37 + VertexStageInput_0 _S8 = VertexStageInput_0(_S6, _S7, uint(gl_VertexIndex)); GlyphData_0 glyph_0 = ((glyphData_0)._data[(_S8.glyphIndex_0)]); - float xpos_0 = _S8.position_0.x + glyph_0.bearing_0.x * _S8.scale_0; - float ypos_0 = _S8.position_0.y - (glyph_0.size_0.y - glyph_0.bearing_0.y) * _S8.scale_0; + float xpos_0 = _S8.position_0.x + glyph_0.bearing_0.x * scale_0._data; + float ypos_0 = _S8.position_0.y - (glyph_0.size_0.y - glyph_0.bearing_0.y) * scale_0._data; - float w_0 = glyph_0.size_0.x * _S8.scale_0; + float w_0 = glyph_0.size_0.x * scale_0._data; + float h_0 = glyph_0.size_0.y * scale_0._data; + vec4 coordinates_0[4] = { vec4(xpos_0, ypos_0 + h_0, float(0), float(0)), vec4(xpos_0, ypos_0, float(0), float(1)), vec4(xpos_0 + w_0, ypos_0, float(1), float(0)), vec4(xpos_0 + w_0, ypos_0 + h_0, float(1), float(1)) }; - vec4 coordinates_0[4] = { vec4(xpos_0, ypos_0 + glyph_0.size_0.y * _S8.scale_0, float(0), float(0)), vec4(xpos_0, ypos_0, float(0), float(1)), vec4(xpos_0 + w_0, ypos_0, float(1), float(0)), vec4(xpos_0 + w_0, ypos_0 + w_0, float(1), float(1)) }; - -#line 46 +#line 47 vec4 vertex_0 = coordinates_0[_S8.vertexId_0]; -#line 53 +#line 54 VertexStageOutput_0 output_0; output_0.uvCoords_0 = vertex_0.zw; - vec4 _S9 = (((vec4(vertex_0.xy, float(0), float(1))) * (gViewParams_0._data.projectionMatrix_0))); + vec4 _S9 = (((vec4(vertex_0.xy, float(0), float(1))) * (viewData_0._data.projectionMatrix_0))); -#line 55 +#line 56 output_0.position_1 = _S9; output_0.glyphIndex_1 = _S8.glyphIndex_0; VertexStageOutput_0 _S10 = output_0; -#line 57 +#line 58 gl_Position = _S10.position_1; -#line 57 - _S3 = _S10.uvCoords_0; +#line 58 + _S4 = _S10.uvCoords_0; -#line 57 - _S4 = _S10.glyphIndex_1; +#line 58 + _S5 = _S10.glyphIndex_1; -#line 57 +#line 58 return; } diff --git a/src/Engine/Asset/FontAsset.cpp b/src/Engine/Asset/FontAsset.cpp index 4ccb9b1..01245fd 100644 --- a/src/Engine/Asset/FontAsset.cpp +++ b/src/Engine/Asset/FontAsset.cpp @@ -30,6 +30,10 @@ void FontAsset::save() assert(false && "Cannot save font files"); } +// in case of the space character there is no bitmap +// so we create a single pixel empty texture +uint8 transparentPixel = 0; + void FontAsset::load() { FT_Library ft; @@ -43,18 +47,26 @@ void FontAsset::load() if(FT_Load_Char(face, c, FT_LOAD_RENDER)) { std::cout << "error loading " << (char)c << std::endl; + continue; } + Glyph& glyph = glyphs[c]; + glyph.size = IVector2(face->glyph->bitmap.width, face->glyph->bitmap.rows); + glyph.bearing = IVector2(face->glyph->bitmap_left, face->glyph->bitmap_top); + glyph.advance = face->glyph->advance.x; TextureCreateInfo imageData; imageData.format = Gfx::SE_FORMAT_R8_UINT; imageData.width = face->glyph->bitmap.width; imageData.height = face->glyph->bitmap.rows; imageData.resourceData.data = face->glyph->bitmap.buffer; imageData.resourceData.size = imageData.width * imageData.height; - Glyph& glyph = glyphs[c]; + if(imageData.width == 0 || imageData.width == 0) + { + imageData.width = 1; + imageData.height = 1; + imageData.resourceData.size = sizeof(uint8); + imageData.resourceData.data = &transparentPixel; + } glyph.texture = graphics->createTexture2D(imageData); - glyph.size = IVector2(face->glyph->bitmap.width, face->glyph->bitmap.rows); - glyph.bearing = IVector2(face->glyph->bitmap_left, face->glyph->bitmap_top); - glyph.advance = face->glyph->advance.x; } FT_Done_Face(face); FT_Done_FreeType(ft); diff --git a/src/Engine/Asset/FontLoader.h b/src/Engine/Asset/FontLoader.h index 331ada5..390044f 100644 --- a/src/Engine/Asset/FontLoader.h +++ b/src/Engine/Asset/FontLoader.h @@ -1,7 +1,6 @@ #pragma once #include "MinimalEngine.h" #include "Containers/List.h" -#include "ThreadPool.h" #include namespace Seele diff --git a/src/Engine/Asset/MaterialLoader.cpp b/src/Engine/Asset/MaterialLoader.cpp index f50d881..32909f0 100644 --- a/src/Engine/Asset/MaterialLoader.cpp +++ b/src/Engine/Asset/MaterialLoader.cpp @@ -32,7 +32,7 @@ void MaterialLoader::import(std::filesystem::path, PMaterialAsset asset) asset->load(); graphics->getShaderCompiler()->registerMaterial(asset); AssetRegistry::get().registerMaterial(asset); - //co_return; + ////co_return; } PMaterialAsset MaterialLoader::getPlaceHolderMaterial() diff --git a/src/Engine/Asset/MaterialLoader.h b/src/Engine/Asset/MaterialLoader.h index b011a08..1d452fd 100644 --- a/src/Engine/Asset/MaterialLoader.h +++ b/src/Engine/Asset/MaterialLoader.h @@ -1,7 +1,6 @@ #pragma once #include "MinimalEngine.h" #include "Containers/List.h" -#include "ThreadPool.h" #include namespace Seele diff --git a/src/Engine/Asset/MeshLoader.h b/src/Engine/Asset/MeshLoader.h index e313931..c929ba2 100644 --- a/src/Engine/Asset/MeshLoader.h +++ b/src/Engine/Asset/MeshLoader.h @@ -1,7 +1,6 @@ #pragma once #include "MinimalEngine.h" #include "Containers/List.h" -#include "ThreadPool.h" #include struct aiScene; diff --git a/src/Engine/Asset/TextureLoader.cpp b/src/Engine/Asset/TextureLoader.cpp index 06e53fb..08350d0 100644 --- a/src/Engine/Asset/TextureLoader.cpp +++ b/src/Engine/Asset/TextureLoader.cpp @@ -71,5 +71,5 @@ void TextureLoader::import(std::filesystem::path path, PTextureAsset textureAsse textureAsset->load(); textureAsset->setStatus(Asset::Status::Ready); - //co_return; + ////co_return; } \ No newline at end of file diff --git a/src/Engine/Asset/TextureLoader.h b/src/Engine/Asset/TextureLoader.h index 5a7ea5d..f527f3f 100644 --- a/src/Engine/Asset/TextureLoader.h +++ b/src/Engine/Asset/TextureLoader.h @@ -1,7 +1,6 @@ #pragma once #include "MinimalEngine.h" #include "Containers/List.h" -#include "ThreadPool.h" #include namespace Seele diff --git a/src/Engine/CMakeLists.txt b/src/Engine/CMakeLists.txt index 0b39d31..35054ff 100644 --- a/src/Engine/CMakeLists.txt +++ b/src/Engine/CMakeLists.txt @@ -3,8 +3,6 @@ target_sources(Engine EngineTypes.h MinimalEngine.h MinimalEngine.cpp - ThreadPool.h - ThreadPool.cpp main.cpp) add_subdirectory(Asset/) diff --git a/src/Engine/Containers/Array.h b/src/Engine/Containers/Array.h index 83c7abd..9bccde0 100644 --- a/src/Engine/Containers/Array.h +++ b/src/Engine/Containers/Array.h @@ -247,8 +247,8 @@ public: } return endIt; } - //template Pred> template + requires std::predicate constexpr iterator find(Pred pred) const noexcept { for (size_type i = 0; i < arraySize; ++i) @@ -337,9 +337,9 @@ public: } constexpr void remove(iterator it, bool keepOrder = true) { - remove(it - beginIt, keepOrder); + removeAt(it - beginIt, keepOrder); } - constexpr void remove(size_type index, bool keepOrder = true) + constexpr void removeAt(size_type index, bool keepOrder = true) { if (keepOrder) { diff --git a/src/Engine/Containers/Map.h b/src/Engine/Containers/Map.h index 86cfdef..98a7038 100644 --- a/src/Engine/Containers/Map.h +++ b/src/Engine/Containers/Map.h @@ -232,16 +232,16 @@ public: , root(other.root) , _size(other._size) , comp(other.comp) + , iteratorsDirty(true) { - markIteratorsDirty(); } constexpr Map(Map&& other) noexcept : nodeContainer(std::move(other.nodeContainer)) , root(std::move(other.root)) , _size(std::move(other._size)) , comp(std::move(other.comp)) + , iteratorsDirty(true) { - markIteratorsDirty(); } constexpr ~Map() noexcept { diff --git a/src/Engine/Graphics/GraphicsEnums.cpp b/src/Engine/Graphics/GraphicsEnums.cpp index 536bef5..16465c9 100644 --- a/src/Engine/Graphics/GraphicsEnums.cpp +++ b/src/Engine/Graphics/GraphicsEnums.cpp @@ -1,6 +1,6 @@ #include "GraphicsEnums.h" -using namespace Gfx; +using namespace Seele; uint32 Gfx::currentFrameIndex = 0; double Gfx::currentFrameDelta = 0; \ No newline at end of file diff --git a/src/Engine/Graphics/GraphicsEnums.h b/src/Engine/Graphics/GraphicsEnums.h index ea63ee9..89f1c88 100644 --- a/src/Engine/Graphics/GraphicsEnums.h +++ b/src/Engine/Graphics/GraphicsEnums.h @@ -1,8 +1,8 @@ #pragma once #include "MinimalEngine.h" + namespace Seele { - enum class KeyCode { /* Printable keys */ diff --git a/src/Engine/Graphics/GraphicsInitializer.h b/src/Engine/Graphics/GraphicsInitializer.h index 81c91f2..bf77843 100644 --- a/src/Engine/Graphics/GraphicsInitializer.h +++ b/src/Engine/Graphics/GraphicsInitializer.h @@ -23,7 +23,7 @@ struct GraphicsInitializer : applicationName("SeeleEngine") , engineName("SeeleEngine") , windowLayoutFile(nullptr) - , layers{} + , layers{"VK_LAYER_KHRONOS_validation"} , instanceExtensions{} , deviceExtensions{"VK_KHR_swapchain"} , windowHandle(nullptr) @@ -101,12 +101,13 @@ struct IndexBufferCreateInfo struct UniformBufferCreateInfo { BulkResourceData resourceData = BulkResourceData(); - uint8 bDynamic : 1 = 0; + uint8 bDynamic = 0; }; struct StructuredBufferCreateInfo { BulkResourceData resourceData; - uint8 bDynamic: 1; + uint32 stride; + uint8 bDynamic = 0; }; struct ShaderCreateInfo { diff --git a/src/Engine/Graphics/GraphicsResources.cpp b/src/Engine/Graphics/GraphicsResources.cpp index 06de0c2..0acbfcc 100644 --- a/src/Engine/Graphics/GraphicsResources.cpp +++ b/src/Engine/Graphics/GraphicsResources.cpp @@ -194,9 +194,10 @@ bool UniformBuffer::updateContents(const BulkResourceData& resourceData) return true; } -StructuredBuffer::StructuredBuffer(QueueFamilyMapping mapping, const BulkResourceData& resourceData) +StructuredBuffer::StructuredBuffer(QueueFamilyMapping mapping, uint32 stride, const BulkResourceData& resourceData) : Buffer(mapping, resourceData.owner) , contents(resourceData.size) + , stride(stride) { } StructuredBuffer::~StructuredBuffer() @@ -366,12 +367,7 @@ RenderTargetLayout::RenderTargetLayout(Array inputAttac } Window::Window(const WindowCreateInfo &createInfo) - : sizeX(createInfo.width) - , sizeY(createInfo.height) - , bFullscreen(createInfo.bFullscreen) - , title(createInfo.title) - , pixelFormat(createInfo.pixelFormat) - , samples(createInfo.numSamples) + : windowState(createInfo) { } diff --git a/src/Engine/Graphics/GraphicsResources.h b/src/Engine/Graphics/GraphicsResources.h index e674cba..7dfb08c 100644 --- a/src/Engine/Graphics/GraphicsResources.h +++ b/src/Engine/Graphics/GraphicsResources.h @@ -387,11 +387,11 @@ class IndexBuffer : public Buffer public: IndexBuffer(QueueFamilyMapping mapping, uint32 size, Gfx::SeIndexType index, QueueType startQueueType); virtual ~IndexBuffer(); - inline uint32 getNumIndices() const + constexpr uint32 getNumIndices() const { return numIndices; } - inline Gfx::SeIndexType getIndexType() const + constexpr Gfx::SeIndexType getIndexType() const { return indexType; } @@ -409,7 +409,7 @@ DEFINE_REF(IndexBuffer) class StructuredBuffer : public Buffer { public: - StructuredBuffer(QueueFamilyMapping mapping, const BulkResourceData& bulkResourceData); + StructuredBuffer(QueueFamilyMapping mapping, uint32 stride, const BulkResourceData& bulkResourceData); virtual ~StructuredBuffer(); virtual bool updateContents(const BulkResourceData& resourceData); bool isDataEquals(StructuredBuffer* other) @@ -428,12 +428,18 @@ public: } return true; } + constexpr uint32 getStride() const + { + return stride; + } protected: - Array contents; // Inherited via QueueOwnedResource virtual void executeOwnershipBarrier(QueueType newOwner) = 0; virtual void executePipelineBarrier(SeAccessFlags srcAccess, SePipelineStageFlags srcStage, SeAccessFlags dstAccess, SePipelineStageFlags dstStage) = 0; + + Array contents; + uint32 stride; }; DEFINE_REF(StructuredBuffer) @@ -590,28 +596,23 @@ public: virtual void setCloseCallback(std::function callback) = 0; SeFormat getSwapchainFormat() const { - return pixelFormat; + return windowState.pixelFormat; } SeSampleCountFlags getNumSamples() const { - return samples; + return windowState.numSamples; } uint32 getSizeX() const { - return sizeX; + return windowState.width; } uint32 getSizeY() const { - return sizeY; + return windowState.height; } protected: - uint32 sizeX; - uint32 sizeY; - bool bFullscreen; - const char *title; - SeFormat pixelFormat; - uint32 samples; + WindowCreateInfo windowState; }; DEFINE_REF(Window) diff --git a/src/Engine/Graphics/RenderPass/BasePass.cpp b/src/Engine/Graphics/RenderPass/BasePass.cpp index da9b253..0b69011 100644 --- a/src/Engine/Graphics/RenderPass/BasePass.cpp +++ b/src/Engine/Graphics/RenderPass/BasePass.cpp @@ -20,7 +20,7 @@ BasePassMeshProcessor::~BasePassMeshProcessor() { } -MainJob BasePassMeshProcessor::processMeshBatch( +void BasePassMeshProcessor::processMeshBatch( const MeshBatch& batch, // const PPrimitiveComponent primitiveComponent, const Gfx::PRenderPass& renderPass, @@ -66,7 +66,7 @@ MainJob BasePassMeshProcessor::processMeshBatch( } std::scoped_lock lock(commandLock); renderCommands.add(renderCommand); - co_return; + //co_return; } BasePass::BasePass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source) @@ -114,7 +114,7 @@ BasePass::~BasePass() { } -MainJob BasePass::beginFrame() +void BasePass::beginFrame() { processor->clearCommands(); primitiveLayout->reset(); @@ -135,10 +135,10 @@ MainJob BasePass::beginFrame() descriptorSets[INDEX_VIEW_PARAMS]->updateBuffer(0, viewParamBuffer); descriptorSets[INDEX_VIEW_PARAMS]->writeChanges(); //std::cout << "BasePass beginFrame()" << std::endl; - co_return; + //co_return; } -MainJob BasePass::render() +void BasePass::render() { oLightIndexList->pipelineBarrier( Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, @@ -155,23 +155,20 @@ MainJob BasePass::render() descriptorSets[INDEX_LIGHT_ENV]->updateTexture(5, oLightGrid); descriptorSets[INDEX_LIGHT_ENV]->writeChanges(); graphics->beginRenderPass(renderPass); - List jobs; for (auto &&meshBatch : passData.staticDrawList) { - //jobs.add( - co_await processor->processMeshBatch(meshBatch, renderPass, basePassLayout, primitiveLayout, descriptorSets); + processor->processMeshBatch(meshBatch, renderPass, basePassLayout, primitiveLayout, descriptorSets); } - //co_await Job::all(jobs); graphics->executeCommands(processor->getRenderCommands()); graphics->endRenderPass(); //std::cout << "BasePass render()" << std::endl; - co_return; + //co_return; } -MainJob BasePass::endFrame() +void BasePass::endFrame() { //std::cout << "BasePass endFrame()" << std::endl; - co_return; + //co_return; } void BasePass::publishOutputs() diff --git a/src/Engine/Graphics/RenderPass/BasePass.h b/src/Engine/Graphics/RenderPass/BasePass.h index c63ac42..e62eb24 100644 --- a/src/Engine/Graphics/RenderPass/BasePass.h +++ b/src/Engine/Graphics/RenderPass/BasePass.h @@ -11,7 +11,7 @@ public: BasePassMeshProcessor(Gfx::PViewport viewport, Gfx::PGraphics graphics, uint8 translucentBasePass); virtual ~BasePassMeshProcessor(); - virtual MainJob processMeshBatch( + virtual void processMeshBatch( const MeshBatch& batch, // const PPrimitiveComponent primitiveComponent, const Gfx::PRenderPass& renderPass, @@ -37,9 +37,9 @@ class BasePass : public RenderPass public: BasePass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source); virtual ~BasePass(); - virtual MainJob beginFrame() override; - virtual MainJob render() override; - virtual MainJob endFrame() override; + virtual void beginFrame() override; + virtual void render() override; + virtual void endFrame() override; virtual void publishOutputs() override; virtual void createRenderPass() override; static void modifyRenderPassMacros(Map& defines); diff --git a/src/Engine/Graphics/RenderPass/DepthPrepass.cpp b/src/Engine/Graphics/RenderPass/DepthPrepass.cpp index b87b640..2326a12 100644 --- a/src/Engine/Graphics/RenderPass/DepthPrepass.cpp +++ b/src/Engine/Graphics/RenderPass/DepthPrepass.cpp @@ -18,7 +18,7 @@ DepthPrepassMeshProcessor::~DepthPrepassMeshProcessor() { } -MainJob DepthPrepassMeshProcessor::processMeshBatch( +void DepthPrepassMeshProcessor::processMeshBatch( const MeshBatch& batch, // const PPrimitiveComponent primitiveComponent, const Gfx::PRenderPass& renderPass, @@ -27,7 +27,7 @@ MainJob DepthPrepassMeshProcessor::processMeshBatch( Array descriptorSets, int32 /*staticMeshId*/) { - //std::cout << "Depth job started" << std::endl; + //std::cout << "Depth void started" << std::endl; PMaterialAsset material = batch.material; //const Gfx::MaterialShadingModel shadingModel = material->getShadingModel(); @@ -65,7 +65,7 @@ MainJob DepthPrepassMeshProcessor::processMeshBatch( std::scoped_lock lock(commandLock); renderCommands.add(renderCommand); //std::cout << "Finished depth job" << std::endl; - co_return; + //co_return; } DepthPrepass::DepthPrepass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source) @@ -97,7 +97,7 @@ DepthPrepass::~DepthPrepass() { } -MainJob DepthPrepass::beginFrame() +void DepthPrepass::beginFrame() { processor->clearCommands(); primitiveLayout->reset(); @@ -116,33 +116,30 @@ MainJob DepthPrepass::beginFrame() descriptorSets[INDEX_VIEW_PARAMS]->updateBuffer(0, viewParamBuffer); descriptorSets[INDEX_VIEW_PARAMS]->writeChanges(); //std::cout << "DepthPrepass beginFrame()" << std::endl; - co_return; + //co_return; } -MainJob DepthPrepass::render() +void DepthPrepass::render() { depthAttachment->getTexture()->pipelineBarrier( Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT); depthAttachment->getTexture()->transferOwnership(Gfx::QueueType::GRAPHICS); graphics->beginRenderPass(renderPass); - List jobs; for (auto &&meshBatch : passData.staticDrawList) { - //jobs.add( - co_await processor->processMeshBatch(meshBatch, renderPass, depthPrepassLayout, primitiveLayout, descriptorSets); + processor->processMeshBatch(meshBatch, renderPass, depthPrepassLayout, primitiveLayout, descriptorSets); } - //co_await Job::all(jobs); graphics->executeCommands(processor->getRenderCommands()); graphics->endRenderPass(); //std::cout << "DepthPrepass render()" << std::endl; - co_return; + //co_return; } -MainJob DepthPrepass::endFrame() +void DepthPrepass::endFrame() { //std::cout << "DepthPrepass endFrame()" << std::endl; - co_return; + //co_return; } void DepthPrepass::publishOutputs() diff --git a/src/Engine/Graphics/RenderPass/DepthPrepass.h b/src/Engine/Graphics/RenderPass/DepthPrepass.h index 83fad40..db00cbc 100644 --- a/src/Engine/Graphics/RenderPass/DepthPrepass.h +++ b/src/Engine/Graphics/RenderPass/DepthPrepass.h @@ -11,7 +11,7 @@ public: DepthPrepassMeshProcessor(Gfx::PViewport viewport, Gfx::PGraphics graphics); virtual ~DepthPrepassMeshProcessor(); - virtual MainJob processMeshBatch( + virtual void processMeshBatch( const MeshBatch& batch, const Gfx::PRenderPass& renderPass, Gfx::PPipelineLayout pipelineLayout, @@ -34,9 +34,9 @@ class DepthPrepass : public RenderPass public: DepthPrepass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source); ~DepthPrepass(); - virtual MainJob beginFrame() override; - virtual MainJob render() override; - virtual MainJob endFrame() override; + virtual void beginFrame() override; + virtual void render() override; + virtual void endFrame() override; virtual void publishOutputs() override; virtual void createRenderPass() override; static void modifyRenderPassMacros(Map& defines); diff --git a/src/Engine/Graphics/RenderPass/LightCullingPass.cpp b/src/Engine/Graphics/RenderPass/LightCullingPass.cpp index 24b4e27..f6c2069 100644 --- a/src/Engine/Graphics/RenderPass/LightCullingPass.cpp +++ b/src/Engine/Graphics/RenderPass/LightCullingPass.cpp @@ -18,7 +18,7 @@ LightCullingPass::~LightCullingPass() } -MainJob LightCullingPass::beginFrame() +void LightCullingPass::beginFrame() { uint32_t viewportWidth = viewport->getSizeX(); uint32_t viewportHeight = viewport->getSizeY(); @@ -61,13 +61,13 @@ MainJob LightCullingPass::beginFrame() cullingDescriptorSet->updateBuffer(0, viewParamsBuffer); cullingDescriptorSet->updateBuffer(1, dispatchParamsBuffer); - cullingDescriptorSet->updateBuffer(3, frustumBuffer); - cullingDescriptorSet->updateBuffer(4, oLightIndexCounter); - cullingDescriptorSet->updateBuffer(5, tLightIndexCounter); - cullingDescriptorSet->updateBuffer(6, oLightIndexList); - cullingDescriptorSet->updateBuffer(7, tLightIndexList); - cullingDescriptorSet->updateTexture(8, oLightGrid); - cullingDescriptorSet->updateTexture(9, tLightGrid); + cullingDescriptorSet->updateBuffer(3, oLightIndexCounter); + cullingDescriptorSet->updateBuffer(4, tLightIndexCounter); + cullingDescriptorSet->updateBuffer(5, oLightIndexList); + cullingDescriptorSet->updateBuffer(6, tLightIndexList); + cullingDescriptorSet->updateTexture(7, oLightGrid); + cullingDescriptorSet->updateTexture(8, tLightGrid); + cullingDescriptorSet->updateBuffer(9, frustumBuffer); lightEnvDescriptorSet->updateBuffer(0, directLightBuffer); @@ -76,10 +76,10 @@ MainJob LightCullingPass::beginFrame() lightEnvDescriptorSet->updateBuffer(3, numPointLightBuffer); lightEnvDescriptorSet->writeChanges(); //std::cout << "LightCulling beginFrame()" << std::endl; - co_return; + //co_return; } -MainJob LightCullingPass::render() +void LightCullingPass::render() { oLightIndexList->pipelineBarrier( Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, @@ -104,13 +104,13 @@ MainJob LightCullingPass::render() depthAttachment->changeLayout(Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); depthAttachment->transferOwnership(Gfx::QueueType::GRAPHICS); //std::cout << "LightCulling render()" << std::endl; - co_return; + //co_return; } -MainJob LightCullingPass::endFrame() +void LightCullingPass::endFrame() { //std::cout << "LightCulling endFrame()" << std::endl; - co_return; + //co_return; } void LightCullingPass::publishOutputs() @@ -122,65 +122,6 @@ void LightCullingPass::publishOutputs() dispatchParams.numThreadGroups = numThreadGroups; dispatchParams.numThreads = numThreadGroups * glm::uvec3(BLOCK_SIZE, BLOCK_SIZE, 1); - BulkResourceData resourceData; - StructuredBufferCreateInfo structInfo; - uint32 counterReset = 0; - resourceData.size = sizeof(uint32); - resourceData.data = (uint8*)&counterReset; - resourceData.owner = Gfx::QueueType::COMPUTE; - structInfo.bDynamic = true; - structInfo.resourceData = resourceData; - oLightIndexCounter = graphics->createStructuredBuffer(structInfo); - tLightIndexCounter = graphics->createStructuredBuffer(structInfo); - resourceData.data = nullptr; - resourceData.size = sizeof(uint32_t) - * dispatchParams.numThreadGroups.x - * dispatchParams.numThreadGroups.y - * dispatchParams.numThreadGroups.z * 200; - structInfo.resourceData = resourceData; - structInfo.bDynamic = false; - oLightIndexList = graphics->createStructuredBuffer(structInfo); - tLightIndexList = graphics->createStructuredBuffer(structInfo); - resources->registerBufferOutput("LIGHTCULLING_OLIGHTLIST", oLightIndexList); - resources->registerBufferOutput("LIGHTCULLING_TLIGHTLIST", tLightIndexList); - - resourceData.size = sizeof(DirectionalLight) * MAX_DIRECTIONAL_LIGHTS; - structInfo.resourceData = resourceData; - structInfo.bDynamic = true; - directLightBuffer = graphics->createStructuredBuffer(structInfo); - resourceData.size = sizeof(PointLight) * MAX_POINT_LIGHTS; - structInfo.resourceData = resourceData; - pointLightBuffer = graphics->createStructuredBuffer(structInfo); - - UniformBufferCreateInfo uniformInfo; - resourceData.size = sizeof(uint32); - uniformInfo.resourceData = resourceData; - uniformInfo.bDynamic = true; - numDirLightBuffer = graphics->createUniformBuffer(uniformInfo); - uniformInfo.resourceData = resourceData; - uniformInfo.bDynamic = true; - numPointLightBuffer = graphics->createUniformBuffer(uniformInfo); - - resources->registerBufferOutput("DIRECTIONAL_LIGHTS", directLightBuffer); - resources->registerUniformOutput("NUM_DIRECTIONAL_LIGHTS", numDirLightBuffer); - resources->registerBufferOutput("POINT_LIGHTS", pointLightBuffer); - resources->registerUniformOutput("NUM_POINT_LIGHTS", numPointLightBuffer); - - TextureCreateInfo textureInfo; - textureInfo.width = dispatchParams.numThreadGroups.x; - textureInfo.height = dispatchParams.numThreadGroups.y; - textureInfo.format = Gfx::SE_FORMAT_R32G32_UINT; - textureInfo.usage = Gfx::SE_IMAGE_USAGE_STORAGE_BIT; - oLightGrid = graphics->createTexture2D(textureInfo); - tLightGrid = graphics->createTexture2D(textureInfo); - - resources->registerTextureOutput("LIGHTCULLING_OLIGHTGRID", oLightGrid); - resources->registerTextureOutput("LIGHTCULLING_TLIGHTGRID", tLightGrid); -} - - -void LightCullingPass::createRenderPass() -{ cullingDescriptorLayout = graphics->createDescriptorLayout("CullingLayout"); //ViewParams @@ -189,28 +130,28 @@ void LightCullingPass::createRenderPass() cullingDescriptorLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER); //DepthTexture cullingDescriptorLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE); - //Frustums - cullingDescriptorLayout->addDescriptorBinding(3, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER); //o_lightIndexCounter - cullingDescriptorLayout->addDescriptorBinding(4, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER); + cullingDescriptorLayout->addDescriptorBinding(3, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER); //t_lightIndexCounter - cullingDescriptorLayout->addDescriptorBinding(5, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER); + cullingDescriptorLayout->addDescriptorBinding(4, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER); //o_lightIndexList - cullingDescriptorLayout->addDescriptorBinding(6, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER); + cullingDescriptorLayout->addDescriptorBinding(5, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER); //t_lightIndexList - cullingDescriptorLayout->addDescriptorBinding(7, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER); + cullingDescriptorLayout->addDescriptorBinding(6, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER); //o_lightGrid - cullingDescriptorLayout->addDescriptorBinding(8, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE); + cullingDescriptorLayout->addDescriptorBinding(7, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE); //t_lightGrid - cullingDescriptorLayout->addDescriptorBinding(9, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE); + cullingDescriptorLayout->addDescriptorBinding(8, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE); + //Frustums + cullingDescriptorLayout->addDescriptorBinding(9, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, viewportWidth * viewportHeight); lightEnvDescriptorLayout = graphics->createDescriptorLayout("LightEnv"); // Directional Lights - lightEnvDescriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER); + lightEnvDescriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, MAX_DIRECTIONAL_LIGHTS); lightEnvDescriptorLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER); // Point Lights - lightEnvDescriptorLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER); + lightEnvDescriptorLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, MAX_POINT_LIGHTS); lightEnvDescriptorLayout->addDescriptorBinding(3, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER); cullingLayout = graphics->createPipelineLayout(); @@ -238,7 +179,80 @@ void LightCullingPass::createRenderPass() pipelineInfo.computeShader = cullingShader; pipelineInfo.pipelineLayout = cullingLayout; cullingPipeline = graphics->createComputePipeline(pipelineInfo); + + uint32 counterReset = 0; + StructuredBufferCreateInfo structInfo = + { + .resourceData = { + .size = sizeof(uint32), + .data = (uint8*)&counterReset, + .owner = Gfx::QueueType::COMPUTE, + }, + .stride = sizeof(uint32), + .bDynamic = true, + }; + oLightIndexCounter = graphics->createStructuredBuffer(structInfo); + tLightIndexCounter = graphics->createStructuredBuffer(structInfo); + structInfo = { + .resourceData = { + .size = (uint32)sizeof(uint32) + * dispatchParams.numThreadGroups.x + * dispatchParams.numThreadGroups.y + * dispatchParams.numThreadGroups.z * 200, + .data = nullptr, + .owner = Gfx::QueueType::COMPUTE + }, + .stride = sizeof(uint32), + .bDynamic = false, + }; + oLightIndexList = graphics->createStructuredBuffer(structInfo); + tLightIndexList = graphics->createStructuredBuffer(structInfo); + resources->registerBufferOutput("LIGHTCULLING_OLIGHTLIST", oLightIndexList); + resources->registerBufferOutput("LIGHTCULLING_TLIGHTLIST", tLightIndexList); + structInfo = { + .resourceData = { + .size = sizeof(DirectionalLight) * MAX_DIRECTIONAL_LIGHTS, + .data = nullptr, + }, + .stride = sizeof(DirectionalLight), + .bDynamic = true, + }; + directLightBuffer = graphics->createStructuredBuffer(structInfo); + structInfo.resourceData.size = sizeof(PointLight) * MAX_POINT_LIGHTS; + pointLightBuffer = graphics->createStructuredBuffer(structInfo); + + UniformBufferCreateInfo uniformInfo = { + .resourceData = { + .size = sizeof(uint32), + .data = nullptr + }, + .bDynamic = true + }; + numDirLightBuffer = graphics->createUniformBuffer(uniformInfo); + numPointLightBuffer = graphics->createUniformBuffer(uniformInfo); + + resources->registerBufferOutput("DIRECTIONAL_LIGHTS", directLightBuffer); + resources->registerUniformOutput("NUM_DIRECTIONAL_LIGHTS", numDirLightBuffer); + resources->registerBufferOutput("POINT_LIGHTS", pointLightBuffer); + resources->registerUniformOutput("NUM_POINT_LIGHTS", numPointLightBuffer); + + TextureCreateInfo textureInfo = { + .width = dispatchParams.numThreadGroups.x, + .height = dispatchParams.numThreadGroups.y, + .format = Gfx::SE_FORMAT_R32G32_UINT, + .usage = Gfx::SE_IMAGE_USAGE_STORAGE_BIT, + }; + oLightGrid = graphics->createTexture2D(textureInfo); + tLightGrid = graphics->createTexture2D(textureInfo); + + resources->registerTextureOutput("LIGHTCULLING_OLIGHTGRID", oLightGrid); + resources->registerTextureOutput("LIGHTCULLING_TLIGHTGRID", tLightGrid); +} + + +void LightCullingPass::createRenderPass() +{ depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH")->getTexture(); } @@ -254,11 +268,13 @@ void LightCullingPass::setupFrustums() glm::uvec3 numThreads = glm::ceil(glm::vec3(viewportWidth / (float)BLOCK_SIZE, viewportHeight / (float)BLOCK_SIZE, 1)); glm::uvec3 numThreadGroups = glm::ceil(glm::vec3(numThreads.x / (float)BLOCK_SIZE, numThreads.y / (float)BLOCK_SIZE, 1)); - viewParams.viewMatrix = source->getViewMatrix(); - viewParams.projectionMatrix = source->getProjectionMatrix(); - viewParams.inverseProjectionMatrix = glm::inverse(source->getProjectionMatrix()); - viewParams.screenDimensions = glm::vec2(viewportWidth, viewportHeight); - viewParams.cameraPosition = Vector4(source->getCameraPosition(), 0); + viewParams = { + .viewMatrix = source->getViewMatrix(), + .projectionMatrix = source->getProjectionMatrix(), + .inverseProjectionMatrix = glm::inverse(source->getProjectionMatrix()), + .cameraPosition = Vector4(source->getCameraPosition(), 0), + .screenDimensions = glm::vec2(viewportWidth, viewportHeight), + }; dispatchParams.numThreads = numThreads; dispatchParams.numThreadGroups = numThreadGroups; @@ -283,7 +299,6 @@ void LightCullingPass::setupFrustums() createInfo.defines["INDEX_VIEW_PARAMS"] = "0"; frustumShader = graphics->createComputeShader(createInfo); - ComputePipelineCreateInfo pipelineInfo; pipelineInfo.computeShader = frustumShader; pipelineInfo.pipelineLayout = frustumLayout; @@ -304,11 +319,14 @@ void LightCullingPass::setupFrustums() uniformInfo.bDynamic = false; dispatchParamsBuffer = graphics->createUniformBuffer(uniformInfo); - StructuredBufferCreateInfo structuredInfo; - resourceInfo.size = sizeof(Frustum) * numThreads.x * numThreads.y * numThreads.z; - resourceInfo.data = nullptr; - structuredInfo.resourceData = resourceInfo; - structuredInfo.bDynamic = false; + StructuredBufferCreateInfo structuredInfo = { + .resourceData = { + .size = sizeof(Frustum) * numThreads.x * numThreads.y * numThreads.z, + .data = nullptr, + }, + .stride = sizeof(Frustum), + .bDynamic = false, + }; frustumBuffer = graphics->createStructuredBuffer(structuredInfo); frustumDescriptorSet = frustumDescriptorLayout->allocateDescriptorSet(); diff --git a/src/Engine/Graphics/RenderPass/LightCullingPass.h b/src/Engine/Graphics/RenderPass/LightCullingPass.h index a0ceef6..a83e0e8 100644 --- a/src/Engine/Graphics/RenderPass/LightCullingPass.h +++ b/src/Engine/Graphics/RenderPass/LightCullingPass.h @@ -18,9 +18,9 @@ class LightCullingPass : public RenderPass public: LightCullingPass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor camera); virtual ~LightCullingPass(); - virtual MainJob beginFrame() override; - virtual MainJob render() override; - virtual MainJob endFrame() override; + virtual void beginFrame() override; + virtual void render() override; + virtual void endFrame() override; virtual void publishOutputs() override; virtual void createRenderPass() override; static void modifyRenderPassMacros(Map& defines); diff --git a/src/Engine/Graphics/RenderPass/MeshProcessor.h b/src/Engine/Graphics/RenderPass/MeshProcessor.h index a8d84f4..2dd18f4 100644 --- a/src/Engine/Graphics/RenderPass/MeshProcessor.h +++ b/src/Engine/Graphics/RenderPass/MeshProcessor.h @@ -3,7 +3,6 @@ #include "Scene/Scene.h" #include "Graphics/GraphicsResources.h" #include "Graphics/MeshBatch.h" -#include "ThreadPool.h" namespace Seele { @@ -17,7 +16,7 @@ public: protected: PScene scene; Gfx::PGraphics graphics; - virtual MainJob processMeshBatch( + virtual void processMeshBatch( const MeshBatch& batch, // const PPrimitiveComponent primitiveComponent, const Gfx::PRenderPass& renderPass, diff --git a/src/Engine/Graphics/RenderPass/RenderPass.h b/src/Engine/Graphics/RenderPass/RenderPass.h index d87a31a..4d17db3 100644 --- a/src/Engine/Graphics/RenderPass/RenderPass.h +++ b/src/Engine/Graphics/RenderPass/RenderPass.h @@ -2,7 +2,6 @@ #include "MinimalEngine.h" #include "Math/Math.h" #include "RenderGraph.h" -#include "ThreadPool.h" namespace Seele { @@ -22,9 +21,9 @@ public: void updateViewFrame(RenderPassDataType viewFrame) { passData = std::move(viewFrame); } - virtual MainJob beginFrame() = 0; - virtual MainJob render() = 0; - virtual MainJob endFrame() = 0; + virtual void beginFrame() = 0; + virtual void render() = 0; + virtual void endFrame() = 0; virtual void publishOutputs() = 0; virtual void createRenderPass() = 0; void setResources(PRenderGraphResources resources) { this->resources = resources; } diff --git a/src/Engine/Graphics/RenderPass/TextPass.cpp b/src/Engine/Graphics/RenderPass/TextPass.cpp index 0f391a8..5cbeafb 100644 --- a/src/Engine/Graphics/RenderPass/TextPass.cpp +++ b/src/Engine/Graphics/RenderPass/TextPass.cpp @@ -16,7 +16,7 @@ TextPass::~TextPass() } -MainJob TextPass::beginFrame() +void TextPass::beginFrame() { for(TextRender& render : passData.texts) { @@ -37,25 +37,18 @@ MainJob TextPass::beginFrame() vbInfo.numVertices = static_cast(instanceData.size()); vbInfo.vertexSize = sizeof(GlyphInstanceData); vbInfo.resourceData.data = reinterpret_cast(instanceData.data()); - vbInfo.resourceData.size = static_cast(instanceData.size()); + vbInfo.resourceData.size = static_cast(instanceData.size() * sizeof(GlyphInstanceData)); resources.vertexBuffer = graphics->createVertexBuffer(vbInfo); - resources.descriptorSet = descriptorLayout->allocateDescriptorSet(); - resources.descriptorSet->updateBuffer(0, projectionBuffer); - resources.descriptorSet->updateSampler(1, glyphSampler); - resources.descriptorSet->updateBuffer(2, fontData.structuredBuffer); - resources.descriptorSet->writeChanges(); + resources.glyphDataSet = fontData.glyphDataSet; + resources.textureArraySet = fontData.textureArraySet; - resources.textureArraySet = descriptorLayout->allocateDescriptorSet(); - resources.textureArraySet->updateTextureArray(0, fontData.textures); - - resources.textureArraySet->writeChanges(); resources.scale = render.scale; } - co_return; + //co_return; } -MainJob TextPass::render() +void TextPass::render() { graphics->beginRenderPass(renderPass); Array commands; @@ -64,7 +57,7 @@ MainJob TextPass::render() Gfx::PRenderCommand command = graphics->createRenderCommand("TextPassCommand"); command->setViewport(viewport); command->bindPipeline(pipeline); - + command->bindDescriptor({generalSet, resources.glyphDataSet, resources.textureArraySet}); command->bindVertexBuffer({VertexInputStream(0, 0, resources.vertexBuffer)}); command->pushConstants(pipelineLayout, Gfx::SE_SHADER_STAGE_VERTEX_BIT, 0, sizeof(float), &resources.scale); @@ -73,12 +66,13 @@ MainJob TextPass::render() } graphics->executeCommands(commands); graphics->endRenderPass(); - co_return; + textResources.clear(); + //co_return; } -MainJob TextPass::endFrame() +void TextPass::endFrame() { - co_return; + //co_return; } void TextPass::publishOutputs() @@ -123,16 +117,20 @@ void TextPass::createRenderPass() }); declaration = graphics->createVertexDeclaration(elements); - descriptorLayout = graphics->createDescriptorLayout("TextDescriptor"); - descriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER); - descriptorLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_SAMPLER); - descriptorLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, 128, Gfx::SE_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT); - descriptorLayout->create(); + generalLayout = graphics->createDescriptorLayout("TextGeneral"); + generalLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER); + generalLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_SAMPLER); + generalLayout->create(); + + glyphDataLayout = graphics->createDescriptorLayout("TextGlyphData"); + glyphDataLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER); + glyphDataLayout->create(); - textureArrayLayout = graphics->createDescriptorLayout("TextureArray"); + textureArrayLayout = graphics->createDescriptorLayout("TextTextureArray"); textureArrayLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 128, Gfx::SE_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT); textureArrayLayout->create(); + Matrix4 projectionMatrix = glm::ortho(0.f, (float)viewport->getSizeX(), 0.f, (float)viewport->getSizeY()); projectionBuffer = graphics->createUniformBuffer({ .resourceData = { @@ -146,12 +144,18 @@ void TextPass::createRenderPass() .magFilter = Gfx::SE_FILTER_LINEAR, .minFilter = Gfx::SE_FILTER_LINEAR, .addressModeU = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, - .addressModeV = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE + .addressModeV = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, }); + generalSet = generalLayout->allocateDescriptorSet(); + generalSet->updateBuffer(0, projectionBuffer); + generalSet->updateSampler(1, glyphSampler); + generalSet->writeChanges(); + pipelineLayout = graphics->createPipelineLayout(); - pipelineLayout->addDescriptorLayout(0, descriptorLayout); - pipelineLayout->addDescriptorLayout(1, textureArrayLayout); + pipelineLayout->addDescriptorLayout(0, generalLayout); + pipelineLayout->addDescriptorLayout(1, glyphDataLayout); + pipelineLayout->addDescriptorLayout(2, textureArrayLayout); pipelineLayout->addPushConstants({ .stageFlags = Gfx::SE_SHADER_STAGE_VERTEX_BIT, .offset = 0, @@ -168,6 +172,15 @@ void TextPass::createRenderPass() pipelineInfo.renderPass = renderPass; pipelineInfo.pipelineLayout = pipelineLayout; pipelineInfo.rasterizationState.cullMode = Gfx::SE_CULL_MODE_NONE; + pipelineInfo.colorBlend.attachmentCount = 1; + pipelineInfo.colorBlend.blendAttachments[0].blendEnable = true; + pipelineInfo.colorBlend.blendAttachments[0].colorWriteMask = Gfx::SE_COLOR_COMPONENT_R_BIT | Gfx::SE_COLOR_COMPONENT_G_BIT | Gfx::SE_COLOR_COMPONENT_B_BIT | Gfx::SE_COLOR_COMPONENT_A_BIT; + pipelineInfo.colorBlend.blendAttachments[0].srcColorBlendFactor = Gfx::SE_BLEND_FACTOR_SRC_ALPHA; + pipelineInfo.colorBlend.blendAttachments[0].dstColorBlendFactor = Gfx::SE_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; + pipelineInfo.colorBlend.blendAttachments[0].alphaBlendOp = Gfx::SE_BLEND_OP_ADD; + pipelineInfo.colorBlend.blendAttachments[0].srcAlphaBlendFactor = Gfx::SE_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; + pipelineInfo.colorBlend.blendAttachments[0].dstAlphaBlendFactor = Gfx::SE_BLEND_FACTOR_ZERO; + pipelineInfo.colorBlend.blendAttachments[0].alphaBlendOp = Gfx::SE_BLEND_OP_ADD; pipelineInfo.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; pipeline = graphics->createGraphicsPipeline(pipelineInfo); @@ -181,20 +194,33 @@ TextPass::FontData& TextPass::getFontData(PFontAsset font) const Map& fontGlyphs = font->getGlyphData(); FontData& fd = fontData[font]; Array buffer; + Array textures; buffer.reserve(fontGlyphs.size()); for(const auto& [key, value] : fontGlyphs) { fd.characterToGlyphIndex[key] = static_cast(buffer.size()); fd.characterAdvance[key] = value.advance; - fd.textures.add(value.texture); GlyphData& gd = buffer.add(); gd.bearing = value.bearing; gd.size = value.size; + textures.add(value.texture); } - StructuredBufferCreateInfo bufferInfo; - bufferInfo.bDynamic = false; - bufferInfo.resourceData.data = reinterpret_cast(buffer.data()); - bufferInfo.resourceData.size = static_cast(buffer.size()); - fd.structuredBuffer = graphics->createStructuredBuffer(bufferInfo); + StructuredBufferCreateInfo bufferInfo = { + .resourceData = { + .size = static_cast(buffer.size() * sizeof(GlyphData)), + .data = reinterpret_cast(buffer.data()), + }, + .stride = sizeof(GlyphData), + .bDynamic = false, + }; + + Gfx::PStructuredBuffer glyphBuffer = graphics->createStructuredBuffer(bufferInfo); + fd.glyphDataSet = glyphDataLayout->allocateDescriptorSet(); + fd.glyphDataSet->updateBuffer(0, glyphBuffer); + fd.glyphDataSet->writeChanges(); + + fd.textureArraySet = textureArrayLayout->allocateDescriptorSet(); + fd.textureArraySet->updateTextureArray(0, textures); + fd.textureArraySet->writeChanges(); return fontData[font]; } diff --git a/src/Engine/Graphics/RenderPass/TextPass.h b/src/Engine/Graphics/RenderPass/TextPass.h index aeb1d06..5d194c2 100644 --- a/src/Engine/Graphics/RenderPass/TextPass.h +++ b/src/Engine/Graphics/RenderPass/TextPass.h @@ -27,9 +27,9 @@ class TextPass : public RenderPass public: TextPass(Gfx::PGraphics graphics, Gfx::PViewport viewport, Gfx::PRenderTargetAttachment renderTarget); virtual ~TextPass(); - virtual MainJob beginFrame() override; - virtual MainJob render() override; - virtual MainJob endFrame() override; + virtual void beginFrame() override; + virtual void render() override; + virtual void endFrame() override; virtual void publishOutputs() override; virtual void createRenderPass() override; private: @@ -45,8 +45,8 @@ private: }; struct FontData { - Gfx::PStructuredBuffer structuredBuffer; - Array textures; + Gfx::PDescriptorSet glyphDataSet; + Gfx::PDescriptorSet textureArraySet; Map characterToGlyphIndex; // Logically this should be part of GlyphData, // but because GlyphData mirrors shader data and we need @@ -58,9 +58,9 @@ private: struct TextResources { - Gfx::PDescriptorSet descriptorSet; - Gfx::PDescriptorSet textureArraySet; Gfx::PVertexBuffer vertexBuffer; + Gfx::PDescriptorSet glyphDataSet; + Gfx::PDescriptorSet textureArraySet; float scale; }; Array textResources; @@ -69,9 +69,12 @@ private: Gfx::PRenderTargetAttachment depthAttachment; Gfx::PTexture2D depthBuffer; - Gfx::PDescriptorLayout descriptorLayout; + Gfx::PDescriptorLayout generalLayout; + Gfx::PDescriptorLayout glyphDataLayout; Gfx::PDescriptorLayout textureArrayLayout; + Gfx::PDescriptorSet generalSet; + Gfx::PUniformBuffer projectionBuffer; Gfx::PSamplerState glyphSampler; diff --git a/src/Engine/Graphics/RenderPass/UIPass.cpp b/src/Engine/Graphics/RenderPass/UIPass.cpp index 0c59947..7efc8bc 100644 --- a/src/Engine/Graphics/RenderPass/UIPass.cpp +++ b/src/Engine/Graphics/RenderPass/UIPass.cpp @@ -15,12 +15,12 @@ UIPass::~UIPass() } -MainJob UIPass::beginFrame() +void UIPass::beginFrame() { - co_return; + //co_return; } -MainJob UIPass::render() +void UIPass::render() { graphics->beginRenderPass(renderPass); Gfx::PRenderCommand command = graphics->createRenderCommand("UIPassCommand"); @@ -29,12 +29,12 @@ MainJob UIPass::render() command->draw(4, 1, 0, 0); graphics->executeCommands(Array({command})); graphics->endRenderPass(); - co_return; + //co_return; } -MainJob UIPass::endFrame() +void UIPass::endFrame() { - co_return; + //co_return; } void UIPass::publishOutputs() diff --git a/src/Engine/Graphics/RenderPass/UIPass.h b/src/Engine/Graphics/RenderPass/UIPass.h index f2b5248..2e50cd0 100644 --- a/src/Engine/Graphics/RenderPass/UIPass.h +++ b/src/Engine/Graphics/RenderPass/UIPass.h @@ -16,9 +16,9 @@ class UIPass : public RenderPass public: UIPass(Gfx::PGraphics graphics, Gfx::PViewport viewport, Gfx::PRenderTargetAttachment renderTarget); virtual ~UIPass(); - virtual MainJob beginFrame() override; - virtual MainJob render() override; - virtual MainJob endFrame() override; + virtual void beginFrame() override; + virtual void render() override; + virtual void endFrame() override; virtual void publishOutputs() override; virtual void createRenderPass() override; private: diff --git a/src/Engine/Graphics/Vulkan/VulkanAllocator.cpp b/src/Engine/Graphics/Vulkan/VulkanAllocator.cpp index fbcef8c..cc3ac44 100644 --- a/src/Engine/Graphics/Vulkan/VulkanAllocator.cpp +++ b/src/Engine/Graphics/Vulkan/VulkanAllocator.cpp @@ -90,10 +90,9 @@ PSubAllocation Allocation::getSuballocation(VkDeviceSize requestedSize, VkDevice return nullptr; } } - for (auto it : freeRanges) + for (auto& [allocatedOffset, freeAllocation] : freeRanges) { - PSubAllocation freeAllocation = it.value; - VkDeviceSize allocatedOffset = freeAllocation->allocatedOffset; + assert(allocatedOffset == freeAllocation->allocatedOffset); VkDeviceSize alignedOffset = align(allocatedOffset, alignment); VkDeviceSize alignmentAdjustment = alignedOffset - allocatedOffset; VkDeviceSize size = alignmentAdjustment + requestedSize; @@ -112,8 +111,8 @@ PSubAllocation Allocation::getSuballocation(VkDeviceSize requestedSize, VkDevice freeAllocation->alignedOffset += size; PSubAllocation subAlloc = new SubAllocation(this, allocatedOffset, size, alignedOffset, size); activeAllocations[allocatedOffset] = subAlloc.getHandle(); - freeRanges.erase(allocatedOffset); freeRanges[freeAllocation->allocatedOffset] = freeAllocation; + freeRanges.erase(allocatedOffset); bytesUsed += size; return subAlloc; } @@ -136,9 +135,8 @@ void Allocation::markFree(SubAllocation *allocation) { std::scoped_lock lck(lock); //Join lower bound - for (auto freeRange : freeRanges) + for (auto& [allocatedOffset, freeAlloc] : freeRanges) { - PSubAllocation freeAlloc = freeRange.value; if (freeAlloc->allocatedOffset <= lowerBound && freeAlloc->allocatedOffset + freeAlloc->allocatedSize >= upperBound) { @@ -157,24 +155,24 @@ void Allocation::markFree(SubAllocation *allocation) auto foundAlloc = freeRanges.find(upperBound); if (foundAlloc != freeRanges.end()) { - freeRangeToDelete = foundAlloc->value; + freeRangeToDelete = foundAlloc->second; // There is a free allocation ending where the new free one ends if (allocHandle != nullptr) { // extend allocHandle by another foundAlloc->allocatedSize bytes - allocHandle->allocatedSize += foundAlloc->value->allocatedSize; - freeRanges.erase(foundAlloc->key); + allocHandle->allocatedSize += foundAlloc->second->allocatedSize; + freeRanges.erase(foundAlloc->first); } else { // set foundAlloc back by size amount - allocHandle = foundAlloc->value; + allocHandle = foundAlloc->second; allocHandle->allocatedOffset -= allocation->allocatedSize; allocHandle->alignedOffset -= allocation->allocatedSize; // place back at correct offset freeRanges[allocHandle->allocatedOffset] = allocHandle; // remove from offset map since key changes - freeRanges.erase(foundAlloc->key); + freeRanges.erase(foundAlloc->first); } } @@ -259,7 +257,7 @@ void Allocator::free(Allocation *allocation) { if (heap.allocations[i] == allocation) { - heap.allocations.remove(i, false); + heap.allocations.removeAt(i, false); return; } } diff --git a/src/Engine/Graphics/Vulkan/VulkanAllocator.h b/src/Engine/Graphics/Vulkan/VulkanAllocator.h index 2c911a6..0d3f32d 100644 --- a/src/Engine/Graphics/Vulkan/VulkanAllocator.h +++ b/src/Engine/Graphics/Vulkan/VulkanAllocator.h @@ -99,8 +99,8 @@ private: VkDeviceSize bytesAllocated; VkDeviceSize bytesUsed; VkDeviceMemory allocatedMemory; - Map activeAllocations; - Map freeRanges; + std::map activeAllocations; + std::map freeRanges; std::mutex lock; void *mappedPointer; uint8 isDedicated : 1; diff --git a/src/Engine/Graphics/Vulkan/VulkanBuffer.cpp b/src/Engine/Graphics/Vulkan/VulkanBuffer.cpp index 62c44c8..8889756 100644 --- a/src/Engine/Graphics/Vulkan/VulkanBuffer.cpp +++ b/src/Engine/Graphics/Vulkan/VulkanBuffer.cpp @@ -3,7 +3,6 @@ #include "VulkanGraphics.h" #include "VulkanCommandBuffer.h" #include "VulkanAllocator.h" -#include "ThreadPool.h" using namespace Seele; using namespace Seele::Vulkan; @@ -65,11 +64,11 @@ ShaderBuffer::~ShaderBuffer() { PCmdBuffer cmdBuffer = graphics->getQueueCommands(owner)->getCommands(); VkDevice device = graphics->getDevice(); - auto deletionLambda = [cmdBuffer, device](VkBuffer buffer) -> Job + auto deletionLambda = [cmdBuffer, device](VkBuffer buffer) -> void { //co_await cmdBuffer->asyncWait(); //vkDestroyBuffer(device, buffer, nullptr); - co_return; + //co_return; }; for (uint32 i = 0; i < numBuffers; ++i) { @@ -355,7 +354,7 @@ VkAccessFlags UniformBuffer::getDestAccessMask() } StructuredBuffer::StructuredBuffer(PGraphics graphics, const StructuredBufferCreateInfo &resourceData) - : Gfx::StructuredBuffer(graphics->getFamilyMapping(), resourceData.resourceData) + : Gfx::StructuredBuffer(graphics->getFamilyMapping(), resourceData.stride, resourceData.resourceData) , Vulkan::ShaderBuffer(graphics, resourceData.resourceData.size, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, currentOwner, resourceData.bDynamic) { if (resourceData.resourceData.data != nullptr) diff --git a/src/Engine/Graphics/Vulkan/VulkanCommandBuffer.cpp b/src/Engine/Graphics/Vulkan/VulkanCommandBuffer.cpp index 019ed7c..8724a4a 100644 --- a/src/Engine/Graphics/Vulkan/VulkanCommandBuffer.cpp +++ b/src/Engine/Graphics/Vulkan/VulkanCommandBuffer.cpp @@ -250,6 +250,7 @@ void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet) { assert(threadId == std::this_thread::get_id()); auto descriptor = descriptorSet.cast(); + assert(descriptor->writeDescriptors.size() == 0); boundDescriptors.add(descriptor.getHandle()); descriptor->bind(); @@ -263,6 +264,7 @@ void RenderCommand::bindDescriptor(const Array& descriptorS for(uint32 i = 0; i < descriptorSets.size(); ++i) { auto descriptorSet = descriptorSets[i].cast(); + assert(descriptorSet->writeDescriptors.size() == 0); descriptorSet->bind(); boundDescriptors.add(descriptorSet.getHandle()); @@ -370,6 +372,7 @@ void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet) { assert(threadId == std::this_thread::get_id()); auto descriptor = descriptorSet.cast(); + assert(descriptor->writeDescriptors.size() == 0); boundDescriptors.add(descriptor.getHandle()); descriptor->bind(); @@ -384,9 +387,11 @@ void ComputeCommand::bindDescriptor(const Array& descriptor for(uint32 i = 0; i < descriptorSets.size(); ++i) { auto descriptorSet = descriptorSets[i].cast(); - boundDescriptors.add(descriptorSet.getHandle()); + assert(descriptorSet->writeDescriptors.size() == 0); descriptorSet->bind(); + //std::cout << "Binding descriptor " << descriptorSet->getHandle() << " to cmd " << handle << std::endl; + boundDescriptors.add(descriptorSet.getHandle()); sets[descriptorSet->getSetIndex()] = descriptorSet->getHandle(); } vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline->getLayout(), 0, (uint32)descriptorSets.size(), sets, 0, nullptr); diff --git a/src/Engine/Graphics/Vulkan/VulkanDescriptorSets.cpp b/src/Engine/Graphics/Vulkan/VulkanDescriptorSets.cpp index c93fa39..e35cf3c 100644 --- a/src/Engine/Graphics/Vulkan/VulkanDescriptorSets.cpp +++ b/src/Engine/Graphics/Vulkan/VulkanDescriptorSets.cpp @@ -139,9 +139,9 @@ void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBu cachedData[binding] = new UniformBuffer(*vulkanBuffer.getHandle()); } -void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PStructuredBuffer uniformBuffer) +void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PStructuredBuffer structuredBuffer) { - PStructuredBuffer vulkanBuffer = uniformBuffer.cast(); + PStructuredBuffer vulkanBuffer = structuredBuffer.cast(); StructuredBuffer* cachedBuffer = reinterpret_cast(cachedData[binding]); if(vulkanBuffer.getHandle() == cachedBuffer) { @@ -330,7 +330,7 @@ void DescriptorAllocator::allocateDescriptorSet(Gfx::PDescriptorSet &descriptorS uint32 counts = 0; for(const auto& binding : layout.bindings) { - if(binding.binding & Gfx::SE_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT) + if(binding.descriptorCount > 0) { counts = binding.descriptorCount; } diff --git a/src/Engine/Graphics/Vulkan/VulkanDescriptorSets.h b/src/Engine/Graphics/Vulkan/VulkanDescriptorSets.h index 4ec3cce..4265dcf 100644 --- a/src/Engine/Graphics/Vulkan/VulkanDescriptorSets.h +++ b/src/Engine/Graphics/Vulkan/VulkanDescriptorSets.h @@ -119,6 +119,8 @@ private: bool currentlyInUse; friend class DescriptorAllocator; friend class CmdBuffer; + friend class RenderCommand; + friend class ComputeCommand; }; DEFINE_REF(DescriptorSet) diff --git a/src/Engine/Graphics/Vulkan/VulkanGraphics.cpp b/src/Engine/Graphics/Vulkan/VulkanGraphics.cpp index 2578f81..cb2989a 100644 --- a/src/Engine/Graphics/Vulkan/VulkanGraphics.cpp +++ b/src/Engine/Graphics/Vulkan/VulkanGraphics.cpp @@ -12,6 +12,7 @@ #include "Graphics/GraphicsResources.h" #include +using namespace Seele; using namespace Seele::Vulkan; thread_local PCommandBufferManager Seele::Vulkan::Graphics::graphicsCommands = nullptr; @@ -570,7 +571,7 @@ void Graphics::createDevice(GraphicsInitializer initializer) VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_RESOURCE_TRACKING_BIT_NV | VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_AUTOMATIC_CHECKPOINTS_BIT_NV | VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_SHADER_DEBUG_INFO_BIT_NV; - deviceInfo.pNext = &crashDiagInfo; + descriptorIndexing.pNext = &crashDiagInfo; #endif deviceInfo.enabledExtensionCount = (uint32)initializer.deviceExtensions.size(); deviceInfo.ppEnabledExtensionNames = initializer.deviceExtensions.data(); diff --git a/src/Engine/Graphics/Vulkan/VulkanGraphicsEnums.cpp b/src/Engine/Graphics/Vulkan/VulkanGraphicsEnums.cpp index ba89021..cd2b220 100644 --- a/src/Engine/Graphics/Vulkan/VulkanGraphicsEnums.cpp +++ b/src/Engine/Graphics/Vulkan/VulkanGraphicsEnums.cpp @@ -1,5 +1,6 @@ #include "VulkanGraphicsEnums.h" +using namespace Seele; using namespace Seele::Vulkan; using namespace Seele::Gfx; diff --git a/src/Engine/Graphics/Vulkan/VulkanGraphicsResources.cpp b/src/Engine/Graphics/Vulkan/VulkanGraphicsResources.cpp index fc842f8..66dd1cc 100644 --- a/src/Engine/Graphics/Vulkan/VulkanGraphicsResources.cpp +++ b/src/Engine/Graphics/Vulkan/VulkanGraphicsResources.cpp @@ -23,7 +23,7 @@ Semaphore::~Semaphore() Fence::Fence(PGraphics graphics) : graphics(graphics) - , signaled("Fence") + , signaled(false) { VkFenceCreateInfo info = init::FenceCreateInfo(0); @@ -45,8 +45,8 @@ bool Fence::isSignaled() switch (res) { case VK_SUCCESS: - signaled.raise(); - return true; + signaled = true; + return signaled; case VK_NOT_READY: break; default: @@ -60,7 +60,7 @@ void Fence::reset() if (signaled) { vkResetFences(graphics->getDevice(), 1, &fence); - signaled.reset(); + signaled = false; } } @@ -71,7 +71,7 @@ void Fence::wait(uint32 timeout) switch (r) { case VK_SUCCESS: - signaled.raise(); + signaled = true; break; case VK_TIMEOUT: break; diff --git a/src/Engine/Graphics/Vulkan/VulkanGraphicsResources.h b/src/Engine/Graphics/Vulkan/VulkanGraphicsResources.h index cba2e4e..97f861e 100644 --- a/src/Engine/Graphics/Vulkan/VulkanGraphicsResources.h +++ b/src/Engine/Graphics/Vulkan/VulkanGraphicsResources.h @@ -3,7 +3,6 @@ #include #include "Graphics/GraphicsResources.h" #include "VulkanAllocator.h" -#include "ThreadPool.h" namespace Seele { @@ -43,10 +42,10 @@ public: return fence; } void wait(uint32 timeout); - Event& operator co_await() + /*Event& operator co_await() { return signaled; - } + }*/ bool operator<(const Fence &other) const { return fence < other.fence; @@ -54,7 +53,7 @@ public: private: PGraphics graphics; - Event signaled; + bool signaled; VkFence fence; }; DEFINE_REF(Fence) @@ -357,6 +356,11 @@ public: virtual void setFileCallback(std::function callback) override; virtual void setCloseCallback(std::function callback); + VkFormat getPixelFormat() const + { + return cast(windowState.pixelFormat); + } + std::function keyCallback; std::function mouseMoveCallback; std::function mouseButtonCallback; @@ -381,7 +385,6 @@ protected: VkInstance instance; VkSwapchainKHR swapchain; VkSampleCountFlags numSamples; - VkFormat pixelFormat; VkPresentModeKHR presentMode; VkSurfaceKHR surface; VkSurfaceFormatKHR surfaceFormat; diff --git a/src/Engine/Graphics/Vulkan/VulkanTexture.cpp b/src/Engine/Graphics/Vulkan/VulkanTexture.cpp index 3bb87d1..d6c2d15 100644 --- a/src/Engine/Graphics/Vulkan/VulkanTexture.cpp +++ b/src/Engine/Graphics/Vulkan/VulkanTexture.cpp @@ -4,7 +4,6 @@ #include "VulkanGraphicsEnums.h" #include "VulkanAllocator.h" #include "VulkanCommandBuffer.h" -#include "ThreadPool.h" #include using namespace Seele; @@ -162,21 +161,21 @@ TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType, TextureHandle::~TextureHandle() { - auto cmdBuffer = graphics->getQueueCommands(currentOwner)->getCommands(); - VkDevice device = graphics->getDevice(); - VkImageView view = defaultView; - VkImage img = image; - auto deletionLambda = [cmdBuffer, device, view, img]() -> Job - { - //vkDestroyImageView(device, view, nullptr); - //vkDestroyImage(device, img, nullptr); - co_return; - }; - deletionLambda(); + //auto cmdBuffer = graphics->getQueueCommands(currentOwner)->getCommands(); + //VkDevice device = graphics->getDevice(); + //VkImageView view = defaultView; + //VkImage img = image; + //vkDestroyImageView(device, view, nullptr); + //vkDestroyImage(device, img, nullptr); + //co_return; } TextureHandle* TextureBase::cast(Gfx::PTexture texture) { + if(texture == nullptr) + { + return nullptr; + } if(texture->getTexture2D() != nullptr) { PTexture2D texture2D = texture.cast(); diff --git a/src/Engine/Graphics/Vulkan/VulkanViewport.cpp b/src/Engine/Graphics/Vulkan/VulkanViewport.cpp index e42978b..d93a97a 100644 --- a/src/Engine/Graphics/Vulkan/VulkanViewport.cpp +++ b/src/Engine/Graphics/Vulkan/VulkanViewport.cpp @@ -50,7 +50,6 @@ Window::Window(PGraphics graphics, const WindowCreateInfo &createInfo) , instance(graphics->getInstance()) , swapchain(VK_NULL_HANDLE) , numSamples(createInfo.numSamples) - , pixelFormat(cast(createInfo.pixelFormat)) { glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); GLFWwindow *handle = glfwCreateWindow(createInfo.width, createInfo.height, createInfo.title, createInfo.bFullscreen ? glfwGetPrimaryMonitor() : nullptr, nullptr); @@ -194,11 +193,7 @@ void Window::advanceBackBuffer() void Window::recreateSwapchain(const WindowCreateInfo &windowInfo) { destroySwapchain(); - sizeX = windowInfo.width; - sizeY = windowInfo.height; - pixelFormat = cast(windowInfo.pixelFormat); - bFullscreen = windowInfo.bFullscreen; - + windowState = windowInfo; uint32_t numFormats; VK_CHECK(vkGetPhysicalDeviceSurfaceFormatsKHR(graphics->getPhysicalDevice(), surface, &numFormats, nullptr)); Array formats(numFormats); @@ -234,6 +229,10 @@ void Window::present() while (presentResult != VK_SUCCESS) { presentResult = vkQueuePresentKHR(graphics->getGraphicsCommands()->getQueue()->getHandle(), &info); + if(presentResult == VK_ERROR_OUT_OF_DATE_KHR) + { + recreateSwapchain(windowState); + } } Gfx::currentFrameIndex = (Gfx::currentFrameIndex + 1)%Gfx::numFramesBuffered; static double lastFrameTime = 0.f; @@ -259,8 +258,8 @@ void Window::createSwapchain() } VkExtent2D extent; - extent.width = sizeX; - extent.height = sizeY; + extent.width = getSizeX(); + extent.height = getSizeY(); VkSwapchainCreateInfoKHR swapchainInfo = init::SwapchainCreateInfo( surface, @@ -283,8 +282,8 @@ void Window::createSwapchain() TextureCreateInfo backBufferCreateInfo; - backBufferCreateInfo.width = sizeX; - backBufferCreateInfo.height = sizeY; + backBufferCreateInfo.width = getSizeX(); + backBufferCreateInfo.height = getSizeY(); backBufferCreateInfo.usage = Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; backBufferCreateInfo.resourceData.owner = Gfx::QueueType::GRAPHICS; backBufferCreateInfo.format = cast(surfaceFormat.format); diff --git a/src/Engine/Material/MaterialAsset.cpp b/src/Engine/Material/MaterialAsset.cpp index 8cbee6d..dc52e3c 100644 --- a/src/Engine/Material/MaterialAsset.cpp +++ b/src/Engine/Material/MaterialAsset.cpp @@ -7,10 +7,11 @@ #include #include -Gfx::ShaderMap MaterialAsset::shaderMap; +using namespace Seele; + +Seele::Gfx::ShaderMap MaterialAsset::shaderMap; std::mutex MaterialAsset::shaderMapLock; -using namespace Seele; using json = nlohmann::json; using namespace Seele; diff --git a/src/Engine/MinimalEngine.h b/src/Engine/MinimalEngine.h index 5cec2fb..bec6615 100644 --- a/src/Engine/MinimalEngine.h +++ b/src/Engine/MinimalEngine.h @@ -154,6 +154,10 @@ public: template constexpr RefPtr(const RefPtr &other) { + if(other == nullptr) + { + return; + } F *f = other.getObject()->getHandle(); assert(static_cast(f)); object = (RefObject *)other.getObject(); @@ -357,5 +361,3 @@ private: RefPtr pointer; }; } // namespace Seele - -using namespace Seele; \ No newline at end of file diff --git a/src/Engine/Scene/Actor/Actor.cpp b/src/Engine/Scene/Actor/Actor.cpp index 97b02fb..1912345 100644 --- a/src/Engine/Scene/Actor/Actor.cpp +++ b/src/Engine/Scene/Actor/Actor.cpp @@ -22,26 +22,24 @@ void Actor::launchStart() } start(); } -Array Actor::launchTick(float deltaTime) const +void Actor::launchTick(float deltaTime) const { - Array result = rootComponent->launchTick(deltaTime); + rootComponent->launchTick(deltaTime); for(auto child : children) { - result.addAll(child->launchTick(deltaTime)); + child->launchTick(deltaTime); } - result.add(tick(deltaTime)); - return result; + tick(deltaTime); } -Array Actor::launchUpdate() +void Actor::launchUpdate() { - Array result = rootComponent->launchUpdate(); + rootComponent->launchUpdate(); for(auto child : children) { - result.addAll(child->launchUpdate()); + child->launchUpdate(); } - result.add(update()); - return result; + update(); } void Actor::notifySceneAttach(PScene scene) { diff --git a/src/Engine/Scene/Actor/Actor.h b/src/Engine/Scene/Actor/Actor.h index f3e2941..f61a420 100644 --- a/src/Engine/Scene/Actor/Actor.h +++ b/src/Engine/Scene/Actor/Actor.h @@ -1,7 +1,6 @@ #pragma once #include "MinimalEngine.h" #include "Math/Transform.h" -#include "ThreadPool.h" namespace Seele { @@ -15,10 +14,10 @@ public: virtual ~Actor(); virtual void launchStart(); virtual void start() {} - Array launchTick(float deltaTime) const; - virtual Job tick(float) const { co_return; } - Array launchUpdate(); - virtual Job update() { co_return; } + void launchTick(float deltaTime) const; + virtual void tick(float) const { }//co_return; } + void launchUpdate(); + virtual void update() { }//co_return; } void notifySceneAttach(PScene scene); PScene getScene(); diff --git a/src/Engine/Scene/Components/Component.cpp b/src/Engine/Scene/Components/Component.cpp index 7d77bc4..1ed9e65 100644 --- a/src/Engine/Scene/Components/Component.cpp +++ b/src/Engine/Scene/Components/Component.cpp @@ -20,26 +20,22 @@ void Component::launchStart() start(); } -Array Component::launchTick(float deltaTime) const +void Component::launchTick(float deltaTime) const { - Array result; for(auto child : children) { - result.addAll(child->launchTick(deltaTime)); + child->launchTick(deltaTime); } - result.add(tick(deltaTime)); - return result; + tick(deltaTime); } -Array Component::launchUpdate() +void Component::launchUpdate() { - Array result; for(auto child : children) { - result.addAll(child->launchUpdate()); + child->launchUpdate(); } - result.add(update()); - return result; + update(); } PComponent Component::getParent() diff --git a/src/Engine/Scene/Components/Component.h b/src/Engine/Scene/Components/Component.h index c00f660..0dce8ac 100644 --- a/src/Engine/Scene/Components/Component.h +++ b/src/Engine/Scene/Components/Component.h @@ -2,7 +2,6 @@ #include "MinimalEngine.h" #include "Math/Transform.h" #include "Scene/Util.h" -#include "ThreadPool.h" namespace Seele { @@ -16,10 +15,10 @@ public: virtual ~Component(); void launchStart(); virtual void start() {}; - Array launchTick(float deltaTime) const; - virtual Job tick(float) const { co_return; } - Array launchUpdate(); - virtual Job update() { co_return; } + void launchTick(float deltaTime) const; + virtual void tick(float) const { }//co_return; } + void launchUpdate(); + virtual void update() { }//co_return; } PComponent getParent(); PActor getOwner(); const Array& getChildComponents(); diff --git a/src/Engine/Scene/Components/MyComponent.cpp b/src/Engine/Scene/Components/MyComponent.cpp index 5e5cf4c..9d28c62 100644 --- a/src/Engine/Scene/Components/MyComponent.cpp +++ b/src/Engine/Scene/Components/MyComponent.cpp @@ -12,19 +12,19 @@ void MyComponent::start() otherComp.update(); } -Job MyComponent::tick(float) const +void MyComponent::tick(float) const { //std::cout << "MyComponent::tick" << std::endl; ++writable; //std::cout << "MyComponent::tick finished" << std::endl; otherComp->data = *writable; - co_return; + //co_return; } -Job MyComponent::update() +void MyComponent::update() { //std::cout << "MyComponent::update" << std::endl; writable.update(); //std::cout << "MyComponent::update finished" << std::endl; - co_return; + //co_return; } diff --git a/src/Engine/Scene/Components/MyComponent.h b/src/Engine/Scene/Components/MyComponent.h index c5522e3..2788bdd 100644 --- a/src/Engine/Scene/Components/MyComponent.h +++ b/src/Engine/Scene/Components/MyComponent.h @@ -9,8 +9,8 @@ class MyComponent : public Component public: MyComponent(); virtual void start(); - virtual Job tick(float deltatime) const; - virtual Job update(); + virtual void tick(float deltatime) const; + virtual void update(); private: Writable otherComp; Writable writable = 0; diff --git a/src/Engine/Scene/Components/MyOtherComponent.cpp b/src/Engine/Scene/Components/MyOtherComponent.cpp index ba13385..0dc308f 100644 --- a/src/Engine/Scene/Components/MyOtherComponent.cpp +++ b/src/Engine/Scene/Components/MyOtherComponent.cpp @@ -2,14 +2,14 @@ using namespace Seele; -Job MyOtherComponent::tick(float) const +void MyOtherComponent::tick(float) const { //std::cout << *data << std::endl; - co_return; + //co_return; } -Job MyOtherComponent::update() +void MyOtherComponent::update() { data.update(); - co_return; + //co_return; } diff --git a/src/Engine/Scene/Components/MyOtherComponent.h b/src/Engine/Scene/Components/MyOtherComponent.h index 51793ad..ed7d957 100644 --- a/src/Engine/Scene/Components/MyOtherComponent.h +++ b/src/Engine/Scene/Components/MyOtherComponent.h @@ -6,8 +6,8 @@ namespace Seele class MyOtherComponent : public Component { public: - virtual Job tick(float deltaTime) const; - virtual Job update(); + virtual void tick(float deltaTime) const; + virtual void update(); Writable data = Writable(0); private: }; diff --git a/src/Engine/Scene/Scene.cpp b/src/Engine/Scene/Scene.cpp index e1fcb86..f21dbbc 100644 --- a/src/Engine/Scene/Scene.cpp +++ b/src/Engine/Scene/Scene.cpp @@ -44,37 +44,33 @@ void Scene::start() static int64 lastUpdate; static uint64 numUpdates; -Job Scene::beginUpdate(double deltaTime) +void Scene::beginUpdate(double deltaTime) { //std::cout << "Scene::beginUpdate" << std::endl; auto startTime = std::chrono::high_resolution_clock::now(); - //Array jobs; for(auto actor : rootActors) { - co_await Job::all(actor->launchTick(static_cast(deltaTime))); + actor->launchTick(static_cast(deltaTime)); } - //co_await Job::all(std::move(jobs)); auto endTime = std::chrono::high_resolution_clock::now(); - int64 delta = (endTime - startTime).count(); + int64 delta = std::chrono::duration_cast(endTime - startTime).count(); lastUpdate += delta; numUpdates++; - if(lastUpdate > 1000) + if(lastUpdate > 1000000) { - lastUpdate -= 1000; + lastUpdate -= 1000000; std::cout << numUpdates << " updates per second" << std::endl; numUpdates = 0; } } -Job Scene::commitUpdate() +void Scene::commitUpdate() { //std::cout << "Scene::commitUpdate" << std::endl; - //std::vector jobs; for(auto actor : rootActors) { - co_await Job::all(actor->launchUpdate()); + actor->launchUpdate(); } - //co_await Job::all(std::move(jobs)); //std::cout << "Scene::commitUpdate finished waiting" << std::endl; } diff --git a/src/Engine/Scene/Scene.h b/src/Engine/Scene/Scene.h index e653eb7..99e29b2 100644 --- a/src/Engine/Scene/Scene.h +++ b/src/Engine/Scene/Scene.h @@ -39,8 +39,8 @@ public: Scene(Gfx::PGraphics graphics); ~Scene(); void start(); - Job beginUpdate(double deltaTime); - Job commitUpdate(); + void beginUpdate(double deltaTime); + void commitUpdate(); void addActor(PActor actor); void addPrimitiveComponent(PPrimitiveComponent comp); diff --git a/src/Engine/Window/InspectorView.cpp b/src/Engine/Window/InspectorView.cpp index 7f5bb3b..0021b0f 100644 --- a/src/Engine/Window/InspectorView.cpp +++ b/src/Engine/Window/InspectorView.cpp @@ -22,7 +22,7 @@ InspectorView::InspectorView(Gfx::PGraphics graphics, PWindow window, const View TextRender& render = textPassData.texts.add(); render.font = AssetRegistry::findFont("Calibri"); render.text = "Seele Engine"; - render.position = Vector2(0.5f, 0.5f); + render.position = Vector2(200.f, 300.f); render.scale = 1.0f; render.textColor = Vector4(1, 1, 1, 1); } @@ -31,14 +31,14 @@ InspectorView::~InspectorView() { } -Job InspectorView::beginUpdate() +void InspectorView::beginUpdate() { - co_return; + //co_return; } -Job InspectorView::update() +void InspectorView::update() { - co_return; + //co_return; } void InspectorView::commitUpdate() @@ -50,14 +50,14 @@ void InspectorView::prepareRender() textPass.updateViewFrame(textPassData); } -MainJob InspectorView::render() +void InspectorView::render() { - return uiPass.beginFrame() - .then(textPass.beginFrame()) - .then(uiPass.render()) - .then(textPass.render()) - .then(uiPass.endFrame()) - .then(textPass.endFrame()); + uiPass.beginFrame(); + textPass.beginFrame(); + uiPass.render(); + textPass.render(); + uiPass.endFrame(); + textPass.endFrame(); } void InspectorView::keyCallback(KeyCode, InputAction, KeyModifier) diff --git a/src/Engine/Window/InspectorView.h b/src/Engine/Window/InspectorView.h index d5c2e9d..af75dd5 100644 --- a/src/Engine/Window/InspectorView.h +++ b/src/Engine/Window/InspectorView.h @@ -14,12 +14,12 @@ public: InspectorView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &createInfo); virtual ~InspectorView(); - virtual Job beginUpdate() override; - virtual Job update() override; + virtual void beginUpdate() override; + virtual void update() override; virtual void commitUpdate() override; virtual void prepareRender() override; - virtual MainJob render() override; + virtual void render() override; void selectActor(); protected: UIPass uiPass; diff --git a/src/Engine/Window/SceneView.cpp b/src/Engine/Window/SceneView.cpp index f57b0d4..6eb4746 100644 --- a/src/Engine/Window/SceneView.cpp +++ b/src/Engine/Window/SceneView.cpp @@ -68,16 +68,16 @@ Seele::SceneView::~SceneView() { } -Job SceneView::beginUpdate() +void SceneView::beginUpdate() { - co_await scene->beginUpdate(Gfx::currentFrameDelta); - co_return; + scene->beginUpdate(Gfx::currentFrameDelta); + //co_return; } -Job SceneView::update() +void SceneView::update() { - co_await scene->commitUpdate(); - co_return; + scene->commitUpdate(); + //co_return; } void SceneView::commitUpdate() @@ -94,17 +94,17 @@ void SceneView::prepareRender() basePass.updateViewFrame(basePassData); } -MainJob SceneView::render() +void SceneView::render() { - return depthPrepass.beginFrame() - .then(lightCullingPass.beginFrame()) - .then(basePass.beginFrame()) - .then(depthPrepass.render()) - .then(lightCullingPass.render()) - .then(basePass.render()) - .then(depthPrepass.endFrame()) - .then(lightCullingPass.endFrame()) - .then(basePass.endFrame()); + depthPrepass.beginFrame(); + lightCullingPass.beginFrame(); + basePass.beginFrame(); + depthPrepass.render(); + lightCullingPass.render(); + basePass.render(); + depthPrepass.endFrame(); + lightCullingPass.endFrame(); + basePass.endFrame(); } static float cameraSpeed = 1; diff --git a/src/Engine/Window/SceneView.h b/src/Engine/Window/SceneView.h index 015552d..7e28e59 100644 --- a/src/Engine/Window/SceneView.h +++ b/src/Engine/Window/SceneView.h @@ -13,12 +13,12 @@ class SceneView : public View public: SceneView(Gfx::PGraphics graphics, PWindow owner, const ViewportCreateInfo &createInfo); ~SceneView(); - virtual Job beginUpdate() override; - virtual Job update() override; + virtual void beginUpdate() override; + virtual void update() override; virtual void commitUpdate() override; virtual void prepareRender() override; - virtual MainJob render() override; + virtual void render() override; PScene getScene() const { return scene; } private: diff --git a/src/Engine/Window/View.h b/src/Engine/Window/View.h index eee9a2c..0cb94e9 100644 --- a/src/Engine/Window/View.h +++ b/src/Engine/Window/View.h @@ -1,6 +1,5 @@ #pragma once #include "Graphics/RenderPass/RenderGraph.h" -#include "ThreadPool.h" namespace Seele { @@ -13,15 +12,15 @@ public: virtual ~View(); // These are called from the view thread, and handle updating game data - virtual Job beginUpdate() = 0; - virtual Job update() = 0; + virtual void beginUpdate() = 0; + virtual void update() = 0; // End frame is called with a lock, so it is safe to write to shared memory virtual void commitUpdate() = 0; // These are called from the render thread // prepare render is also locked, so reading from shared memory is also safe virtual void prepareRender() = 0; - virtual MainJob render() = 0; + virtual void render() = 0; void applyArea(URect area); void setFocused(); diff --git a/src/Engine/Window/Window.cpp b/src/Engine/Window/Window.cpp index 8a4d66b..fa4dc85 100644 --- a/src/Engine/Window/Window.cpp +++ b/src/Engine/Window/Window.cpp @@ -16,29 +16,32 @@ Window::~Window() void Window::addView(PView view) { - WindowView* windowView = new WindowView(view); + //WindowView* windowView = new WindowView(view); //windowView->worker = std::thread(&Window::viewWorker, this, windowView); - views.add(windowView); - viewWorker(views.size() - 1); + views.add(view); + //viewWorker(views.size() - 1); } -MainJob Window::render() +void Window::render() { - gfxHandle->beginFrame(); - for(auto& windowView : views) + while(owner->isActive()) { + gfxHandle->beginFrame(); + for(auto& view : views) { - std::scoped_lock lock(windowView->workerMutex); - windowView->view->prepareRender(); + view->beginUpdate(); + view->update(); + view->commitUpdate(); + view->prepareRender(); + view->render(); + } + gfxHandle->endFrame(); + if(owner->isActive()) + { + render(); } - co_await windowView->view->render(); } - gfxHandle->endFrame(); - if(owner->isActive()) - { - render(); - } - co_return; + //co_return; } Gfx::PWindow Window::getGfxHandle() @@ -63,7 +66,7 @@ void Window::setFocused(PView view) }); } -Job Window::viewWorker(size_t viewIndex) +/*void Window::viewWorker(size_t viewIndex) { WindowView* windowView = views[viewIndex]; co_await windowView->view->beginUpdate(); @@ -79,5 +82,5 @@ Job Window::viewWorker(size_t viewIndex) { viewWorker(viewIndex); } - co_return; -} + //co_return; +}*/ diff --git a/src/Engine/Window/Window.h b/src/Engine/Window/Window.h index c16207e..48f6941 100644 --- a/src/Engine/Window/Window.h +++ b/src/Engine/Window/Window.h @@ -1,11 +1,10 @@ #pragma once #include "Graphics/GraphicsResources.h" #include "View.h" -#include "ThreadPool.h" namespace Seele { -struct WindowView +/*struct WindowView { PView view; Event updateFinished; @@ -14,8 +13,8 @@ struct WindowView : view(view) , updateFinished(view->getName()) {} -}; -DEFINE_REF(WindowView) +};*/ +//DEFINE_REF(WindowView) DECLARE_REF(WindowManager) // The logical window, with the graphics proxy class Window @@ -24,16 +23,16 @@ public: Window(PWindowManager owner, Gfx::PWindow handle); ~Window(); void addView(PView view); - MainJob render(); + void render(); Gfx::PWindow getGfxHandle(); void setFocused(PView view); protected: PWindowManager owner; - Array views; + Array views; Gfx::PWindow gfxHandle; - Job viewWorker(size_t viewIndex); + //void viewWorker(size_t viewIndex); }; DEFINE_REF(Window) } // namespace Seele \ No newline at end of file diff --git a/src/Engine/main.cpp b/src/Engine/main.cpp index a2e713d..0276733 100644 --- a/src/Engine/main.cpp +++ b/src/Engine/main.cpp @@ -36,7 +36,5 @@ int main() sceneView->setFocused(); window->render(); - - getGlobalThreadPool().mainLoop(); return 0; } \ No newline at end of file diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 404de08..408d5df 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,12 +1,19 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ".") find_package(Boost COMPONENTS unit_test_framework REQUIRED) - -include_directories(${ENGINE_ROOT}) -include_directories(${Boost_INCLUDE_DIRS}) +find_package(Aftermath REQUIRED) add_subdirectory(Engine/) + +target_include_directories(Seele_unit_tests PRIVATE ${ENGINE_ROOT}) +target_include_directories(Seele_unit_tests PRIVATE ${Boost_INCLUDE_DIRS}) +target_include_directories(Seele_unit_tests PRIVATE ${GLM_INCLUDE_DIRS}) +target_include_directories(Seele_unit_tests PRIVATE ${Vulkan_INCLUDE_DIR}) +target_include_directories(Seele_unit_tests PRIVATE ${NSAM_INCLUDE_DIRS}) + target_link_libraries(Seele_unit_tests ${Boost_LIBRARIES}) +target_link_libraries(Seele_unit_tests ${Vulkan_LIBRARY}) +target_link_libraries(Seele_unit_tests ${NSAM_LIBRARIES}) if(UNIX) target_compile_definitions(Seele_unit_tests PRIVATE -DBOOST_TEST_DYN_LINK) endif() diff --git a/test/Engine/CMakeLists.txt b/test/Engine/CMakeLists.txt index 0b7e60b..3bf7e40 100644 --- a/test/Engine/CMakeLists.txt +++ b/test/Engine/CMakeLists.txt @@ -3,8 +3,8 @@ target_sources(Seele_unit_tests ../../src/Engine/MinimalEngine.cpp ../../src/Engine/ThreadPool.cpp EngineTest.h - EngineTest.cpp - ThreadPool.cpp) + EngineTest.cpp) + #ThreadPool.cpp) target_include_directories(Seele_unit_tests PUBLIC ./) add_subdirectory(Containers/) add_subdirectory(Graphics/) diff --git a/test/Engine/Containers/Array.cpp b/test/Engine/Containers/Array.cpp index 9a8b7e7..cbed168 100644 --- a/test/Engine/Containers/Array.cpp +++ b/test/Engine/Containers/Array.cpp @@ -57,6 +57,17 @@ BOOST_AUTO_TEST_CASE(remove_keeporder) BOOST_CHECK_EQUAL(array.size(), 4); } +BOOST_AUTO_TEST_CASE(find) +{ + Array array; + for(uint32 i = 0; i < 100; ++i) + { + array.add(i); + } + auto it = array.find([](uint8 elem){ return elem / 9 == 9; }); + BOOST_CHECK_EQUAL(*it, 81); +} + BOOST_AUTO_TEST_CASE(remove_swap) { Array array; @@ -65,7 +76,7 @@ BOOST_AUTO_TEST_CASE(remove_swap) array.add(3); array.add(4); array.add(5); - array.remove(1, false); + array.removeAt(1, false); BOOST_CHECK_EQUAL(array[1], 5); BOOST_CHECK_EQUAL(array[2], 3); BOOST_CHECK_EQUAL(array[3], 4); diff --git a/test/Engine/EngineTest.cpp b/test/Engine/EngineTest.cpp index ca6f235..9bf57ed 100644 --- a/test/Engine/EngineTest.cpp +++ b/test/Engine/EngineTest.cpp @@ -1,6 +1,5 @@ #include "EngineTest.h" #include "MinimalEngine.h" -#include "ThreadPool.h" #define BOOST_TEST_MODULE SeeleEngine #include //#include @@ -9,7 +8,7 @@ using namespace Seele; Seele::GlobalFixture::~GlobalFixture() { - getGlobalThreadPool().waitIdle(); + //getGlobalThreadPool().waitIdle(); } BOOST_TEST_GLOBAL_FIXTURE(GlobalFixture);