Create draw buffer

main
noah metz 2024-10-15 11:44:59 -06:00
parent 1895aefe22
commit 068bc2213b
3 changed files with 48 additions and 1 deletions

@ -34,10 +34,18 @@ typedef struct TextStruct {
uint32_t offset;
} Text;
typedef struct DrawCommandStruct {
uint32_t vertex_count;
uint32_t instance_count;
uint32_t first_vertex;
uint32_t first_instance;
} DrawCommand;
typedef struct TextPointersStruct {
VkDeviceAddress strings;
VkDeviceAddress codes;
VkDeviceAddress characters;
VkDeviceAddress draw;
} TextPointers;
typedef struct CharStruct {

@ -19,7 +19,7 @@ struct String {
vec4 color;
float size;
uint offset;
uint length;
uint len;
};
layout(buffer_reference, std430) readonly buffer SymbolList{
@ -46,15 +46,30 @@ layout(set = 0, binding = 0) uniform Font {
SymbolList symbol_list;
} font;
layout(buffer_reference, std430) buffer DrawCommand {
uint vertex_count;
uint instance_count;
uint first_vertx;
uint first_instance;
};
layout(buffer_reference, std430) readonly buffer Pointers {
Strings strings;
Characters codes;
CharacterList characters;
DrawCommand draw;
};
layout(std430, push_constant) uniform Push {
Pointers pointers;
} push;
layout(local_size_x = 1) in;
void main() {
uint gID = gl_GlobalInvocationID.x;
String string = push.pointers.strings.strings[gID];
uint buffer_pos = atomicAdd(push.pointers.draw.instance_count, string.len);
// Write the characters to push.pointers.characters.characters[buffer_pos:buffer_pos+string.len)
}

@ -197,6 +197,25 @@ VkResult render_thread(GLFWwindow* window, RenderContext* render_context) {
vmaUnmapMemory(render_context->allocator, text_memory);
VkBuffer draw_buffer;
VmaAllocation draw_memory;
VkBufferCreateInfo draw_buffer_info = {
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
.size = sizeof(DrawCommand),
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
};
VmaAllocationCreateInfo draw_memory_info = {
.usage = VMA_MEMORY_USAGE_GPU_ONLY,
};
result = vmaCreateBuffer(render_context->allocator, &draw_buffer_info, &draw_memory_info, &draw_buffer, &draw_memory, NULL);
if(result != VK_SUCCESS) {
return result;
}
VkBuffer text_pointer_buffer;
VmaAllocation text_pointer_memory;
@ -227,6 +246,11 @@ VkResult render_thread(GLFWwindow* window, RenderContext* render_context) {
.buffer = text_buffer,
};
pointers->characters = vkGetBufferDeviceAddress(render_context->device, &test_address_info);
VkBufferDeviceAddressInfo draw_address_info = {
.sType = VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO,
.buffer = draw_buffer,
};
pointers->draw = vkGetBufferDeviceAddress(render_context->device, &draw_address_info);
vmaUnmapMemory(render_context->allocator, text_pointer_memory);
VkBufferDeviceAddressInfo pointers_address_info = {