zink: implement ARB_texture_query_lod
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Wed, 15 Jul 2020 17:51:18 +0000 (13:51 -0400)
committerMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Fri, 6 Nov 2020 23:10:04 +0000 (18:10 -0500)
just needed hooking up the spirv function to the tex op

Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7484>

docs/features.txt
src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c
src/gallium/drivers/zink/nir_to_spirv/spirv_builder.c
src/gallium/drivers/zink/nir_to_spirv/spirv_builder.h
src/gallium/drivers/zink/zink_screen.c

index 9d966b5..c5211b5 100644 (file)
@@ -135,7 +135,7 @@ GL 4.0, GLSL 4.00 --- all DONE: i965/gen7+, nvc0, r600, radeonsi, llvmpipe, virg
   GL_ARB_texture_buffer_object_rgb32                    DONE (freedreno, i965/gen6+, softpipe, swr)
   GL_ARB_texture_cube_map_array                         DONE (i965/gen6+, nv50, softpipe, swr, zink)
   GL_ARB_texture_gather                                 DONE (freedreno, i965/gen6+, nv50, softpipe, swr, v3d, panfrost)
-  GL_ARB_texture_query_lod                              DONE (freedreno, i965, nv50, softpipe, swr, v3d, panfrost)
+  GL_ARB_texture_query_lod                              DONE (freedreno, i965, nv50, softpipe, swr, v3d, panfrost, zink)
   GL_ARB_transform_feedback2                            DONE (i965/gen6+, nv50, softpipe, swr, v3d, panfrost)
   GL_ARB_transform_feedback3                            DONE (i965/gen7+, softpipe, swr)
 
index 5a54caa..b202169 100644 (file)
@@ -1862,7 +1862,8 @@ emit_tex(struct ntv_context *ctx, nir_tex_instr *tex)
           tex->op == nir_texop_txd ||
           tex->op == nir_texop_txf ||
           tex->op == nir_texop_txf_ms ||
-          tex->op == nir_texop_txs);
+          tex->op == nir_texop_txs ||
+          tex->op == nir_texop_lod);
    assert(tex->texture_index == tex->sampler_index);
 
    SpvId coord = 0, proj = 0, bias = 0, lod = 0, dref = 0, dx = 0, dy = 0,
@@ -1983,7 +1984,13 @@ emit_tex(struct ntv_context *ctx, nir_tex_instr *tex)
                                                             constituents,
                                                             coord_components);
    }
-
+   if (tex->op == nir_texop_lod) {
+      SpvId result = spirv_builder_emit_image_query_lod(&ctx->builder,
+                                                         dest_type, load,
+                                                         coord);
+      store_dest(ctx, &tex->dest, result, tex->dest_type);
+      return;
+   }
    SpvId actual_dest_type = dest_type;
    if (dref)
       actual_dest_type = spirv_builder_type_float(&ctx->builder, 32);
index cc361a0..f82ea82 100644 (file)
@@ -759,6 +759,26 @@ spirv_builder_emit_image_query_size(struct spirv_builder *b,
 }
 
 SpvId
+spirv_builder_emit_image_query_lod(struct spirv_builder *b,
+                                    SpvId result_type,
+                                    SpvId image,
+                                    SpvId coords)
+{
+   int opcode = SpvOpImageQueryLod;
+   int words = 5;
+
+   SpvId result = spirv_builder_new_id(b);
+   spirv_buffer_prepare(&b->instructions, b->mem_ctx, words);
+   spirv_buffer_emit_word(&b->instructions, opcode | (words << 16));
+   spirv_buffer_emit_word(&b->instructions, result_type);
+   spirv_buffer_emit_word(&b->instructions, result);
+   spirv_buffer_emit_word(&b->instructions, image);
+   spirv_buffer_emit_word(&b->instructions, coords);
+
+   return result;
+}
+
+SpvId
 spirv_builder_emit_ext_inst(struct spirv_builder *b, SpvId result_type,
                             SpvId set, uint32_t instruction,
                             const SpvId *args, size_t num_args)
index 9912891..5ed0d46 100644 (file)
@@ -268,6 +268,12 @@ spirv_builder_emit_image_query_size(struct spirv_builder *b,
                                     SpvId lod);
 
 SpvId
+spirv_builder_emit_image_query_lod(struct spirv_builder *b,
+                                    SpvId result_type,
+                                    SpvId image,
+                                    SpvId coords);
+
+SpvId
 spirv_builder_emit_ext_inst(struct spirv_builder *b, SpvId result_type,
                             SpvId set, uint32_t instruction,
                             const SpvId args[], size_t num_args);
index b15dbfd..96c6945 100644 (file)
@@ -99,6 +99,7 @@ zink_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
    case PIPE_CAP_NPOT_TEXTURES:
    case PIPE_CAP_TGSI_TEXCOORD:
    case PIPE_CAP_DRAW_INDIRECT:
+   case PIPE_CAP_TEXTURE_QUERY_LOD:
       return 1;
 
    case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR: