horrible uniform pool API
This commit is contained in:
6
rendering_api/vulkan/src/uniforms/vulkan_uniform.h
Normal file
6
rendering_api/vulkan/src/uniforms/vulkan_uniform.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
typedef struct gnPlatformUniform_t {
|
||||
VkDescriptorSet set;
|
||||
} gnPlatformUniform;
|
||||
38
rendering_api/vulkan/src/uniforms/vulkan_uniform_layout.c
Normal file
38
rendering_api/vulkan/src/uniforms/vulkan_uniform_layout.c
Normal file
@@ -0,0 +1,38 @@
|
||||
#include "vulkan_uniform_layout.h"
|
||||
#include <shader_module/vulkan_shader_module.h>
|
||||
|
||||
VkDescriptorType vkGryphnUniformType(gnUniformType type) {
|
||||
switch(type) {
|
||||
case GN_UNIFORM_BUFFER_DESCRIPTOR: return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
||||
case GN_UNIFORM_TYPE_MAX: return VK_DESCRIPTOR_TYPE_MAX_ENUM;
|
||||
}
|
||||
}
|
||||
|
||||
VkDescriptorSetLayout* vkGryphnCreateSetLayouts(
|
||||
const gnUniformLayout* layout, uint32_t* setCount,
|
||||
VkDevice device
|
||||
) {
|
||||
gnUniformLayout uniformLayout = *layout;
|
||||
|
||||
*setCount = uniformLayout.uniformBindingCount;
|
||||
VkDescriptorSetLayout* sets = malloc(sizeof(VkDescriptorSetLayoutBinding) * uniformLayout.uniformBindingCount);
|
||||
for (int i = 0; i < uniformLayout.uniformBindingCount; i++) {
|
||||
VkDescriptorSetLayoutBinding setLayout = {
|
||||
.binding = uniformLayout.uniformBindings[i].binding,
|
||||
.descriptorCount = 1,
|
||||
.descriptorType = vkGryphnUniformType(uniformLayout.uniformBindings[i].type),
|
||||
.stageFlags = vkGryphnShaderModuleStage(uniformLayout.uniformBindings[i].stage)
|
||||
};
|
||||
|
||||
VkDescriptorSetLayoutCreateInfo info = {
|
||||
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
|
||||
.bindingCount = 1,
|
||||
.pBindings = &setLayout
|
||||
};
|
||||
|
||||
if (vkCreateDescriptorSetLayout(device, &info, NULL, sets) != VK_SUCCESS) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return sets;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <core/uniforms/gryphn_uniform_layout.h>
|
||||
|
||||
VkDescriptorSetLayout* vkGryphnCreateSetLayouts(const gnUniformLayout* layout, uint32_t* setCount, VkDevice device);
|
||||
@@ -1,11 +1,46 @@
|
||||
#include "vulkan_uniform_pool.h"
|
||||
#include "vulkan_uniform_layout.h"
|
||||
#include "stdlib.h"
|
||||
#include "output_device/vulkan_output_devices.h"
|
||||
|
||||
gnReturnCode gnCreateUniformPoolFn(gnUniformPool pool, gnDeviceHandle device) {
|
||||
pool->uniformPool = malloc(sizeof(struct gnPlatformUniformPool_t));
|
||||
|
||||
pool->uniformPool->maxUniformPools = 0;
|
||||
pool->uniformPool->uniformPoolCount = 0;
|
||||
|
||||
pool->uniformPool->poolCount = pool->uniformPool->maxPoolCount = 1;
|
||||
pool->uniformPool->pools = malloc(sizeof(VkDescriptorPool) * pool->uniformPool->maxPoolCount);
|
||||
return GN_SUCCESS;
|
||||
}
|
||||
|
||||
gnUniform* gnUniformPoolAllocateUniformsFn(gnUniformPool pool, const gnUniformLayout layout) {
|
||||
uint32_t setCount;
|
||||
VkDescriptorSetLayout* layouts = vkGryphnCreateSetLayouts(&layout, &setCount, pool->device->outputDevice->device);
|
||||
VkDescriptorPoolSize* sizes = malloc(sizeof(VkDescriptorPoolSize) * layout.uniformBindingCount);
|
||||
|
||||
gnUniform* uniforms = malloc(sizeof(gnUniform) * setCount);
|
||||
for (int i = 0; i < layout.uniformBindingCount; i++) {
|
||||
|
||||
}
|
||||
|
||||
VkDescriptorPoolCreateInfo poolInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
|
||||
.poolSizeCount = layout.uniformBindingCount,
|
||||
.maxSets = layout.uniformBindingCount,
|
||||
.pPoolSizes = sizes,
|
||||
};
|
||||
|
||||
if (pool->uniformPool->poolCount >= pool->uniformPool->maxPoolCount) {
|
||||
pool->uniformPool->maxPoolCount *= 2;
|
||||
pool->uniformPool->pools = realloc(pool->uniformPool->pools, sizeof(VkDescriptorPool) * pool->uniformPool->maxPoolCount);
|
||||
}
|
||||
|
||||
if (vkCreateDescriptorPool(
|
||||
pool->device->outputDevice->device, &poolInfo, NULL,
|
||||
&pool->uniformPool->pools[pool->uniformPool->poolCount]
|
||||
) != VK_SUCCESS)
|
||||
return NULL;
|
||||
pool->uniformPool->poolCount++;
|
||||
|
||||
|
||||
free(layouts);
|
||||
free(sizes);
|
||||
return uniforms;
|
||||
}
|
||||
|
||||
@@ -3,13 +3,7 @@
|
||||
#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;
|
||||
uint32_t poolCount, maxPoolCount;
|
||||
VkDescriptorPool* pools;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user