gallium: change pipe_image_view::first_element/last_element -> offset/size
authorMarek Olšák <marek.olsak@amd.com>
Fri, 12 Aug 2016 00:33:41 +0000 (02:33 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Wed, 17 Aug 2016 12:15:33 +0000 (14:15 +0200)
This is required by OpenGL. Our hardware supports this.

Example: Bind RGBA32F with offset = 4 bytes.

Acked-by: Ilia Mirkin <imirkin@alum.mit.edu>
Acked-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/gallium/auxiliary/util/u_dump_state.c
src/gallium/drivers/nouveau/nvc0/nvc0_state.c
src/gallium/drivers/nouveau/nvc0/nvc0_tex.c
src/gallium/drivers/radeonsi/si_descriptors.c
src/gallium/drivers/softpipe/sp_image.c
src/gallium/drivers/trace/tr_dump_state.c
src/gallium/include/pipe/p_state.h
src/mesa/state_tracker/st_atom_image.c
src/mesa/state_tracker/st_cb_readpixels.c

index 4568dc6ba31f1b41dc75ab55c538c422b676f555..6aecee1e622dd7b8bf890fa0aaa368c9eda62b53 100644 (file)
@@ -722,8 +722,8 @@ util_dump_image_view(FILE *stream, const struct pipe_image_view *state)
    util_dump_member(stream, format, state, format);
 
    if (state->resource->target == PIPE_BUFFER) {
-      util_dump_member(stream, uint, state, u.buf.first_element);
-      util_dump_member(stream, uint, state, u.buf.last_element);
+      util_dump_member(stream, uint, state, u.buf.offset);
+      util_dump_member(stream, uint, state, u.buf.size);
    }
    else {
       util_dump_member(stream, uint, state, u.tex.first_layer);
index fcb695aaf4d7429076c8b482e85a1bfdcc97f465..b9ac9f49ad91cae1cd19c3cdbded660438db3336 100644 (file)
@@ -1271,8 +1271,8 @@ nvc0_bind_images_range(struct nvc0_context *nvc0, const unsigned s,
             if (img->resource == NULL)
                continue;
             if (img->resource->target == PIPE_BUFFER &&
-                img->u.buf.first_element == pimages[p].u.buf.first_element &&
-                img->u.buf.last_element == pimages[p].u.buf.last_element)
+                img->u.buf.offset == pimages[p].u.buf.offset &&
+                img->u.buf.size == pimages[p].u.buf.size)
                continue;
             if (img->resource->target != PIPE_BUFFER &&
                 img->u.tex.first_layer == pimages[p].u.tex.first_layer &&
index b6e0ba831f69056eeb9300d26799e0e0396f60b0..4fa262195f3bde0faa56ba2cf4ca4ed76084eee4 100644 (file)
@@ -259,11 +259,8 @@ gm107_create_texture_view_from_image(struct pipe_context *pipe,
    templ.swizzle_a = PIPE_SWIZZLE_W;
 
    if (target == PIPE_BUFFER) {
-      templ.u.buf.offset = view->u.buf.first_element *
-                           util_format_get_blocksize(view->format);
-      templ.u.buf.size = (view->u.buf.last_element -
-                          view->u.buf.first_element + 1) *
-                         util_format_get_blocksize(view->format);
+      templ.u.buf.offset = view->u.buf.offset;
+      templ.u.buf.size = view->u.buf.size;
    } else {
       templ.u.tex.first_layer = view->u.tex.first_layer;
       templ.u.tex.last_layer = view->u.tex.last_layer;
@@ -776,7 +773,7 @@ nvc0_get_surface_dims(struct pipe_image_view *view, int *width, int *height,
 
    *width = *height = *depth = 1;
    if (res->base.target == PIPE_BUFFER) {
-      *width = view->u.buf.last_element - view->u.buf.first_element + 1;
+      *width = view->u.buf.size / util_format_get_blocksize(view->format);
       return;
    }
 
@@ -807,17 +804,12 @@ void
 nvc0_mark_image_range_valid(const struct pipe_image_view *view)
 {
    struct nv04_resource *res = (struct nv04_resource *)view->resource;
-   const struct util_format_description *desc;
-   unsigned stride;
 
    assert(view->resource->target == PIPE_BUFFER);
 
-   desc = util_format_description(view->format);
-   stride = desc->block.bits / 8;
-
    util_range_add(&res->valid_buffer_range,
-                  stride * (view->u.buf.first_element),
-                  stride * (view->u.buf.last_element + 1));
+                  view->u.buf.offset,
+                  view->u.buf.offset + view->u.buf.size);
 }
 
 void
@@ -903,9 +895,7 @@ nve4_set_surface_info(struct nouveau_pushbuf *push,
 #endif
 
    if (res->base.target == PIPE_BUFFER) {
-      unsigned blocksize = util_format_get_blocksize(view->format);
-
-      address += view->u.buf.first_element * blocksize;
+      address += view->u.buf.offset;
 
       info[0]  = address >> 8;
       info[2]  = width - 1;
@@ -1030,7 +1020,7 @@ nvc0_validate_suf(struct nvc0_context *nvc0, int s)
          if (res->base.target == PIPE_BUFFER) {
             unsigned blocksize = util_format_get_blocksize(view->format);
 
-            address += view->u.buf.first_element * blocksize;
+            address += view->u.buf.offset;
             assert(!(address & 0xff));
 
             if (view->access & PIPE_IMAGE_ACCESS_WRITE)
index a3e456410f9c673e00618c4a5057d73a5b93c716..0e026e957cd2d7cbf2c659fb4fa4283b6bda9691 100644 (file)
@@ -600,17 +600,12 @@ static void
 si_mark_image_range_valid(const struct pipe_image_view *view)
 {
        struct r600_resource *res = (struct r600_resource *)view->resource;
-       const struct util_format_description *desc;
-       unsigned stride;
 
        assert(res && res->b.b.target == PIPE_BUFFER);
 
-       desc = util_format_description(view->format);
-       stride = desc->block.bits / 8;
-
        util_range_add(&res->valid_buffer_range,
-                      stride * (view->u.buf.first_element),
-                      stride * (view->u.buf.last_element + 1));
+                      view->u.buf.offset,
+                      view->u.buf.offset + view->u.buf.size);
 }
 
 static void si_set_shader_image(struct si_context *ctx,
@@ -641,11 +636,8 @@ static void si_set_shader_image(struct si_context *ctx,
 
                si_make_buffer_descriptor(screen, res,
                                          view->format,
-                                         view->u.buf.first_element *
-                                         util_format_get_blocksize(view->format),
-                                         (view->u.buf.last_element -
-                                          view->u.buf.first_element + 1) *
-                                         util_format_get_blocksize(view->format),
+                                         view->u.buf.offset,
+                                         view->u.buf.size,
                                          descs->list + slot * 8);
                images->compressed_colortex_mask &= ~(1 << slot);
        } else {
index 0be11cb86402b4eb7b593eeb96e616f203fbbce3..d5547e294aba576beaa348303202e4824f0147af 100644 (file)
@@ -39,7 +39,7 @@ get_image_offset(const struct softpipe_resource *spr,
    int base_layer = 0;
 
    if (spr->base.target == PIPE_BUFFER)
-      return iview->u.buf.first_element * util_format_get_blocksize(format);
+      return iview->u.buf.offset;
 
    if (spr->base.target == PIPE_TEXTURE_1D_ARRAY ||
        spr->base.target == PIPE_TEXTURE_2D_ARRAY ||
@@ -153,7 +153,7 @@ get_dimensions(const struct pipe_image_view *iview,
                unsigned *depth)
 {
    if (tgsi_tex_instr == TGSI_TEXTURE_BUFFER) {
-      *width = iview->u.buf.last_element - iview->u.buf.first_element + 1;
+      *width = iview->u.buf.size / util_format_get_blocksize(pformat);
       *height = 1;
       *depth = 1;
       /*
@@ -752,7 +752,7 @@ sp_tgsi_get_dims(const struct tgsi_image *image,
       return;
 
    if (params->tgsi_tex_instr == TGSI_TEXTURE_BUFFER) {
-      dims[0] = iview->u.buf.last_element - iview->u.buf.first_element + 1;
+      dims[0] = iview->u.buf.size / util_format_get_blocksize(iview->format);
       dims[1] = dims[2] = dims[3] = 0;
       return;
    }
index d80037aa47f15d7cf1146618e18f4e84e1da6a35..c5740d080d2060016f7060f2ddd278211df2e3f8 100644 (file)
@@ -760,8 +760,8 @@ void trace_dump_image_view(const struct pipe_image_view *state)
    if (state->resource->target == PIPE_BUFFER) {
       trace_dump_member_begin("buf");
       trace_dump_struct_begin(""); /* anonymous */
-      trace_dump_member(uint, &state->u.buf, first_element);
-      trace_dump_member(uint, &state->u.buf, last_element);
+      trace_dump_member(uint, &state->u.buf, offset);
+      trace_dump_member(uint, &state->u.buf, size);
       trace_dump_struct_end(); /* anonymous */
       trace_dump_member_end(); /* buf */
    } else {
index 1fd63532084a46973c6008b85f11b4595bf74fd8..ebd03379e947dd947f35d87045837b5d0aa0132f 100644 (file)
@@ -456,8 +456,8 @@ struct pipe_image_view
          unsigned level:8;            /**< mipmap level to use */
       } tex;
       struct {
-         unsigned first_element;
-         unsigned last_element;
+         unsigned offset;   /**< offset in bytes */
+         unsigned size;     /**< size of the accessible sub-range in bytes */
       } buf;
    } u;
 };
index e80fc14bf4163685ff0e5c5bce3aa66d895dadc0..4d76ac972d956aa7ebf4f6a0ea85a19d188ccf22 100644 (file)
@@ -88,19 +88,13 @@ st_bind_images(struct st_context *st, struct gl_linked_shader *shader,
 
       if (stObj->pt->target == PIPE_BUFFER) {
          unsigned base, size;
-         unsigned f, n;
-         const struct util_format_description *desc
-            = util_format_description(img->format);
 
          base = stObj->base.BufferOffset;
          assert(base < stObj->pt->width0);
          size = MIN2(stObj->pt->width0 - base, (unsigned)stObj->base.BufferSize);
 
-         f = (base / (desc->block.bits / 8)) * desc->block.width;
-         n = (size / (desc->block.bits / 8)) * desc->block.width;
-         assert(n > 0);
-         img->u.buf.first_element = f;
-         img->u.buf.last_element  = f + (n - 1);
+         img->u.buf.offset = base;
+         img->u.buf.size = size;
       } else {
          img->u.tex.level = u->Level + stObj->base.MinLevel;
          if (stObj->pt->target == PIPE_TEXTURE_3D) {
index 8eb839d16a90639c07bf7e3fc63b5b79eb19c16c..3cfdf78f1905628368abfc557c68fdee002a20de 100644 (file)
@@ -192,8 +192,9 @@ try_pbo_readpixels(struct st_context *st, struct st_renderbuffer *strb,
       image.resource = addr.buffer;
       image.format = dst_format;
       image.access = PIPE_IMAGE_ACCESS_WRITE;
-      image.u.buf.first_element = addr.first_element;
-      image.u.buf.last_element = addr.last_element;
+      image.u.buf.offset = addr.first_element * addr.bytes_per_pixel;
+      image.u.buf.size = (addr.last_element - addr.first_element + 1) *
+                         addr.bytes_per_pixel;
 
       cso_set_shader_images(cso, PIPE_SHADER_FRAGMENT, 0, 1, &image);
    }