X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fprogram%2Fsampler.cpp;h=f118552d64ef922a47ce01ccd85cf4fd76d23b21;hb=eb63640c1d38a200a7b1540405051d3ff79d0d8a;hp=9a813c87955e0fb613342808eb014ee799367238;hpb=195bbe8ce218533569dde1368d04da0fd229913d;p=mesa.git diff --git a/src/mesa/program/sampler.cpp b/src/mesa/program/sampler.cpp index 9a813c87955..f118552d64e 100644 --- a/src/mesa/program/sampler.cpp +++ b/src/mesa/program/sampler.cpp @@ -23,28 +23,16 @@ * DEALINGS IN THE SOFTWARE. */ -#include -#include "ir.h" -#include "glsl_types.h" -#include "ir_visitor.h" - -extern "C" { -#include "main/compiler.h" #include "main/mtypes.h" +#include "compiler/glsl_types.h" +#include "compiler/glsl/ir.h" +#include "compiler/glsl/ir_uniform.h" +#include "compiler/glsl/ir_visitor.h" +#include "compiler/glsl/program.h" +#include "program/hash_table.h" #include "program/prog_parameter.h" -} - -static void fail_link(struct gl_shader_program *prog, const char *fmt, ...) PRINTFLIKE(2, 3); - -static void fail_link(struct gl_shader_program *prog, const char *fmt, ...) -{ - va_list args; - va_start(args, fmt); - prog->InfoLog = talloc_vasprintf_append(prog->InfoLog, fmt, args); - va_end(args); +#include "program/program.h" - prog->LinkStatus = GL_FALSE; -} class get_sampler_name : public ir_hierarchical_visitor { @@ -52,7 +40,7 @@ public: get_sampler_name(ir_dereference *last, struct gl_shader_program *shader_program) { - this->mem_ctx = talloc_new(NULL); + this->mem_ctx = ralloc_context(NULL); this->shader_program = shader_program; this->name = NULL; this->offset = 0; @@ -61,7 +49,7 @@ public: ~get_sampler_name() { - talloc_free(this->mem_ctx); + ralloc_free(this->mem_ctx); } virtual ir_visitor_status visit(ir_dereference_variable *ir) @@ -72,7 +60,7 @@ public: virtual ir_visitor_status visit_leave(ir_dereference_record *ir) { - this->name = talloc_asprintf(mem_ctx, "%s.%s", name, ir->field); + this->name = ralloc_asprintf(mem_ctx, "%s.%s", name, ir->field); return visit_continue; } @@ -91,16 +79,14 @@ public: * all that would work would be an unrolled loop counter that ends * up being constant above. */ - shader_program->InfoLog = - talloc_asprintf_append(shader_program->InfoLog, - "warning: Variable sampler array index " - "unsupported.\nThis feature of the language " - "was removed in GLSL 1.20 and is unlikely " - "to be supported for 1.10 in Mesa.\n"); + ralloc_strcat(&shader_program->InfoLog, + "warning: Variable sampler array index unsupported.\n" + "This feature of the language was removed in GLSL 1.20 " + "and is unlikely to be supported for 1.10 in Mesa.\n"); i = 0; } if (ir != last) { - this->name = talloc_asprintf(mem_ctx, "%s[%d]", name, i); + this->name = ralloc_asprintf(mem_ctx, "%s[%d]", name, i); } else { offset = i; } @@ -114,7 +100,7 @@ public: ir_dereference *last; }; -extern "C" { + int _mesa_get_sampler_uniform_value(class ir_dereference *sampler, struct gl_shader_program *shader_program, @@ -122,19 +108,37 @@ _mesa_get_sampler_uniform_value(class ir_dereference *sampler, { get_sampler_name getname(sampler, shader_program); - sampler->accept(&getname); + GLuint shader = _mesa_program_enum_to_shader_stage(prog->Target); - GLint index = _mesa_lookup_parameter_index(prog->Parameters, -1, - getname.name); + sampler->accept(&getname); - if (index < 0) { - fail_link(shader_program, - "failed to find sampler named %s.\n", getname.name); + unsigned location; + if (!shader_program->UniformHash->get(location, getname.name)) { + linker_error(shader_program, + "failed to find sampler named %s.\n", getname.name); return 0; } - index += getname.offset; + if (!shader_program->UniformStorage[location].opaque[shader].active) { + assert(0 && "cannot return a sampler"); + linker_error(shader_program, + "cannot return a sampler named %s, because it is not " + "used in this shader stage. This is a driver bug.\n", + getname.name); + return 0; + } - return prog->Parameters->ParameterValues[index][0]; + return shader_program->UniformStorage[location].opaque[shader].index + + getname.offset; } + + +class ir_rvalue * +_mesa_get_sampler_array_nonconst_index(class ir_dereference *sampler) +{ + ir_dereference_array *deref_arr = sampler->as_dereference_array(); + if (!deref_arr || deref_arr->array_index->as_constant()) + return NULL; + + return deref_arr->array_index; }