It suddenly works again?

This commit is contained in:
Dynamitos
2023-12-14 09:04:23 +01:00
parent 88004ce70f
commit 462999858f
10 changed files with 45 additions and 43 deletions
+1 -1
+7 -5
View File
@@ -2,6 +2,7 @@ import AABB;
struct MeshletDescription struct MeshletDescription
{ {
AABB boundingBox;
uint32_t vertexCount; uint32_t vertexCount;
uint32_t primitiveCount; uint32_t primitiveCount;
uint32_t vertexOffset; uint32_t vertexOffset;
@@ -10,11 +11,12 @@ struct MeshletDescription
struct MeshData struct MeshData
{ {
uint32_t meshletOffset = 0; uint32_t numMeshlets;
uint16_t numMeshlets = 0; uint32_t meshletOffset;
uint16_t indicesOffset = 0; uint32_t firstIndex;
uint32_t firstIndex = 0; uint32_t numIndices;
uint32_t numIndices = 0; uint32_t indicesOffset;
uint32_t pad0[3];
}; };
static const uint MAX_VERTICES = 64; static const uint MAX_VERTICES = 64;
+2 -1
View File
@@ -4,6 +4,7 @@
namespace Seele namespace Seele
{ {
// Input codes matching GLFW for convenience, since its the primary windowing system
enum class KeyCode : size_t enum class KeyCode : size_t
{ {
/* Printable keys */ /* Printable keys */
@@ -164,7 +165,7 @@ typedef uint32 KeyModifierFlags;
namespace Gfx namespace Gfx
{ {
static constexpr bool useAsyncCompute = true; static constexpr bool useAsyncCompute = true;
static constexpr bool waitIdleOnSubmit = false; static constexpr bool waitIdleOnSubmit = true;
static constexpr bool useMeshShading = true; static constexpr bool useMeshShading = true;
static constexpr uint32 numFramesBuffered = 3; static constexpr uint32 numFramesBuffered = 3;
+2 -2
View File
@@ -116,9 +116,9 @@ void VertexData::loadMesh(MeshId id, Array<uint32> loadedIndices, Array<Meshlet>
}); });
} }
meshData[id].add(MeshData{ meshData[id].add(MeshData{
.numMeshlets = numMeshlets,
.meshletOffset = meshletOffset, .meshletOffset = meshletOffset,
.numMeshlets = (uint16)numMeshlets, .indicesOffset = (uint32)meshOffsets[id],
.indicesOffset = (uint16)meshOffsets[id],
}); });
currentMesh += numMeshlets; currentMesh += numMeshlets;
} }
+4 -3
View File
@@ -41,13 +41,13 @@ public:
}; };
struct MeshData struct MeshData
{ {
uint32 numMeshlets = 0;
uint32 meshletOffset = 0; uint32 meshletOffset = 0;
uint16 numMeshlets = 0;
uint16 indicesOffset = 0;
uint32 firstIndex = 0; uint32 firstIndex = 0;
uint32 numIndices = 0; uint32 numIndices = 0;
uint32 indicesOffset = 0;
uint32 pad0[3];
}; };
static_assert(sizeof(MeshData) == 16);
struct MeshInstanceData struct MeshInstanceData
{ {
InstanceData instance; InstanceData instance;
@@ -93,6 +93,7 @@ protected:
VertexData(); VertexData();
struct MeshletDescription struct MeshletDescription
{ {
AABB boundingBox;
uint32_t vertexCount; uint32_t vertexCount;
uint32_t primitiveCount; uint32_t primitiveCount;
uint32_t vertexOffset; uint32_t vertexOffset;
+20 -8
View File
@@ -246,8 +246,8 @@ uint32 Allocator::findMemoryType(uint32 typeFilter, VkMemoryPropertyFlags proper
throw std::runtime_error("error finding memory"); throw std::runtime_error("error finding memory");
} }
StagingBuffer::StagingBuffer(PGraphics graphics, OSubAllocation allocation, VkBuffer buffer, VkDeviceSize size) StagingBuffer::StagingBuffer(PGraphics graphics, OSubAllocation allocation, VkBuffer buffer, VkDeviceSize size, Gfx::QueueType owner)
: QueueOwnedResource(graphics->getFamilyMapping(), Gfx::QueueType::DEDICATED_TRANSFER) : QueueOwnedResource(graphics->getFamilyMapping(), owner)
, graphics(graphics) , graphics(graphics)
, allocation(std::move(allocation)) , allocation(std::move(allocation))
, buffer(buffer) , buffer(buffer)
@@ -258,10 +258,9 @@ StagingBuffer::StagingBuffer(PGraphics graphics, OSubAllocation allocation, VkBu
StagingBuffer::~StagingBuffer() StagingBuffer::~StagingBuffer()
{ {
graphics->getDestructionManager()->queueBuffer( graphics->getDestructionManager()->queueBuffer(
graphics->getDedicatedTransferCommands()->getCommands(), buffer); graphics->getQueueCommands(currentOwner)->getCommands(), buffer);
graphics->getDestructionManager()->queueAllocation( graphics->getDestructionManager()->queueAllocation(
graphics->getDedicatedTransferCommands()->getCommands(), std::move(allocation)); graphics->getQueueCommands(currentOwner)->getCommands(), std::move(allocation));
graphics->getDedicatedTransferCommands()->submitCommands();
} }
void* StagingBuffer::map() void* StagingBuffer::map()
@@ -296,7 +295,19 @@ void StagingBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner)
void StagingBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, void StagingBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) 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) 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; //std::cout << "Creating new stagingbuffer" << std::endl;
uint32 queueIndex = graphics->getFamilyMapping().getQueueTypeFamilyIndex(Gfx::QueueType::DEDICATED_TRANSFER); uint32 queueIndex = graphics->getFamilyMapping().getQueueTypeFamilyIndex(Gfx::QueueType::DEDICATED_TRANSFER);
@@ -345,7 +356,8 @@ OStagingBuffer StagingManager::create(uint64 size)
graphics, graphics,
pool->allocate(memReqs, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT, buffer), pool->allocate(memReqs, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT, buffer),
buffer, buffer,
size size,
owner
); );
vkBindBufferMemory(graphics->getDevice(), buffer, stagingBuffer->getMemory(), stagingBuffer->getOffset()); vkBindBufferMemory(graphics->getDevice(), buffer, stagingBuffer->getMemory(), stagingBuffer->getOffset());
+2 -2
View File
@@ -145,7 +145,7 @@ DEFINE_REF(Allocator)
class StagingBuffer : public Gfx::QueueOwnedResource class StagingBuffer : public Gfx::QueueOwnedResource
{ {
public: public:
StagingBuffer(PGraphics graphics, OSubAllocation allocation, VkBuffer buffer, VkDeviceSize size); StagingBuffer(PGraphics graphics, OSubAllocation allocation, VkBuffer buffer, VkDeviceSize size, Gfx::QueueType owner);
~StagingBuffer(); ~StagingBuffer();
void* map(); void* map();
void flush(); void flush();
@@ -176,7 +176,7 @@ class StagingManager
public: public:
StagingManager(PGraphics graphics, PAllocator pool); StagingManager(PGraphics graphics, PAllocator pool);
~StagingManager(); ~StagingManager();
OStagingBuffer create(uint64 size); OStagingBuffer create(uint64 size, Gfx::QueueType owner);
private: private:
PGraphics graphics; PGraphics graphics;
+4 -18
View File
@@ -176,20 +176,6 @@ void * Buffer::mapRegion(uint64 regionOffset, uint64 regionSize, bool writeOnly)
{ {
void *data = nullptr; 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; PendingBuffer pending;
pending.writeOnly = writeOnly; pending.writeOnly = writeOnly;
pending.prevQueue = owner; pending.prevQueue = owner;
@@ -198,7 +184,7 @@ void * Buffer::mapRegion(uint64 regionOffset, uint64 regionSize, bool writeOnly)
if (writeOnly) if (writeOnly)
{ {
//requestOwnershipTransfer(Gfx::QueueType::DEDICATED_TRANSFER); //requestOwnershipTransfer(Gfx::QueueType::DEDICATED_TRANSFER);
OStagingBuffer stagingBuffer = graphics->getStagingManager()->create(regionSize); OStagingBuffer stagingBuffer = graphics->getStagingManager()->create(regionSize, owner);
data = stagingBuffer->map(); data = stagingBuffer->map();
pending.stagingBuffer = std::move(stagingBuffer); 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); 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 = { VkBufferCopy regions = {
.srcOffset = 0, .srcOffset = 0,
@@ -280,7 +266,7 @@ UniformBuffer::UniformBuffer(PGraphics graphics, const UniformBufferCreateInfo &
{ {
if(createInfo.dynamic) if(createInfo.dynamic)
{ {
dedicatedStagingBuffer = graphics->getStagingManager()->create(createInfo.sourceData.size); dedicatedStagingBuffer = graphics->getStagingManager()->create(createInfo.sourceData.size, owner);
} }
if (createInfo.sourceData.data != nullptr) if (createInfo.sourceData.data != nullptr)
{ {
@@ -367,7 +353,7 @@ ShaderBuffer::ShaderBuffer(PGraphics graphics, const ShaderBufferCreateInfo &sou
{ {
if(sourceData.dynamic) if(sourceData.dynamic)
{ {
dedicatedStagingBuffer = graphics->getStagingManager()->create(sourceData.sourceData.size); dedicatedStagingBuffer = graphics->getStagingManager()->create(sourceData.sourceData.size, currentOwner);
} }
if (sourceData.sourceData.data != nullptr) if (sourceData.sourceData.data != nullptr)
{ {
+1 -1
View File
@@ -52,7 +52,7 @@ void Queue::submitCommandBuffer(PCommand command, const Array<VkSemaphore>& sign
if (Gfx::waitIdleOnSubmit) if (Gfx::waitIdleOnSubmit)
{ {
command->fence->wait(200 * 1000ull); command->fence->wait(1000 * 1000ull);
} }
command->checkFence(); command->checkFence();
+2 -2
View File
@@ -124,7 +124,7 @@ TextureBase::TextureBase(PGraphics graphics, VkImageViewType viewType,
if(sourceData.size > 0) if(sourceData.size > 0)
{ {
changeLayout(Gfx::SE_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); 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(); void* data = staging->map();
std::memcpy(data, sourceData.data, sourceData.size); std::memcpy(data, sourceData.data, sourceData.size);
staging->flush(); 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; 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; auto prevlayout = layout;
changeLayout(Gfx::SE_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); changeLayout(Gfx::SE_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
PCommand cmdBuffer = graphics->getQueueCommands(currentOwner)->getCommands(); PCommand cmdBuffer = graphics->getQueueCommands(currentOwner)->getCommands();