redo shader mapping
This commit is contained in:
@@ -6,9 +6,31 @@
|
|||||||
|
|
||||||
gnReturnCode openglCreateGraphicsPipeline(gnGraphicsPipeline graphicsPipeline, gnOutputDevice device, gnGraphicsPipelineInfo info) {
|
gnReturnCode openglCreateGraphicsPipeline(gnGraphicsPipeline graphicsPipeline, gnOutputDevice device, gnGraphicsPipelineInfo info) {
|
||||||
graphicsPipeline->graphicsPipeline = malloc(sizeof(gnPlatformGraphicsPipeline));
|
graphicsPipeline->graphicsPipeline = malloc(sizeof(gnPlatformGraphicsPipeline));
|
||||||
|
|
||||||
|
GLuint* ids = malloc(sizeof(GLuint) * info.shaderModuleCount);
|
||||||
|
for (int i = 0; i < info.shaderModuleCount; i++) {
|
||||||
|
glShader shader = glCompilerCompilerShader(info.shaderModules[i]->shaderModule->compiler, &info.uniformLayout);
|
||||||
|
|
||||||
|
ids[i] = glCreateShader(gnShaderTypeToGLEnum(info.shaderModules[i]->info.stage));
|
||||||
|
const char* source = shader.source;
|
||||||
|
printf("Shader Source %s\n", source);
|
||||||
|
glShaderSource(ids[i], 1, &source, NULL);
|
||||||
|
glCompileShader(ids[i]);
|
||||||
|
|
||||||
|
GLint returnCode;
|
||||||
|
glGetShaderiv(ids[i], GL_COMPILE_STATUS, &returnCode);
|
||||||
|
if(!returnCode) {
|
||||||
|
char infoLog[512];
|
||||||
|
glGetShaderInfoLog(ids[i], 512, NULL, infoLog);
|
||||||
|
gnDebuggerSetErrorMessage(device->instance->debugger, (gnMessageData){
|
||||||
|
.message = gnCreateString(infoLog)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
graphicsPipeline->graphicsPipeline->program = glCreateProgram();
|
graphicsPipeline->graphicsPipeline->program = glCreateProgram();
|
||||||
for (int i = 0; i < info.shaderModuleCount; i++)
|
for (int i = 0; i < info.shaderModuleCount; i++)
|
||||||
glAttachShader(graphicsPipeline->graphicsPipeline->program, info.shaderModules[i]->shaderModule->id);
|
glAttachShader(graphicsPipeline->graphicsPipeline->program, ids[i]);
|
||||||
glLinkProgram(graphicsPipeline->graphicsPipeline->program);
|
glLinkProgram(graphicsPipeline->graphicsPipeline->program);
|
||||||
GLint linked;
|
GLint linked;
|
||||||
glGetProgramiv(graphicsPipeline->graphicsPipeline->program, GL_LINK_STATUS, &linked);
|
glGetProgramiv(graphicsPipeline->graphicsPipeline->program, GL_LINK_STATUS, &linked);
|
||||||
@@ -24,6 +46,9 @@ gnReturnCode openglCreateGraphicsPipeline(gnGraphicsPipeline graphicsPipeline, g
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < info.shaderModuleCount; i++)
|
||||||
|
glDeleteShader(ids[i]);
|
||||||
|
|
||||||
glCreateVertexArrays(1, &graphicsPipeline->graphicsPipeline->vertexArrayObject);
|
glCreateVertexArrays(1, &graphicsPipeline->graphicsPipeline->vertexArrayObject);
|
||||||
|
|
||||||
glVertexArrayAttribFormat(graphicsPipeline->graphicsPipeline->vertexArrayObject, 0, 3, GL_FLOAT, GL_FALSE, 0);
|
glVertexArrayAttribFormat(graphicsPipeline->graphicsPipeline->vertexArrayObject, 0, 3, GL_FLOAT, GL_FALSE, 0);
|
||||||
|
@@ -5,16 +5,15 @@ typedef struct glCompiler_t {
|
|||||||
spirv_cross::CompilerGLSL* glsl;
|
spirv_cross::CompilerGLSL* glsl;
|
||||||
} glInternalCompiler;
|
} glInternalCompiler;
|
||||||
|
|
||||||
void handle_resources(spirv_cross::CompilerGLSL& compiler, spirv_cross::SmallVector<spirv_cross::Resource>& resources, int* currentBinding, glSet* setMap) {
|
|
||||||
|
|
||||||
|
void handle_resources(spirv_cross::CompilerGLSL& compiler, spirv_cross::SmallVector<spirv_cross::Resource>& resources, glSet* setMap) {
|
||||||
for (size_t i = 0; i < resources.size(); i++) {
|
for (size_t i = 0; i < resources.size(); i++) {
|
||||||
uint32_t
|
uint32_t
|
||||||
set = compiler.get_decoration(resources[i].id, spv::DecorationDescriptorSet),
|
set = compiler.get_decoration(resources[i].id, spv::DecorationDescriptorSet),
|
||||||
binding = compiler.get_decoration(resources[i].id, spv::DecorationBinding);
|
binding = compiler.get_decoration(resources[i].id, spv::DecorationBinding);
|
||||||
setMap[set].bindings[binding] = *currentBinding;
|
|
||||||
|
|
||||||
compiler.unset_decoration(resources[i].id, spv::DecorationBinding);
|
compiler.unset_decoration(resources[i].id, spv::DecorationBinding);
|
||||||
compiler.set_decoration(resources[i].id, spv::DecorationBinding, *currentBinding);
|
compiler.set_decoration(resources[i].id, spv::DecorationBinding, setMap[set].bindings[binding]);
|
||||||
*currentBinding = (*currentBinding) + 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,16 +24,21 @@ GN_CPP_FUNCTION glCompiler glCreateCompiler(glCompilerInfo* info) {
|
|||||||
// compiler->glsl->set_common_options(options);
|
// compiler->glsl->set_common_options(options);
|
||||||
return compiler;
|
return compiler;
|
||||||
}
|
}
|
||||||
GN_CPP_FUNCTION glShader glCompilerCompilerShader(glCompiler compiler) {
|
GN_CPP_FUNCTION glShader glCompilerCompilerShader(glCompiler compiler, gnUniformLayout* layout) {
|
||||||
int current_binding = 0;
|
|
||||||
|
|
||||||
glShader shader = {};
|
glShader shader = {};
|
||||||
auto arg_buffers = compiler->glsl->get_shader_resources();
|
uint32_t currentBinding = 0;
|
||||||
handle_resources(*compiler->glsl, arg_buffers.uniform_buffers, ¤t_binding, shader.sets);
|
for (uint32_t i = 0; i < layout->setCount; i++) {
|
||||||
handle_resources(*compiler->glsl, arg_buffers.storage_buffers, ¤t_binding, shader.sets);
|
for (size_t c = 0; c < layout->sets[i].uniformBindingCount; c++) {
|
||||||
handle_resources(*compiler->glsl, arg_buffers.sampled_images, ¤t_binding, shader.sets);
|
gnUniformBinding gryphnBinding = layout->sets[i].uniformBindings[c];
|
||||||
|
shader.sets[i].bindings[c] = currentBinding;
|
||||||
|
currentBinding++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
shader.sets[0].bindings[3] = 69;
|
auto arg_buffers = compiler->glsl->get_shader_resources();
|
||||||
|
handle_resources(*compiler->glsl, arg_buffers.uniform_buffers, shader.sets);
|
||||||
|
handle_resources(*compiler->glsl, arg_buffers.storage_buffers, shader.sets);
|
||||||
|
handle_resources(*compiler->glsl, arg_buffers.sampled_images, shader.sets);
|
||||||
|
|
||||||
std::string output = compiler->glsl->compile();
|
std::string output = compiler->glsl->compile();
|
||||||
shader.source = (char*)malloc(sizeof(char*) * (output.size() + 1));
|
shader.source = (char*)malloc(sizeof(char*) * (output.size() + 1));
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
#include "stdint.h"
|
#include "stdint.h"
|
||||||
#include "glad/glad.h"
|
#include "glad/glad.h"
|
||||||
#include "utils/gryphn_cpp_function.h"
|
#include "utils/gryphn_cpp_function.h"
|
||||||
|
#include "core/src/uniforms/gryphn_uniform_layout.h"
|
||||||
|
|
||||||
#define MAX_OPENGL_SETS 16
|
#define MAX_OPENGL_SETS 16
|
||||||
#define MAX_OPENGL_BINDINGS 32
|
#define MAX_OPENGL_BINDINGS 32
|
||||||
@@ -28,5 +29,5 @@ typedef struct glShader {
|
|||||||
|
|
||||||
typedef struct glCompiler_t* glCompiler;
|
typedef struct glCompiler_t* glCompiler;
|
||||||
GN_CPP_FUNCTION glCompiler glCreateCompiler(glCompilerInfo* info);
|
GN_CPP_FUNCTION glCompiler glCreateCompiler(glCompilerInfo* info);
|
||||||
GN_CPP_FUNCTION glShader glCompilerCompilerShader(glCompiler compiler);
|
GN_CPP_FUNCTION glShader glCompilerCompilerShader(glCompiler compiler, gnUniformLayout* layout);
|
||||||
GN_CPP_FUNCTION void glDestroyCompiler(glCompiler compiler);
|
GN_CPP_FUNCTION void glDestroyCompiler(glCompiler compiler);
|
||||||
|
@@ -1,11 +1,7 @@
|
|||||||
#include "opengl_shader_module.h"
|
#include "opengl_shader_module.h"
|
||||||
#include "opengl_shader_compiler.h"
|
#include "opengl_shader_compiler.h"
|
||||||
#include "output_device/gryphn_output_device.h"
|
|
||||||
#include "instance/gryphn_instance.h"
|
|
||||||
#include "stdlib.h"
|
#include "stdlib.h"
|
||||||
|
|
||||||
#include "stdio.h"
|
|
||||||
|
|
||||||
GLenum gnShaderTypeToGLEnum(gnShaderModuleStage stage) {
|
GLenum gnShaderTypeToGLEnum(gnShaderModuleStage stage) {
|
||||||
switch (stage) {
|
switch (stage) {
|
||||||
case GN_VERTEX_SHADER_MODULE: return GL_VERTEX_SHADER;
|
case GN_VERTEX_SHADER_MODULE: return GL_VERTEX_SHADER;
|
||||||
@@ -21,29 +17,10 @@ gnReturnCode openglCreateShaderModule(gnShaderModule module, gnDevice device, gn
|
|||||||
.wordCount = shaderModuleInfo.size / 4,
|
.wordCount = shaderModuleInfo.size / 4,
|
||||||
.entryPoint = gnToCString(shaderModuleInfo.entryPoint),
|
.entryPoint = gnToCString(shaderModuleInfo.entryPoint),
|
||||||
};
|
};
|
||||||
glCompiler compiler = glCreateCompiler(&info);
|
module->shaderModule->compiler = glCreateCompiler(&info);
|
||||||
module->shaderModule->shader = glCompilerCompilerShader(compiler);
|
|
||||||
glDestroyCompiler(compiler);
|
|
||||||
|
|
||||||
module->shaderModule->id = glCreateShader(gnShaderTypeToGLEnum(shaderModuleInfo.stage));
|
|
||||||
const char* source = module->shaderModule->shader.source;
|
|
||||||
printf("Shader Source %s\n", source);
|
|
||||||
glShaderSource(module->shaderModule->id, 1, &source, NULL);
|
|
||||||
glCompileShader(module->shaderModule->id);
|
|
||||||
|
|
||||||
GLint returnCode;
|
|
||||||
glGetShaderiv(module->shaderModule->id, GL_COMPILE_STATUS, &returnCode);
|
|
||||||
if(!returnCode) {
|
|
||||||
char infoLog[512];
|
|
||||||
glGetShaderInfoLog(module->shaderModule->id, 512, NULL, infoLog);
|
|
||||||
gnDebuggerSetErrorMessage(device->instance->debugger, (gnMessageData){
|
|
||||||
.message = gnCreateString(infoLog)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return GN_SUCCESS;
|
return GN_SUCCESS;
|
||||||
}
|
}
|
||||||
void openglDestroyShaderModule(gnShaderModule module) {
|
void openglDestroyShaderModule(gnShaderModule module) {
|
||||||
glDeleteShader(module->shaderModule->id);
|
glDestroyCompiler(module->shaderModule->compiler);
|
||||||
free(module->shaderModule);
|
free(module->shaderModule);
|
||||||
}
|
}
|
||||||
|
@@ -3,9 +3,10 @@
|
|||||||
#include "opengl_shader_compiler.h"
|
#include "opengl_shader_compiler.h"
|
||||||
|
|
||||||
typedef struct gnPlatformShaderModule_t {
|
typedef struct gnPlatformShaderModule_t {
|
||||||
glShader shader;
|
glCompiler compiler;
|
||||||
GLuint id;
|
|
||||||
} gnPlatformShaderModule;
|
} gnPlatformShaderModule;
|
||||||
|
|
||||||
|
GLenum gnShaderTypeToGLEnum(gnShaderModuleStage stage);
|
||||||
|
|
||||||
gnReturnCode openglCreateShaderModule(gnShaderModule module, gnDevice device, gnShaderModuleInfo shaderModuleInfo);
|
gnReturnCode openglCreateShaderModule(gnShaderModule module, gnDevice device, gnShaderModuleInfo shaderModuleInfo);
|
||||||
void openglDestroyShaderModule(gnShaderModule module);
|
void openglDestroyShaderModule(gnShaderModule module);
|
||||||
|
Reference in New Issue
Block a user