From 7eedaf61ba880571e7736a064295e969a9b03f6c Mon Sep 17 00:00:00 2001 From: Dynamitos Date: Thu, 4 Apr 2024 08:30:59 +0200 Subject: [PATCH] Updating slang --- CMakeLists.txt | 1 - cmake/SuperBuild.cmake | 20 ++--- res/shaders/LightCulling.slang | 8 +- res/shaders/MeshletBasePass.slang | 40 +++------- res/shaders/lib/LightEnv.slang | 5 -- res/shaders/lib/Scene.slang | 4 +- src/Engine/Graphics/RenderPass/BasePass.cpp | 7 +- .../Graphics/RenderPass/DepthPrepass.cpp | 26 +++++-- .../Graphics/RenderPass/LightCullingPass.cpp | 6 +- src/Engine/Graphics/VertexData.cpp | 78 +++++++++---------- src/Engine/Graphics/VertexData.h | 4 +- src/Engine/Graphics/Vulkan/Graphics.cpp | 2 +- vcpkg.json | 3 +- 13 files changed, 93 insertions(+), 111 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a2c409..cbabe16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,7 +50,6 @@ find_package(nlohmann_json CONFIG REQUIRED) find_package(fmt CONFIG REQUIRED) find_package(VulkanMemoryAllocator CONFIG REQUIRED) - if(UNIX) find_package(Threads REQUIRED) endif() diff --git a/cmake/SuperBuild.cmake b/cmake/SuperBuild.cmake index 6a94938..8f405c9 100644 --- a/cmake/SuperBuild.cmake +++ b/cmake/SuperBuild.cmake @@ -5,21 +5,21 @@ include (ExternalProject) add_library(shader-slang-glslang SHARED IMPORTED) add_library(shader-slang SHARED IMPORTED) if(WIN32) - set(SLANG_ROOT ${EXTERNAL_ROOT}/slang/bin/windows-x64/release) - set_target_properties(shader-slang-glslang PROPERTIES IMPORTED_LOCATION ${SLANG_ROOT}/slang-glslang.dll) - set_target_properties(shader-slang-glslang PROPERTIES IMPORTED_IMPLIB ${SLANG_ROOT}/slang.lib) - set_target_properties(shader-slang PROPERTIES IMPORTED_LOCATION ${SLANG_ROOT}/slang.dll) - set_target_properties(shader-slang PROPERTIES IMPORTED_IMPLIB ${SLANG_ROOT}/slang.lib) + set(SLANG_ROOT ${EXTERNAL_ROOT}/vcpkg/packages/shader-slang_x64-windows/) + set_target_properties(shader-slang-glslang PROPERTIES IMPORTED_LOCATION ${SLANG_ROOT}/bin/slang-glslang.dll) + set_target_properties(shader-slang-glslang PROPERTIES IMPORTED_IMPLIB ${SLANG_ROOT}/lib/slang.lib) + set_target_properties(shader-slang PROPERTIES IMPORTED_LOCATION ${SLANG_ROOT}/bin/slang.dll) + set_target_properties(shader-slang PROPERTIES IMPORTED_IMPLIB ${SLANG_ROOT}/lib/slang.lib) target_link_libraries(shader-slang INTERFACE shader-slang-glslang) install(FILES - ${SLANG_ROOT}/slang-glslang.dll - ${SLANG_ROOT}/slang.dll + ${SLANG_ROOT}/bin/slang-glslang.dll + ${SLANG_ROOT}/bin/slang.dll DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) install(FILES - ${SLANG_ROOT}/slang.lib + ${SLANG_ROOT}/lib/slang.lib DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) elseif(APPLE) - set(SLANG_ROOT ${EXTERNAL_ROOT}/slang/bin/macosx-aarch64/release) + set(SLANG_ROOT ${EXTERNAL_ROOT}/vcpkg/packages/shader-slang_${CMAKE_PLATFORM}-macos/) set_target_properties(shader-slang-glslang PROPERTIES IMPORTED_LOCATION ${SLANG_ROOT}/libslang-glslang.dylib) set_target_properties(shader-slang PROPERTIES IMPORTED_LOCATION ${SLANG_ROOT}/libslang.dylib) target_link_libraries(shader-slang INTERFACE shader-slang-glslang) @@ -29,7 +29,7 @@ elseif(APPLE) DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) endif() target_include_directories(shader-slang INTERFACE - $ + $ $ ) diff --git a/res/shaders/LightCulling.slang b/res/shaders/LightCulling.slang index 0de119e..a34eded 100644 --- a/res/shaders/LightCulling.slang +++ b/res/shaders/LightCulling.slang @@ -32,6 +32,7 @@ groupshared uint uMinDepth; groupshared uint uMaxDepth; groupshared Frustum groupFrustum; +groupshared float4x4 viewMatrix; groupshared uint oLightCount; groupshared uint oLightIndexStartOffset; @@ -72,6 +73,7 @@ void cullLights(ComputeShaderInput in) uint uDepth = asuint(fDepth); if(in.groupIndex == 0) { + viewMatrix = pViewParams.viewMatrix; uMinDepth = 0xffffffff; uMaxDepth = 0x0; oLightCount = 0; @@ -98,11 +100,11 @@ void cullLights(ComputeShaderInput in) for ( uint i = in.groupIndex; i < pLightEnv.numPointLights; i += BLOCK_SIZE * BLOCK_SIZE ) { PointLight light = pLightEnv.pointLights[i]; - float3 light_VS = light.getViewPosition(); - if(light.insideFrustum(groupFrustum, light_VS, nearClipVS, maxDepthVS)) + float3 light_VS = mul(viewMatrix, float4(light.position_WS.xyz, 1.0f)).xyz; + //if(light.insideFrustum(groupFrustum, light_VS, nearClipVS, maxDepthVS)) { tAppendLight(i); - if(!light.insidePlane(minPlane, light_VS)) + //if(!light.insidePlane(minPlane, light_VS)) { oAppendLight(i); } diff --git a/res/shaders/MeshletBasePass.slang b/res/shaders/MeshletBasePass.slang index 7327ead..a824a3d 100644 --- a/res/shaders/MeshletBasePass.slang +++ b/res/shaders/MeshletBasePass.slang @@ -47,7 +47,7 @@ void taskMain( { uint m = mesh.meshletOffset + i; MeshletDescription meshlet = pScene.meshletInfos[m]; - if(meshlet.bounding.insideFrustum(localToView, viewFrustum)) + //if(meshlet.bounding.insideFrustum(localToView, viewFrustum)) { uint index; InterlockedAdd(head, 1, index); @@ -72,41 +72,23 @@ void meshMain( in uint threadID: SV_GroupIndex, in uint groupID: SV_GroupID, in payload MeshPayload meshPayload, - out Vertices vertices, - out Indices indices + OutputVertices vertices, + OutputIndices indices ){ InstanceData inst = pScene.instances[meshPayload.instanceId[groupID]]; MeshData md = pScene.meshData[meshPayload.instanceId[groupID]]; MeshletDescription m = pScene.meshletInfos[meshPayload.meshletId[groupID]]; SetMeshOutputCounts(m.vertexCount, m.primitiveCount); - uint p = min(threadID, m.primitiveCount - 1); + for(uint i = threadID; i < MAX_PRIMITIVES; i += MESH_GROUP_SIZE) { - uint local_idx0 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 0]; - uint local_idx1 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 1]; - uint local_idx2 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 2]; - indices[p] = uint3(local_idx0, local_idx1, local_idx2); - } - p = min(threadID + 32, m.primitiveCount - 1); - { - uint local_idx0 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 0]; - uint local_idx1 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 1]; - uint local_idx2 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 2]; - indices[p] = uint3(local_idx0, local_idx1, local_idx2); - } - p = min(threadID + 64, m.primitiveCount - 1); - { - uint local_idx0 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 0]; - uint local_idx1 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 1]; - uint local_idx2 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 2]; - indices[p] = uint3(local_idx0, local_idx1, local_idx2); - } - p = min(threadID + 96, m.primitiveCount - 1); - { - uint local_idx0 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 0]; - uint local_idx1 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 1]; - uint local_idx2 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 2]; - indices[p] = uint3(local_idx0, local_idx1, local_idx2); + uint p = min(i, m.primitiveCount - 1); + { + uint local_idx0 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 0]; + uint local_idx1 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 1]; + uint local_idx2 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 2]; + indices[p] = uint3(local_idx0, local_idx1, local_idx2); + } } GroupMemoryBarrierWithGroupSync(); diff --git a/res/shaders/lib/LightEnv.slang b/res/shaders/lib/LightEnv.slang index 074ef11..608ef05 100644 --- a/res/shaders/lib/LightEnv.slang +++ b/res/shaders/lib/LightEnv.slang @@ -32,11 +32,6 @@ struct PointLight : ILightEnv float illuminance = max(1 - d / colorRange.w, 0); return illuminance * brdf.evaluate(params.tbn, params.viewDir_TS, -normalize(lightDir_TS), colorRange.xyz); } - float3 getViewPosition() - { - float4 position_VS = mul(pViewParams.viewMatrix, position_WS); - return position_VS.xyz / position_VS.w; - } bool insidePlane(Plane plane, float3 position_VS) { diff --git a/res/shaders/lib/Scene.slang b/res/shaders/lib/Scene.slang index 3567f00..82cd316 100644 --- a/res/shaders/lib/Scene.slang +++ b/res/shaders/lib/Scene.slang @@ -2,7 +2,7 @@ import Bounding; struct MeshletDescription { - AABB bounding; + BoundingSphere bounding; uint32_t vertexCount; uint32_t primitiveCount; uint32_t vertexOffset; @@ -13,7 +13,7 @@ struct MeshletDescription struct MeshData { - AABB bounding; + BoundingSphere bounding; uint32_t numMeshlets; uint32_t meshletOffset; uint32_t firstIndex; diff --git a/src/Engine/Graphics/RenderPass/BasePass.cpp b/src/Engine/Graphics/RenderPass/BasePass.cpp index 07131dc..4566480 100644 --- a/src/Engine/Graphics/RenderPass/BasePass.cpp +++ b/src/Engine/Graphics/RenderPass/BasePass.cpp @@ -56,9 +56,6 @@ void BasePass::render() tLightGrid->pipelineBarrier( Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT); - depthAttachment.getTexture()->pipelineBarrier( - Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, - Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT, Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT); descriptorSets[INDEX_VIEW_PARAMS] = viewParamsSet; descriptorSets[INDEX_LIGHT_ENV] = scene->getLightEnvironment()->getDescriptorSet(); @@ -197,7 +194,7 @@ void BasePass::publishOutputs() void BasePass::createRenderPass() { depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH"); - depthAttachment.setLoadOp(Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR); + depthAttachment.setLoadOp(Gfx::SE_ATTACHMENT_LOAD_OP_LOAD); depthAttachment.setInitialLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL); depthAttachment.setFinalLayout(Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{ @@ -238,7 +235,7 @@ void BasePass::createRenderPass() .dstAccess = Gfx::SE_ACCESS_NONE, }, }; - renderPass = graphics->createRenderPass(std::move(layout), {dependency}, viewport); + renderPass = graphics->createRenderPass(std::move(layout), std::move(dependency), viewport); oLightIndexList = resources->requestBuffer("LIGHTCULLING_OLIGHTLIST"); tLightIndexList = resources->requestBuffer("LIGHTCULLING_TLIGHTLIST"); oLightGrid = resources->requestTexture("LIGHTCULLING_OLIGHTGRID"); diff --git a/src/Engine/Graphics/RenderPass/DepthPrepass.cpp b/src/Engine/Graphics/RenderPass/DepthPrepass.cpp index 4294943..a9e2d4a 100644 --- a/src/Engine/Graphics/RenderPass/DepthPrepass.cpp +++ b/src/Engine/Graphics/RenderPass/DepthPrepass.cpp @@ -161,15 +161,25 @@ void DepthPrepass::createRenderPass() Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{ .depthAttachment = depthAttachment, }; - Gfx::SubPassDependency dependency = { - .srcSubpass = ~0U, - .dstSubpass = 0, - .srcStage = Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, - .dstStage = Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT, - .srcAccess = Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, - .dstAccess = Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, + Array dependency = { + { + .srcSubpass = ~0U, + .dstSubpass = 0, + .srcStage = Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, + .dstStage = Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT, + .srcAccess = Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, + .dstAccess = Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, + }, + { + .srcSubpass = 0, + .dstSubpass = ~0U, + .srcStage = Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, + .dstStage = Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + .srcAccess = Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, + .dstAccess = Gfx::SE_ACCESS_SHADER_READ_BIT, + } }; - renderPass = graphics->createRenderPass(std::move(layout), {dependency}, viewport); + renderPass = graphics->createRenderPass(std::move(layout), dependency, viewport); } void DepthPrepass::modifyRenderPassMacros(Map&) diff --git a/src/Engine/Graphics/RenderPass/LightCullingPass.cpp b/src/Engine/Graphics/RenderPass/LightCullingPass.cpp index b2b220b..032ae2f 100644 --- a/src/Engine/Graphics/RenderPass/LightCullingPass.cpp +++ b/src/Engine/Graphics/RenderPass/LightCullingPass.cpp @@ -51,9 +51,6 @@ void LightCullingPass::beginFrame(const Component::Camera& cam) void LightCullingPass::render() { - depthAttachment->pipelineBarrier( - Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, - Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); depthAttachment->transferOwnership(Gfx::QueueType::COMPUTE); cullingDescriptorSet->updateTexture(0, depthAttachment); cullingDescriptorSet->updateBuffer(1, oLightIndexCounter); @@ -70,7 +67,6 @@ void LightCullingPass::render() Array commands = {computeCommand}; //std::cout << "Execute" << std::endl; graphics->executeCommands(commands); - graphics->waitDeviceIdle(); } void LightCullingPass::endFrame() @@ -157,7 +153,7 @@ void LightCullingPass::publishOutputs() .size = (uint32)sizeof(uint32) * dispatchParams.numThreadGroups.x * dispatchParams.numThreadGroups.y - * dispatchParams.numThreadGroups.z * 1024 * 16, + * dispatchParams.numThreadGroups.z * 8192, .data = nullptr, .owner = Gfx::QueueType::COMPUTE }, diff --git a/src/Engine/Graphics/VertexData.cpp b/src/Engine/Graphics/VertexData.cpp index cc09785..b76e39e 100644 --- a/src/Engine/Graphics/VertexData.cpp +++ b/src/Engine/Graphics/VertexData.cpp @@ -44,43 +44,43 @@ void VertexData::updateMesh(PMesh mesh, Component::Transform& transform) }, .data = data, }); - for (size_t i = 0; i < data.numMeshlets; ++i) - { - auto bounding = meshlets[data.meshletOffset + i].bounding; - StaticArray corners; - corners[0] = transform.toMatrix() * Vector4(bounding.min.x, bounding.min.y, bounding.min.z, 1); - corners[1] = transform.toMatrix() * Vector4(bounding.min.x, bounding.min.y, bounding.max.z, 1); - corners[2] = transform.toMatrix() * Vector4(bounding.min.x, bounding.max.y, bounding.min.z, 1); - corners[3] = transform.toMatrix() * Vector4(bounding.min.x, bounding.max.y, bounding.max.z, 1); - corners[4] = transform.toMatrix() * Vector4(bounding.max.x, bounding.min.y, bounding.min.z, 1); - corners[5] = transform.toMatrix() * Vector4(bounding.max.x, bounding.min.y, bounding.max.z, 1); - corners[6] = transform.toMatrix() * Vector4(bounding.max.x, bounding.max.y, bounding.min.z, 1); - corners[7] = transform.toMatrix() * Vector4(bounding.max.x, bounding.max.y, bounding.max.z, 1); - addDebugVertex(DebugVertex{ .position = corners[0], .color = meshlets[data.meshletOffset + i].color }); - addDebugVertex(DebugVertex{ .position = corners[1], .color = meshlets[data.meshletOffset + i].color }); - addDebugVertex(DebugVertex{ .position = corners[0], .color = meshlets[data.meshletOffset + i].color }); - addDebugVertex(DebugVertex{ .position = corners[2], .color = meshlets[data.meshletOffset + i].color }); - addDebugVertex(DebugVertex{ .position = corners[1], .color = meshlets[data.meshletOffset + i].color }); - addDebugVertex(DebugVertex{ .position = corners[3], .color = meshlets[data.meshletOffset + i].color }); - addDebugVertex(DebugVertex{ .position = corners[2], .color = meshlets[data.meshletOffset + i].color }); - addDebugVertex(DebugVertex{ .position = corners[3], .color = meshlets[data.meshletOffset + i].color }); - addDebugVertex(DebugVertex{ .position = corners[0], .color = meshlets[data.meshletOffset + i].color }); - addDebugVertex(DebugVertex{ .position = corners[4], .color = meshlets[data.meshletOffset + i].color }); - addDebugVertex(DebugVertex{ .position = corners[1], .color = meshlets[data.meshletOffset + i].color }); - addDebugVertex(DebugVertex{ .position = corners[5], .color = meshlets[data.meshletOffset + i].color }); - addDebugVertex(DebugVertex{ .position = corners[2], .color = meshlets[data.meshletOffset + i].color }); - addDebugVertex(DebugVertex{ .position = corners[6], .color = meshlets[data.meshletOffset + i].color }); - addDebugVertex(DebugVertex{ .position = corners[3], .color = meshlets[data.meshletOffset + i].color }); - addDebugVertex(DebugVertex{ .position = corners[7], .color = meshlets[data.meshletOffset + i].color }); - addDebugVertex(DebugVertex{ .position = corners[4], .color = meshlets[data.meshletOffset + i].color }); - addDebugVertex(DebugVertex{ .position = corners[5], .color = meshlets[data.meshletOffset + i].color }); - addDebugVertex(DebugVertex{ .position = corners[4], .color = meshlets[data.meshletOffset + i].color }); - addDebugVertex(DebugVertex{ .position = corners[6], .color = meshlets[data.meshletOffset + i].color }); - addDebugVertex(DebugVertex{ .position = corners[6], .color = meshlets[data.meshletOffset + i].color }); - addDebugVertex(DebugVertex{ .position = corners[7], .color = meshlets[data.meshletOffset + i].color }); - addDebugVertex(DebugVertex{ .position = corners[5], .color = meshlets[data.meshletOffset + i].color }); - addDebugVertex(DebugVertex{ .position = corners[7], .color = meshlets[data.meshletOffset + i].color }); - } + //for (size_t i = 0; i < data.numMeshlets; ++i) + //{ + // auto bounding = meshlets[data.meshletOffset + i].bounding; + // StaticArray corners; + // corners[0] = transform.toMatrix() * Vector4(bounding.min.x, bounding.min.y, bounding.min.z, 1); + // corners[1] = transform.toMatrix() * Vector4(bounding.min.x, bounding.min.y, bounding.max.z, 1); + // corners[2] = transform.toMatrix() * Vector4(bounding.min.x, bounding.max.y, bounding.min.z, 1); + // corners[3] = transform.toMatrix() * Vector4(bounding.min.x, bounding.max.y, bounding.max.z, 1); + // corners[4] = transform.toMatrix() * Vector4(bounding.max.x, bounding.min.y, bounding.min.z, 1); + // corners[5] = transform.toMatrix() * Vector4(bounding.max.x, bounding.min.y, bounding.max.z, 1); + // corners[6] = transform.toMatrix() * Vector4(bounding.max.x, bounding.max.y, bounding.min.z, 1); + // corners[7] = transform.toMatrix() * Vector4(bounding.max.x, bounding.max.y, bounding.max.z, 1); + // addDebugVertex(DebugVertex{ .position = corners[0], .color = meshlets[data.meshletOffset + i].color }); + // addDebugVertex(DebugVertex{ .position = corners[1], .color = meshlets[data.meshletOffset + i].color }); + // addDebugVertex(DebugVertex{ .position = corners[0], .color = meshlets[data.meshletOffset + i].color }); + // addDebugVertex(DebugVertex{ .position = corners[2], .color = meshlets[data.meshletOffset + i].color }); + // addDebugVertex(DebugVertex{ .position = corners[1], .color = meshlets[data.meshletOffset + i].color }); + // addDebugVertex(DebugVertex{ .position = corners[3], .color = meshlets[data.meshletOffset + i].color }); + // addDebugVertex(DebugVertex{ .position = corners[2], .color = meshlets[data.meshletOffset + i].color }); + // addDebugVertex(DebugVertex{ .position = corners[3], .color = meshlets[data.meshletOffset + i].color }); + // addDebugVertex(DebugVertex{ .position = corners[0], .color = meshlets[data.meshletOffset + i].color }); + // addDebugVertex(DebugVertex{ .position = corners[4], .color = meshlets[data.meshletOffset + i].color }); + // addDebugVertex(DebugVertex{ .position = corners[1], .color = meshlets[data.meshletOffset + i].color }); + // addDebugVertex(DebugVertex{ .position = corners[5], .color = meshlets[data.meshletOffset + i].color }); + // addDebugVertex(DebugVertex{ .position = corners[2], .color = meshlets[data.meshletOffset + i].color }); + // addDebugVertex(DebugVertex{ .position = corners[6], .color = meshlets[data.meshletOffset + i].color }); + // addDebugVertex(DebugVertex{ .position = corners[3], .color = meshlets[data.meshletOffset + i].color }); + // addDebugVertex(DebugVertex{ .position = corners[7], .color = meshlets[data.meshletOffset + i].color }); + // addDebugVertex(DebugVertex{ .position = corners[4], .color = meshlets[data.meshletOffset + i].color }); + // addDebugVertex(DebugVertex{ .position = corners[5], .color = meshlets[data.meshletOffset + i].color }); + // addDebugVertex(DebugVertex{ .position = corners[4], .color = meshlets[data.meshletOffset + i].color }); + // addDebugVertex(DebugVertex{ .position = corners[6], .color = meshlets[data.meshletOffset + i].color }); + // addDebugVertex(DebugVertex{ .position = corners[6], .color = meshlets[data.meshletOffset + i].color }); + // addDebugVertex(DebugVertex{ .position = corners[7], .color = meshlets[data.meshletOffset + i].color }); + // addDebugVertex(DebugVertex{ .position = corners[5], .color = meshlets[data.meshletOffset + i].color }); + // addDebugVertex(DebugVertex{ .position = corners[7], .color = meshlets[data.meshletOffset + i].color }); + //} } matInstanceData.materialInstance = referencedInstance; referencedInstance->updateDescriptor(); @@ -164,7 +164,7 @@ void VertexData::loadMesh(MeshId id, Array loadedIndices, Array primitiveIndices.resize(primitiveOffset + (m.numPrimitives * 3)); std::memcpy(primitiveIndices.data() + primitiveOffset, m.primitiveLayout, m.numPrimitives * 3 * sizeof(uint8)); meshlets.add(MeshletDescription{ - .bounding = m.boundingBox, + .bounding = m.boundingBox.toSphere(), .vertexCount = m.numVertices, .primitiveCount = m.numPrimitives, .vertexOffset = vertexOffset, @@ -173,7 +173,7 @@ void VertexData::loadMesh(MeshId id, Array loadedIndices, Array }); } meshData[id].add(MeshData{ - .bounding = meshAABB, + .bounding = meshAABB.toSphere(), .numMeshlets = numMeshlets, .meshletOffset = meshletOffset, .indicesOffset = (uint32)meshOffsets[id], diff --git a/src/Engine/Graphics/VertexData.h b/src/Engine/Graphics/VertexData.h index 95d7c91..28898a2 100644 --- a/src/Engine/Graphics/VertexData.h +++ b/src/Engine/Graphics/VertexData.h @@ -32,7 +32,7 @@ public: }; struct MeshData { - AABB bounding; + BoundingSphere bounding; uint32 numMeshlets = 0; uint32 meshletOffset = 0; uint32 firstIndex = 0; @@ -85,7 +85,7 @@ protected: VertexData(); struct MeshletDescription { - AABB bounding; + BoundingSphere bounding; uint32_t vertexCount; uint32_t primitiveCount; uint32_t vertexOffset; diff --git a/src/Engine/Graphics/Vulkan/Graphics.cpp b/src/Engine/Graphics/Vulkan/Graphics.cpp index 0b18274..28735cb 100644 --- a/src/Engine/Graphics/Vulkan/Graphics.cpp +++ b/src/Engine/Graphics/Vulkan/Graphics.cpp @@ -35,12 +35,12 @@ Graphics::~Graphics() { vkDeviceWaitIdle(handle); pipelineCache = nullptr; - allocator = nullptr; allocatedFramebuffers.clear(); shaderCompiler = nullptr; pools.clear(); queues.clear(); destructionManager = nullptr; + allocator = nullptr; vkDestroyDevice(handle, nullptr); DestroyDebugUtilsMessengerEXT(instance, nullptr, callback); vkDestroyInstance(instance, nullptr); diff --git a/vcpkg.json b/vcpkg.json index 290a6b6..d023adf 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -11,6 +11,7 @@ "nlohmann-json", "fmt", "gtest", - "vulkan-memory-allocator" + "vulkan-memory-allocator", + "shader-slang" ] } \ No newline at end of file