uniform pool

This commit is contained in:
Greg Wells
2025-06-08 09:49:48 -04:00
parent 1825a39946
commit 292187b494
15 changed files with 93 additions and 19 deletions

View File

@@ -22,3 +22,4 @@
#include <core/present/gryphn_present.h> #include <core/present/gryphn_present.h>
#include <core/shader_input/gryphn_shader_layout.h> #include <core/shader_input/gryphn_shader_layout.h>
#include <core/buffers/gryphn_buffer.h> #include <core/buffers/gryphn_buffer.h>
#include <core/uniforms/gryphn_uniform_pool.h>

View File

@@ -5,10 +5,13 @@
#include "output_device/vulkan_physical_device.h" #include "output_device/vulkan_physical_device.h"
VkBufferUsageFlags vkGryphnBufferType(gnBufferType type) { VkBufferUsageFlags vkGryphnBufferType(gnBufferType type) {
switch (type) { VkBufferUsageFlags usageFlags = 0;
case GN_VERTEX_BUFFER: return VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; switch (type) {
case GN_INDEX_BUFFER: return VK_BUFFER_USAGE_INDEX_BUFFER_BIT; case GN_VERTEX_BUFFER: usageFlags |= VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; break;
} case GN_INDEX_BUFFER: usageFlags |= VK_BUFFER_USAGE_INDEX_BUFFER_BIT; break;
case GN_UNIFORM_BUFFER: usageFlags |= VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; break;
}
return usageFlags;
} }
gnReturnCode VkCreateBuffer( gnReturnCode VkCreateBuffer(
@@ -93,20 +96,29 @@ gnReturnCode gnCreateBufferFn(gnBufferHandle buffer, gnOutputDeviceHandle device
VkBufferUsageFlags usage = vkGryphnBufferType(info.type); VkBufferUsageFlags usage = vkGryphnBufferType(info.type);
buffer->buffer->useStagingBuffer = gnFalse; buffer->buffer->useStagingBuffer = gnFalse;
if (info.usage == GN_STATIC_DRAW) { if (info.usage == GN_STATIC_DRAW) {
gnReturnCode createdBuffer = VkCreateBuffer( buffer->buffer->useStagingBuffer = gnTrue;
VkCreateBuffer(
&buffer->buffer->stagingBuffer, &buffer->buffer->stagingBufferMemory, &buffer->buffer->stagingBuffer, &buffer->buffer->stagingBufferMemory,
info, device->outputDevice->device, device->physicalDevice.physicalDevice->device, info, device->outputDevice->device, device->physicalDevice.physicalDevice->device,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, VK_BUFFER_USAGE_TRANSFER_SRC_BIT VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
VK_BUFFER_USAGE_TRANSFER_SRC_BIT
); );
usage |= VK_BUFFER_USAGE_TRANSFER_DST_BIT;
buffer->buffer->useStagingBuffer = gnTrue;
}
gnReturnCode createdBuffer = VkCreateBuffer( return VkCreateBuffer(
&buffer->buffer->buffer, &buffer->buffer->bufferMemory, &buffer->buffer->buffer, &buffer->buffer->bufferMemory,
info, device->outputDevice->device, device->physicalDevice.physicalDevice->device, info, device->outputDevice->device, device->physicalDevice.physicalDevice->device,
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, usage VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
vkGryphnBufferType(info.type) | VK_BUFFER_USAGE_TRANSFER_DST_BIT
); );
} else {
return VkCreateBuffer(
&buffer->buffer->buffer, &buffer->buffer->bufferMemory,
info, device->outputDevice->device, device->physicalDevice.physicalDevice->device,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
vkGryphnBufferType(info.type)
);
}
return GN_SUCCESS; return GN_SUCCESS;

View File

@@ -7,7 +7,7 @@ gnReturnCode gnCreateCommandPoolFn(struct gnCommandPool_t* commandPool, struct g
VkCommandPoolCreateInfo poolInfo = { VkCommandPoolCreateInfo poolInfo = {
.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, .flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,
.queueFamilyIndex = info.queueIndex .queueFamilyIndex = info.queueIndex,
}; };
if (vkCreateCommandPool(device->outputDevice->device, &poolInfo, NULL, &commandPool->commandPool->commandPool) != VK_SUCCESS) { if (vkCreateCommandPool(device->outputDevice->device, &poolInfo, NULL, &commandPool->commandPool->commandPool) != VK_SUCCESS) {

View File

@@ -62,7 +62,7 @@ VkFormat vkGryphnVertexFormat(gnVertexFormat format) {
VkDescriptorType vkGryphnUniformType(gnUniformType type) { VkDescriptorType vkGryphnUniformType(gnUniformType type) {
switch(type) { switch(type) {
case GN_UNIFORM_BUFFER: return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; case GN_UNIFORM_BUFFER_DESCRIPTOR: return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
} }
} }

View File

@@ -0,0 +1,11 @@
#include "vulkan_uniform_pool.h"
#include "stdlib.h"
gnReturnCode gnCreateUniformPoolFn(gnUniformPool pool, gnDeviceHandle device) {
pool->uniformPool = malloc(sizeof(struct gnPlatformUniformPool_t));
pool->uniformPool->maxUniformPools = 0;
pool->uniformPool->uniformPoolCount = 0;
return GN_SUCCESS;
}

View File

@@ -0,0 +1,15 @@
#pragma once
#include <vulkan/vulkan.h>
#include <core/uniforms/gryphn_uniform_pool.h>
#include "core/uniforms/gryphn_uniform_layout.h"
typedef struct VkGryphnUniformPool {
VkDescriptorPool pool;
gnUniformType type;
} VkGryphnUniformPool;
struct gnPlatformUniformPool_t {
int maxUniformPools;
int uniformPoolCount;
VkGryphnUniformPool* pools;
};

View File

@@ -8,8 +8,9 @@ typedef enum gnIndexType {
} gnIndexType; } gnIndexType;
typedef enum gnBufferType { typedef enum gnBufferType {
GN_VERTEX_BUFFER = 0x00000001f, GN_VERTEX_BUFFER = 0x00000001,
GN_INDEX_BUFFER = 0x00000002f, GN_INDEX_BUFFER = 0x00000002,
GN_UNIFORM_BUFFER = 0x00000004
} gnBufferType; } gnBufferType;
typedef enum gnBufferUsage { typedef enum gnBufferUsage {

View File

@@ -24,3 +24,4 @@ GN_HANDLE(gnSemaphore);
GN_HANDLE(gnFence); GN_HANDLE(gnFence);
GN_HANDLE(gnFramebuffer); GN_HANDLE(gnFramebuffer);
GN_HANDLE(gnBuffer); GN_HANDLE(gnBuffer);
GN_HANDLE(gnUniformPool);

View File

@@ -87,6 +87,8 @@ typedef struct gnDeviceFunctions_t {
void* (*_gnMapBuffer)(gnBufferHandle buffer); void* (*_gnMapBuffer)(gnBufferHandle buffer);
void (*_gnDestroyBuffer)(gnBufferHandle buffer); void (*_gnDestroyBuffer)(gnBufferHandle buffer);
gnReturnCode (*_gnCreateUniformPool)(gnUniformPool pool, gnDeviceHandle device);
gnReturnCode (*_gnCreateFence)(gnFenceHandle fence, gnOutputDeviceHandle device); gnReturnCode (*_gnCreateFence)(gnFenceHandle fence, gnOutputDeviceHandle device);
void (*_gnSignalFence)(gnFenceHandle fence); void (*_gnSignalFence)(gnFenceHandle fence);
void (*_gnWaitForFence)(gnFenceHandle fence, uint64_t timeout); void (*_gnWaitForFence)(gnFenceHandle fence, uint64_t timeout);

View File

@@ -88,6 +88,7 @@ void gnLoadDeviceFunctions(struct gnDynamicLibrary_t* lib, struct gnDeviceFuncti
gnLoadDLLFunction(lib, functions->_gnBufferData, "gnBufferDataFn"); gnLoadDLLFunction(lib, functions->_gnBufferData, "gnBufferDataFn");
gnLoadDLLFunction(lib, functions->_gnMapBuffer, "gnMapBufferFn"); gnLoadDLLFunction(lib, functions->_gnMapBuffer, "gnMapBufferFn");
gnLoadDLLFunction(lib, functions->_gnDestroyBuffer, "gnDestroyBufferFn"); gnLoadDLLFunction(lib, functions->_gnDestroyBuffer, "gnDestroyBufferFn");
gnLoadDLLFunction(lib, functions->_gnCreateUniformPool, "gnCreateUniformPoolFn");
gnLoadDLLFunction(lib, functions->_gnCreateFence, "gnCreateFenceFn"); gnLoadDLLFunction(lib, functions->_gnCreateFence, "gnCreateFenceFn");
gnLoadDLLFunction(lib, functions->_gnSignalFence, "gnSignalFenceFn"); gnLoadDLLFunction(lib, functions->_gnSignalFence, "gnSignalFenceFn");
gnLoadDLLFunction(lib, functions->_gnWaitForFence, "gnWaitForFenceFn"); gnLoadDLLFunction(lib, functions->_gnWaitForFence, "gnWaitForFenceFn");

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include <core/output_device/gryphn_output_device.h> #include <core/output_device/gryphn_output_device.h>
#include <core/pipelines/gryphn_uniform_layout.h> #include <core/uniforms/gryphn_uniform_layout.h>
#include <core/renderpass/gryphn_render_pass_descriptor.h> #include <core/renderpass/gryphn_render_pass_descriptor.h>
#include <core/shader_module/gryphn_shader_module.h> #include <core/shader_module/gryphn_shader_module.h>
#include "utils/math/gryphn_vec2.h" #include "utils/math/gryphn_vec2.h"

View File

@@ -0,0 +1,7 @@
// #pragma once
// #ifdef GN_REVEAL_IMPL
// struct gnUniform_t {
// };
// #endif

View File

@@ -3,7 +3,7 @@
#include "core/shader_module/gryphn_shader_module.h" #include "core/shader_module/gryphn_shader_module.h"
typedef enum gnUniformType { typedef enum gnUniformType {
GN_UNIFORM_BUFFER GN_UNIFORM_BUFFER_DESCRIPTOR
} gnUniformType; } gnUniformType;
typedef struct gnUniformBinding { typedef struct gnUniformBinding {

View File

@@ -0,0 +1,10 @@
#include "gryphn_uniform_pool.h"
#include "core/output_device/gryphn_output_device.h"
#include "core/gryphn_platform_functions.h"
#include "stdlib.h"
gnReturnCode gnCreateUniformPool(gnUniformPool* pool, gnDeviceHandle device) {
*pool = malloc(sizeof(struct gnUniformPool_t));
(*pool)->device = device;
return device->deviceFunctions->_gnCreateUniformPool(*pool, device);
}

View File

@@ -0,0 +1,13 @@
#pragma once
#include "core/gryphn_handles.h"
#include "utils/gryphn_error_code.h"
#ifdef GN_REVEAL_IMPL
struct gnUniformPool_t {
struct gnPlatformUniformPool_t* uniformPool;
gnDeviceHandle device;
};
#endif
gnReturnCode gnCreateUniformPool(gnUniformPool* pool, gnDeviceHandle device);
// void gnUniformPoolAllocateUniforms