diff --git a/external/vcpkg b/external/vcpkg index fe87e02..5c7c15b 160000 --- a/external/vcpkg +++ b/external/vcpkg @@ -1 +1 @@ -Subproject commit fe87e026b263e89739c4b7c885f000ace2abc95d +Subproject commit 5c7c15b964f9ceceb798cb154bc9ec2c68158462 diff --git a/res/shaders/lib/Scene.slang b/res/shaders/lib/Scene.slang index 9c6b16e..8200467 100644 --- a/res/shaders/lib/Scene.slang +++ b/res/shaders/lib/Scene.slang @@ -2,6 +2,7 @@ import AABB; struct MeshletDescription { + AABB boundingBox; uint32_t vertexCount; uint32_t primitiveCount; uint32_t vertexOffset; @@ -10,11 +11,12 @@ struct MeshletDescription struct MeshData { - uint32_t meshletOffset = 0; - uint16_t numMeshlets = 0; - uint16_t indicesOffset = 0; - uint32_t firstIndex = 0; - uint32_t numIndices = 0; + uint32_t numMeshlets; + uint32_t meshletOffset; + uint32_t firstIndex; + uint32_t numIndices; + uint32_t indicesOffset; + uint32_t pad0[3]; }; static const uint MAX_VERTICES = 64; diff --git a/src/Engine/Graphics/Enums.h b/src/Engine/Graphics/Enums.h index e5715c4..e710a16 100644 --- a/src/Engine/Graphics/Enums.h +++ b/src/Engine/Graphics/Enums.h @@ -4,6 +4,7 @@ namespace Seele { +// Input codes matching GLFW for convenience, since its the primary windowing system enum class KeyCode : size_t { /* Printable keys */ @@ -164,7 +165,7 @@ typedef uint32 KeyModifierFlags; namespace Gfx { static constexpr bool useAsyncCompute = true; -static constexpr bool waitIdleOnSubmit = false; +static constexpr bool waitIdleOnSubmit = true; static constexpr bool useMeshShading = true; static constexpr uint32 numFramesBuffered = 3; diff --git a/src/Engine/Graphics/VertexData.cpp b/src/Engine/Graphics/VertexData.cpp index 01eebae..6a91042 100644 --- a/src/Engine/Graphics/VertexData.cpp +++ b/src/Engine/Graphics/VertexData.cpp @@ -116,9 +116,9 @@ void VertexData::loadMesh(MeshId id, Array loadedIndices, Array }); } meshData[id].add(MeshData{ + .numMeshlets = numMeshlets, .meshletOffset = meshletOffset, - .numMeshlets = (uint16)numMeshlets, - .indicesOffset = (uint16)meshOffsets[id], + .indicesOffset = (uint32)meshOffsets[id], }); currentMesh += numMeshlets; } diff --git a/src/Engine/Graphics/VertexData.h b/src/Engine/Graphics/VertexData.h index ca84478..40d6383 100644 --- a/src/Engine/Graphics/VertexData.h +++ b/src/Engine/Graphics/VertexData.h @@ -41,13 +41,13 @@ public: }; struct MeshData { + uint32 numMeshlets = 0; uint32 meshletOffset = 0; - uint16 numMeshlets = 0; - uint16 indicesOffset = 0; uint32 firstIndex = 0; uint32 numIndices = 0; + uint32 indicesOffset = 0; + uint32 pad0[3]; }; - static_assert(sizeof(MeshData) == 16); struct MeshInstanceData { InstanceData instance; @@ -93,6 +93,7 @@ protected: VertexData(); struct MeshletDescription { + AABB boundingBox; uint32_t vertexCount; uint32_t primitiveCount; uint32_t vertexOffset; diff --git a/src/Engine/Graphics/Vulkan/Allocator.cpp b/src/Engine/Graphics/Vulkan/Allocator.cpp index 33d5237..4edc3b1 100644 --- a/src/Engine/Graphics/Vulkan/Allocator.cpp +++ b/src/Engine/Graphics/Vulkan/Allocator.cpp @@ -246,8 +246,8 @@ uint32 Allocator::findMemoryType(uint32 typeFilter, VkMemoryPropertyFlags proper throw std::runtime_error("error finding memory"); } -StagingBuffer::StagingBuffer(PGraphics graphics, OSubAllocation allocation, VkBuffer buffer, VkDeviceSize size) - : QueueOwnedResource(graphics->getFamilyMapping(), Gfx::QueueType::DEDICATED_TRANSFER) +StagingBuffer::StagingBuffer(PGraphics graphics, OSubAllocation allocation, VkBuffer buffer, VkDeviceSize size, Gfx::QueueType owner) + : QueueOwnedResource(graphics->getFamilyMapping(), owner) , graphics(graphics) , allocation(std::move(allocation)) , buffer(buffer) @@ -258,10 +258,9 @@ StagingBuffer::StagingBuffer(PGraphics graphics, OSubAllocation allocation, VkBu StagingBuffer::~StagingBuffer() { graphics->getDestructionManager()->queueBuffer( - graphics->getDedicatedTransferCommands()->getCommands(), buffer); + graphics->getQueueCommands(currentOwner)->getCommands(), buffer); graphics->getDestructionManager()->queueAllocation( - graphics->getDedicatedTransferCommands()->getCommands(), std::move(allocation)); - graphics->getDedicatedTransferCommands()->submitCommands(); + graphics->getQueueCommands(currentOwner)->getCommands(), std::move(allocation)); } void* StagingBuffer::map() @@ -296,7 +295,19 @@ void StagingBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) void StagingBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) { - assert(false); + PCommand commandBuffer = graphics->getQueueCommands(currentOwner)->getCommands(); + VkBufferMemoryBarrier barrier = { + .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, + .pNext = nullptr, + .srcAccessMask = srcAccess, + .dstAccessMask = dstAccess, + .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .buffer = buffer, + .offset = 0, + .size = size, + }; + vkCmdPipelineBarrier(commandBuffer->getHandle(), srcStage, dstStage, 0, 0, nullptr, 1, &barrier, 0, nullptr); } StagingManager::StagingManager(PGraphics graphics, PAllocator pool) @@ -308,7 +319,7 @@ StagingManager::~StagingManager() { } -OStagingBuffer StagingManager::create(uint64 size) +OStagingBuffer StagingManager::create(uint64 size, Gfx::QueueType owner) { //std::cout << "Creating new stagingbuffer" << std::endl; uint32 queueIndex = graphics->getFamilyMapping().getQueueTypeFamilyIndex(Gfx::QueueType::DEDICATED_TRANSFER); @@ -345,7 +356,8 @@ OStagingBuffer StagingManager::create(uint64 size) graphics, pool->allocate(memReqs, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT, buffer), buffer, - size + size, + owner ); vkBindBufferMemory(graphics->getDevice(), buffer, stagingBuffer->getMemory(), stagingBuffer->getOffset()); diff --git a/src/Engine/Graphics/Vulkan/Allocator.h b/src/Engine/Graphics/Vulkan/Allocator.h index cee0983..82a72ec 100644 --- a/src/Engine/Graphics/Vulkan/Allocator.h +++ b/src/Engine/Graphics/Vulkan/Allocator.h @@ -145,7 +145,7 @@ DEFINE_REF(Allocator) class StagingBuffer : public Gfx::QueueOwnedResource { public: - StagingBuffer(PGraphics graphics, OSubAllocation allocation, VkBuffer buffer, VkDeviceSize size); + StagingBuffer(PGraphics graphics, OSubAllocation allocation, VkBuffer buffer, VkDeviceSize size, Gfx::QueueType owner); ~StagingBuffer(); void* map(); void flush(); @@ -176,7 +176,7 @@ class StagingManager public: StagingManager(PGraphics graphics, PAllocator pool); ~StagingManager(); - OStagingBuffer create(uint64 size); + OStagingBuffer create(uint64 size, Gfx::QueueType owner); private: PGraphics graphics; diff --git a/src/Engine/Graphics/Vulkan/Buffer.cpp b/src/Engine/Graphics/Vulkan/Buffer.cpp index 2f8bf16..bbb0cdb 100644 --- a/src/Engine/Graphics/Vulkan/Buffer.cpp +++ b/src/Engine/Graphics/Vulkan/Buffer.cpp @@ -176,20 +176,6 @@ void * Buffer::mapRegion(uint64 regionOffset, uint64 regionSize, bool writeOnly) { void *data = nullptr; - /*if (bVolatile) - { - if (lockMode == RLM_ReadOnly) - { - assert(0); - } - else - { - throw new std::logic_error("TODO implement volatile buffers"); - //device->getRHIDevice()->getTemp - } - }*/ - //assert(bStatic || bDynamic || bUAV); - PendingBuffer pending; pending.writeOnly = writeOnly; pending.prevQueue = owner; @@ -198,7 +184,7 @@ void * Buffer::mapRegion(uint64 regionOffset, uint64 regionSize, bool writeOnly) if (writeOnly) { //requestOwnershipTransfer(Gfx::QueueType::DEDICATED_TRANSFER); - OStagingBuffer stagingBuffer = graphics->getStagingManager()->create(regionSize); + OStagingBuffer stagingBuffer = graphics->getStagingManager()->create(regionSize, owner); data = stagingBuffer->map(); pending.stagingBuffer = std::move(stagingBuffer); } @@ -223,7 +209,7 @@ void * Buffer::mapRegion(uint64 regionOffset, uint64 regionSize, bool writeOnly) }; vkCmdPipelineBarrier(handle, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 1, &barrier, 0, nullptr); - OStagingBuffer stagingBuffer = graphics->getStagingManager()->create(size); + OStagingBuffer stagingBuffer = graphics->getStagingManager()->create(size, owner); VkBufferCopy regions = { .srcOffset = 0, @@ -280,7 +266,7 @@ UniformBuffer::UniformBuffer(PGraphics graphics, const UniformBufferCreateInfo & { if(createInfo.dynamic) { - dedicatedStagingBuffer = graphics->getStagingManager()->create(createInfo.sourceData.size); + dedicatedStagingBuffer = graphics->getStagingManager()->create(createInfo.sourceData.size, owner); } if (createInfo.sourceData.data != nullptr) { @@ -367,7 +353,7 @@ ShaderBuffer::ShaderBuffer(PGraphics graphics, const ShaderBufferCreateInfo &sou { if(sourceData.dynamic) { - dedicatedStagingBuffer = graphics->getStagingManager()->create(sourceData.sourceData.size); + dedicatedStagingBuffer = graphics->getStagingManager()->create(sourceData.sourceData.size, currentOwner); } if (sourceData.sourceData.data != nullptr) { diff --git a/src/Engine/Graphics/Vulkan/Queue.cpp b/src/Engine/Graphics/Vulkan/Queue.cpp index 2365d9f..b10670b 100644 --- a/src/Engine/Graphics/Vulkan/Queue.cpp +++ b/src/Engine/Graphics/Vulkan/Queue.cpp @@ -52,7 +52,7 @@ void Queue::submitCommandBuffer(PCommand command, const Array& sign if (Gfx::waitIdleOnSubmit) { - command->fence->wait(200 * 1000ull); + command->fence->wait(1000 * 1000ull); } command->checkFence(); diff --git a/src/Engine/Graphics/Vulkan/Texture.cpp b/src/Engine/Graphics/Vulkan/Texture.cpp index 130fec7..4d7e806 100644 --- a/src/Engine/Graphics/Vulkan/Texture.cpp +++ b/src/Engine/Graphics/Vulkan/Texture.cpp @@ -124,7 +124,7 @@ TextureBase::TextureBase(PGraphics graphics, VkImageViewType viewType, if(sourceData.size > 0) { changeLayout(Gfx::SE_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); - OStagingBuffer staging = graphics->getStagingManager()->create(sourceData.size); + OStagingBuffer staging = graphics->getStagingManager()->create(sourceData.size, owner); void* data = staging->map(); std::memcpy(data, sourceData.data, sourceData.size); staging->flush(); @@ -228,7 +228,7 @@ void TextureBase::download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Arra { uint64 imageSize = width * height * depth * Gfx::getFormatInfo(format).blockSize; - OStagingBuffer stagingbuffer = graphics->getStagingManager()->create(imageSize); + OStagingBuffer stagingbuffer = graphics->getStagingManager()->create(imageSize, currentOwner); auto prevlayout = layout; changeLayout(Gfx::SE_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); PCommand cmdBuffer = graphics->getQueueCommands(currentOwner)->getCommands();