horrible uniform pool API
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
#include "output_device/vulkan_output_devices.h"
|
#include "output_device/vulkan_output_devices.h"
|
||||||
#include "shader_module/vulkan_shader_module.h"
|
#include "shader_module/vulkan_shader_module.h"
|
||||||
#include "renderpass/vulkan_render_pass_descriptor.h"
|
#include "renderpass/vulkan_render_pass_descriptor.h"
|
||||||
|
#include "uniforms/vulkan_uniform_layout.h"
|
||||||
|
|
||||||
VkDynamicState vkGryphnDynamicStateToVulkanDynamicState(enum gnDynamicState_e state) {
|
VkDynamicState vkGryphnDynamicStateToVulkanDynamicState(enum gnDynamicState_e state) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
@@ -60,13 +61,7 @@ VkFormat vkGryphnVertexFormat(gnVertexFormat format) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VkDescriptorType vkGryphnUniformType(gnUniformType type) {
|
gnReturnCode gnCreateGraphicsPipelineFn(gnGraphicsPipeline graphicsPipeline, gnDevice device, gnGraphicsPipelineInfo info) {
|
||||||
switch(type) {
|
|
||||||
case GN_UNIFORM_BUFFER_DESCRIPTOR: return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
gnReturnCode gnCreateGraphicsPipelineFn(struct gnGraphicsPipeline_t* graphicsPipeline, struct gnOutputDevice_t* device, struct gnGraphicsPipelineInfo_t info) {
|
|
||||||
graphicsPipeline->graphicsPipeline = malloc(sizeof(gnPlatformGraphicsPipeline));
|
graphicsPipeline->graphicsPipeline = malloc(sizeof(gnPlatformGraphicsPipeline));
|
||||||
|
|
||||||
for (int i = 0; i < GN_DYNAMIC_STATE_MAX; i++) graphicsPipeline->graphicsPipeline->isDynamic[i] = gnFalse;
|
for (int i = 0; i < GN_DYNAMIC_STATE_MAX; i++) graphicsPipeline->graphicsPipeline->isDynamic[i] = gnFalse;
|
||||||
@@ -184,27 +179,9 @@ gnReturnCode gnCreateGraphicsPipelineFn(struct gnGraphicsPipeline_t* graphicsPip
|
|||||||
.blendConstants[3] = 0.0f
|
.blendConstants[3] = 0.0f
|
||||||
};
|
};
|
||||||
|
|
||||||
graphicsPipeline->graphicsPipeline->setCount = info.uniformLayout.uniformBindingCount;
|
graphicsPipeline->graphicsPipeline->sets = vkGryphnCreateSetLayouts(
|
||||||
graphicsPipeline->graphicsPipeline->sets = malloc(sizeof(VkDescriptorSetLayoutBinding) * info.uniformLayout.uniformBindingCount);
|
&info.uniformLayout, &graphicsPipeline->graphicsPipeline->setCount, device->outputDevice->device
|
||||||
for (int i = 0; i < info.uniformLayout.uniformBindingCount; i++) {
|
);
|
||||||
VkDescriptorSetLayoutBinding setLayout = {
|
|
||||||
.binding = info.uniformLayout.uniformBindings[i].binding,
|
|
||||||
.descriptorCount = 1,
|
|
||||||
.descriptorType = vkGryphnUniformType(info.uniformLayout.uniformBindings[i].type),
|
|
||||||
.stageFlags = vkGryphnShaderModuleStage(info.uniformLayout.uniformBindings[i].stage)
|
|
||||||
};
|
|
||||||
|
|
||||||
VkDescriptorSetLayoutCreateInfo info = {
|
|
||||||
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
|
|
||||||
.bindingCount = 1,
|
|
||||||
.pBindings = &setLayout
|
|
||||||
};
|
|
||||||
|
|
||||||
if (vkCreateDescriptorSetLayout(device->outputDevice->device, &info, NULL, &graphicsPipeline->graphicsPipeline->sets[i]) != VK_SUCCESS) {
|
|
||||||
return GN_FAILED_TO_CREATE_UNIFORM_LAYOUT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
VkPipelineLayoutCreateInfo pipelineLayoutInfo = {
|
VkPipelineLayoutCreateInfo pipelineLayoutInfo = {
|
||||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
|
||||||
|
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_pool.h"
|
||||||
|
#include "vulkan_uniform_layout.h"
|
||||||
#include "stdlib.h"
|
#include "stdlib.h"
|
||||||
|
#include "output_device/vulkan_output_devices.h"
|
||||||
|
|
||||||
gnReturnCode gnCreateUniformPoolFn(gnUniformPool pool, gnDeviceHandle device) {
|
gnReturnCode gnCreateUniformPoolFn(gnUniformPool pool, gnDeviceHandle device) {
|
||||||
pool->uniformPool = malloc(sizeof(struct gnPlatformUniformPool_t));
|
pool->uniformPool = malloc(sizeof(struct gnPlatformUniformPool_t));
|
||||||
|
pool->uniformPool->poolCount = pool->uniformPool->maxPoolCount = 1;
|
||||||
pool->uniformPool->maxUniformPools = 0;
|
pool->uniformPool->pools = malloc(sizeof(VkDescriptorPool) * pool->uniformPool->maxPoolCount);
|
||||||
pool->uniformPool->uniformPoolCount = 0;
|
|
||||||
|
|
||||||
return GN_SUCCESS;
|
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_pool.h>
|
||||||
#include "core/uniforms/gryphn_uniform_layout.h"
|
#include "core/uniforms/gryphn_uniform_layout.h"
|
||||||
|
|
||||||
typedef struct VkGryphnUniformPool {
|
|
||||||
VkDescriptorPool pool;
|
|
||||||
gnUniformType type;
|
|
||||||
} VkGryphnUniformPool;
|
|
||||||
|
|
||||||
struct gnPlatformUniformPool_t {
|
struct gnPlatformUniformPool_t {
|
||||||
int maxUniformPools;
|
uint32_t poolCount, maxPoolCount;
|
||||||
int uniformPoolCount;
|
VkDescriptorPool* pools;
|
||||||
VkGryphnUniformPool* pools;
|
|
||||||
};
|
};
|
||||||
|
@@ -25,3 +25,4 @@ GN_HANDLE(gnFence);
|
|||||||
GN_HANDLE(gnFramebuffer);
|
GN_HANDLE(gnFramebuffer);
|
||||||
GN_HANDLE(gnBuffer);
|
GN_HANDLE(gnBuffer);
|
||||||
GN_HANDLE(gnUniformPool);
|
GN_HANDLE(gnUniformPool);
|
||||||
|
GN_HANDLE(gnUniform);
|
||||||
|
@@ -88,6 +88,7 @@ typedef struct gnDeviceFunctions_t {
|
|||||||
void (*_gnDestroyBuffer)(gnBufferHandle buffer);
|
void (*_gnDestroyBuffer)(gnBufferHandle buffer);
|
||||||
|
|
||||||
gnReturnCode (*_gnCreateUniformPool)(gnUniformPool pool, gnDeviceHandle device);
|
gnReturnCode (*_gnCreateUniformPool)(gnUniformPool pool, gnDeviceHandle device);
|
||||||
|
gnUniform* (*_gnUniformPoolAllocateUniforms)(gnUniformPool pool, const gnUniformLayout layout);
|
||||||
|
|
||||||
gnReturnCode (*_gnCreateFence)(gnFenceHandle fence, gnOutputDeviceHandle device);
|
gnReturnCode (*_gnCreateFence)(gnFenceHandle fence, gnOutputDeviceHandle device);
|
||||||
void (*_gnSignalFence)(gnFenceHandle fence);
|
void (*_gnSignalFence)(gnFenceHandle fence);
|
||||||
|
@@ -90,6 +90,7 @@ void gnLoadDeviceFunctions(struct gnDynamicLibrary_t* lib, struct gnDeviceFuncti
|
|||||||
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->_gnCreateUniformPool, "gnCreateUniformPoolFn");
|
||||||
|
gnLoadDLLFunction(lib, functions->_gnUniformPoolAllocateUniforms, "gnUniformPoolAllocateUniformsFn");
|
||||||
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");
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
// #pragma once
|
#pragma once
|
||||||
|
|
||||||
// #ifdef GN_REVEAL_IMPL
|
#ifdef GN_REVEAL_IMPL
|
||||||
// struct gnUniform_t {
|
struct gnUniform_t {
|
||||||
|
struct gnPlatformUniform_t* uniform;
|
||||||
// };
|
};
|
||||||
// #endif
|
#endif
|
||||||
|
@@ -3,7 +3,8 @@
|
|||||||
#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_DESCRIPTOR
|
GN_UNIFORM_BUFFER_DESCRIPTOR,
|
||||||
|
GN_UNIFORM_TYPE_MAX
|
||||||
} gnUniformType;
|
} gnUniformType;
|
||||||
|
|
||||||
typedef struct gnUniformBinding {
|
typedef struct gnUniformBinding {
|
||||||
|
@@ -8,3 +8,7 @@ gnReturnCode gnCreateUniformPool(gnUniformPool* pool, gnDeviceHandle device) {
|
|||||||
(*pool)->device = device;
|
(*pool)->device = device;
|
||||||
return device->deviceFunctions->_gnCreateUniformPool(*pool, device);
|
return device->deviceFunctions->_gnCreateUniformPool(*pool, device);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gnUniform* gnUniformPoolAllocateUniforms(gnUniformPool pool, const gnUniformLayout layout) {
|
||||||
|
return pool->device->deviceFunctions->_gnUniformPoolAllocateUniforms(pool, layout);
|
||||||
|
}
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "core/gryphn_handles.h"
|
#include "core/gryphn_handles.h"
|
||||||
#include "utils/gryphn_error_code.h"
|
#include "utils/gryphn_error_code.h"
|
||||||
|
#include "core/uniforms/gryphn_uniform_layout.h"
|
||||||
|
|
||||||
#ifdef GN_REVEAL_IMPL
|
#ifdef GN_REVEAL_IMPL
|
||||||
struct gnUniformPool_t {
|
struct gnUniformPool_t {
|
||||||
@@ -10,4 +11,4 @@ struct gnUniformPool_t {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
gnReturnCode gnCreateUniformPool(gnUniformPool* pool, gnDeviceHandle device);
|
gnReturnCode gnCreateUniformPool(gnUniformPool* pool, gnDeviceHandle device);
|
||||||
// void gnUniformPoolAllocateUniforms
|
gnUniform* gnUniformPoolAllocateUniforms(gnUniformPool pool, const gnUniformLayout layout);
|
||||||
|
Reference in New Issue
Block a user