From 314a85dedfd55179d6635cb7f95f6a51505efc45 Mon Sep 17 00:00:00 2001 From: Maksim Belov Date: Sat, 5 Oct 2024 19:16:38 +0300 Subject: [PATCH] Feat[renderer]: add version detection and add more shader types --- .../src/code/ir_print_glsl_visitor.cpp | 57 +++++++++++++++---- .../glsl_optimizer/src/compiler/glsl/ir.h | 9 +++ 2 files changed, 55 insertions(+), 11 deletions(-) diff --git a/app/src/main/tinywrapper/glsl_optimizer/src/code/ir_print_glsl_visitor.cpp b/app/src/main/tinywrapper/glsl_optimizer/src/code/ir_print_glsl_visitor.cpp index 2ab21cc..481a49e 100644 --- a/app/src/main/tinywrapper/glsl_optimizer/src/code/ir_print_glsl_visitor.cpp +++ b/app/src/main/tinywrapper/glsl_optimizer/src/code/ir_print_glsl_visitor.cpp @@ -191,6 +191,19 @@ char * IR_TO_GLSL::Convert( if(print_precision) { res.append("precision %s float;\nprecision %s int;\n", "highp", "highp"); + res.append("precision %1$s sampler3D;\n" + "precision %1$s samplerCubeShadow;\n" + "precision %1$s sampler2DShadow;\n" + "precision %1$s sampler2DArray;\n" + "precision %1$s sampler2DArrayShadow;\n" + "precision %1$s isampler2D;\n" + "precision %1$s isampler3D;\n" + "precision %1$s isamplerCube;\n" + "precision %1$s isampler2DArray;\n" + "precision %1$s usampler2D;\n" + "precision %1$s usampler3D;\n" + "precision %1$s usamplerCube;\n" + "precision %1$s usampler2DArray;\n", "lowp"); } for (unsigned i = 0; i < state->num_user_structures; i++) @@ -406,13 +419,11 @@ IR_TO_GLSL::visit(ir_variable* ir) if(ir->type->is_void()) return; - // TODO restore uniform blocks - /* if ( ir->is_in_uniform_block()) // only supporting uniform blocks for now, might add SSBOs later { visit_uniform_block( ir ); return; - }*/ + } char binding[32] = { 0 }; if (ir->data.binding) snprintf(binding, sizeof(binding), "binding=%i ", ir->data.binding); @@ -1259,9 +1270,24 @@ IR_TO_GLSL::visit(ir_texture* ir) }else { ir->coordinate->accept(this); // accept as usual if the function aint wacky } - + GLenum type_enum = ir->sampler->type->gl_type; + bool buffer_texture_sampler; + switch(type_enum) { + case GL_SAMPLER_BUFFER: + case GL_INT_SAMPLER_BUFFER: + case GL_UNSIGNED_INT_SAMPLER_BUFFER: + case GL_IMAGE_BUFFER: + case GL_INT_IMAGE_BUFFER: + case GL_UNSIGNED_INT_IMAGE_BUFFER: + buffer_texture_sampler = true; + break; + default: + buffer_texture_sampler = false; + } // lod - if ((ir->op == ir_txl || ir->op == ir_txf) && state->language_version >= 130) + // Don't print LOD if fetching texel from buffer texture + bool is_txf_from_buffer_texture = ir->op == ir_txf && buffer_texture_sampler; + if ((ir->op == ir_txl || ir->op == ir_txf) && state->language_version >= 130 && !is_txf_from_buffer_texture) { generated_source.append(", "); ir->lod_info.lod->accept(this); @@ -2139,12 +2165,21 @@ void IR_TO_GLSL::visit_uniform_block(ir_variable *ir) { default: packing = nullptr; break; } - // TODO: handle explicit locations and bindings within layout expression for uniform blocks. - // that does not appear to be getting preserved. - if ( packing ) - { - generated_source.append( "layout(%s) ", packing ); - } + bool explicit_location = ir->data.explicit_location; + bool output_layout_qualifier = packing || explicit_location; + if(output_layout_qualifier) { + generated_source.append("layout("); + char insert_comma[] = {0, 0}; + if(packing) { + generated_source.append("%s%s", insert_comma, packing); + insert_comma[0] = ','; + } + if(explicit_location) { + generated_source.append("%slocation=%i", insert_comma, ir->data.location); + insert_comma[0] = ','; + } + generated_source.append(")"); + } generated_source.append( "uniform %s {\n", itype->name ); for ( unsigned int i = 0; i < itype->length; i++ ) diff --git a/app/src/main/tinywrapper/glsl_optimizer/src/compiler/glsl/ir.h b/app/src/main/tinywrapper/glsl_optimizer/src/compiler/glsl/ir.h index b800f99..147e493 100644 --- a/app/src/main/tinywrapper/glsl_optimizer/src/compiler/glsl/ir.h +++ b/app/src/main/tinywrapper/glsl_optimizer/src/compiler/glsl/ir.h @@ -447,6 +447,15 @@ public: this->interface_type != NULL; } + /** + * Determine whether or not a variable is part of an uniform block. + */ + inline bool is_in_uniform_block() const + { + return this->data.mode == ir_var_uniform && + this->interface_type != NULL; + } + /** * Determine whether or not a variable is the declaration of an interface * block