descriptor heap rewrite

This commit is contained in:
Jorijn van der Graaf 2026-04-05 22:53:59 +02:00
commit f8e142fb06
31 changed files with 429 additions and 1017 deletions

View file

@ -64,32 +64,15 @@ namespace Crafter {
>;
export template <typename T, bool Mapped, bool Adressable, bool Staged> requires ((Mapped && !Staged) || (!Mapped && Staged) || (!Mapped && !Staged))
export template <typename T, bool Mapped, bool Adressable>
class VulkanBuffer;
export template <typename T>
class VulkanBufferStaged {
VulkanBuffer<T, true, false, false>* stagingBuffer;
};
export class VulkanBufferStagedEmpty {};
template<typename T, bool Staged>
using VulkanBufferStagedConditional =
std::conditional_t<
Staged,
VulkanBufferStaged<T>,
VulkanBufferStagedEmpty
>;
export template <typename T, bool Mapped, bool Adressable, bool Staged> requires ((Mapped && !Staged) || (!Mapped && Staged) || (!Mapped && !Staged))
class VulkanBuffer : public VulkanBufferBase, public VulkanBufferMappedConditional<T, Mapped>, public VulkanBufferAdressableConditional<Adressable>, public VulkanBufferStagedConditional<T, Staged> {
export template <typename T, bool Mapped, bool Adressable>
class VulkanBuffer : public VulkanBufferBase, public VulkanBufferMappedConditional<T, Mapped>, public VulkanBufferAdressableConditional<Adressable> {
public:
VulkanBuffer() = default;
void Create(VkBufferUsageFlags usageFlags, VkMemoryPropertyFlags memoryPropertyFlags, std::uint32_t count) {
if constexpr(Staged) {
new (&VulkanBufferMappedConditional<T, true>::stagingBuffer) VulkanBuffer<T, true, false, false>();
VulkanBufferMappedConditional<T, true>::stagingBuffer->Create(VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, count);
}
VkBufferCreateInfo bufferCreateInfo {};
bufferCreateInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
@ -117,7 +100,7 @@ namespace Crafter {
descriptor.offset = 0;
descriptor.buffer = buffer;
descriptor.range = VK_WHOLE_SIZE;
descriptor.range = sizeof(T)*count;
Device::CheckVkResult(vkBindBufferMemory(Device::device, buffer, memory, 0));
@ -141,9 +124,6 @@ namespace Crafter {
vkDestroyBuffer(Device::device, buffer, nullptr);
vkFreeMemory(Device::device, memory, nullptr);
buffer = VK_NULL_HANDLE;
if constexpr(Staged) {
delete VulkanBufferMappedConditional<T, true>::stagingBuffer;
}
}
void Resize(VkBufferUsageFlags usageFlags, VkMemoryPropertyFlags memoryPropertyFlags, std::uint32_t count) {
@ -237,22 +217,6 @@ namespace Crafter {
};
vkInvalidateMappedMemoryRanges(Device::device, 1, &range);
}
void FlushDevice(VkCommandBuffer cmd) requires(Staged) {
VulkanBufferStagedConditional<T, true>::stagingBuffer.FlushDevice(VK_ACCESS_TRANSFER_READ_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT);
VulkanBufferStagedConditional<T, true>::stagingBuffer.Copy(cmd, this);
}
void FlushDevice(VkCommandBuffer cmd, VkAccessFlags dstAccessMask, VkPipelineStageFlags dstStageMask) requires(Staged) {
VulkanBufferStagedConditional<T, true>::stagingBuffer.FlushDevice(VK_ACCESS_TRANSFER_READ_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT);
VulkanBufferStagedConditional<T, true>::stagingBuffer.Copy(cmd, this, VK_ACCESS_TRANSFER_WRITE_BIT, dstAccessMask, VK_PIPELINE_STAGE_TRANSFER_BIT, dstStageMask);
}
void FlushHost(VkCommandBuffer cmd) requires(Staged) {
Copy(cmd, VulkanBufferStagedConditional<T, true>::stagingBuffer);
VulkanBufferStagedConditional<T, true>::stagingBuffer.FlushHost();
}
VulkanBuffer(VulkanBuffer&& other) {
descriptor = other.descriptor;
@ -265,9 +229,6 @@ namespace Crafter {
if constexpr(Mapped) {
VulkanBufferMappedConditional<T, true>::value = other.VulkanBufferMappedConditional<T, true>::value;
}
if constexpr(Staged) {
VulkanBufferStagedConditional<T, true>::stagingBuffer = other.VulkanBufferStagedConditional<T, true>::stagingBuffer;
}
};
~VulkanBuffer() {