first commit
This commit is contained in:
35
rendering_api/vulkan/src/shaders/vulkan_shader.cpp
Normal file
35
rendering_api/vulkan/src/shaders/vulkan_shader.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <vulkan/vulkan.h>
|
||||
#include "core/shaders/gryphn_shader.h"
|
||||
#include "vulkan_shader_module.h"
|
||||
|
||||
VkShaderStageFlagBits vulkanShaderModuleType(gnShaderModuleStage name) {
|
||||
if (name == GN_VERTEX_SHADER_MODULE) return VK_SHADER_STAGE_VERTEX_BIT;
|
||||
if (name == GN_FRAGMENT_SHADER_MODULE) return VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||
return VK_SHADER_STAGE_VERTEX_BIT; // assume that shits a vertex shader
|
||||
}
|
||||
|
||||
GN_EXPORT gnReturnCode gnBuildShaderFn(gnShader* shader) {
|
||||
for (int i = 0; i < gnListLength(shader->shaderModules); i++) {
|
||||
gnShaderModule* module = gnListGetPtr(shader->shaderModules, i);
|
||||
// std::cout << "Building ";
|
||||
// if (module->shaderType == GN_VERTEX_SHADER_MODULE) std::cout << "GN_VERTEX_SHADER_MODULE";
|
||||
// if (module->shaderType == GN_FRAGMENT_SHADER_MODULE) std::cout << "GN_FRAGMENT_SHADER_MODULE";
|
||||
// std::cout << " shader\n";
|
||||
|
||||
|
||||
module->shaderModule->stageCreateInfo = {};
|
||||
module->shaderModule->stageCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
||||
module->shaderModule->stageCreateInfo.stage = vulkanShaderModuleType(module->shaderType);
|
||||
module->shaderModule->stageCreateInfo.module = module->shaderModule->module;
|
||||
module->shaderModule->stageCreateInfo.pName = "main";
|
||||
}
|
||||
|
||||
return GN_SUCCESS;
|
||||
}
|
||||
|
||||
GN_EXPORT void gnShaderDestroyModulesFn(gnShader& shader) {
|
||||
for (int i = 0; i < gnListLength(shader.shaderModules); i++) {
|
||||
gnShaderModule* module = gnListGetPtr(shader.shaderModules, i);
|
||||
gnDestroyShaderModule(*module);
|
||||
}
|
||||
}
|
6
rendering_api/vulkan/src/shaders/vulkan_shader.h
Normal file
6
rendering_api/vulkan/src/shaders/vulkan_shader.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
#include "vulkan_shader_module.h"
|
||||
|
||||
struct gnPlatformShader {
|
||||
|
||||
};
|
34
rendering_api/vulkan/src/shaders/vulkan_shader_module.cpp
Normal file
34
rendering_api/vulkan/src/shaders/vulkan_shader_module.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include "core/shaders/gryphn_shader_module.h"
|
||||
#include <vulkan/vulkan.h>
|
||||
#include "vulkan_shader_module.h"
|
||||
#include "../output_device/vulkan_output_devices.h"
|
||||
|
||||
void vulkanShaderModule(gnShaderModule* shaderModule) {
|
||||
if (shaderModule->shaderModule == nullptr) shaderModule->shaderModule = new gnPlatformShaderModule();
|
||||
}
|
||||
|
||||
GN_EXPORT gnReturnCode gnBuildShaderModuleFn(gnShaderModule* module, const gnOutputDevice& outputDevice) {
|
||||
vulkanShaderModule(module);
|
||||
if (module->codeSize < 0 || module->shaderData == nullptr) {
|
||||
// TODO: add in error codes so that I can pick up on these errors and not just return that the creation failed
|
||||
return GN_FAILED;
|
||||
}
|
||||
|
||||
if (module->shaderUse == GN_GRAPHICS_PIPELINE) {
|
||||
VkShaderModuleCreateInfo createInfo{};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
|
||||
createInfo.codeSize = module->codeSize;
|
||||
createInfo.pCode = reinterpret_cast<const uint32_t*>(module->shaderData);
|
||||
|
||||
if (vkCreateShaderModule(outputDevice.outputDevice->device, &createInfo, nullptr, &module->shaderModule->module) != VK_SUCCESS) {
|
||||
return GN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
module->shaderModule->device = &outputDevice;
|
||||
return GN_SUCCESS;
|
||||
}
|
||||
|
||||
GN_EXPORT void gnDestroyShaderModuleFn(gnShaderModule& module) {
|
||||
vkDestroyShaderModule(const_cast<gnOutputDevice*>(module.shaderModule->device)->outputDevice->device, module.shaderModule->module, nullptr);
|
||||
}
|
10
rendering_api/vulkan/src/shaders/vulkan_shader_module.h
Normal file
10
rendering_api/vulkan/src/shaders/vulkan_shader_module.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <vulkan/vulkan.h>
|
||||
#include "core/output_device/gryphn_output_device.h"
|
||||
#include <vulkan/vulkan_core.h>
|
||||
|
||||
struct gnPlatformShaderModule {
|
||||
VkShaderModule module;
|
||||
VkShaderEXT shader;
|
||||
VkPipelineShaderStageCreateInfo stageCreateInfo;
|
||||
const gnOutputDevice* device;
|
||||
};
|
Reference in New Issue
Block a user