rename to projects (DOES NOT COMPILE)
This commit is contained in:
45
projects/apis/vulkan/src/uniforms/vulkan_uniform.c
Normal file
45
projects/apis/vulkan/src/uniforms/vulkan_uniform.c
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "vulkan_uniform.h"
|
||||
#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 = {
|
||||
.buffer = info->buffer->buffer->buffer.buffer,
|
||||
.offset = info->offset,
|
||||
.range = info->size
|
||||
};
|
||||
|
||||
VkWriteDescriptorSet write = {
|
||||
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
||||
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||
.descriptorCount = 1,
|
||||
.pBufferInfo = &bufferInfo,
|
||||
.dstSet = uniform->uniform->set,
|
||||
.dstBinding = info->binding,
|
||||
.dstArrayElement = 0
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
7
projects/apis/vulkan/src/uniforms/vulkan_uniform.h
Normal file
7
projects/apis/vulkan/src/uniforms/vulkan_uniform.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
#include <vulkan/vulkan.h>
|
||||
#include "core/uniforms/gryphn_uniform.h"
|
||||
|
||||
typedef struct gnPlatformUniform_t {
|
||||
VkDescriptorSet set;
|
||||
} gnPlatformUniform;
|
39
projects/apis/vulkan/src/uniforms/vulkan_uniform_layout.c
Normal file
39
projects/apis/vulkan/src/uniforms/vulkan_uniform_layout.c
Normal file
@@ -0,0 +1,39 @@
|
||||
#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_IMAGE_DESCRIPTOR: return VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
||||
case GN_UNIFORM_TYPE_MAX: return VK_DESCRIPTOR_TYPE_MAX_ENUM;
|
||||
}
|
||||
}
|
||||
|
||||
VkDescriptorSetLayout vkGryphnCreateSetLayouts(
|
||||
const gnUniformSet* set,
|
||||
VkDevice device
|
||||
) {
|
||||
VkDescriptorSetLayout vkLayout;
|
||||
gnUniformSet uniformSet = *set;
|
||||
|
||||
VkDescriptorSetLayoutBinding* bindings = malloc(sizeof(VkDescriptorSetLayoutBinding) * uniformSet.uniformBindingCount);
|
||||
for (int i = 0; i < uniformSet.uniformBindingCount; i++) {
|
||||
bindings[i] = (VkDescriptorSetLayoutBinding){
|
||||
.binding = uniformSet.uniformBindings[i].binding,
|
||||
.descriptorCount = 1,
|
||||
.descriptorType = vkGryphnUniformType(uniformSet.uniformBindings[i].type),
|
||||
.stageFlags = vkGryphnShaderModuleStage(uniformSet.uniformBindings[i].stage)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
VkDescriptorSetLayoutCreateInfo info = {
|
||||
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
|
||||
.bindingCount = uniformSet.uniformBindingCount,
|
||||
.pBindings = bindings
|
||||
};
|
||||
|
||||
if (vkCreateDescriptorSetLayout(device, &info, NULL, &vkLayout) != VK_SUCCESS)
|
||||
return NULL;
|
||||
return vkLayout;
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <core/uniforms/gryphn_uniform_layout.h>
|
||||
|
||||
VkDescriptorSetLayout vkGryphnCreateSetLayouts(const gnUniformSet* set, VkDevice device);
|
||||
VkDescriptorType vkGryphnUniformType(gnUniformType type);
|
136
projects/apis/vulkan/src/uniforms/vulkan_uniform_pool.c
Normal file
136
projects/apis/vulkan/src/uniforms/vulkan_uniform_pool.c
Normal file
@@ -0,0 +1,136 @@
|
||||
#include "vulkan_uniform_pool.h"
|
||||
#include "vulkan_uniform_layout.h"
|
||||
#include "stdlib.h"
|
||||
#include "output_device/vulkan_output_devices.h"
|
||||
#include "core/uniforms/gryphn_uniform.h"
|
||||
#include "vulkan_uniform.h"
|
||||
#include "stdio.h"
|
||||
|
||||
VkGryphnUniformPool* GetLastUniformPool(VkGryphnUniformPoolArrayList* list) { return &list->data[list->count - 1]; }
|
||||
|
||||
gnReturnCode gnCreateUniformPoolFn(gnUniformPool pool, gnDeviceHandle device) {
|
||||
pool->uniformPool = malloc(sizeof(struct gnPlatformUniformPool_t));
|
||||
pool->uniformPool->pools = VkGryphnUniformPoolArrayListCreate();
|
||||
|
||||
if (device->outputDevice->enabledOversizedDescriptorPools == gnTrue) {
|
||||
{
|
||||
VkGryphnUniformPool firstPool = {
|
||||
.pool = VK_NULL_HANDLE,
|
||||
.layouts = VkDescriptorSetLayoutArrayListCreate()
|
||||
};
|
||||
VkGryphnUniformPoolArrayListAdd(&pool->uniformPool->pools, firstPool);
|
||||
} // scopped because the add function copies and I don't want it lying around
|
||||
|
||||
VkGryphnUniformPool* currentPool = GetLastUniformPool(&pool->uniformPool->pools);
|
||||
VkDescriptorPoolCreateInfo poolInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
|
||||
.flags = VK_DESCRIPTOR_POOL_CREATE_ALLOW_OVERALLOCATION_SETS_BIT_NV,
|
||||
.poolSizeCount = 0,
|
||||
.pPoolSizes = NULL,
|
||||
.maxSets = 0
|
||||
};
|
||||
|
||||
if (vkCreateDescriptorPool(
|
||||
pool->device->outputDevice->device, &poolInfo, NULL,
|
||||
¤tPool->pool
|
||||
) != VK_SUCCESS)
|
||||
return GN_FAILED_TO_ALLOCATE_MEMORY;
|
||||
}
|
||||
|
||||
return GN_SUCCESS;
|
||||
}
|
||||
|
||||
gnUniform* gnUniformPoolAllocateUniformsFn(gnUniformPool pool, gnUniformAllocationInfo allocInfo) {
|
||||
gnBool fixedAllocation = !pool->device->outputDevice->enabledOversizedDescriptorPools;
|
||||
if (fixedAllocation) {
|
||||
VkGryphnUniformPool newPool = {
|
||||
.pool = VK_NULL_HANDLE,
|
||||
.layouts = VkDescriptorSetLayoutArrayListCreate()
|
||||
};
|
||||
|
||||
// TODO: redo this, its not warning me IDK why cuz its totally wrong
|
||||
VkDescriptorPoolSize uniformBufferSize = {
|
||||
.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||
.descriptorCount = 0
|
||||
};
|
||||
|
||||
VkDescriptorPoolSize imageSize = {
|
||||
.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||
.descriptorCount = 0
|
||||
};
|
||||
|
||||
for (int i = 0; i < allocInfo.setCount; i++) {
|
||||
for (int c = 0; c < allocInfo.sets[i].uniformBindingCount; c++) {
|
||||
if (allocInfo.sets[i].uniformBindings[i].type == GN_UNIFORM_BUFFER_DESCRIPTOR) uniformBufferSize.descriptorCount++;
|
||||
if (allocInfo.sets[i].uniformBindings[i].type == GN_IMAGE_DESCRIPTOR) imageSize.descriptorCount++;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t count = 0;
|
||||
VkDescriptorPoolSize poolSizes[2] = {};
|
||||
|
||||
if (uniformBufferSize.descriptorCount > 0) {
|
||||
poolSizes[count] = uniformBufferSize;
|
||||
count++;
|
||||
}
|
||||
|
||||
if (imageSize.descriptorCount > 0) {
|
||||
poolSizes[count] = imageSize;
|
||||
count++;
|
||||
}
|
||||
|
||||
VkDescriptorPoolCreateInfo poolInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
|
||||
.poolSizeCount = count,
|
||||
.pPoolSizes = poolSizes,
|
||||
.maxSets = allocInfo.setCount
|
||||
};
|
||||
|
||||
if (vkCreateDescriptorPool(
|
||||
pool->device->outputDevice->device, &poolInfo, NULL,
|
||||
&newPool.pool
|
||||
) != VK_SUCCESS)
|
||||
return NULL;
|
||||
|
||||
VkGryphnUniformPoolArrayListAdd(&pool->uniformPool->pools, newPool);
|
||||
} // scopped for same reasons as before
|
||||
|
||||
VkGryphnUniformPool* currentPool = GetLastUniformPool(&pool->uniformPool->pools);
|
||||
|
||||
uint32_t startingCount = currentPool->layouts.count;
|
||||
VkDescriptorSetLayoutArrayListExpand(¤tPool->layouts, allocInfo.setCount);
|
||||
|
||||
for (int i = 0; i < allocInfo.setCount; i++) {
|
||||
VkDescriptorSetLayoutArrayListAdd(
|
||||
¤tPool->layouts,
|
||||
vkGryphnCreateSetLayouts(&allocInfo.sets[i], pool->device->outputDevice->device)
|
||||
);
|
||||
}
|
||||
|
||||
VkDescriptorSetAllocateInfo vkAllocInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
|
||||
.descriptorPool = currentPool->pool,
|
||||
.descriptorSetCount = allocInfo.setCount,
|
||||
.pSetLayouts = ¤tPool->layouts.data[startingCount]
|
||||
};
|
||||
|
||||
VkDescriptorSet* sets = malloc(sizeof(VkDescriptorSet) * allocInfo.setCount);
|
||||
if (vkAllocateDescriptorSets(pool->device->outputDevice->device, &vkAllocInfo, sets) != VK_SUCCESS)
|
||||
return NULL;
|
||||
|
||||
gnUniform* uniforms = malloc(sizeof(gnUniform) * allocInfo.setCount);
|
||||
for (int i = 0; i < allocInfo.setCount; i++) {
|
||||
uniforms[i] = malloc(sizeof(struct gnUniform_t));
|
||||
uniforms[i]->uniform = malloc(sizeof(struct gnPlatformUniform_t));
|
||||
uniforms[i]->uniform->set = sets[i];
|
||||
}
|
||||
return uniforms;
|
||||
}
|
||||
|
||||
void gnDestroyUniformPoolFn(gnUniformPool pool) {
|
||||
for (int k = 0; k < pool->uniformPool->pools.count; k++) {
|
||||
vkDestroyDescriptorPool(pool->device->outputDevice->device, pool->uniformPool->pools.data[k].pool, NULL);
|
||||
for (int i = 0; i < pool->uniformPool->pools.data[k].layouts.count; i++)
|
||||
vkDestroyDescriptorSetLayout(pool->device->outputDevice->device, pool->uniformPool->pools.data[k].layouts.data[i], NULL);
|
||||
}
|
||||
}
|
15
projects/apis/vulkan/src/uniforms/vulkan_uniform_pool.h
Normal file
15
projects/apis/vulkan/src/uniforms/vulkan_uniform_pool.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <core/uniforms/gryphn_uniform_pool.h>
|
||||
|
||||
GN_ARRAY_LIST(VkDescriptorSetLayout);
|
||||
|
||||
typedef struct VkGryphnUniformPool {
|
||||
VkDescriptorPool pool;
|
||||
VkDescriptorSetLayoutArrayList layouts;
|
||||
} VkGryphnUniformPool;
|
||||
GN_ARRAY_LIST(VkGryphnUniformPool);
|
||||
|
||||
struct gnPlatformUniformPool_t {
|
||||
VkGryphnUniformPoolArrayList pools;
|
||||
};
|
Reference in New Issue
Block a user