Drawing a textured quad

Added new assets
Loaded all texture assets into game state
Loaded the basic pipeline
Setup a hard-coded quad to test drawing
Created a very jank vertex struct
Added ReadEntireFile for filesystem
Added getting file size from file handle
Added a descriptor pool to each in flight frame
Changed Vk_BufferCreate to handle multiple uses
Added shader building to the windows.bat build script
This commit is contained in:
2025-10-04 21:42:04 +01:00
parent b1a805cea8
commit 187359f747
27 changed files with 470 additions and 57 deletions

View File

@@ -1,9 +1,14 @@
void G_ImagesLoad(M_Arena *arena) {
M_TempScope(1, &arena) {
void G_ImagesLoad(G_State *game) {
M_TempScope(0, 0) {
FS_List assets = FS_PathList(temp.arena, S("assets"));
Vk_Buffer staging = Vk_BufferCreate(MB(256), true /* host_visible */);
Vk_Buffer staging = { 0 };
staging.size = MB(256);
staging.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
staging.host_visible = true;
Vk_BufferCreate(&staging);
U8 *base = staging.data;
U64 offset = 0;
@@ -14,12 +19,16 @@ void G_ImagesLoad(M_Arena *arena) {
for (FS_Entry *it = assets.first; it != 0; it = it->next) {
if (Str8_EndsWith(it->basename, S("png"))) {
if (Str8_Equal(it->basename, S("saloon_ext.png"), 0)) {
printf("IMAGE SALOON == %d\n", n_images);
}
n_images += 1;
}
}
VkBufferImageCopy copy = { 0 };
G_Image *images = M_ArenaPush(arena, G_Image, .count = n_images);
game->images = M_ArenaPush(game->arena, G_Image, .count = n_images);
n_images = 0;
// Image upload is sbi_load -> copy to staging -> upload to gpu texture
@@ -30,7 +39,7 @@ void G_ImagesLoad(M_Arena *arena) {
stbi_uc *data = stbi_load((const char *) it->path.data, &w, &h, &c, 4);
if (data) {
G_Image *image = &images[n_images];
G_Image *image = &game->images[n_images];
U64 image_sz = 4 * w * h;
@@ -56,7 +65,7 @@ void G_ImagesLoad(M_Arena *arena) {
n_images += 1;
image->name = Str8_Copy(arena, Str8_RemoveAfterLast(it->basename, '.'));
image->name = Str8_Copy(game->arena, Str8_RemoveAfterLast(it->basename, '.'));
image->image.width = w;
image->image.height = h;
@@ -117,3 +126,70 @@ void G_ImagesLoad(M_Arena *arena) {
Vk_CommandBufferSubmit(cmds, true /* wait */);
}
}
void G_PipelinesLoad(G_State *game) {
game->pipelines = M_ArenaPush(game->arena, Vk_Pipeline, .count = 1);
Vk_Pipeline *basic = &game->pipelines[0];
VkShaderModule vshader = 0, fshader = 0;
M_TempScope(0, 0) {
Str8 vshader_code = FS_ReadEntireFile(temp.arena, S("assets/shaders/basic.vert.spv"));
Str8 fshader_code = FS_ReadEntireFile(temp.arena, S("assets/shaders/basic.frag.spv"));
VkShaderModuleCreateInfo create_info = { 0 };
create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
create_info.pCode = (U32 *) vshader_code.data;
create_info.codeSize = vshader_code.count;
vk.CreateShaderModule(vk.device, &create_info, 0, &vshader);
create_info.pCode = (U32 *) fshader_code.data;
create_info.codeSize = fshader_code.count;
vk.CreateShaderModule(vk.device, &create_info, 0, &fshader);
}
// Create pipeline layout, its insane what you have to do for this because the ALREADY KNOW
// all of this information
{
VkDescriptorSetLayoutBinding bindings[2] = { 0 };
bindings[0].binding = 0;
bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
bindings[0].descriptorCount = 1;
bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
bindings[1].binding = 1;
bindings[1].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
bindings[1].descriptorCount = 1;
bindings[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
VkDescriptorSetLayoutCreateInfo set_info = { 0 };
set_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
set_info.bindingCount = 2;
set_info.pBindings = bindings;
vk.CreateDescriptorSetLayout(vk.device, &set_info, 0, &basic->layout.set);
VkPipelineLayoutCreateInfo layout_create = { 0 };
layout_create.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
layout_create.setLayoutCount = 1;
layout_create.pSetLayouts = &basic->layout.set;
vk.CreatePipelineLayout(vk.device, &layout_create, 0, &basic->layout.pipeline);
}
basic->targets.items[0] = vk.swapchain.format.format;
basic->targets.count = 1;
basic->shaders.count = 2;
basic->shaders.items[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
basic->shaders.items[0].handle = vshader;
basic->shaders.items[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
basic->shaders.items[1].handle = fshader;
Vk_PipelineCreate(basic);
}