glsl/nir: int constants as float for native_integers=false
authorJonathan Marek <jonathan@marek.ca>
Mon, 12 Nov 2018 18:08:50 +0000 (13:08 -0500)
committerJason Ekstrand <jason@jlekstrand.net>
Fri, 11 Jan 2019 19:16:11 +0000 (19:16 +0000)
All alu instructions emitted with native_integers=false expect float
(or bool in some cases) constants, so this change is necessary.

This will cause changes with some intrinsics which had integer sources,
such as nir_intrinsic_load_uniform. Apparently it might cause issues with
some opt passes, but perhaps those don't apply in OpenGL ES 2.0 cases?

Signed-off-by: Jonathan Marek <jonathan@marek.ca>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/compiler/glsl/glsl_to_nir.cpp

index fac9a6a0f5072f629f794925b3fd3269564b340f..8a19399d8907f8036365f19486381782a87e90db 100644 (file)
@@ -94,6 +94,8 @@ private:
 
    nir_deref_instr *evaluate_deref(ir_instruction *ir);
 
+   nir_constant *constant_copy(ir_constant *ir, void *mem_ctx);
+
    /* most recent deref instruction created */
    nir_deref_instr *deref;
 
@@ -196,8 +198,8 @@ nir_visitor::evaluate_deref(ir_instruction *ir)
    return this->deref;
 }
 
-static nir_constant *
-constant_copy(ir_constant *ir, void *mem_ctx)
+nir_constant *
+nir_visitor::constant_copy(ir_constant *ir, void *mem_ctx)
 {
    if (ir == NULL)
       return NULL;
@@ -215,7 +217,10 @@ constant_copy(ir_constant *ir, void *mem_ctx)
       assert(cols == 1);
 
       for (unsigned r = 0; r < rows; r++)
-         ret->values[0].u32[r] = ir->value.u[r];
+         if (supports_ints)
+            ret->values[0].u32[r] = ir->value.u[r];
+         else
+            ret->values[0].f32[r] = ir->value.u[r];
 
       break;
 
@@ -224,7 +229,10 @@ constant_copy(ir_constant *ir, void *mem_ctx)
       assert(cols == 1);
 
       for (unsigned r = 0; r < rows; r++)
-         ret->values[0].i32[r] = ir->value.i[r];
+         if (supports_ints)
+            ret->values[0].i32[r] = ir->value.i[r];
+         else
+            ret->values[0].f32[r] = ir->value.i[r];
 
       break;