Feat[renderer]: add version detection and add more shader types

This commit is contained in:
Maksim Belov 2024-10-05 19:16:38 +03:00
parent 4286785b9c
commit 314a85dedf
2 changed files with 55 additions and 11 deletions

View File

@ -191,6 +191,19 @@ char * IR_TO_GLSL::Convert(
if(print_precision) { if(print_precision) {
res.append("precision %s float;\nprecision %s int;\n", "highp", "highp"); 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++) 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()) if(ir->type->is_void())
return; return;
// TODO restore uniform blocks
/*
if ( ir->is_in_uniform_block()) // only supporting uniform blocks for now, might add SSBOs later if ( ir->is_in_uniform_block()) // only supporting uniform blocks for now, might add SSBOs later
{ {
visit_uniform_block( ir ); visit_uniform_block( ir );
return; return;
}*/ }
char binding[32] = { 0 }; char binding[32] = { 0 };
if (ir->data.binding) if (ir->data.binding)
snprintf(binding, sizeof(binding), "binding=%i ", ir->data.binding); snprintf(binding, sizeof(binding), "binding=%i ", ir->data.binding);
@ -1259,9 +1270,24 @@ IR_TO_GLSL::visit(ir_texture* ir)
}else { }else {
ir->coordinate->accept(this); // accept as usual if the function aint wacky 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 // 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(", "); generated_source.append(", ");
ir->lod_info.lod->accept(this); ir->lod_info.lod->accept(this);
@ -2139,12 +2165,21 @@ void IR_TO_GLSL::visit_uniform_block(ir_variable *ir) {
default: packing = nullptr; break; default: packing = nullptr; break;
} }
// TODO: handle explicit locations and bindings within layout expression for uniform blocks. bool explicit_location = ir->data.explicit_location;
// that does not appear to be getting preserved. bool output_layout_qualifier = packing || explicit_location;
if ( packing ) if(output_layout_qualifier) {
{ generated_source.append("layout(");
generated_source.append( "layout(%s) ", packing ); 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 ); generated_source.append( "uniform %s {\n", itype->name );
for ( unsigned int i = 0; i < itype->length; i++ ) for ( unsigned int i = 0; i < itype->length; i++ )

View File

@ -447,6 +447,15 @@ public:
this->interface_type != NULL; 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 * Determine whether or not a variable is the declaration of an interface
* block * block