Light Culling still doesn't work properly

This commit is contained in:
Dynamitos
2022-02-24 22:38:26 +01:00
parent 5268bb68e2
commit 84049a762c
44 changed files with 163 additions and 151 deletions
+3 -3
View File
@@ -8,7 +8,7 @@
"name": "Engine Debug (Linux)", "name": "Engine Debug (Linux)",
"type": "cppdbg", "type": "cppdbg",
"request": "launch", "request": "launch",
"program": "${workspaceRoot}/bin/Debug/SeeleEngine", "program": "${workspaceRoot}/bin/Debug/Engine",
"args": [], "args": [],
"stopAtEntry": false, "stopAtEntry": false,
"cwd": "${workspaceRoot}/bin/Debug", "cwd": "${workspaceRoot}/bin/Debug",
@@ -27,7 +27,7 @@
"name": "Engine Debug", "name": "Engine Debug",
"type": "cppvsdbg", "type": "cppvsdbg",
"request": "launch", "request": "launch",
"program": "${workspaceRoot}/bin/Debug/SeeleEngine.exe", "program": "${workspaceRoot}/bin/Debug/Engine.exe",
"args": [], "args": [],
"stopAtEntry": false, "stopAtEntry": false,
"cwd": "${workspaceRoot}/bin/Debug", "cwd": "${workspaceRoot}/bin/Debug",
@@ -47,7 +47,7 @@
"name": "Engine Release", "name": "Engine Release",
"type": "cppvsdbg", "type": "cppvsdbg",
"request": "launch", "request": "launch",
"program": "${workspaceRoot}/bin/Release/SeeleEngine.exe", "program": "${workspaceRoot}/bin/Release/Engine.exe",
"args": [], "args": [],
"stopAtEntry": false, "stopAtEntry": false,
"cwd": "${workspaceRoot}/bin/Release", "cwd": "${workspaceRoot}/bin/Release",
+1
View File
@@ -134,5 +134,6 @@
}, },
"git.ignoreSubmodules": true, "git.ignoreSubmodules": true,
"cmake.configureOnOpen": true, "cmake.configureOnOpen": true,
"cmake.parallelJobs": 0,
"C_Cpp.intelliSenseEngineFallback": "Enabled" "C_Cpp.intelliSenseEngineFallback": "Enabled"
} }
+23 -23
View File
@@ -77,19 +77,19 @@ if(CMAKE_DEBUG_POSTFIX)
add_compile_definitions(ENABLE_VALIDATION) add_compile_definitions(ENABLE_VALIDATION)
add_compile_definitions(SEELE_DEBUG) add_compile_definitions(SEELE_DEBUG)
endif() endif()
add_executable(SeeleEngine "") add_executable(Engine "")
target_link_libraries(SeeleEngine ${Vulkan_LIBRARY}) target_link_libraries(Engine ${Vulkan_LIBRARY})
target_link_libraries(SeeleEngine ${Boost_LIBRARIES}) target_link_libraries(Engine ${Boost_LIBRARIES})
target_link_libraries(SeeleEngine ${GLFW_LIBRARIES}) target_link_libraries(Engine ${GLFW_LIBRARIES})
target_link_libraries(SeeleEngine ${SLANG_LIBRARIES}) target_link_libraries(Engine ${SLANG_LIBRARIES})
target_link_libraries(SeeleEngine ${ASSIMP_LIBRARIES}) target_link_libraries(Engine ${ASSIMP_LIBRARIES})
target_link_libraries(SeeleEngine ${NSAM_LIBRARIES}) target_link_libraries(Engine ${NSAM_LIBRARIES})
target_link_libraries(SeeleEngine ${KTX_LIBRARIES}) target_link_libraries(Engine ${KTX_LIBRARIES})
if(UNIX) if(UNIX)
target_link_libraries(SeeleEngine Threads::Threads) target_link_libraries(Engine Threads::Threads)
target_link_libraries(SeeleEngine dl) target_link_libraries(Engine dl)
endif() endif()
target_precompile_headers(SeeleEngine target_precompile_headers(Engine
PRIVATE PRIVATE
<assert.h> <assert.h>
<atomic> <atomic>
@@ -111,9 +111,9 @@ add_subdirectory(src/)
if(MSVC) if(MSVC)
set(_CRT_SECURE_NO_WARNINGS) set(_CRT_SECURE_NO_WARNINGS)
target_compile_options(SeeleEngine PRIVATE /Zi) target_compile_options(Engine PRIVATE /Zi /MP)
else() else()
target_compile_options(SeeleEngine PRIVATE -g -Wall -Wextra -Wno-delete-incomplete -pedantic -fcoroutines) target_compile_options(Engine PRIVATE -g -Wall -Wextra -Wno-delete-incomplete -pedantic -fcoroutines)
endif() endif()
add_executable(Seele_unit_tests "") add_executable(Seele_unit_tests "")
@@ -121,19 +121,19 @@ add_subdirectory(test/)
if(WIN32) if(WIN32)
add_custom_target(copy-binaries ALL add_custom_target(copy-binaries ALL
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SLANG_BINARIES} $<TARGET_FILE_DIR:SeeleEngine> COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SLANG_BINARIES} $<TARGET_FILE_DIR:Engine>
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SLANG_GLSLANG} $<TARGET_FILE_DIR:SeeleEngine> COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SLANG_GLSLANG} $<TARGET_FILE_DIR:Engine>
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${GLFW_BINARY} $<TARGET_FILE_DIR:SeeleEngine> COMMAND ${CMAKE_COMMAND} -E copy_if_different ${GLFW_BINARY} $<TARGET_FILE_DIR:Engine>
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${ASSIMP_BINARY} $<TARGET_FILE_DIR:SeeleEngine> COMMAND ${CMAKE_COMMAND} -E copy_if_different ${ASSIMP_BINARY} $<TARGET_FILE_DIR:Engine>
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${NSAM_BINARIES} $<TARGET_FILE_DIR:SeeleEngine> COMMAND ${CMAKE_COMMAND} -E copy_if_different ${NSAM_BINARIES} $<TARGET_FILE_DIR:Engine>
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${NSAM_LLVM} $<TARGET_FILE_DIR:SeeleEngine> COMMAND ${CMAKE_COMMAND} -E copy_if_different ${NSAM_LLVM} $<TARGET_FILE_DIR:Engine>
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${KTX_BINARIES} $<TARGET_FILE_DIR:SeeleEngine>) COMMAND ${CMAKE_COMMAND} -E copy_if_different ${KTX_BINARIES} $<TARGET_FILE_DIR:Engine>)
else() else()
add_custom_target(copy-binaries ALL COMMAND "") add_custom_target(copy-binaries ALL COMMAND "")
endif() endif()
add_custom_target(copy-runtime-files ALL add_custom_target(SeeleEngine ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/res $<TARGET_FILE_DIR:SeeleEngine> COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/res $<TARGET_FILE_DIR:Engine>
DEPENDS SeeleEngine copy-binaries) DEPENDS Engine copy-binaries)
+23 -2
View File
@@ -23,21 +23,42 @@
</LinkedListItems> </LinkedListItems>
</Expand> </Expand>
</Type> </Type>
<Type Name="Seele::Pair&lt;*,*&gt;">
<DisplayString>[{key}, {value}]</DisplayString>
<Expand>
<Item Name="[key]">key</Item>
<Item Name="[value]">value</Item>
</Expand>
</Type>
<Type Name="Seele::Map&lt;*&gt;"> <Type Name="Seele::Map&lt;*&gt;">
<DisplayString>{{size={_size}}</DisplayString> <DisplayString>{{size={_size}}</DisplayString>
<Expand> <Expand>
<Item Name="[size]">_size</Item> <Item Name="[size]">_size</Item>
<Item Name="[comp]">comp</Item> <Item Name="[comp]">comp</Item>
<ArrayItems> <ArrayItems>
<Size>nodeContainer.arraySize</Size> <Size>_size</Size>
<ValuePointer>nodeContainer._data</ValuePointer> <ValuePointer>nodeContainer._data</ValuePointer>
</ArrayItems> </ArrayItems>
</Expand> </Expand>
</Type> </Type>
<Type Name="Seele::Map&lt;*&gt;::IteratorBase&lt;*&gt;">
<DisplayString Condition="nodeContainer.arraySize==0">empty</DisplayString>
<DisplayString>[{nodeContainer._data[node].pair}]</DisplayString>
<Expand>
<ExpandedItem>nodeContainer._data[node].pair</ExpandedItem>
</Expand>
</Type>
<Type Name="Seele::RefPtr&lt;*&gt;"> <Type Name="Seele::RefPtr&lt;*&gt;">
<DisplayString>RefPtr {*object->handle} {object->refCount.load()} references</DisplayString> <DisplayString Condition="object == nullptr">empty</DisplayString>
<DisplayString>RefPtr {*object->handle} {object->refCount} references</DisplayString>
<Expand> <Expand>
<ExpandedItem>object->handle</ExpandedItem> <ExpandedItem>object->handle</ExpandedItem>
</Expand> </Expand>
</Type> </Type>
<Type Name="Seele::UniquePtr&lt;*&gt;">
<DisplayString>UniquePtr {*handle}</DisplayString>
<Expand>
<ExpandedItem>handle</ExpandedItem>
</Expand>
</Type>
</AutoVisualizer> </AutoVisualizer>
+18 -8
View File
@@ -23,19 +23,26 @@ layout(set = INDEX_VIEW_PARAMS, binding = 3)
StructuredBuffer<Frustum> frustums; StructuredBuffer<Frustum> frustums;
layout(set = INDEX_VIEW_PARAMS, binding = 4) layout(set = INDEX_VIEW_PARAMS, binding = 4)
RWStructuredBuffer<uint> oLightIndexCounter; globallycoherent RWStructuredBuffer<uint> oLightIndexCounter;
layout(set = INDEX_VIEW_PARAMS, binding = 5) layout(set = INDEX_VIEW_PARAMS, binding = 5)
RWStructuredBuffer<uint> tLightIndexCounter; globallycoherent RWStructuredBuffer<uint> tLightIndexCounter;
layout(set = INDEX_VIEW_PARAMS, binding = 6) layout(set = INDEX_VIEW_PARAMS, binding = 6)
RWStructuredBuffer<uint> oLightIndexList; RWStructuredBuffer<uint> oLightIndexList;
layout(set = INDEX_VIEW_PARAMS, binding = 7) layout(set = INDEX_VIEW_PARAMS, binding = 7)
RWStructuredBuffer<uint> tLightIndexList; RWStructuredBuffer<uint> tLightIndexList;
layout(set = INDEX_VIEW_PARAMS, binding = 8) layout(set = INDEX_VIEW_PARAMS, binding = 8)
RWTexture2D<uint2> oLightGrid; RWTexture2D<uint2> oLightGrid;
layout(set = INDEX_VIEW_PARAMS, binding = 9) layout(set = INDEX_VIEW_PARAMS, binding = 9)
RWTexture2D<uint2> tLightGrid; RWTexture2D<uint2> tLightGrid;
// Debug
//layout(set = INDEX_VIEW_PARAMS, binding = 10)
//Texture2D lightCountHeatMap;
//layout(set = INDEX_VIEW_PARAMS, binding = 11)
//RWTexture2D<float4> debugTexture;
groupshared uint uMinDepth; groupshared uint uMinDepth;
groupshared uint uMaxDepth; groupshared uint uMaxDepth;
@@ -74,8 +81,8 @@ void tAppendLight(uint lightIndex)
[shader("compute")] [shader("compute")]
void cullLights(ComputeShaderInput in) void cullLights(ComputeShaderInput in)
{ {
int3 texCoord = int3(in.dispatchThreadID.xy, 0); int2 texCoord = in.dispatchThreadID.xy;
float fDepth = depthTextureVS.Load(texCoord).r; float fDepth = depthTextureVS.Load(int3(texCoord, 0)).r;
uint uDepth = asuint(fDepth); uint uDepth = asuint(fDepth);
if(in.groupIndex == 0) if(in.groupIndex == 0)
@@ -88,6 +95,7 @@ void cullLights(ComputeShaderInput in)
} }
GroupMemoryBarrierWithGroupSync(); GroupMemoryBarrierWithGroupSync();
InterlockedMin(uMinDepth, uDepth); InterlockedMin(uMinDepth, uDepth);
InterlockedMax(uMaxDepth, uDepth); InterlockedMax(uMaxDepth, uDepth);
@@ -120,22 +128,24 @@ void cullLights(ComputeShaderInput in)
if(in.groupIndex == 0) if(in.groupIndex == 0)
{ {
InterlockedAdd(oLightIndexCounter[0], (uint)oLightCount, oLightIndexStartOffset); InterlockedAdd(oLightIndexCounter[0], oLightCount, oLightIndexStartOffset);
oLightGrid[in.groupID.xy] = uint2(oLightIndexStartOffset, oLightCount); oLightGrid[in.groupID.xy] = uint2(oLightIndexStartOffset, oLightCount);
InterlockedAdd(tLightIndexCounter[0], (uint)tLightCount, tLightIndexStartOffset); InterlockedAdd(tLightIndexCounter[0], tLightCount, tLightIndexStartOffset);
tLightGrid[in.groupID.xy] = uint2(tLightIndexStartOffset, tLightCount); tLightGrid[in.groupID.xy] = uint2(tLightIndexStartOffset, tLightCount);
} }
GroupMemoryBarrierWithGroupSync(); GroupMemoryBarrierWithGroupSync();
for (uint j = in.groupIndex; j < (uint)oLightCount; j += BLOCK_SIZE * BLOCK_SIZE) for (uint j = in.groupIndex; j < oLightCount; j += BLOCK_SIZE * BLOCK_SIZE)
{ {
oLightIndexList[oLightIndexStartOffset + j] = oLightList[j]; oLightIndexList[oLightIndexStartOffset + j] = oLightList[j];
} }
// For transparent geometry. // For transparent geometry.
for ( uint k = in.groupIndex; k < (uint)tLightCount; k += BLOCK_SIZE * BLOCK_SIZE ) for ( uint k = in.groupIndex; k < tLightCount; k += BLOCK_SIZE * BLOCK_SIZE )
{ {
tLightIndexList[tLightIndexStartOffset + k] = tLightList[k]; tLightIndexList[tLightIndexStartOffset + k] = tLightList[k];
} }
} }
+4 -10
View File
@@ -1,6 +1,6 @@
const static float PI = 3.1415926535897932f; const static float PI = 3.1415926535897932f;
const static uint MAX_PARTICLES = 65536; const static uint MAX_PARTICLES = 65536;
const static uint BLOCK_SIZE = 8; const static uint BLOCK_SIZE = 32;
struct ViewParameter struct ViewParameter
{ {
@@ -31,7 +31,7 @@ float4 screenToView( float4 screen )
float2 texCoord = screen.xy / gViewParams.screenDimensions; float2 texCoord = screen.xy / gViewParams.screenDimensions;
// Convert to clip space // Convert to clip space
float4 clip = float4( float2( texCoord.x, -texCoord.y ) * 2.0f - 1.0f, screen.z, screen.w ); float4 clip = float4( float2( texCoord.x, 1.0f-texCoord.y ) * 2.0f - 1.0f, screen.z, screen.w );
return clipToView( clip ); return clipToView( clip );
} }
@@ -40,9 +40,6 @@ struct Plane
{ {
float3 n; float3 n;
float d; float d;
float3 p0;
float3 p1;
float3 p2;
}; };
struct Frustum struct Frustum
@@ -53,15 +50,12 @@ Plane computePlane(float3 p0, float3 p1, float3 p2)
{ {
Plane plane; Plane plane;
float3 v0 = p2 - p0; float3 v0 = p1 - p0;
float3 v2 = p1 - p0; float3 v2 = p2 - p0;
plane.n = normalize(cross(v0, v2)); plane.n = normalize(cross(v0, v2));
plane.d = dot(plane.n, p0); plane.d = dot(plane.n, p0);
plane.p0 = p0;
plane.p1 = p1;
plane.p2 = p2;
return plane; return plane;
} }
+6 -3
View File
@@ -22,7 +22,6 @@ struct DirectionalLight : ILightEnv
struct PointLight : ILightEnv struct PointLight : ILightEnv
{ {
float4 positionWS; float4 positionWS;
float4 positionVS;
float4 colorRange; float4 colorRange;
float3 illuminate<B:IBRDF>(MaterialFragmentParameter input, B brdf, float3 viewDir) float3 illuminate<B:IBRDF>(MaterialFragmentParameter input, B brdf, float3 viewDir)
@@ -36,14 +35,14 @@ struct PointLight : ILightEnv
bool insidePlane(Plane plane) bool insidePlane(Plane plane)
{ {
return dot(plane.n, positionVS.xyz) - plane.d < -colorRange.w; return dot(plane.n, getViewPos().xyz) - plane.d < -colorRange.w;
} }
bool insideFrustum(Frustum frustum, float zNear, float zFar) bool insideFrustum(Frustum frustum, float zNear, float zFar)
{ {
bool result = true; bool result = true;
if(positionVS.z - colorRange.w > zNear || positionVS.z + colorRange.w < zFar) if(getViewPos().z - colorRange.w > zNear || getViewPos().z + colorRange.w < zFar)
{ {
result = false; result = false;
} }
@@ -56,6 +55,10 @@ struct PointLight : ILightEnv
} }
return result; return result;
} }
float3 getViewPos()
{
return mul(gViewParams.viewMatrix, positionWS).xyz;
}
}; };
layout(set = INDEX_LIGHT_ENV, binding = 0, std430) layout(set = INDEX_LIGHT_ENV, binding = 0, std430)
+1 -1
View File
@@ -1,4 +1,4 @@
target_sources(SeeleEngine target_sources(Engine
PRIVATE PRIVATE
Asset.h Asset.h
Asset.cpp Asset.cpp
+2 -2
View File
@@ -27,12 +27,12 @@ void MaterialLoader::importAsset(const std::filesystem::path& name)
import(name, asset); import(name, asset);
} }
Job MaterialLoader::import(std::filesystem::path, PMaterialAsset asset) void MaterialLoader::import(std::filesystem::path, PMaterialAsset asset)
{ {
asset->load(); asset->load();
graphics->getShaderCompiler()->registerMaterial(asset); graphics->getShaderCompiler()->registerMaterial(asset);
AssetRegistry::get().registerMaterial(asset); AssetRegistry::get().registerMaterial(asset);
co_return; //co_return;
} }
PMaterialAsset MaterialLoader::getPlaceHolderMaterial() PMaterialAsset MaterialLoader::getPlaceHolderMaterial()
+1 -1
View File
@@ -18,7 +18,7 @@ public:
void importAsset(const std::filesystem::path& name); void importAsset(const std::filesystem::path& name);
PMaterialAsset getPlaceHolderMaterial(); PMaterialAsset getPlaceHolderMaterial();
private: private:
Job import(std::filesystem::path filePath, PMaterialAsset asset); void import(std::filesystem::path filePath, PMaterialAsset asset);
Gfx::PGraphics graphics; Gfx::PGraphics graphics;
List<std::future<void>> futures; List<std::future<void>> futures;
PMaterialAsset placeholderMaterial; PMaterialAsset placeholderMaterial;
+2 -2
View File
@@ -38,7 +38,7 @@ PTextureAsset TextureLoader::getPlaceholderTexture()
return placeholderAsset; return placeholderAsset;
} }
Job TextureLoader::import(std::filesystem::path path, PTextureAsset textureAsset) void TextureLoader::import(std::filesystem::path path, PTextureAsset textureAsset)
{ {
int x, y, n; int x, y, n;
unsigned char* data = stbi_load(path.string().c_str(), &x, &y, &n, 4); unsigned char* data = stbi_load(path.string().c_str(), &x, &y, &n, 4);
@@ -70,5 +70,5 @@ Job TextureLoader::import(std::filesystem::path path, PTextureAsset textureAsset
textureAsset->load(); textureAsset->load();
textureAsset->setStatus(Asset::Status::Ready); textureAsset->setStatus(Asset::Status::Ready);
co_return; //co_return;
} }
+1 -1
View File
@@ -19,7 +19,7 @@ public:
void importAsset(const std::filesystem::path& filePath); void importAsset(const std::filesystem::path& filePath);
PTextureAsset getPlaceholderTexture(); PTextureAsset getPlaceholderTexture();
private: private:
Job import(std::filesystem::path path, PTextureAsset asset); void import(std::filesystem::path path, PTextureAsset asset);
Gfx::PGraphics graphics; Gfx::PGraphics graphics;
List<std::future<void>> futures; List<std::future<void>> futures;
PTextureAsset placeholderAsset; PTextureAsset placeholderAsset;
+1 -1
View File
@@ -1,4 +1,4 @@
target_sources(SeeleEngine target_sources(Engine
PRIVATE PRIVATE
EngineTypes.h EngineTypes.h
MinimalEngine.h MinimalEngine.h
+2 -2
View File
@@ -320,7 +320,7 @@ public:
{ {
remove(it - beginIt, keepOrder); remove(it - beginIt, keepOrder);
} }
constexpr void remove(int index, bool keepOrder = true) constexpr void remove(size_type index, bool keepOrder = true)
{ {
if (keepOrder) if (keepOrder)
{ {
@@ -333,7 +333,7 @@ public:
{ {
_data[index] = std::move(_data[arraySize - 1]); _data[index] = std::move(_data[arraySize - 1]);
} }
arraySize--; std::allocator_traits<allocator_type>::destroy(allocator, &_data[--arraySize]);
markIteratorDirty(); markIteratorDirty();
} }
constexpr void resize(size_type newSize) constexpr void resize(size_type newSize)
+1 -1
View File
@@ -1,4 +1,4 @@
target_sources(SeeleEngine target_sources(Engine
PRIVATE PRIVATE
Array.h Array.h
Map.h Map.h
+1 -1
View File
@@ -1,4 +1,4 @@
target_sources(SeeleEngine target_sources(Engine
PRIVATE PRIVATE
GraphicsResources.h GraphicsResources.h
GraphicsResources.cpp GraphicsResources.cpp
@@ -134,6 +134,7 @@ MainJob BasePass::beginFrame()
descriptorSets[INDEX_VIEW_PARAMS] = viewLayout->allocateDescriptorSet(); descriptorSets[INDEX_VIEW_PARAMS] = viewLayout->allocateDescriptorSet();
descriptorSets[INDEX_VIEW_PARAMS]->updateBuffer(0, viewParamBuffer); descriptorSets[INDEX_VIEW_PARAMS]->updateBuffer(0, viewParamBuffer);
descriptorSets[INDEX_VIEW_PARAMS]->writeChanges(); descriptorSets[INDEX_VIEW_PARAMS]->writeChanges();
//std::cout << "BasePass beginFrame()" << std::endl;
co_return; co_return;
} }
@@ -163,11 +164,13 @@ MainJob BasePass::render()
//co_await Job::all(jobs); //co_await Job::all(jobs);
graphics->executeCommands(processor->getRenderCommands()); graphics->executeCommands(processor->getRenderCommands());
graphics->endRenderPass(); graphics->endRenderPass();
//std::cout << "BasePass render()" << std::endl;
co_return; co_return;
} }
MainJob BasePass::endFrame() MainJob BasePass::endFrame()
{ {
//std::cout << "BasePass endFrame()" << std::endl;
co_return; co_return;
} }
@@ -1,4 +1,4 @@
target_sources(SeeleEngine target_sources(Engine
PRIVATE PRIVATE
BasePass.h BasePass.h
BasePass.cpp BasePass.cpp
@@ -115,6 +115,7 @@ MainJob DepthPrepass::beginFrame()
descriptorSets[INDEX_VIEW_PARAMS] = viewLayout->allocateDescriptorSet(); descriptorSets[INDEX_VIEW_PARAMS] = viewLayout->allocateDescriptorSet();
descriptorSets[INDEX_VIEW_PARAMS]->updateBuffer(0, viewParamBuffer); descriptorSets[INDEX_VIEW_PARAMS]->updateBuffer(0, viewParamBuffer);
descriptorSets[INDEX_VIEW_PARAMS]->writeChanges(); descriptorSets[INDEX_VIEW_PARAMS]->writeChanges();
//std::cout << "DepthPrepass beginFrame()" << std::endl;
co_return; co_return;
} }
@@ -134,11 +135,13 @@ MainJob DepthPrepass::render()
//co_await Job::all(jobs); //co_await Job::all(jobs);
graphics->executeCommands(processor->getRenderCommands()); graphics->executeCommands(processor->getRenderCommands());
graphics->endRenderPass(); graphics->endRenderPass();
//std::cout << "DepthPrepass render()" << std::endl;
co_return; co_return;
} }
MainJob DepthPrepass::endFrame() MainJob DepthPrepass::endFrame()
{ {
//std::cout << "DepthPrepass endFrame()" << std::endl;
co_return; co_return;
} }
@@ -75,7 +75,7 @@ MainJob LightCullingPass::beginFrame()
lightEnvDescriptorSet->updateBuffer(2, pointLightBuffer); lightEnvDescriptorSet->updateBuffer(2, pointLightBuffer);
lightEnvDescriptorSet->updateBuffer(3, numPointLightBuffer); lightEnvDescriptorSet->updateBuffer(3, numPointLightBuffer);
lightEnvDescriptorSet->writeChanges(); lightEnvDescriptorSet->writeChanges();
//std::cout << "Finished light culling beginFrame()" << std::endl; //std::cout << "LightCulling beginFrame()" << std::endl;
co_return; co_return;
} }
@@ -103,11 +103,13 @@ MainJob LightCullingPass::render()
graphics->executeCommands(commands); graphics->executeCommands(commands);
depthAttachment->changeLayout(Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); depthAttachment->changeLayout(Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
depthAttachment->transferOwnership(Gfx::QueueType::GRAPHICS); depthAttachment->transferOwnership(Gfx::QueueType::GRAPHICS);
//std::cout << "LightCulling render()" << std::endl;
co_return; co_return;
} }
MainJob LightCullingPass::endFrame() MainJob LightCullingPass::endFrame()
{ {
//std::cout << "LightCulling endFrame()" << std::endl;
co_return; co_return;
} }
@@ -26,7 +26,7 @@ public:
static void modifyRenderPassMacros(Map<const char*, const char*>& defines); static void modifyRenderPassMacros(Map<const char*, const char*>& defines);
private: private:
void setupFrustums(); void setupFrustums();
static constexpr uint32 BLOCK_SIZE = 8; static constexpr uint32 BLOCK_SIZE = 32;
static constexpr uint32 INDEX_LIGHT_ENV = 1; static constexpr uint32 INDEX_LIGHT_ENV = 1;
struct DispatchParams struct DispatchParams
{ {
@@ -39,9 +39,6 @@ private:
{ {
Vector n; Vector n;
float d; float d;
Vector p0;
Vector p1;
Vector p2;
}; };
struct Frustum struct Frustum
{ {
+1 -1
View File
@@ -1,4 +1,4 @@
target_sources(SeeleEngine target_sources(Engine
PRIVATE PRIVATE
NsightAftermathGpuCrashTracker.h NsightAftermathGpuCrashTracker.h
NsightAftermathGpuCrashTracker.cpp NsightAftermathGpuCrashTracker.cpp
+1 -1
View File
@@ -146,7 +146,7 @@ public:
private: private:
enum enum
{ {
MemoryBlockSize = 64 * 1024 * 1024 // 64MB MemoryBlockSize = 16 * 1024 * 1024 // 16MB
}; };
struct HeapInfo struct HeapInfo
{ {
@@ -332,7 +332,7 @@ PCommandBufferManager Graphics::getTransferCommands()
} }
PCommandBufferManager Graphics::getDedicatedTransferCommands() PCommandBufferManager Graphics::getDedicatedTransferCommands()
{ {
if(dedicatedTransferCommands == dedicatedTransferCommands) if(dedicatedTransferCommands == nullptr)
{ {
dedicatedTransferCommands = new CommandBufferManager(this, dedicatedTransferQueue); dedicatedTransferCommands = new CommandBufferManager(this, dedicatedTransferQueue);
} }
+1 -1
View File
@@ -1,4 +1,4 @@
target_sources(SeeleEngine target_sources(Engine
PRIVATE PRIVATE
BRDF.h BRDF.h
BRDF.cpp BRDF.cpp
+1 -1
View File
@@ -1,4 +1,4 @@
target_sources(SeeleEngine target_sources(Engine
PRIVATE PRIVATE
Math.h Math.h
Matrix.h Matrix.h
+1 -1
View File
@@ -1,4 +1,4 @@
target_sources(SeeleEngine target_sources(Engine
PRIVATE PRIVATE
Actor.cpp Actor.cpp
Actor.h Actor.h
+1 -1
View File
@@ -1,4 +1,4 @@
target_sources(SeeleEngine target_sources(Engine
PRIVATE PRIVATE
Util.h Util.h
Scene.cpp Scene.cpp
+1 -1
View File
@@ -1,4 +1,4 @@
target_sources(SeeleEngine target_sources(Engine
PRIVATE PRIVATE
CameraComponent.h CameraComponent.h
CameraComponent.cpp CameraComponent.cpp
@@ -4,7 +4,7 @@ using namespace Seele;
Job MyOtherComponent::tick(float deltaTime) const Job MyOtherComponent::tick(float deltaTime) const
{ {
std::cout << *data << std::endl; //std::cout << *data << std::endl;
co_return; co_return;
} }
+4 -4
View File
@@ -19,13 +19,13 @@ Scene::Scene(Gfx::PGraphics graphics)
lightEnv.directionalLights[0].intensity = Vector4(1, 1, 1, 1); lightEnv.directionalLights[0].intensity = Vector4(1, 1, 1, 1);
lightEnv.numDirectionalLights = 1; lightEnv.numDirectionalLights = 1;
srand((unsigned int)time(NULL)); srand((unsigned int)time(NULL));
for(uint32 i = 0; i < 16; ++i) for(uint32 i = 0; i < 256; ++i)
{ {
lightEnv.pointLights[i].colorRange = Vector4(frand(), frand(), frand(), frand() * 30); lightEnv.pointLights[i].colorRange = Vector4(frand(), frand(), frand(), frand() * 300);
lightEnv.pointLights[i].positionWS = Vector4(frand() * 100-50, frand(), frand() * 100-50, 1); lightEnv.pointLights[i].positionWS = Vector4(frand() * 100-50, frand(), frand() * 100-50, 1);
} }
lightEnv.numPointLights = 16; lightEnv.numPointLights = 256;
lightEnv.pointLights[0].colorRange = Vector4(1, 1, 1, 1000); lightEnv.pointLights[0].colorRange = Vector4(1, 0, 1, 1000);
lightEnv.pointLights[0].positionWS = Vector4(0, 10, 0, 1); lightEnv.pointLights[0].positionWS = Vector4(0, 10, 0, 1);
} }
+1 -2
View File
@@ -19,7 +19,6 @@ struct DirectionalLight
struct PointLight struct PointLight
{ {
Vector4 positionWS; Vector4 positionWS;
Vector4 positionVS;
Vector4 colorRange; Vector4 colorRange;
}; };
@@ -46,7 +45,7 @@ public:
const std::vector<PPrimitiveComponent>& getPrimitives() const { return primitives; } const std::vector<PPrimitiveComponent>& getPrimitives() const { return primitives; }
const std::vector<StaticMeshBatch>& getStaticMeshes() const { return staticMeshes; } const std::vector<StaticMeshBatch>& getStaticMeshes() const { return staticMeshes; }
const LightEnv& getLightBuffer() const { return lightEnv; } LightEnv& getLightBuffer() { return lightEnv; }
private: private:
std::vector<StaticMeshBatch> staticMeshes; std::vector<StaticMeshBatch> staticMeshes;
std::vector<PActor> rootActors; std::vector<PActor> rootActors;
+10 -13
View File
@@ -4,6 +4,7 @@
#include "MinimalEngine.h" #include "MinimalEngine.h"
#include "Containers/List.h" #include "Containers/List.h"
#include "Concepts.h" #include "Concepts.h"
#include <source_location>
namespace Seele namespace Seele
{ {
@@ -66,11 +67,11 @@ struct JobPromiseBase
EXECUTING, EXECUTING,
DONE DONE
}; };
JobPromiseBase() JobPromiseBase(const std::source_location& location = std::source_location::current())
{ {
handle = std::coroutine_handle<JobPromiseBase<MainJob>>::from_promise(*this); handle = std::coroutine_handle<JobPromiseBase<MainJob>>::from_promise(*this);
id = globalCounter++; id = globalCounter++;
finishedEvent = Event(std::format("Job {}", id)); finishedEvent = Event(std::string(location.file_name()).append(": ").append(location.function_name()));
} }
~JobPromiseBase() ~JobPromiseBase()
{} {}
@@ -101,6 +102,7 @@ struct JobPromiseBase
finishedEvent.raise(); finishedEvent.raise();
if(continuation) if(continuation)
{ {
std::scoped_lock lock(continuation->promiseLock);
getGlobalThreadPool().scheduleJob(continuation); getGlobalThreadPool().scheduleJob(continuation);
continuation->removeRef(); continuation->removeRef();
} }
@@ -108,6 +110,7 @@ struct JobPromiseBase
void setContinuation(JobPromiseBase* cont) void setContinuation(JobPromiseBase* cont)
{ {
std::scoped_lock lock(promiseLock, cont->promiseLock); std::scoped_lock lock(promiseLock, cont->promiseLock);
assert(cont->ready());
continuation = cont; continuation = cont;
cont->state = State::SCHEDULED; cont->state = State::SCHEDULED;
cont->addRef(); cont->addRef();
@@ -148,12 +151,12 @@ struct JobPromiseBase
} }
void schedule() void schedule()
{ {
//dont lock here, as it is already locked from outside
std::scoped_lock lock(promiseLock); std::scoped_lock lock(promiseLock);
if(!handle || done() || !ready()) if(!handle || done() || !ready())
{ {
return; return;
} }
state = State::SCHEDULED;
getGlobalThreadPool().scheduleJob(this); getGlobalThreadPool().scheduleJob(this);
} }
void addRef() void addRef()
@@ -243,6 +246,7 @@ public:
JobBase&& then(JobBase&& continuation) JobBase&& then(JobBase&& continuation)
{ {
promise->setContinuation(continuation.promise); promise->setContinuation(continuation.promise);
promise->schedule();
return std::move(continuation); return std::move(continuation);
} }
bool done() bool done()
@@ -253,19 +257,12 @@ public:
{ {
promise->finalize(); promise->finalize();
} }
Event operator co_await() Event operator co_await() const
{ {
Event result = promise->finishedEvent; // the co_await operator keeps a reference to this, we it won't
// if we schedule the promise now, it might finish and self destruct
// but there is no way for us to know that
// but as the co_await operator keeps a reference to this, we it won't
// be scheduled from the destructor // be scheduled from the destructor
promise->schedule(); promise->schedule();
// so we reset the promise so we don't schedule it when this destructs return promise->finishedEvent;
promise->removeRef();
promise = nullptr;
// but we still have to provide with the event, so we get that first
return result;
} }
static JobBase all() = delete; static JobBase all() = delete;
template<iterable Iterable> template<iterable Iterable>
+1 -1
View File
@@ -1,4 +1,4 @@
target_sources(SeeleEngine target_sources(Engine
PRIVATE PRIVATE
HorizontalLayout.h HorizontalLayout.h
HorizontalLayout.cpp HorizontalLayout.cpp
+1 -1
View File
@@ -1,4 +1,4 @@
target_sources(SeeleEngine target_sources(Engine
PRIVATE PRIVATE
Element.h Element.h
Element.cpp) Element.cpp)
+1 -1
View File
@@ -1,4 +1,4 @@
target_sources(SeeleEngine target_sources(Engine
PRIVATE PRIVATE
InspectorView.h InspectorView.h
InspectorView.cpp InspectorView.cpp
+3 -5
View File
@@ -41,11 +41,9 @@ void InspectorView::prepareRender()
MainJob InspectorView::render() MainJob InspectorView::render()
{ {
co_await uiPass.beginFrame(); return uiPass.beginFrame()
co_await uiPass.render(); .then(uiPass.render())
co_await uiPass.endFrame(); .then(uiPass.endFrame());
renderFinishedEvent.raise();
co_return;
} }
void InspectorView::keyCallback(KeyCode, InputAction, KeyModifier) void InspectorView::keyCallback(KeyCode, InputAction, KeyModifier)
+14 -12
View File
@@ -34,7 +34,7 @@ Seele::SceneView::SceneView(Gfx::PGraphics graphics, PWindow owner, const Viewpo
PPrimitiveComponent ayaka = new PrimitiveComponent(AssetRegistry::findMesh("Ayaka")); PPrimitiveComponent ayaka = new PrimitiveComponent(AssetRegistry::findMesh("Ayaka"));
ayaka->addWorldTranslation(Vector(0, 0, 0)); ayaka->addWorldTranslation(Vector(0, 0, 0));
ayaka->setWorldScale(Vector(10, 10, 10)); ayaka->setWorldScale(Vector(10, 10, 10));
scene->addPrimitiveComponent(ayaka); //scene->addPrimitiveComponent(ayaka);
PPrimitiveComponent plane = new PrimitiveComponent(AssetRegistry::findMesh("plane")); PPrimitiveComponent plane = new PrimitiveComponent(AssetRegistry::findMesh("plane"));
plane->setWorldScale(Vector(100, 100, 100)); plane->setWorldScale(Vector(100, 100, 100));
@@ -97,17 +97,19 @@ void SceneView::prepareRender()
MainJob SceneView::render() MainJob SceneView::render()
{ {
co_await depthPrepass.beginFrame(); return MainJob::all(
co_await lightCullingPass.beginFrame(); depthPrepass.beginFrame(),
co_await basePass.beginFrame(); lightCullingPass.beginFrame(),
co_await depthPrepass.render(); basePass.beginFrame())
co_await lightCullingPass.render(); .then(depthPrepass.render())
co_await basePass.render(); .then(lightCullingPass.render())
co_await depthPrepass.endFrame(); .then(basePass.render())
co_await lightCullingPass.endFrame(); .then(
co_await basePass.endFrame(); MainJob::all(
renderFinishedEvent.raise(); depthPrepass.endFrame(),
co_return; lightCullingPass.endFrame(),
basePass.endFrame())
);
} }
void SceneView::keyCallback(KeyCode code, InputAction action, KeyModifier) void SceneView::keyCallback(KeyCode code, InputAction action, KeyModifier)
-1
View File
@@ -8,7 +8,6 @@ View::View(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &vi
: graphics(graphics) : graphics(graphics)
, owner(window) , owner(window)
, name(name) , name(name)
, renderFinishedEvent(std::format("{}RenderFinished", name))
{ {
viewport = graphics->createViewport(owner->getGfxHandle(), viewportInfo); viewport = graphics->createViewport(owner->getGfxHandle(), viewportInfo);
} }
-3
View File
@@ -24,15 +24,12 @@ public:
virtual MainJob render() = 0; virtual MainJob render() = 0;
void applyArea(URect area); void applyArea(URect area);
void setFocused(); void setFocused();
Event renderFinished() { return renderFinishedEvent; }
void resetRender() { renderFinishedEvent.reset(); }
protected: protected:
Gfx::PGraphics graphics; Gfx::PGraphics graphics;
Gfx::PViewport viewport; Gfx::PViewport viewport;
PWindow owner; PWindow owner;
std::string name; std::string name;
Event renderFinishedEvent;
virtual void keyCallback(KeyCode code, InputAction action, KeyModifier modifier) = 0; virtual void keyCallback(KeyCode code, InputAction action, KeyModifier modifier) = 0;
virtual void mouseMoveCallback(double xPos, double yPos) = 0; virtual void mouseMoveCallback(double xPos, double yPos) = 0;
+7 -9
View File
@@ -27,21 +27,16 @@ void Window::addView(PView view)
MainJob Window::render() MainJob Window::render()
{ {
gfxHandle->beginFrame(); gfxHandle->beginFrame();
Array<MainJob> jobs;
for(auto& windowView : views) for(auto& windowView : views)
{ {
co_await windowView->updateFinished;
windowView->updateFinished.reset();
{ {
std::scoped_lock lock(windowView->workerMutex); std::scoped_lock lock(windowView->workerMutex);
windowView->view->prepareRender(); windowView->view->prepareRender();
} }
windowView->view->render(); jobs.add(windowView->view->render());
}
for(auto& windowView : views)
{
co_await windowView->view->renderFinished();
windowView->view->resetRender();
} }
co_await MainJob::all(jobs);
gfxHandle->endFrame(); gfxHandle->endFrame();
if(owner->isActive()) if(owner->isActive())
{ {
@@ -82,8 +77,11 @@ Job Window::viewWorker(size_t viewIndex)
windowView->view->commitUpdate(); windowView->view->commitUpdate();
} }
//std::cout << "Update completed" << std::endl; //std::cout << "Update completed" << std::endl;
windowView->updateFinished.raise(); //windowView->updateFinished.raise();
// enqueue next frame update // enqueue next frame update
if(owner->isActive())
{
viewWorker(viewIndex); viewWorker(viewIndex);
}
co_return; co_return;
} }
+1 -2
View File
@@ -41,7 +41,6 @@ void WindowManager::notifyWindowClosed(PWindow window)
windows.remove(windows.find(window)); windows.remove(windows.find(window));
if(windows.empty()) if(windows.empty())
{ {
std::scoped_lock lock(windowsLock); getGlobalThreadPool().cleanup();
windowsCV.notify_all();
} }
} }
-7
View File
@@ -22,16 +22,9 @@ public:
{ {
return windows.size(); return windows.size();
} }
void waitForCompletion()
{
std::unique_lock lock(windowsLock);
windowsCV.wait(lock);
}
private: private:
Array<PWindow> windows; Array<PWindow> windows;
std::mutex windowsLock;
std::condition_variable windowsCV;
static Gfx::PGraphics graphics; static Gfx::PGraphics graphics;
}; };
DEFINE_REF(WindowManager) DEFINE_REF(WindowManager)
-4
View File
@@ -93,18 +93,15 @@ uint64 basicAllState2 = 0;
Job basicAllFirst() Job basicAllFirst()
{ {
basicAllState1 = 10; basicAllState1 = 10;
std::cout << "AllFirst" << std::endl;
co_return; co_return;
} }
Job basicAllSecond() Job basicAllSecond()
{ {
basicAllState2 = 10; basicAllState2 = 10;
std::cout << "AllSecond" << std::endl;
co_return; co_return;
} }
Job basicAllThen() Job basicAllThen()
{ {
std::cout << "AllThen" << std::endl;
BOOST_REQUIRE_EQUAL(basicAllState1, 10); BOOST_REQUIRE_EQUAL(basicAllState1, 10);
BOOST_REQUIRE_EQUAL(basicAllState2, 10); BOOST_REQUIRE_EQUAL(basicAllState2, 10);
co_return; co_return;
@@ -129,7 +126,6 @@ BOOST_AUTO_TEST_CASE(basic_callable)
.then([=]() -> Job .then([=]() -> Job
{ {
BOOST_REQUIRE_EQUAL(basicCallable, 10); BOOST_REQUIRE_EQUAL(basicCallable, 10);
std::cout << "callable" << std::endl;
co_return; co_return;
}); });
} }