freedreno: use rsc->slice accessor everywhere
[mesa.git] / src / gallium / drivers / freedreno / a5xx / fd5_image.c
index 028497f3a108d738894ce70d6bee850df4cc2645..2f3389072b04cf5398ffbe1e31f48f53021dbbfd 100644 (file)
@@ -62,6 +62,7 @@ static void translate_image(struct fd5_image *img, struct pipe_image_view *pimg)
        enum pipe_format format = pimg->format;
        struct pipe_resource *prsc = pimg->resource;
        struct fd_resource *rsc = fd_resource(prsc);
+       struct fd_resource_slice *slice = NULL;
        unsigned lvl;
 
        if (!pimg->resource) {
@@ -83,8 +84,9 @@ static void translate_image(struct fd5_image *img, struct pipe_image_view *pimg)
                img->pitch  = pimg->u.buf.size;
        } else {
                lvl = pimg->u.tex.level;
+               slice = fd_resource_slice(rsc, lvl);
                img->offset = fd_resource_offset(rsc, lvl, pimg->u.tex.first_layer);
-               img->pitch  = rsc->slices[lvl].pitch * rsc->cpp;
+               img->pitch  = slice->pitch * rsc->cpp;
        }
 
        img->width     = u_minify(prsc->width0, lvl);
@@ -110,7 +112,7 @@ static void translate_image(struct fd5_image *img, struct pipe_image_view *pimg)
                img->depth = layers;
                break;
        case PIPE_TEXTURE_3D:
-               img->array_pitch = rsc->slices[lvl].size0;
+               img->array_pitch = slice->size0;
                img->depth = u_minify(prsc->depth0, lvl);
                break;
        default:
@@ -189,46 +191,25 @@ static void emit_image_ssbo(struct fd_ringbuffer *ring, unsigned slot,
        }
 }
 
-/* Note that to avoid conflicts with textures and non-image "SSBO"s, images
- * are placedd, in reverse order, at the end of the state block, so for
- * example the sampler state:
- *
- *   0:   first texture
- *   1:   second texture
- *   ....
- *   N-1: second image
- *   N:   first image
- */
-static unsigned
-get_image_slot(unsigned index)
-{
-       /* TODO figure out real limit per generation, and don't hardcode.
-        * This needs to match get_image_slot() in ir3_compiler_nir.
-        * Possibly should be factored out into shared helper?
-        */
-       const unsigned max_samplers = 16;
-       return max_samplers - index - 1;
-}
-
 /* Emit required "SSBO" and sampler state.  The sampler state is used by the
  * hw for imageLoad(), and "SSBO" state for imageStore().  Returns max sampler
  * used.
  */
 void
 fd5_emit_images(struct fd_context *ctx, struct fd_ringbuffer *ring,
-               enum pipe_shader_type shader)
+               enum pipe_shader_type shader, const struct ir3_shader_variant *v)
 {
        struct fd_shaderimg_stateobj *so = &ctx->shaderimg[shader];
        unsigned enabled_mask = so->enabled_mask;
+       const struct ir3_ibo_mapping *m = &v->image_mapping;
 
        while (enabled_mask) {
                unsigned index = u_bit_scan(&enabled_mask);
-               unsigned slot = get_image_slot(index);
                struct fd5_image img;
 
                translate_image(&img, &so->si[index]);
 
-               emit_image_tex(ring, slot, &img, shader);
-               emit_image_ssbo(ring, slot, &img, shader);
+               emit_image_tex(ring, m->image_to_tex[index] + m->tex_base, &img, shader);
+               emit_image_ssbo(ring, m->image_to_ibo[index], &img, shader);
        }
 }