gallivm/sample: fix lod query on array textures.
authorDave Airlie <airlied@redhat.com>
Mon, 17 Aug 2020 01:09:19 +0000 (11:09 +1000)
committerDave Airlie <airlied@redhat.com>
Wed, 19 Aug 2020 00:16:27 +0000 (10:16 +1000)
The lod query doesn't take a layer, but the code tries to use one,
detect lodq and don't use a layer in those cases.

There appears to be no GL tests for this behaviour, but the vulkan
CTS hits it.

Fixes:
dEQP-VK.glsl.texture_functions.query.texturequerylod.*

Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6339>

src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c

index e0d751690ed4dea6b94f665a082382a7759159f0..0f0c2fade21c5ac8e0e3a3552ab22efb223cf021 100644 (file)
@@ -2100,7 +2100,7 @@ lp_build_sample_common(struct lp_build_sample_context *bld,
                       !explicit_lod);
       lp_build_cube_lookup(bld, coords, derivs, &cube_rho, &cube_derivs, need_derivs);
       derivs = &cube_derivs;
-      if (target == PIPE_TEXTURE_CUBE_ARRAY) {
+      if (target == PIPE_TEXTURE_CUBE_ARRAY && !is_lodq) {
          /* calculate cube layer coord now */
          LLVMValueRef layer = lp_build_iround(&bld->coord_bld, coords[3]);
          LLVMValueRef six = lp_build_const_int_vec(bld->gallivm, bld->int_coord_type, 6);
@@ -2109,8 +2109,8 @@ lp_build_sample_common(struct lp_build_sample_context *bld,
          /* because of seamless filtering can't add it to face (coords[2]) here. */
       }
    }
-   else if (target == PIPE_TEXTURE_1D_ARRAY ||
-            target == PIPE_TEXTURE_2D_ARRAY) {
+   else if ((target == PIPE_TEXTURE_1D_ARRAY ||
+             target == PIPE_TEXTURE_2D_ARRAY) && !is_lodq) {
       coords[2] = lp_build_iround(&bld->coord_bld, coords[2]);
       coords[2] = lp_build_layer_coord(bld, texture_index, FALSE, coords[2], NULL);
    }
@@ -3483,14 +3483,22 @@ lp_build_sample_gen_func(struct gallivm_state *gallivm,
    unsigned num_param = 0;
    unsigned i, num_coords, num_derivs, num_offsets, layer;
    enum lp_sampler_lod_control lod_control;
+   enum lp_sampler_op_type op_type;
    boolean need_cache = FALSE;
 
    lod_control = (sample_key & LP_SAMPLER_LOD_CONTROL_MASK) >>
                     LP_SAMPLER_LOD_CONTROL_SHIFT;
 
+   op_type = (sample_key & LP_SAMPLER_OP_TYPE_MASK) >>
+                    LP_SAMPLER_OP_TYPE_SHIFT;
+
    get_target_info(static_texture_state->target,
                    &num_coords, &num_derivs, &num_offsets, &layer);
 
+   /* lod query doesn't take a layer */
+   if (layer && op_type == LP_SAMPLER_OP_LODQ)
+      layer = 0;
+
    if (dynamic_state->cache_ptr) {
       const struct util_format_description *format_desc;
       format_desc = util_format_description(static_texture_state->format);
@@ -3601,14 +3609,22 @@ lp_build_sample_soa_func(struct gallivm_state *gallivm,
    const LLVMValueRef *offsets = params->offsets;
    const struct lp_derivatives *derivs = params->derivs;
    enum lp_sampler_lod_control lod_control;
+   enum lp_sampler_op_type op_type;
    boolean need_cache = FALSE;
 
    lod_control = (sample_key & LP_SAMPLER_LOD_CONTROL_MASK) >>
                     LP_SAMPLER_LOD_CONTROL_SHIFT;
 
+   op_type = (sample_key & LP_SAMPLER_OP_TYPE_MASK) >>
+                    LP_SAMPLER_OP_TYPE_SHIFT;
+
    get_target_info(static_texture_state->target,
                    &num_coords, &num_derivs, &num_offsets, &layer);
 
+   /* lod query doesn't take a layer */
+   if (layer && op_type == LP_SAMPLER_OP_LODQ)
+      layer = 0;
+
    if (dynamic_state->cache_ptr) {
       const struct util_format_description *format_desc;
       format_desc = util_format_description(static_texture_state->format);