finish cross compiliation to GLSL
This commit is contained in:
@@ -4,8 +4,8 @@
|
||||
#include "utils/gryphn_cpp_function.h"
|
||||
#include <core/src/uniforms/gryphn_uniform_layout.h>
|
||||
|
||||
#define MAX_METAL_SETS 32
|
||||
#define MAX_METAL_BINDINGS 16
|
||||
#define MAX_METAL_SETS 16
|
||||
#define MAX_METAL_BINDINGS 32
|
||||
|
||||
typedef struct mtlCompiler_t* mtlCompiler;
|
||||
|
||||
|
@@ -5,15 +5,45 @@ typedef struct glCompiler_t {
|
||||
spirv_cross::CompilerGLSL* glsl;
|
||||
} glInternalCompiler;
|
||||
|
||||
void handle_resources(spirv_cross::CompilerGLSL& compiler, spirv_cross::SmallVector<spirv_cross::Resource>& resources, int* currentBinding, glSet* setMap) {
|
||||
for (size_t i = 0; i < resources.size(); i++) {
|
||||
uint32_t
|
||||
set = compiler.get_decoration(resources[i].id, spv::DecorationDescriptorSet),
|
||||
binding = compiler.get_decoration(resources[i].id, spv::DecorationBinding);
|
||||
setMap[set].bindings[binding] = *currentBinding;
|
||||
|
||||
compiler.unset_decoration(resources[i].id, spv::DecorationBinding);
|
||||
compiler.set_decoration(resources[i].id, spv::DecorationBinding, *currentBinding);
|
||||
*currentBinding = (*currentBinding) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
GN_CPP_FUNCTION glCompiler glCreateCompiler(glCompilerInfo* info) {
|
||||
glInternalCompiler* compiler = (glInternalCompiler*)malloc(sizeof(glInternalCompiler));
|
||||
compiler->glsl = new spirv_cross::CompilerGLSL(info->code, info->wordCount);
|
||||
// spirv_cross::CompilerGLSL::Options options = compiler->glsl->get_common_options();
|
||||
// compiler->glsl->set_common_options(options);
|
||||
return compiler;
|
||||
}
|
||||
GN_CPP_FUNCTION const char* glCompilerCompilerShader(glCompiler compiler) {
|
||||
GN_CPP_FUNCTION glShader glCompilerCompilerShader(glCompiler compiler) {
|
||||
int current_binding = 0;
|
||||
|
||||
glShader shader = {};
|
||||
auto arg_buffers = compiler->glsl->get_shader_resources();
|
||||
handle_resources(*compiler->glsl, arg_buffers.uniform_buffers, ¤t_binding, shader.sets);
|
||||
handle_resources(*compiler->glsl, arg_buffers.storage_buffers, ¤t_binding, shader.sets);
|
||||
handle_resources(*compiler->glsl, arg_buffers.sampled_images, ¤t_binding, shader.sets);
|
||||
|
||||
shader.sets[0].bindings[3] = 69;
|
||||
|
||||
std::string output = compiler->glsl->compile();
|
||||
char* copied_output = (char*)malloc(sizeof(char*) * (output.size() + 1));
|
||||
strcpy(copied_output, output.c_str());
|
||||
copied_output[output.size()] = '\0';
|
||||
return copied_output;
|
||||
shader.source = (char*)malloc(sizeof(char*) * (output.size() + 1));
|
||||
strcpy(shader.source, output.c_str());
|
||||
shader.source[output.size()] = '\0';
|
||||
return shader;
|
||||
}
|
||||
|
||||
GN_CPP_FUNCTION void glDestroyCompiler(glCompiler compiler) {
|
||||
delete compiler->glsl;
|
||||
free(compiler);
|
||||
}
|
||||
|
@@ -3,8 +3,8 @@
|
||||
#include "glad/glad.h"
|
||||
#include "utils/gryphn_cpp_function.h"
|
||||
|
||||
#define MAX_OPENGL_SETS 32
|
||||
#define MAX_OPENGL_BINDINGS 16
|
||||
#define MAX_OPENGL_SETS 16
|
||||
#define MAX_OPENGL_BINDINGS 32
|
||||
|
||||
typedef enum glShaderModuleStage {
|
||||
glVertex = GL_VERTEX_SHADER,
|
||||
@@ -22,10 +22,11 @@ typedef struct glCompilerInfo {
|
||||
typedef struct glSet { uint32_t bindings[MAX_OPENGL_BINDINGS]; } glSet;
|
||||
|
||||
typedef struct glShader {
|
||||
const char* source;
|
||||
char* source;
|
||||
glSet sets[MAX_OPENGL_SETS];
|
||||
} glShader;
|
||||
|
||||
typedef struct glCompiler_t* glCompiler;
|
||||
GN_CPP_FUNCTION glCompiler glCreateCompiler(glCompilerInfo* info);
|
||||
GN_CPP_FUNCTION const char* glCompilerCompilerShader(glCompiler compiler);
|
||||
GN_CPP_FUNCTION glShader glCompilerCompilerShader(glCompiler compiler);
|
||||
GN_CPP_FUNCTION void glDestroyCompiler(glCompiler compiler);
|
||||
|
@@ -9,7 +9,9 @@ gnReturnCode openglCreateShaderModule(gnShaderModule module, gnDevice device, gn
|
||||
.wordCount = shaderModuleInfo.size / 4,
|
||||
.entryPoint = gnToCString(shaderModuleInfo.entryPoint),
|
||||
};
|
||||
module->shaderModule->compiler = glCreateCompiler(&info);
|
||||
glCompiler compiler = glCreateCompiler(&info);
|
||||
module->shaderModule->shader = glCompilerCompilerShader(compiler);
|
||||
glDestroyCompiler(compiler);
|
||||
return GN_SUCCESS;
|
||||
}
|
||||
void openglDestroyShaderModule(gnShaderModule module) {
|
||||
|
@@ -3,7 +3,7 @@
|
||||
#include "opengl_shader_compiler.h"
|
||||
|
||||
typedef struct gnPlatformShaderModule_t {
|
||||
glCompiler compiler;
|
||||
glShader shader;
|
||||
} gnPlatformShaderModule;
|
||||
|
||||
gnReturnCode openglCreateShaderModule(gnShaderModule module, gnDevice device, gnShaderModuleInfo shaderModuleInfo);
|
||||
|
Reference in New Issue
Block a user