nir: remove dependency on glsl
[mesa.git] / src / mesa / program / sampler.cpp
index 9b9412730921845b966ef93927234c5fc7bb7843..84e2504baba170824e52988065b794effd24e2de 100644 (file)
  * DEALINGS IN THE SOFTWARE.
  */
 
-#include "ir.h"
-#include "glsl_types.h"
-#include "ir_visitor.h"
-#include "../glsl/program.h"
-#include "program/hash_table.h"
-#include "ir_uniform.h"
-
-extern "C" {
-#include "main/compiler.h"
 #include "main/mtypes.h"
+#include "glsl/nir/glsl_types.h"
+#include "glsl/ir.h"
+#include "glsl/ir_uniform.h"
+#include "glsl/ir_visitor.h"
+#include "glsl/program.h"
+#include "program/hash_table.h"
 #include "program/prog_parameter.h"
 #include "program/program.h"
-}
+
 
 class get_sampler_name : public ir_hierarchical_visitor
 {
@@ -104,14 +101,14 @@ public:
 };
 
 
-extern "C" int
+int
 _mesa_get_sampler_uniform_value(class ir_dereference *sampler,
                                struct gl_shader_program *shader_program,
                                const struct gl_program *prog)
 {
    get_sampler_name getname(sampler, shader_program);
 
-   GLuint shader = _mesa_program_target_to_index(prog->Target);
+   GLuint shader = _mesa_program_enum_to_shader_stage(prog->Target);
 
    sampler->accept(&getname);
 
@@ -122,7 +119,7 @@ _mesa_get_sampler_uniform_value(class ir_dereference *sampler,
       return 0;
    }
 
-   if (!shader_program->UniformStorage[location].sampler[shader].active) {
+   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 "
@@ -131,6 +128,17 @@ _mesa_get_sampler_uniform_value(class ir_dereference *sampler,
       return 0;
    }
 
-   return shader_program->UniformStorage[location].sampler[shader].index +
+   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;
+}