gryphn+vulkan render pass descriptors
This commit is contained in:
@@ -10,3 +10,4 @@
|
|||||||
#include <core/presentation_queue/gryphn_presentation_queue.h>
|
#include <core/presentation_queue/gryphn_presentation_queue.h>
|
||||||
#include <core/shader_module/gryphn_shader_module.h>
|
#include <core/shader_module/gryphn_shader_module.h>
|
||||||
#include <core/pipelines/graphics_pipeline/gryphn_graphics_pipeline.h>
|
#include <core/pipelines/graphics_pipeline/gryphn_graphics_pipeline.h>
|
||||||
|
#include <core/renderpass/gryphn_render_pass_descriptor.h>
|
||||||
|
@@ -0,0 +1,81 @@
|
|||||||
|
#include "vulkan_render_pass_descriptor.h"
|
||||||
|
#include "vulkan_surface/vulkan_surface.h"
|
||||||
|
#include "output_device/vulkan_output_devices.h"
|
||||||
|
|
||||||
|
VkAttachmentLoadOp vkGryphnLoadOperation(enum gnLoadOperation_e loadOperation) {
|
||||||
|
switch(loadOperation) {
|
||||||
|
case GN_LOAD_OPERATION_LOAD: return VK_ATTACHMENT_LOAD_OP_LOAD;
|
||||||
|
case GN_LOAD_OPERATION_CLEAR: return VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||||
|
case GN_LOAD_OPERATION_DONT_CARE: return VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
VkAttachmentStoreOp vkGryphnStoreOperation(enum gnStoreOperation_e storeOperation) {
|
||||||
|
switch (storeOperation) {
|
||||||
|
case GN_STORE_OPERATION_STORE: return VK_ATTACHMENT_STORE_OP_STORE;
|
||||||
|
case GN_STORE_OPERATION_DONT_CARE: return VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
VkImageLayout vkGryphnImageLayout(enum gnImageLayout_e layout) {
|
||||||
|
switch(layout) {
|
||||||
|
case GN_LAYOUT_UNDEFINED: return VK_IMAGE_LAYOUT_UNDEFINED;
|
||||||
|
case GN_LAYOUT_PRESENTATION_QUEUE_IMAGE: return VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
|
||||||
|
case GN_LAYOUT_TRANSFER_DESTINATION: return VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
|
||||||
|
case GN_COLOR_ATTACHMENT: return VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gnReturnCode gnCreateRenderPassDescriptorFn(struct gnRenderPassDescriptor_t* renderPass, struct gnOutputDevice_t* device, struct gnRenderPassDescriptorInfo_t info) {
|
||||||
|
renderPass->renderPassDescriptor = malloc(sizeof(gnPlatformRenderPassDescriptor));
|
||||||
|
|
||||||
|
VkAttachmentDescription* attachments = malloc(sizeof(VkAttachmentDescription) * info.attachmentCount);
|
||||||
|
for (int i = 0; i < info.attachmentCount; i++) {
|
||||||
|
attachments[i].format = vkGryphnFormatToVulkanFormat(info.attachmentInfos[i].format);
|
||||||
|
attachments[i].samples = VK_SAMPLE_COUNT_1_BIT;
|
||||||
|
|
||||||
|
attachments[i].loadOp = vkGryphnLoadOperation(info.attachmentInfos[i].loadOperation);
|
||||||
|
attachments[i].storeOp = vkGryphnStoreOperation(info.attachmentInfos[i].storeOperation);
|
||||||
|
|
||||||
|
attachments[i].stencilLoadOp = vkGryphnLoadOperation(info.attachmentInfos[i].stencilLoadOperation);
|
||||||
|
attachments[i].stencilStoreOp = vkGryphnStoreOperation(info.attachmentInfos[i].stencilStoreOperation);
|
||||||
|
|
||||||
|
attachments[i].initialLayout = vkGryphnImageLayout(info.attachmentInfos[i].initialLayout);
|
||||||
|
attachments[i].finalLayout = vkGryphnImageLayout(info.attachmentInfos[i].finalLayout);
|
||||||
|
}
|
||||||
|
|
||||||
|
VkSubpassDescription* subpasses = malloc(sizeof(VkSubpassDescription) * info.subpassCount);
|
||||||
|
|
||||||
|
for (int i = 0; i < info.subpassCount; i++) {
|
||||||
|
subpasses[i].pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
||||||
|
subpasses[i].colorAttachmentCount = info.subpassInfos[i].colorAttachmentCount;
|
||||||
|
VkAttachmentReference* colorAttachments = malloc(sizeof(VkAttachmentReference) * info.subpassInfos[i].colorAttachmentCount);
|
||||||
|
for (int c = 0; c < info.subpassInfos[i].colorAttachmentCount; c++) {
|
||||||
|
colorAttachments[c].attachment = info.subpassInfos[i].colorAttachments[c].index;
|
||||||
|
colorAttachments[c].layout = vkGryphnImageLayout(info.subpassInfos[i].colorAttachments[c].imageLayout);
|
||||||
|
}
|
||||||
|
subpasses[i].pColorAttachments = colorAttachments;
|
||||||
|
}
|
||||||
|
|
||||||
|
VkRenderPassCreateInfo renderPassInfo = (VkRenderPassCreateInfo){
|
||||||
|
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
|
||||||
|
.attachmentCount = info.attachmentCount,
|
||||||
|
.pAttachments = attachments,
|
||||||
|
.subpassCount = info.subpassCount,
|
||||||
|
.pSubpasses = subpasses
|
||||||
|
};
|
||||||
|
|
||||||
|
if (vkCreateRenderPass(device->outputDevice->device, &renderPassInfo, NULL, &renderPass->renderPassDescriptor->renderPass) != VK_SUCCESS) {
|
||||||
|
return GN_FAILED_TO_CREATE_RENDER_PASS;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(attachments);
|
||||||
|
free(subpasses);
|
||||||
|
|
||||||
|
return GN_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void gnDestroyRenderPassDescriptorFn(struct gnRenderPassDescriptor_t* renderPass) {
|
||||||
|
vkDestroyRenderPass(renderPass->device->outputDevice->device, renderPass->renderPassDescriptor->renderPass, NULL);
|
||||||
|
}
|
@@ -0,0 +1,7 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "core/renderpass/gryphn_render_pass_descriptor.h"
|
||||||
|
#include <vulkan/vulkan.h>
|
||||||
|
|
||||||
|
typedef struct gnPlatformRenderPassDescriptor_t {
|
||||||
|
VkRenderPass renderPass;
|
||||||
|
} gnPlatformRenderPassDescriptor;
|
@@ -9,6 +9,7 @@
|
|||||||
#include "window_surface/gryphn_surface_create_functions.h"
|
#include "window_surface/gryphn_surface_create_functions.h"
|
||||||
#include "shader_module/gryphn_shader_module.h"
|
#include "shader_module/gryphn_shader_module.h"
|
||||||
#include "pipelines/graphics_pipeline/gryphn_graphics_pipeline.h"
|
#include "pipelines/graphics_pipeline/gryphn_graphics_pipeline.h"
|
||||||
|
#include "renderpass/gryphn_render_pass_descriptor.h"
|
||||||
|
|
||||||
typedef struct gnFunctions_t {
|
typedef struct gnFunctions_t {
|
||||||
gnReturnCode (*_gnCreateInstance)(gnInstance* instance, struct gnInstanceInfo_t info);
|
gnReturnCode (*_gnCreateInstance)(gnInstance* instance, struct gnInstanceInfo_t info);
|
||||||
@@ -56,6 +57,9 @@ typedef struct gnDeviceFunctions_t {
|
|||||||
gnReturnCode (*_gnCreateShaderModule)(struct gnShaderModule_t* module, struct gnOutputDevice_t* device, struct gnShaderModuleInfo_t shaderModuleInfo);
|
gnReturnCode (*_gnCreateShaderModule)(struct gnShaderModule_t* module, struct gnOutputDevice_t* device, struct gnShaderModuleInfo_t shaderModuleInfo);
|
||||||
void (*_gnDestroyShaderModule)(struct gnShaderModule_t* module);
|
void (*_gnDestroyShaderModule)(struct gnShaderModule_t* module);
|
||||||
|
|
||||||
|
gnReturnCode (*_gnCreateRenderPassDescriptor)(struct gnRenderPassDescriptor_t* renderPass, struct gnOutputDevice_t* device, struct gnRenderPassDescriptorInfo_t info);
|
||||||
|
void (*_gnDestroyRenderPassDescriptor)(struct gnRenderPassDescriptor_t* renderPass);
|
||||||
|
|
||||||
gnReturnCode (*_gnCreateGraphicsPipeline)(struct gnGraphicsPipeline_t* pipeline, struct gnOutputDevice_t* device, struct gnGraphicsPipelineInfo_t pipelineInfo);
|
gnReturnCode (*_gnCreateGraphicsPipeline)(struct gnGraphicsPipeline_t* pipeline, struct gnOutputDevice_t* device, struct gnGraphicsPipelineInfo_t pipelineInfo);
|
||||||
void (*_gnDestroyGraphicsPipeline)(struct gnGraphicsPipeline_t* pipeline);
|
void (*_gnDestroyGraphicsPipeline)(struct gnGraphicsPipeline_t* pipeline);
|
||||||
} gnDeviceFunctions;
|
} gnDeviceFunctions;
|
||||||
|
@@ -73,6 +73,8 @@ void gnLoadDeviceFunctions(struct gnDynamicLibrary_t* lib, struct gnDeviceFuncti
|
|||||||
gnLoadDLLFunction(lib, functions->_gnDestroyPresentationQueue, "gnDestroyPresentationQueueFn");
|
gnLoadDLLFunction(lib, functions->_gnDestroyPresentationQueue, "gnDestroyPresentationQueueFn");
|
||||||
gnLoadDLLFunction(lib, functions->_gnCreateShaderModule, "gnCreateShaderModuleFn");
|
gnLoadDLLFunction(lib, functions->_gnCreateShaderModule, "gnCreateShaderModuleFn");
|
||||||
gnLoadDLLFunction(lib, functions->_gnDestroyShaderModule, "gnDestroyShaderModuleFn");
|
gnLoadDLLFunction(lib, functions->_gnDestroyShaderModule, "gnDestroyShaderModuleFn");
|
||||||
|
gnLoadDLLFunction(lib, functions->_gnCreateRenderPassDescriptor, "gnCreateRenderPassDescriptorFn");
|
||||||
|
gnLoadDLLFunction(lib, functions->_gnDestroyRenderPassDescriptor, "gnDestroyRenderPassDescriptorFn");
|
||||||
gnLoadDLLFunction(lib, functions->_gnCreateGraphicsPipeline, "gnCreateGraphicsPipelineFn");
|
gnLoadDLLFunction(lib, functions->_gnCreateGraphicsPipeline, "gnCreateGraphicsPipelineFn");
|
||||||
gnLoadDLLFunction(lib, functions->_gnDestroyGraphicsPipeline, "gnDestroyGraphicsPipelineFn");
|
gnLoadDLLFunction(lib, functions->_gnDestroyGraphicsPipeline, "gnDestroyGraphicsPipelineFn");
|
||||||
}
|
}
|
||||||
|
11
src/core/renderpass/gryphn_render_pass_descriptor.c
Normal file
11
src/core/renderpass/gryphn_render_pass_descriptor.c
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#include "gryphn_render_pass_descriptor.h"
|
||||||
|
#include "core/gryphn_platform_functions.h"
|
||||||
|
|
||||||
|
gnReturnCode gnCreateRenderPassDescriptor(struct gnRenderPassDescriptor_t* renderPass, struct gnOutputDevice_t* device, struct gnRenderPassDescriptorInfo_t info) {
|
||||||
|
renderPass->device = device;
|
||||||
|
return device->deviceFunctions->_gnCreateRenderPassDescriptor(renderPass, device, info);
|
||||||
|
}
|
||||||
|
|
||||||
|
void gnDestroyRenderPassDescriptor(struct gnRenderPassDescriptor_t* renderPass) {
|
||||||
|
renderPass->device->deviceFunctions->_gnDestroyRenderPassDescriptor(renderPass);
|
||||||
|
}
|
52
src/core/renderpass/gryphn_render_pass_descriptor.h
Normal file
52
src/core/renderpass/gryphn_render_pass_descriptor.h
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "utils/types/gryphn_image_format.h"
|
||||||
|
#include "stdint.h"
|
||||||
|
#include "core/output_device/gryphn_output_device.h"
|
||||||
|
|
||||||
|
typedef enum gnLoadOperation_e {
|
||||||
|
GN_LOAD_OPERATION_LOAD, GN_LOAD_OPERATION_CLEAR, GN_LOAD_OPERATION_DONT_CARE
|
||||||
|
} gnLoadOperation;
|
||||||
|
|
||||||
|
typedef enum gnStoreOperation_e {
|
||||||
|
GN_STORE_OPERATION_STORE, GN_STORE_OPERATION_DONT_CARE
|
||||||
|
} gnStoreOperation;
|
||||||
|
|
||||||
|
typedef struct gnRenderPassAttachmentInfo_t {
|
||||||
|
enum gnImageFormat_e format;
|
||||||
|
enum gnLoadOperation_e loadOperation;
|
||||||
|
enum gnStoreOperation_e storeOperation;
|
||||||
|
|
||||||
|
enum gnLoadOperation_e stencilLoadOperation;
|
||||||
|
enum gnStoreOperation_e stencilStoreOperation;
|
||||||
|
|
||||||
|
enum gnImageLayout_e initialLayout;
|
||||||
|
enum gnImageLayout_e finalLayout;
|
||||||
|
} gnRenderPassAttachmentInfo;
|
||||||
|
|
||||||
|
typedef struct gnSubpassAttachmentInfo_t {
|
||||||
|
uint32_t index;
|
||||||
|
enum gnImageLayout_e imageLayout;
|
||||||
|
} gnSubpassAttachmentInfo;
|
||||||
|
|
||||||
|
typedef struct gnSubpassInfo_t {
|
||||||
|
uint32_t colorAttachmentCount;
|
||||||
|
struct gnSubpassAttachmentInfo_t* colorAttachments;
|
||||||
|
} gnSubpassInfo;
|
||||||
|
|
||||||
|
typedef struct gnRenderPassDescriptorInfo_t {
|
||||||
|
uint32_t attachmentCount;
|
||||||
|
struct gnRenderPassAttachmentInfo_t* attachmentInfos;
|
||||||
|
|
||||||
|
uint32_t subpassCount;
|
||||||
|
struct gnSubpassInfo_t* subpassInfos;
|
||||||
|
} gnRenderPassDescriptorInfo;
|
||||||
|
|
||||||
|
struct gnPlatformRenderPassDescriptor_t;
|
||||||
|
|
||||||
|
typedef struct gnRenderPassDescriptor_t {
|
||||||
|
struct gnPlatformRenderPassDescriptor_t* renderPassDescriptor;
|
||||||
|
struct gnOutputDevice_t* device;
|
||||||
|
} gnRenderPassDescriptor;
|
||||||
|
|
||||||
|
gnReturnCode gnCreateRenderPassDescriptor(struct gnRenderPassDescriptor_t* renderPass, struct gnOutputDevice_t* device, struct gnRenderPassDescriptorInfo_t info);
|
||||||
|
void gnDestroyRenderPassDescriptor(struct gnRenderPassDescriptor_t* renderPass);
|
@@ -20,7 +20,8 @@ typedef enum gnReturnCode_t {
|
|||||||
GN_FAILED_TO_CREATE_SHADER_MODULE,
|
GN_FAILED_TO_CREATE_SHADER_MODULE,
|
||||||
GN_FAILED_TO_CONVERT_SHADER_CODE,
|
GN_FAILED_TO_CONVERT_SHADER_CODE,
|
||||||
GN_FAILED_TO_FIND_ENTRY_POINT,
|
GN_FAILED_TO_FIND_ENTRY_POINT,
|
||||||
GN_FAILED_TO_CREATE_UNIFORM_LAYOUT
|
GN_FAILED_TO_CREATE_UNIFORM_LAYOUT,
|
||||||
|
GN_FAILED_TO_CREATE_RENDER_PASS
|
||||||
|
|
||||||
// GN_UNKNOWN_FRAMEBUFFER_ATTACHMENT,
|
// GN_UNKNOWN_FRAMEBUFFER_ATTACHMENT,
|
||||||
// GN_UNKNOWN_FUNCTION,
|
// GN_UNKNOWN_FUNCTION,
|
||||||
@@ -54,5 +55,6 @@ static const char* gnErrorCodeToCString(enum gnReturnCode_t returnCode) {
|
|||||||
case GN_FAILED_TO_CONVERT_SHADER_CODE: return "GN_FAILED_TO_CONVERT_SHADER_CODE";
|
case GN_FAILED_TO_CONVERT_SHADER_CODE: return "GN_FAILED_TO_CONVERT_SHADER_CODE";
|
||||||
case GN_FAILED_TO_FIND_ENTRY_POINT: return "GN_FAILED_TO_FIND_ENTRY_POINT";
|
case GN_FAILED_TO_FIND_ENTRY_POINT: return "GN_FAILED_TO_FIND_ENTRY_POINT";
|
||||||
case GN_FAILED_TO_CREATE_UNIFORM_LAYOUT: return "GN_FAILED_TO_CREATE_UNIFORM_LAYOUT";
|
case GN_FAILED_TO_CREATE_UNIFORM_LAYOUT: return "GN_FAILED_TO_CREATE_UNIFORM_LAYOUT";
|
||||||
|
case GN_FAILED_TO_CREATE_RENDER_PASS: return "GN_FAILED_TO_CREATE_RENDER_PASS";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -12,3 +12,7 @@ typedef enum gnColorSpace_e {
|
|||||||
typedef enum gnImageSharingMode_e {
|
typedef enum gnImageSharingMode_e {
|
||||||
GN_SHARING_MODE_EXCLUSIVE, GN_SHARING_MODE_CONCURRENT
|
GN_SHARING_MODE_EXCLUSIVE, GN_SHARING_MODE_CONCURRENT
|
||||||
} gnImageSharingMode;
|
} gnImageSharingMode;
|
||||||
|
|
||||||
|
typedef enum gnImageLayout_e {
|
||||||
|
GN_LAYOUT_UNDEFINED, GN_LAYOUT_PRESENTATION_QUEUE_IMAGE, GN_LAYOUT_TRANSFER_DESTINATION, GN_COLOR_ATTACHMENT
|
||||||
|
} gnImageLayout;
|
||||||
|
Reference in New Issue
Block a user