writing ui descriptors
This commit is contained in:
parent
3f4ad87746
commit
3fcea6a3d7
8 changed files with 108 additions and 69 deletions
|
|
@ -31,24 +31,12 @@ import :Device;
|
|||
namespace Crafter {
|
||||
export class VulkanBufferBase {
|
||||
public:
|
||||
VkDescriptorBufferInfo descriptor;
|
||||
VkDeviceAddress address;
|
||||
std::uint32_t size;
|
||||
VkBuffer buffer = VK_NULL_HANDLE;
|
||||
VkDeviceMemory memory;
|
||||
};
|
||||
|
||||
export class VulkanBufferAdressable {
|
||||
public:
|
||||
VkDeviceAddress address;
|
||||
};
|
||||
export class VulkanBufferAdressableEmpty {};
|
||||
template<bool Adressable>
|
||||
using VulkanBufferAdressableConditional =
|
||||
std::conditional_t<
|
||||
Adressable,
|
||||
VulkanBufferAdressable,
|
||||
VulkanBufferAdressableEmpty
|
||||
>;
|
||||
|
||||
export template<typename T>
|
||||
class VulkanBufferMapped {
|
||||
public:
|
||||
|
|
@ -63,16 +51,12 @@ namespace Crafter {
|
|||
VulkanBufferMappedEmpty
|
||||
>;
|
||||
|
||||
|
||||
export template <typename T, bool Mapped, bool Adressable>
|
||||
class VulkanBuffer;
|
||||
|
||||
|
||||
export template <typename T, bool Mapped, bool Adressable>
|
||||
class VulkanBuffer : public VulkanBufferBase, public VulkanBufferMappedConditional<T, Mapped>, public VulkanBufferAdressableConditional<Adressable> {
|
||||
export template <typename T, bool Mapped>
|
||||
class VulkanBuffer : public VulkanBufferBase, public VulkanBufferMappedConditional<T, Mapped> {
|
||||
public:
|
||||
VulkanBuffer() = default;
|
||||
void Create(VkBufferUsageFlags usageFlags, VkMemoryPropertyFlags memoryPropertyFlags, std::uint32_t count) {
|
||||
size = count * sizeof(T);
|
||||
|
||||
VkBufferCreateInfo bufferCreateInfo {};
|
||||
bufferCreateInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
|
||||
|
|
@ -87,30 +71,21 @@ namespace Crafter {
|
|||
.allocationSize = memReqs.size,
|
||||
.memoryTypeIndex = Device::GetMemoryType(memReqs.memoryTypeBits, memoryPropertyFlags)
|
||||
};
|
||||
if constexpr(Adressable) {
|
||||
VkMemoryAllocateFlagsInfoKHR allocFlagsInfo {
|
||||
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO_KHR,
|
||||
.flags = VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT_KHR,
|
||||
};
|
||||
memAlloc.pNext = &allocFlagsInfo;
|
||||
Device::CheckVkResult(vkAllocateMemory(Device::device, &memAlloc, nullptr, &memory));
|
||||
} else {
|
||||
Device::CheckVkResult(vkAllocateMemory(Device::device, &memAlloc, nullptr, &memory));
|
||||
}
|
||||
|
||||
descriptor.offset = 0;
|
||||
descriptor.buffer = buffer;
|
||||
descriptor.range = sizeof(T)*count;
|
||||
|
||||
VkMemoryAllocateFlagsInfoKHR allocFlagsInfo {
|
||||
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO_KHR,
|
||||
.flags = VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT_KHR,
|
||||
};
|
||||
memAlloc.pNext = &allocFlagsInfo;
|
||||
Device::CheckVkResult(vkAllocateMemory(Device::device, &memAlloc, nullptr, &memory));
|
||||
|
||||
Device::CheckVkResult(vkBindBufferMemory(Device::device, buffer, memory, 0));
|
||||
|
||||
if constexpr(Adressable) {
|
||||
VkBufferDeviceAddressInfo addressInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO,
|
||||
.buffer = buffer
|
||||
};
|
||||
VulkanBufferAdressableConditional<true>::address = vkGetBufferDeviceAddress(Device::device, &addressInfo);
|
||||
}
|
||||
VkBufferDeviceAddressInfo addressInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO,
|
||||
.buffer = buffer
|
||||
};
|
||||
address = vkGetBufferDeviceAddress(Device::device, &addressInfo);
|
||||
|
||||
if constexpr(Mapped) {
|
||||
Device::CheckVkResult(vkMapMemory(Device::device, memory, 0, memReqs.size, 0, reinterpret_cast<void**>(&(VulkanBufferMappedConditional<T, true>::value))));
|
||||
|
|
@ -137,7 +112,7 @@ namespace Crafter {
|
|||
VkBufferCopy copyRegion = {
|
||||
.srcOffset = 0,
|
||||
.dstOffset = 0,
|
||||
.size = descriptor.range
|
||||
.size = size
|
||||
};
|
||||
|
||||
vkCmdCopyBuffer(
|
||||
|
|
@ -219,13 +194,11 @@ namespace Crafter {
|
|||
}
|
||||
|
||||
VulkanBuffer(VulkanBuffer&& other) {
|
||||
descriptor = other.descriptor;
|
||||
buffer = other.buffer;
|
||||
memory = other.memory;
|
||||
size = other.size;
|
||||
other.buffer = VK_NULL_HANDLE;
|
||||
if constexpr(Adressable) {
|
||||
VulkanBufferAdressableConditional<true>::address = other.VulkanBufferAdressableConditional<true>::address;
|
||||
}
|
||||
address = other.address;
|
||||
if constexpr(Mapped) {
|
||||
VulkanBufferMappedConditional<T, true>::value = other.VulkanBufferMappedConditional<T, true>::value;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue