nir/spirv: Add support for most of the rest of texturing
authorJason Ekstrand <jason.ekstrand@intel.com>
Sat, 5 Sep 2015 21:09:15 +0000 (14:09 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Sat, 5 Sep 2015 21:10:05 +0000 (14:10 -0700)
Assuming this all works, about the only thing left should be some
corner-cases for tg4

src/glsl/nir/spirv_to_nir.c

index 30104f0d09a90bc94330107ded6ca9c4aaec0e91..e6fe74de9e86ecb9d5a7fdb67a98bda4c3995879 100644 (file)
@@ -1547,12 +1547,22 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode,
       break;
    }
 
-   nir_texop texop;
+   /* These all have an explicit depth value as their next source */
    switch (opcode) {
-   case SpvOpImageSampleImplicitLod:
-      texop = nir_texop_tex;
+   case SpvOpImageSampleDrefImplicitLod:
+   case SpvOpImageSampleDrefExplicitLod:
+   case SpvOpImageSampleProjDrefImplicitLod:
+   case SpvOpImageSampleProjDrefExplicitLod:
+      (*p++) = vtn_tex_src(b, w[idx++], nir_tex_src_comparitor);
       break;
+   default:
+      break;
+   }
 
+   /* Figure out the base texture operation */
+   nir_texop texop;
+   switch (opcode) {
+   case SpvOpImageSampleImplicitLod:
    case SpvOpImageSampleExplicitLod:
    case SpvOpImageSampleDrefImplicitLod:
    case SpvOpImageSampleDrefExplicitLod:
@@ -1560,24 +1570,74 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode,
    case SpvOpImageSampleProjExplicitLod:
    case SpvOpImageSampleProjDrefImplicitLod:
    case SpvOpImageSampleProjDrefExplicitLod:
+      texop = nir_texop_tex;
+      break;
+
    case SpvOpImageFetch:
+      texop = nir_texop_txf;
+      break;
+
    case SpvOpImageGather:
    case SpvOpImageDrefGather:
+      texop = nir_texop_tg4;
+      break;
+
    case SpvOpImageQuerySizeLod:
    case SpvOpImageQuerySize:
+      texop = nir_texop_txs;
+      break;
+
    case SpvOpImageQueryLod:
+      texop = nir_texop_lod;
+      break;
+
    case SpvOpImageQueryLevels:
+      texop = nir_texop_query_levels;
+      break;
+
    case SpvOpImageQuerySamples:
    default:
       unreachable("Unhandled opcode");
    }
 
-   /* From now on, the remaining sources are "Optional Image Operands." */
+   /* Now we need to handle some number of optional arguments */
    if (idx < count) {
-      /* XXX handle these (bias, lod, etc.) */
-      assert(0);
-   }
+      uint32_t operands = w[idx++];
+
+      if (operands & SpvImageOperandsBiasMask) {
+         assert(texop == nir_texop_tex);
+         texop = nir_texop_txb;
+         (*p++) = vtn_tex_src(b, w[idx++], nir_tex_src_bias);
+      }
+
+      if (operands & SpvImageOperandsLodMask) {
+         assert(texop == nir_texop_tex);
+         texop = nir_texop_txl;
+         (*p++) = vtn_tex_src(b, w[idx++], nir_tex_src_lod);
+      }
+
+      if (operands & SpvImageOperandsGradMask) {
+         assert(texop == nir_texop_tex);
+         texop = nir_texop_txd;
+         (*p++) = vtn_tex_src(b, w[idx++], nir_tex_src_ddx);
+         (*p++) = vtn_tex_src(b, w[idx++], nir_tex_src_ddy);
+      }
 
+      if (operands & SpvImageOperandsOffsetMask ||
+          operands & SpvImageOperandsConstOffsetMask)
+         (*p++) = vtn_tex_src(b, w[idx++], nir_tex_src_offset);
+
+      if (operands & SpvImageOperandsConstOffsetsMask)
+         assert(!"Constant offsets to texture gather not yet implemented");
+
+      if (operands & SpvImageOperandsSampleMask) {
+         assert(texop == nir_texop_txf);
+         texop = nir_texop_txf_ms;
+         (*p++) = vtn_tex_src(b, w[idx++], nir_tex_src_ms_index);
+      }
+   }
+   /* We should have now consumed exactly all of the arguments */
+   assert(idx == count);
 
    nir_tex_instr *instr = nir_tex_instr_create(b->shader, p - srcs);