Trying to add fluid simulation

This commit is contained in:
Dynamitos committed 2026-04-12 20:49:02 +02:00
1 parent 056589a6f9
commit ac317a3829
65 files changed
+2708 -371

No files matched your search

+5 -4
View File
@@ -4,6 +4,7 @@
#include "Graphics/Enums.h"
#include <fmt/format.h>
#include <vk_mem_alloc.h>
#include <vulkan/vulkan_core.h>
using namespace Seele;
using namespace Seele::Vulkan;
@@ -192,7 +193,8 @@ void BufferAllocation::unmap() {
Buffer::Buffer(PGraphics graphics, uint64 size, VkBufferUsageFlags usage, Gfx::QueueType queueType, bool dynamic, std::string name,
bool createCleared, uint32 clearValue)
: graphics(graphics), currentBuffer(0), initialOwner(queueType),
usage(usage | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT),
usage(usage | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT |
(graphics->supportRayTracing() ? VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR : 0)),
dynamic(dynamic), createCleared(createCleared), name(name), clearValue(clearValue) {
if (size > 0) {
buffers.add(nullptr);
@@ -483,9 +485,8 @@ IndexBuffer::IndexBuffer(PGraphics graphics, const IndexBufferCreateInfo& create
: Gfx::IndexBuffer(graphics->getFamilyMapping(), createInfo),
Vulkan::Buffer(graphics, createInfo.sourceData.size,
VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT |
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | (graphics->supportRayTracing()
? VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR
: 0),
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
(graphics->supportRayTracing() ? VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR : 0),
createInfo.sourceData.owner, false, createInfo.name) {
getAlloc()->updateContents(createInfo.sourceData.offset, createInfo.sourceData.size, createInfo.sourceData.data);
// getAlloc()->pipelineBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_INDEX_READ_BIT,
+2 -2
View File
@@ -455,7 +455,7 @@ void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet descriptor) {
}
}
if (descriptorSet->setHandle->constantsBuffer != nullptr) {
descriptorSet->setHandle->bind();
descriptorSet->setHandle->constantsBuffer->bind();
boundResources.add(PBufferAllocation(descriptorSet->setHandle->constantsBuffer));
}
@@ -482,7 +482,7 @@ void ComputeCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptor
}
}
if (descriptorSet->setHandle->constantsBuffer != nullptr) {
descriptorSet->setHandle->bind();
descriptorSet->setHandle->constantsBuffer->bind();
boundResources.add(PBufferAllocation(descriptorSet->setHandle->constantsBuffer));
}
sets[pipeline->getPipelineLayout()->findParameter(descriptorSet->getName())] = descriptorSet->getHandle();
+20 -20
View File
@@ -175,7 +175,6 @@ Gfx::ODescriptorSet DescriptorPool::allocateDescriptorSet() {
};
vkSetDebugUtilsObjectNameEXT(graphics->getDevice(), &nameInfo);
}
cachedHandles[setIndex]->isUsed = true;
// Found set, stop searching
return new DescriptorSet(graphics, this, cachedHandles[setIndex]);
}
@@ -191,13 +190,11 @@ void DescriptorPool::reset() {}
DescriptorSetHandle::DescriptorSetHandle(PGraphics graphics, const std::string& name) : CommandBoundResource(graphics, name) {}
DescriptorSetHandle::~DescriptorSetHandle() {
graphics->getDestructionManager()->queueResourceForDestruction(std::move(constantsBuffer));
}
DescriptorSetHandle::~DescriptorSetHandle() { graphics->getDestructionManager()->queueResourceForDestruction(std::move(constantsBuffer)); }
DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner, PDescriptorSetHandle setHandle)
: Gfx::DescriptorSet(owner->getLayout()), setHandle(setHandle),
graphics(graphics), owner(owner) {
: Gfx::DescriptorSet(owner->getLayout()), setHandle(setHandle), graphics(graphics), owner(owner) {
setHandle->isUsed = true;
boundResources.resize(owner->getLayout()->bindings.size());
for (uint32 i = 0; i < boundResources.size(); ++i) {
boundResources[i].resize(owner->getLayout()->bindings[i].descriptorCount);
@@ -208,8 +205,10 @@ DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner, PDescrip
constantData.resize(owner->getLayout()->constantsSize);
}
DescriptorSet::~DescriptorSet() {
setHandle->isUsed = false;
DescriptorSet::~DescriptorSet() {
if (setHandle != nullptr) {
setHandle->isUsed = false;
}
}
void DescriptorSet::updateConstants(const std::string& mappingName, uint32 offset, const void* data) {
@@ -406,20 +405,21 @@ void DescriptorSet::writeChanges() {
if (setHandle->constantsBuffer != nullptr) {
graphics->getDestructionManager()->queueResourceForDestruction(std::move(setHandle->constantsBuffer));
}
setHandle->constantsBuffer = new BufferAllocation(graphics, owner->getLayout()->getName(),
VkBufferCreateInfo{
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
.pNext = nullptr,
.size = constantData.size(),
.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
},
VmaAllocationCreateInfo{
.usage = VMA_MEMORY_USAGE_AUTO,
},
Gfx::QueueType::GRAPHICS);
setHandle->constantsBuffer =
new BufferAllocation(graphics, owner->getLayout()->getName(),
VkBufferCreateInfo{
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
.pNext = nullptr,
.size = constantData.size(),
.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
},
VmaAllocationCreateInfo{
.usage = VMA_MEMORY_USAGE_AUTO,
},
Gfx::QueueType::GRAPHICS);
setHandle->constantsBuffer->updateContents(0, constantData.size(), constantData.data());
setHandle->constantsBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_UNIFORM_READ_BIT, Gfx::SE_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Gfx::SE_ACCESS_UNIFORM_READ_BIT, Gfx::SE_PIPELINE_STAGE_ALL_COMMANDS_BIT);
bufferInfos.add(VkDescriptorBufferInfo{
.buffer = setHandle->constantsBuffer->buffer,
.offset = 0,
+5 -1
View File
@@ -68,6 +68,10 @@ class DescriptorSet : public Gfx::DescriptorSet {
public:
DescriptorSet(PGraphics graphics, PDescriptorPool owner, PDescriptorSetHandle setHandle);
virtual ~DescriptorSet();
DescriptorSet(const DescriptorSet&) = delete;
DescriptorSet(DescriptorSet&&) noexcept;
DescriptorSet& operator=(const DescriptorSet&) = delete;
DescriptorSet& operator=(DescriptorSet&&) noexcept;
virtual void writeChanges() override;
virtual void updateConstants(const std::string& name, uint32 offset, const void* data) override;
virtual void updateBuffer(const std::string& name, uint32 index, Gfx::PShaderBuffer shaderBuffer) override;
@@ -91,7 +95,7 @@ class DescriptorSet : public Gfx::DescriptorSet {
// would not work anyways, so casts should be safe
// Array<void*> cachedData;
Array<Array<PCommandBoundResource>> boundResources;
PDescriptorSetHandle setHandle;
PDescriptorSetHandle setHandle = nullptr;
PGraphics graphics;
PDescriptorPool owner;
friend class DescriptorPool;
+7 -6
View File
@@ -812,8 +812,7 @@ void Graphics::setupDebugCallback() {
.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT,
.pNext = nullptr,
.flags = 0,
.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT |
VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT,
.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT,
.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT |
VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT,
.pfnUserCallback = &debugCallback,
@@ -849,11 +848,11 @@ void Graphics::pickPhysicalDevice() {
vkGetPhysicalDeviceProperties2(physicalDevice, &props.get());
features.get<VkPhysicalDeviceFeatures2>().features = {
.geometryShader = false,
.geometryShader = true,
.sampleRateShading = true,
.fillModeNonSolid = true,
.wideLines = false,
.pipelineStatisticsQuery = false,
.wideLines = true,
.pipelineStatisticsQuery = true,
.fragmentStoresAndAtomics = true,
.shaderInt64 = true,
.shaderInt16 = true,
@@ -862,12 +861,14 @@ void Graphics::pickPhysicalDevice() {
features.get<VkPhysicalDeviceVulkan11Features>().multiview = true;
features.get<VkPhysicalDeviceVulkan11Features>().storageBuffer16BitAccess = true;
features.get<VkPhysicalDeviceVulkan11Features>().shaderDrawParameters = true;
features.get<VkPhysicalDeviceVulkan11Features>().uniformAndStorageBuffer16BitAccess = true;
features.get<VkPhysicalDeviceVulkan12Features>().descriptorIndexing = true;
features.get<VkPhysicalDeviceVulkan12Features>().descriptorBindingPartiallyBound = true;
features.get<VkPhysicalDeviceVulkan12Features>().bufferDeviceAddress = true;
features.get<VkPhysicalDeviceVulkan12Features>().storageBuffer8BitAccess = true;
features.get<VkPhysicalDeviceVulkan12Features>().shaderInt8 = true;
features.get<VkPhysicalDeviceVulkan12Features>().uniformAndStorageBuffer8BitAccess = true;
rayTracingFeatures.get<VkPhysicalDeviceAccelerationStructureFeaturesKHR>().accelerationStructure = true;
@@ -915,7 +916,7 @@ void Graphics::pickPhysicalDevice() {
shaderFloatControls = true;
}
}
rayTracingEnabled = rayTracingPipelineSupport && accelerationStructureSupport && hostOperationsSupport && deviceAddressSupport &&
rayTracingEnabled = false &&rayTracingPipelineSupport && accelerationStructureSupport && hostOperationsSupport && deviceAddressSupport &&
descriptorIndexingSupport && spirv14Support && shaderFloatControls;
}