gallium: change pipe_sampler_view::first_element/last_element -> offset/size
[mesa.git] / src / gallium / drivers / softpipe / sp_tex_sample.c
index 5703ca2dedba077092e2723cf21ec42c489e7c4e..c457f896e49c608d3e6a14dbe532016a78b0acaf 100644 (file)
@@ -1500,9 +1500,9 @@ get_gather_value(const struct sp_sampler_view *sp_sview,
 
    /* get correct result using the channel and swizzle */
    switch (swizzle) {
-   case PIPE_SWIZZLE_ZERO:
+   case PIPE_SWIZZLE_0:
       return 0.0;
-   case PIPE_SWIZZLE_ONE:
+   case PIPE_SWIZZLE_1:
       return 1.0;
    default:
       return tx[chan][swizzle];
@@ -2651,7 +2651,7 @@ sample_compare(const struct sp_sampler_view *sp_sview,
       util_format_description(sp_sview->base.format);
    /* not entirely sure we couldn't end up with non-valid swizzle here */
    const unsigned chan_type =
-      format_desc->swizzle[0] <= UTIL_FORMAT_SWIZZLE_W ?
+      format_desc->swizzle[0] <= PIPE_SWIZZLE_W ?
       format_desc->channel[format_desc->swizzle[0]].type :
       UTIL_FORMAT_TYPE_FLOAT;
    const bool is_gather = (control == TGSI_SAMPLER_GATHER);
@@ -2773,11 +2773,11 @@ do_swizzling(const struct pipe_sampler_view *sview,
    const unsigned swizzle_a = sview->swizzle_a;
 
    switch (swizzle_r) {
-   case PIPE_SWIZZLE_ZERO:
+   case PIPE_SWIZZLE_0:
       for (j = 0; j < 4; j++)
          out[0][j] = 0.0f;
       break;
-   case PIPE_SWIZZLE_ONE:
+   case PIPE_SWIZZLE_1:
       for (j = 0; j < 4; j++)
          out[0][j] = 1.0f;
       break;
@@ -2788,11 +2788,11 @@ do_swizzling(const struct pipe_sampler_view *sview,
    }
 
    switch (swizzle_g) {
-   case PIPE_SWIZZLE_ZERO:
+   case PIPE_SWIZZLE_0:
       for (j = 0; j < 4; j++)
          out[1][j] = 0.0f;
       break;
-   case PIPE_SWIZZLE_ONE:
+   case PIPE_SWIZZLE_1:
       for (j = 0; j < 4; j++)
          out[1][j] = 1.0f;
       break;
@@ -2803,11 +2803,11 @@ do_swizzling(const struct pipe_sampler_view *sview,
    }
 
    switch (swizzle_b) {
-   case PIPE_SWIZZLE_ZERO:
+   case PIPE_SWIZZLE_0:
       for (j = 0; j < 4; j++)
          out[2][j] = 0.0f;
       break;
-   case PIPE_SWIZZLE_ONE:
+   case PIPE_SWIZZLE_1:
       for (j = 0; j < 4; j++)
          out[2][j] = 1.0f;
       break;
@@ -2818,11 +2818,11 @@ do_swizzling(const struct pipe_sampler_view *sview,
    }
 
    switch (swizzle_a) {
-   case PIPE_SWIZZLE_ZERO:
+   case PIPE_SWIZZLE_0:
       for (j = 0; j < 4; j++)
          out[3][j] = 0.0f;
       break;
-   case PIPE_SWIZZLE_ONE:
+   case PIPE_SWIZZLE_1:
       for (j = 0; j < 4; j++)
          out[3][j] = 1.0f;
       break;
@@ -2928,10 +2928,10 @@ get_linear_wrap(unsigned mode)
 static inline bool
 any_swizzle(const struct pipe_sampler_view *view)
 {
-   return (view->swizzle_r != PIPE_SWIZZLE_RED ||
-           view->swizzle_g != PIPE_SWIZZLE_GREEN ||
-           view->swizzle_b != PIPE_SWIZZLE_BLUE ||
-           view->swizzle_a != PIPE_SWIZZLE_ALPHA);
+   return (view->swizzle_r != PIPE_SWIZZLE_X ||
+           view->swizzle_g != PIPE_SWIZZLE_Y ||
+           view->swizzle_b != PIPE_SWIZZLE_Z ||
+           view->swizzle_a != PIPE_SWIZZLE_W);
 }
 
 
@@ -3192,7 +3192,7 @@ sp_get_dims(const struct sp_sampler_view *sp_sview,
    const struct pipe_resource *texture = view->texture;
 
    if (view->target == PIPE_BUFFER) {
-      dims[0] = (view->u.buf.last_element - view->u.buf.first_element) + 1;
+      dims[0] = view->u.buf.size / util_format_get_blocksize(view->format);
       /* the other values are undefined, but let's avoid potential valgrind
        * warnings.
        */
@@ -3264,17 +3264,22 @@ sp_get_texels(const struct sp_sampler_view *sp_sview,
    const int width = u_minify(texture->width0, level);
    const int height = u_minify(texture->height0, level);
    const int depth = u_minify(texture->depth0, level);
+   unsigned elem_size, first_element, last_element;
 
    addr.value = 0;
    addr.bits.level = level;
 
    switch (sp_sview->base.target) {
    case PIPE_BUFFER:
+      elem_size = util_format_get_blocksize(sp_sview->base.format);
+      first_element = sp_sview->base.u.buf.offset / elem_size;
+      last_element = (sp_sview->base.u.buf.offset +
+                      sp_sview->base.u.buf.size) / elem_size - 1;
       for (j = 0; j < TGSI_QUAD_SIZE; j++) {
          const int x = CLAMP(v_i[j] + offset[0] +
-                             sp_sview->base.u.buf.first_element,
-                             sp_sview->base.u.buf.first_element,
-                             sp_sview->base.u.buf.last_element);
+                             first_element,
+                             first_element,
+                             last_element);
          tx = get_texel_2d_no_border(sp_sview, addr, x, 0);
          for (c = 0; c < 4; c++) {
             rgba[c][j] = tx[c];