From 7071d018351a0b9ea5b22ae7f4b807c3a2d95ca8 Mon Sep 17 00:00:00 2001 From: Gregory Wells Date: Sat, 14 Jun 2025 22:08:29 -0400 Subject: [PATCH] rgba textures and binding the decriptor sets --- .../src/shader_module/vulkan_shader_module.c | 10 ++++----- .../vulkan/src/textures/vulkan_texture.c | 3 ++- .../vulkan/src/uniforms/vulkan_uniform.c | 21 +++++++++++++++++++ .../src/uniforms/vulkan_uniform_layout.c | 1 + .../src/vulkan_surface/vulkan_surface.c | 3 ++- src/core/gryphn_platform_functions.h | 1 + src/core/instance/init/gryphn_init.c | 1 + src/core/uniforms/gryphn_uniform.c | 4 ++++ src/core/uniforms/gryphn_uniform.h | 6 ++++++ src/core/uniforms/gryphn_uniform_layout.h | 1 + 10 files changed, 44 insertions(+), 7 deletions(-) diff --git a/rendering_api/vulkan/src/shader_module/vulkan_shader_module.c b/rendering_api/vulkan/src/shader_module/vulkan_shader_module.c index 5e8787b..b2c80a0 100644 --- a/rendering_api/vulkan/src/shader_module/vulkan_shader_module.c +++ b/rendering_api/vulkan/src/shader_module/vulkan_shader_module.c @@ -4,11 +4,11 @@ VkShaderStageFlagBits vkGryphnShaderModuleStage(gnShaderModuleStage stage) { VkShaderStageFlagBits outStage = 0; - switch(stage) { - case GN_VERTEX_SHADER_MODULE: outStage |= VK_SHADER_STAGE_VERTEX_BIT; break; - case GN_FRAGMENT_SHADER_MODULE: outStage |= VK_SHADER_STAGE_FRAGMENT_BIT; break; - case GN_ALL_SHADER_MODULE: return VK_SHADER_STAGE_ALL_GRAPHICS; - } + + if ((stage & GN_VERTEX_SHADER_MODULE) == GN_VERTEX_SHADER_MODULE) outStage |= VK_SHADER_STAGE_VERTEX_BIT; + if ((stage & GN_FRAGMENT_SHADER_MODULE) == GN_FRAGMENT_SHADER_MODULE) outStage |= VK_SHADER_STAGE_FRAGMENT_BIT; + if ((stage & GN_ALL_SHADER_MODULE) == GN_ALL_SHADER_MODULE) return VK_SHADER_STAGE_ALL_GRAPHICS; + return outStage; } diff --git a/rendering_api/vulkan/src/textures/vulkan_texture.c b/rendering_api/vulkan/src/textures/vulkan_texture.c index 7d8777f..189c542 100644 --- a/rendering_api/vulkan/src/textures/vulkan_texture.c +++ b/rendering_api/vulkan/src/textures/vulkan_texture.c @@ -6,7 +6,7 @@ VkImageType vkGryphnTextureType(gnTextureType type) { switch(type) { - case GN_TEXTURE_2D: return VK_IMAGE_TYPE_2D; + case GN_TEXTURE_2D: return VK_IMAGE_TYPE_2D; } } @@ -114,6 +114,7 @@ gnReturnCode gnCreateTextureFn(gnTexture texture, gnDevice device, const gnTextu size_t imageSize = info.width * info.height; if (info.format == GN_FORMAT_BGRA8_SRGB) { imageSize *= 4; } + if (info.format == GN_FORMAT_RGBA8_SRGB) { imageSize *= 4; } gnReturnCode staginBufferCreateCode = VkCreateBuffer( &texture->texture->buffer, imageSize, device, diff --git a/rendering_api/vulkan/src/uniforms/vulkan_uniform.c b/rendering_api/vulkan/src/uniforms/vulkan_uniform.c index af0e27a..ae78061 100644 --- a/rendering_api/vulkan/src/uniforms/vulkan_uniform.c +++ b/rendering_api/vulkan/src/uniforms/vulkan_uniform.c @@ -2,6 +2,7 @@ #include "buffers/vulkan_buffer.h" #include "output_device/vulkan_output_devices.h" #include "core/uniforms/gryphn_uniform_pool.h" +#include "textures/vulkan_texture.h" void gnUpdateBufferUniformFn(gnUniform uniform, gnBufferUniformInfo* info) { VkDescriptorBufferInfo bufferInfo = { @@ -22,3 +23,23 @@ void gnUpdateBufferUniformFn(gnUniform uniform, gnBufferUniformInfo* info) { vkUpdateDescriptorSets(uniform->pool->device->outputDevice->device, 1, &write, 0, NULL); } + +void gnUpdateImageUniformFn(gnUniform uniform, gnImageUniformInfo* info) { + VkDescriptorImageInfo imageInfo = { + .imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, + .imageView = info->texture->texture->image.imageView, + .sampler = info->texture->texture->sampler + }; + + VkWriteDescriptorSet write = { + .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, + .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, + .descriptorCount = 1, + .pImageInfo = &imageInfo, + .dstSet = uniform->uniform->set, + .dstBinding = info->binding, + .dstArrayElement = 0 + }; + + vkUpdateDescriptorSets(uniform->pool->device->outputDevice->device, 1, &write, 0, NULL); +} diff --git a/rendering_api/vulkan/src/uniforms/vulkan_uniform_layout.c b/rendering_api/vulkan/src/uniforms/vulkan_uniform_layout.c index 50c911f..64e2290 100644 --- a/rendering_api/vulkan/src/uniforms/vulkan_uniform_layout.c +++ b/rendering_api/vulkan/src/uniforms/vulkan_uniform_layout.c @@ -4,6 +4,7 @@ VkDescriptorType vkGryphnUniformType(gnUniformType type) { switch(type) { case GN_UNIFORM_BUFFER_DESCRIPTOR: return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + case GN_IMAGE_DESCRIPTOR: return VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; case GN_UNIFORM_TYPE_MAX: return VK_DESCRIPTOR_TYPE_MAX_ENUM; } } diff --git a/rendering_api/vulkan/src/vulkan_surface/vulkan_surface.c b/rendering_api/vulkan/src/vulkan_surface/vulkan_surface.c index 9f404d5..e79d3c1 100644 --- a/rendering_api/vulkan/src/vulkan_surface/vulkan_surface.c +++ b/rendering_api/vulkan/src/vulkan_surface/vulkan_surface.c @@ -110,7 +110,8 @@ gnSurfaceDetails gnGetSurfaceDetailsFn( VkFormat vkGryphnFormatToVulkanFormat(gnImageFormat format) { switch (format) { - case GN_FORMAT_BGRA8_SRGB: { return VK_FORMAT_B8G8R8A8_SRGB; } + case GN_FORMAT_BGRA8_SRGB: return VK_FORMAT_B8G8R8A8_SRGB; + case GN_FORMAT_RGBA8_SRGB: return VK_FORMAT_R8G8B8A8_SRGB; default: return VK_FORMAT_UNDEFINED; } } diff --git a/src/core/gryphn_platform_functions.h b/src/core/gryphn_platform_functions.h index c41305d..0c149f8 100644 --- a/src/core/gryphn_platform_functions.h +++ b/src/core/gryphn_platform_functions.h @@ -91,6 +91,7 @@ typedef struct gnDeviceFunctions_t { void (*_gnDestroyUniformPool)(gnUniformPool pool); void (*_gnUpdateBufferUniform)(gnUniform uniform, gnBufferUniformInfo* bufferInfo); + void (*_gnUpdateImageUniform)(gnUniform uniform, gnImageUniformInfo* imageInfo); gnReturnCode (*_gnCreateTexture)(gnTexture texture, gnDevice device, const gnTextureInfo info); void (*_gnTextureData)(gnTextureHandle texture, void* pixelData); diff --git a/src/core/instance/init/gryphn_init.c b/src/core/instance/init/gryphn_init.c index f7ce047..7ea9dcc 100644 --- a/src/core/instance/init/gryphn_init.c +++ b/src/core/instance/init/gryphn_init.c @@ -93,6 +93,7 @@ void gnLoadDeviceFunctions(struct gnDynamicLibrary_t* lib, struct gnDeviceFuncti gnLoadDLLFunction(lib, functions->_gnUniformPoolAllocateUniforms, "gnUniformPoolAllocateUniformsFn"); gnLoadDLLFunction(lib, functions->_gnDestroyUniformPool, "gnDestroyUniformPoolFn"); gnLoadDLLFunction(lib, functions->_gnUpdateBufferUniform, "gnUpdateBufferUniformFn"); + gnLoadDLLFunction(lib, functions->_gnUpdateImageUniform, "gnUpdateImageUniformFn"); gnLoadDLLFunction(lib, functions->_gnCreateTexture, "gnCreateTextureFn"); gnLoadDLLFunction(lib, functions->_gnTextureData, "gnTextureDataFn"); gnLoadDLLFunction(lib, functions->_gnDestroyTexture, "gnDestroyTextureFn"); diff --git a/src/core/uniforms/gryphn_uniform.c b/src/core/uniforms/gryphn_uniform.c index 0e18396..c859a7e 100644 --- a/src/core/uniforms/gryphn_uniform.c +++ b/src/core/uniforms/gryphn_uniform.c @@ -6,3 +6,7 @@ void gnUpdateBufferUniform(gnUniform uniform, gnBufferUniformInfo bufferInfo) { uniform->pool->device->deviceFunctions->_gnUpdateBufferUniform(uniform, &bufferInfo); } + +void gnUpdateImageUniform(gnUniform uniform, gnImageUniformInfo imageInfo) { + uniform->pool->device->deviceFunctions->_gnUpdateImageUniform(uniform, &imageInfo); +} diff --git a/src/core/uniforms/gryphn_uniform.h b/src/core/uniforms/gryphn_uniform.h index 65a6dcb..fd4e904 100644 --- a/src/core/uniforms/gryphn_uniform.h +++ b/src/core/uniforms/gryphn_uniform.h @@ -11,6 +11,11 @@ typedef struct gnBufferUniformInfo { size_t size; } gnBufferUniformInfo; +typedef struct gnImageUniformInfo { + uint32_t binding; + gnTexture texture; +} gnImageUniformInfo; + #ifdef GN_REVEAL_IMPL struct gnUniform_t { struct gnPlatformUniform_t* uniform; @@ -20,3 +25,4 @@ struct gnUniform_t { GN_ARRAY_LIST(gnUniform) void gnUpdateBufferUniform(gnUniform uniform, gnBufferUniformInfo bufferInfo); +void gnUpdateImageUniform(gnUniform uniform, gnImageUniformInfo imageInfo); diff --git a/src/core/uniforms/gryphn_uniform_layout.h b/src/core/uniforms/gryphn_uniform_layout.h index 327c11a..7a4da63 100644 --- a/src/core/uniforms/gryphn_uniform_layout.h +++ b/src/core/uniforms/gryphn_uniform_layout.h @@ -4,6 +4,7 @@ typedef enum gnUniformType { GN_UNIFORM_BUFFER_DESCRIPTOR, + GN_IMAGE_DESCRIPTOR, GN_UNIFORM_TYPE_MAX } gnUniformType;