xref: /aosp_15_r20/external/mesa3d/src/mesa/state_tracker/st_sampler_view.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright 2016 VMware, Inc.
3  * All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sub license, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the
14  * next paragraph) shall be included in all copies or substantial portions
15  * of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
21  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25 
26 #include "pipe/p_context.h"
27 #include "util/format/u_format.h"
28 #include "util/u_inlines.h"
29 
30 #include "main/context.h"
31 #include "main/macros.h"
32 #include "main/mtypes.h"
33 #include "main/teximage.h"
34 #include "main/texobj.h"
35 #include "program/prog_instruction.h"
36 
37 #include "st_context.h"
38 #include "st_sampler_view.h"
39 #include "st_texture.h"
40 #include "st_format.h"
41 #include "st_cb_texture.h"
42 
43 /* Subtract remaining private references. Typically used before
44  * destruction. See the header file for explanation.
45  */
46 static void
st_remove_private_references(struct st_sampler_view * sv)47 st_remove_private_references(struct st_sampler_view *sv)
48 {
49    if (sv->private_refcount) {
50       assert(sv->private_refcount > 0);
51       p_atomic_add(&sv->view->reference.count, -sv->private_refcount);
52       sv->private_refcount = 0;
53    }
54 }
55 
56 /* Return a sampler view while incrementing the refcount by 1. */
57 static struct pipe_sampler_view *
get_sampler_view_reference(struct st_sampler_view * sv,struct pipe_sampler_view * view)58 get_sampler_view_reference(struct st_sampler_view *sv,
59                            struct pipe_sampler_view *view)
60 {
61    if (unlikely(sv->private_refcount <= 0)) {
62       assert(sv->private_refcount == 0);
63 
64       /* This is the number of atomic increments we will skip. */
65       sv->private_refcount = 100000000;
66       p_atomic_add(&view->reference.count, sv->private_refcount);
67    }
68 
69    /* Return a reference while decrementing the private refcount. */
70    sv->private_refcount--;
71    return view;
72 }
73 
74 /**
75  * Set the given view as the current context's view for the texture.
76  *
77  * Overwrites any pre-existing view of the context.
78  *
79  * Takes ownership of the view (i.e., stores the view without incrementing the
80  * reference count).
81  *
82  * \return the view, or NULL on error. In case of error, the reference to the
83  * view is released.
84  */
85 static struct pipe_sampler_view *
st_texture_set_sampler_view(struct st_context * st,struct gl_texture_object * stObj,struct pipe_sampler_view * view,bool glsl130_or_later,bool srgb_skip_decode,bool get_reference,bool locked)86 st_texture_set_sampler_view(struct st_context *st,
87                             struct gl_texture_object *stObj,
88                             struct pipe_sampler_view *view,
89                             bool glsl130_or_later, bool srgb_skip_decode,
90                             bool get_reference, bool locked)
91 {
92    struct st_sampler_views *views;
93    struct st_sampler_view *free = NULL;
94    struct st_sampler_view *sv;
95    GLuint i;
96 
97    if (!locked)
98       simple_mtx_lock(&stObj->validate_mutex);
99    views = stObj->sampler_views;
100 
101    for (i = 0; i < views->count; ++i) {
102       sv = &views->views[i];
103 
104       /* Is the array entry used ? */
105       if (sv->view) {
106          /* check if the context matches */
107          if (sv->view->context == st->pipe) {
108             st_remove_private_references(sv);
109             pipe_sampler_view_reference(&sv->view, NULL);
110             goto found;
111          }
112       } else {
113          /* Found a free slot, remember that */
114          free = sv;
115       }
116    }
117 
118    /* Couldn't find a slot for our context, create a new one */
119    if (free) {
120       sv = free;
121    } else {
122       if (views->count >= views->max) {
123          /* Allocate a larger container. */
124          unsigned new_max = 2 * views->max;
125          unsigned new_size = sizeof(*views) + new_max * sizeof(views->views[0]);
126 
127          if (new_max < views->max ||
128              new_max > (UINT_MAX - sizeof(*views)) / sizeof(views->views[0])) {
129             pipe_sampler_view_reference(&view, NULL);
130             goto out;
131          }
132 
133          struct st_sampler_views *new_views = malloc(new_size);
134          if (!new_views) {
135             pipe_sampler_view_reference(&view, NULL);
136             goto out;
137          }
138 
139          new_views->count = views->count;
140          new_views->max = new_max;
141          memcpy(&new_views->views[0], &views->views[0],
142                views->count * sizeof(views->views[0]));
143 
144          /* Initialize the pipe_sampler_view pointers to zero so that we don't
145           * have to worry about racing against readers when incrementing
146           * views->count.
147           */
148          memset(&new_views->views[views->count], 0,
149                 (new_max - views->count) * sizeof(views->views[0]));
150 
151          /* Use memory release semantics to ensure that concurrent readers will
152           * get the correct contents of the new container.
153           *
154           * Also, the write should be atomic, but that's guaranteed anyway on
155           * all supported platforms.
156           */
157          p_atomic_set(&stObj->sampler_views, new_views);
158 
159          /* We keep the old container around until the texture object is
160           * deleted, because another thread may still be reading from it. We
161           * double the size of the container each time, so we end up with
162           * at most twice the total memory allocation.
163           */
164          views->next = stObj->sampler_views_old;
165          stObj->sampler_views_old = views;
166 
167          views = new_views;
168       }
169 
170       sv = &views->views[views->count];
171 
172       /* Since modification is guarded by the lock, only the write part of the
173        * increment has to be atomic, and that's already guaranteed on all
174        * supported platforms without using an atomic intrinsic.
175        */
176       views->count++;
177    }
178 
179 found:
180    assert(sv->view == NULL);
181 
182    sv->glsl130_or_later = glsl130_or_later;
183    sv->srgb_skip_decode = srgb_skip_decode;
184    sv->view = view;
185    sv->st = st;
186 
187    if (get_reference)
188       view = get_sampler_view_reference(sv, view);
189 
190 out:
191    if (!locked)
192       simple_mtx_unlock(&stObj->validate_mutex);
193    return view;
194 }
195 
196 
197 /**
198  * Return the most-recently validated sampler view for the texture \p stObj
199  * in the given context, if any.
200  *
201  * Performs no additional validation.
202  */
203 struct st_sampler_view *
st_texture_get_current_sampler_view(const struct st_context * st,const struct gl_texture_object * stObj)204 st_texture_get_current_sampler_view(const struct st_context *st,
205                                     const struct gl_texture_object *stObj)
206 {
207    struct st_sampler_views *views = p_atomic_read(&stObj->sampler_views);
208 
209    for (unsigned i = 0; i < views->count; ++i) {
210       struct st_sampler_view *sv = &views->views[i];
211       if (sv->view && sv->view->context == st->pipe)
212          return sv;
213    }
214 
215    return NULL;
216 }
217 
218 
219 /**
220  * For the given texture object, release any sampler views which belong
221  * to the calling context.  This is used to free any sampler views
222  * which belong to the context before the context is destroyed.
223  */
224 void
st_texture_release_context_sampler_view(struct st_context * st,struct gl_texture_object * stObj)225 st_texture_release_context_sampler_view(struct st_context *st,
226                                         struct gl_texture_object *stObj)
227 {
228    GLuint i;
229 
230    simple_mtx_lock(&stObj->validate_mutex);
231    struct st_sampler_views *views = stObj->sampler_views;
232    for (i = 0; i < views->count; ++i) {
233       struct st_sampler_view *sv = &views->views[i];
234 
235       if (sv->view && sv->view->context == st->pipe) {
236          st_remove_private_references(sv);
237          pipe_sampler_view_reference(&sv->view, NULL);
238          break;
239       }
240    }
241    simple_mtx_unlock(&stObj->validate_mutex);
242 }
243 
244 
245 /**
246  * Release all sampler views attached to the given texture object, regardless
247  * of the context.  This is called fairly frequently.  For example, whenever
248  * the texture's base level, max level or swizzle change.
249  */
250 void
st_texture_release_all_sampler_views(struct st_context * st,struct gl_texture_object * stObj)251 st_texture_release_all_sampler_views(struct st_context *st,
252                                      struct gl_texture_object *stObj)
253 {
254    /* TODO: This happens while a texture is deleted, because the Driver API
255     * is asymmetric: the driver allocates the texture object memory, but
256     * mesa/main frees it.
257     */
258    if (!stObj->sampler_views)
259       return;
260 
261    simple_mtx_lock(&stObj->validate_mutex);
262    struct st_sampler_views *views = stObj->sampler_views;
263    for (unsigned i = 0; i < views->count; ++i) {
264       struct st_sampler_view *stsv = &views->views[i];
265       if (stsv->view) {
266          st_remove_private_references(stsv);
267 
268          if (stsv->st && stsv->st != st) {
269             /* Transfer this reference to the zombie list.  It will
270              * likely be freed when the zombie list is freed.
271              */
272             st_save_zombie_sampler_view(stsv->st, stsv->view);
273             stsv->view = NULL;
274          } else {
275             pipe_sampler_view_reference(&stsv->view, NULL);
276          }
277       }
278    }
279    views->count = 0;
280    simple_mtx_unlock(&stObj->validate_mutex);
281 }
282 
283 
284 /*
285  * Delete the texture's sampler views and st_sampler_views containers.
286  * This is to be called just before a texture is deleted.
287  */
288 void
st_delete_texture_sampler_views(struct st_context * st,struct gl_texture_object * stObj)289 st_delete_texture_sampler_views(struct st_context *st,
290                                 struct gl_texture_object *stObj)
291 {
292    st_texture_release_all_sampler_views(st, stObj);
293 
294    /* Free the container of the current per-context sampler views */
295    assert(stObj->sampler_views->count == 0);
296    free(stObj->sampler_views);
297    stObj->sampler_views = NULL;
298 
299    /* Free old sampler view containers */
300    while (stObj->sampler_views_old) {
301       struct st_sampler_views *views = stObj->sampler_views_old;
302       stObj->sampler_views_old = views->next;
303       free(views);
304    }
305 }
306 
307 /**
308  * Return TRUE if the texture's sampler view swizzle is not equal to
309  * the texture's swizzle.
310  *
311  * \param texObj  the st texture object,
312  */
313 ASSERTED static bool
check_sampler_swizzle(const struct st_context * st,const struct gl_texture_object * texObj,const struct pipe_sampler_view * sv,bool glsl130_or_later)314 check_sampler_swizzle(const struct st_context *st,
315                       const struct gl_texture_object *texObj,
316                       const struct pipe_sampler_view *sv,
317                       bool glsl130_or_later)
318 {
319    unsigned swizzle = glsl130_or_later ? texObj->SwizzleGLSL130 : texObj->Swizzle;
320 
321    return ((sv->swizzle_r != GET_SWZ(swizzle, 0)) ||
322            (sv->swizzle_g != GET_SWZ(swizzle, 1)) ||
323            (sv->swizzle_b != GET_SWZ(swizzle, 2)) ||
324            (sv->swizzle_a != GET_SWZ(swizzle, 3)));
325 }
326 
327 
328 static unsigned
last_level(const struct gl_texture_object * texObj)329 last_level(const struct gl_texture_object *texObj)
330 {
331    unsigned ret = MIN2(texObj->Attrib.MinLevel + texObj->_MaxLevel,
332                        texObj->pt->last_level);
333    if (texObj->Immutable)
334       ret = MIN2(ret, texObj->Attrib.MinLevel +
335                  texObj->Attrib.NumLevels - 1);
336    return ret;
337 }
338 
339 
340 static unsigned
last_layer(const struct gl_texture_object * texObj)341 last_layer(const struct gl_texture_object *texObj)
342 {
343    if (texObj->Immutable && texObj->pt->array_size > 1)
344       return MIN2(texObj->Attrib.MinLayer +
345                   texObj->Attrib.NumLayers - 1,
346                   texObj->pt->array_size - 1);
347    return texObj->pt->array_size - 1;
348 }
349 
350 
351 /**
352  * Determine the format for the texture sampler view.
353  */
354 enum pipe_format
st_get_sampler_view_format(const struct st_context * st,const struct gl_texture_object * texObj,bool srgb_skip_decode)355 st_get_sampler_view_format(const struct st_context *st,
356                            const struct gl_texture_object *texObj,
357                            bool srgb_skip_decode)
358 {
359    enum pipe_format format;
360 
361    GLenum baseFormat = _mesa_base_tex_image(texObj)->_BaseFormat;
362    format = texObj->surface_based ? texObj->surface_format : texObj->pt->format;
363 
364    /* From OpenGL 4.3 spec, "Combined Depth/Stencil Textures":
365     *
366     *    "The DEPTH_STENCIL_TEXTURE_MODE is ignored for non
367     *     depth/stencil textures.
368     */
369    const bool has_combined_ds =
370       baseFormat == GL_DEPTH_STENCIL;
371 
372    if (baseFormat == GL_DEPTH_COMPONENT ||
373        baseFormat == GL_DEPTH_STENCIL ||
374        baseFormat == GL_STENCIL_INDEX) {
375       if ((texObj->StencilSampling && has_combined_ds) ||
376           baseFormat == GL_STENCIL_INDEX)
377          format = util_format_stencil_only(format);
378 
379       return format;
380    }
381 
382    /* If sRGB decoding is off, use the linear format */
383    if (srgb_skip_decode)
384       format = util_format_linear(format);
385 
386    /* if resource format matches then YUV wasn't lowered */
387    if (format == texObj->pt->format)
388       return format;
389 
390    /* Use R8_UNORM for video formats */
391    switch (format) {
392    case PIPE_FORMAT_NV12:
393       if (texObj->pt->format == PIPE_FORMAT_R8_G8B8_420_UNORM) {
394          format = PIPE_FORMAT_R8_G8B8_420_UNORM;
395          break;
396       }
397       FALLTHROUGH;
398    case PIPE_FORMAT_NV21:
399       if (texObj->pt->format == PIPE_FORMAT_R8_B8G8_420_UNORM) {
400          format = PIPE_FORMAT_R8_B8G8_420_UNORM;
401          break;
402       }
403       FALLTHROUGH;
404    case PIPE_FORMAT_IYUV:
405       if (texObj->pt->format == PIPE_FORMAT_R8_G8_B8_420_UNORM ||
406           texObj->pt->format == PIPE_FORMAT_R8_B8_G8_420_UNORM) {
407          format = texObj->pt->format;
408          break;
409       }
410       format = PIPE_FORMAT_R8_UNORM;
411       break;
412    case PIPE_FORMAT_P010:
413    case PIPE_FORMAT_P012:
414    case PIPE_FORMAT_P016:
415    case PIPE_FORMAT_P030:
416       format = PIPE_FORMAT_R16_UNORM;
417       break;
418    case PIPE_FORMAT_Y210:
419    case PIPE_FORMAT_Y212:
420    case PIPE_FORMAT_Y216:
421       format = PIPE_FORMAT_R16G16_UNORM;
422       break;
423    case PIPE_FORMAT_Y410:
424       format = PIPE_FORMAT_R10G10B10A2_UNORM;
425       break;
426    case PIPE_FORMAT_Y412:
427    case PIPE_FORMAT_Y416:
428       format = PIPE_FORMAT_R16G16B16A16_UNORM;
429       break;
430    case PIPE_FORMAT_YUYV:
431    case PIPE_FORMAT_YVYU:
432    case PIPE_FORMAT_UYVY:
433    case PIPE_FORMAT_VYUY:
434       if (texObj->pt->format == PIPE_FORMAT_R8G8_R8B8_UNORM ||
435           texObj->pt->format == PIPE_FORMAT_R8B8_R8G8_UNORM ||
436           texObj->pt->format == PIPE_FORMAT_B8R8_G8R8_UNORM ||
437           texObj->pt->format == PIPE_FORMAT_G8R8_B8R8_UNORM) {
438          format = texObj->pt->format;
439          break;
440       }
441       format = PIPE_FORMAT_R8G8_UNORM;
442       break;
443    case PIPE_FORMAT_AYUV:
444       format = PIPE_FORMAT_RGBA8888_UNORM;
445       break;
446    case PIPE_FORMAT_XYUV:
447       format = PIPE_FORMAT_RGBX8888_UNORM;
448       break;
449    default:
450       break;
451    }
452    return format;
453 }
454 
455 static unsigned
gl_astc_decode_precision_to_pipe(GLint precision)456 gl_astc_decode_precision_to_pipe(GLint precision)
457 {
458    switch (precision) {
459    case GL_RGBA8:
460       return PIPE_ASTC_DECODE_FORMAT_UNORM8;
461    case GL_RGB9_E5:
462       return PIPE_ASTC_DECODE_FORMAT_RGB9E5;
463    case GL_RGBA16F:
464    default:
465       return PIPE_ASTC_DECODE_FORMAT_FLOAT16;
466    }
467 }
468 
469 static struct pipe_sampler_view *
st_create_texture_sampler_view_from_stobj(struct st_context * st,struct gl_texture_object * texObj,enum pipe_format format,bool glsl130_or_later)470 st_create_texture_sampler_view_from_stobj(struct st_context *st,
471                                           struct gl_texture_object *texObj,
472                                           enum pipe_format format,
473                                           bool glsl130_or_later)
474 {
475    /* There is no need to clear this structure (consider CPU overhead). */
476    struct pipe_sampler_view templ;
477    unsigned swizzle = glsl130_or_later ? texObj->SwizzleGLSL130 : texObj->Swizzle;
478 
479    templ.format = format;
480    templ.is_tex2d_from_buf = false;
481 
482    if (texObj->level_override >= 0) {
483       templ.u.tex.first_level = templ.u.tex.last_level = texObj->level_override;
484    } else {
485       templ.u.tex.first_level = texObj->Attrib.MinLevel +
486                                 texObj->Attrib.BaseLevel;
487       templ.u.tex.last_level = last_level(texObj);
488    }
489    if (texObj->layer_override >= 0) {
490       templ.u.tex.first_layer = templ.u.tex.last_layer = texObj->layer_override;
491    } else {
492       templ.u.tex.first_layer = texObj->Attrib.MinLayer;
493       templ.u.tex.last_layer = last_layer(texObj);
494    }
495    assert(templ.u.tex.first_layer <= templ.u.tex.last_layer);
496    assert(templ.u.tex.first_level <= templ.u.tex.last_level);
497    templ.target = gl_target_to_pipe(texObj->Target);
498 
499    templ.swizzle_r = GET_SWZ(swizzle, 0);
500    templ.swizzle_g = GET_SWZ(swizzle, 1);
501    templ.swizzle_b = GET_SWZ(swizzle, 2);
502    templ.swizzle_a = GET_SWZ(swizzle, 3);
503 
504    templ.astc_decode_format =
505       gl_astc_decode_precision_to_pipe(texObj->AstcDecodePrecision);
506 
507    return st->pipe->create_sampler_view(st->pipe, texObj->pt, &templ);
508 }
509 
510 struct pipe_sampler_view *
st_get_texture_sampler_view_from_stobj(struct st_context * st,struct gl_texture_object * texObj,const struct gl_sampler_object * samp,bool glsl130_or_later,bool ignore_srgb_decode,bool get_reference)511 st_get_texture_sampler_view_from_stobj(struct st_context *st,
512                                        struct gl_texture_object *texObj,
513                                        const struct gl_sampler_object *samp,
514                                        bool glsl130_or_later,
515                                        bool ignore_srgb_decode,
516                                        bool get_reference)
517 {
518    struct st_sampler_view *sv;
519    bool srgb_skip_decode = false;
520 
521    if (!ignore_srgb_decode && samp->Attrib.sRGBDecode == GL_SKIP_DECODE_EXT)
522       srgb_skip_decode = true;
523 
524    simple_mtx_lock(&texObj->validate_mutex);
525    sv = st_texture_get_current_sampler_view(st, texObj);
526 
527    if (sv &&
528        sv->glsl130_or_later == glsl130_or_later &&
529        sv->srgb_skip_decode == srgb_skip_decode) {
530       /* Debug check: make sure that the sampler view's parameters are
531        * what they're supposed to be.
532        */
533       struct pipe_sampler_view *view = sv->view;
534       assert(texObj->pt == view->texture);
535       assert(!check_sampler_swizzle(st, texObj, view, glsl130_or_later));
536       assert(st_get_sampler_view_format(st, texObj, srgb_skip_decode) == view->format);
537       assert(gl_target_to_pipe(texObj->Target) == view->target);
538       assert(texObj->level_override >= 0 ||
539              texObj->Attrib.MinLevel +
540              texObj->Attrib.BaseLevel == view->u.tex.first_level);
541       assert(texObj->level_override >= 0 || last_level(texObj) == view->u.tex.last_level);
542       assert(texObj->layer_override >= 0 ||
543              texObj->Attrib.MinLayer == view->u.tex.first_layer);
544       assert(texObj->layer_override >= 0 || last_layer(texObj) == view->u.tex.last_layer);
545       assert(texObj->layer_override < 0 ||
546              (texObj->layer_override == view->u.tex.first_layer &&
547               texObj->layer_override == view->u.tex.last_layer));
548       if (get_reference)
549          view = get_sampler_view_reference(sv, view);
550       simple_mtx_unlock(&texObj->validate_mutex);
551       return view;
552    }
553 
554    /* create new sampler view */
555    enum pipe_format format = st_get_sampler_view_format(st, texObj,
556                                                         srgb_skip_decode);
557    struct pipe_sampler_view *view =
558          st_create_texture_sampler_view_from_stobj(st, texObj, format,
559                                                    glsl130_or_later);
560 
561    view = st_texture_set_sampler_view(st, texObj, view,
562                                       glsl130_or_later, srgb_skip_decode,
563                                       get_reference, true);
564    simple_mtx_unlock(&texObj->validate_mutex);
565 
566    return view;
567 }
568 
569 
570 struct pipe_sampler_view *
st_get_buffer_sampler_view_from_stobj(struct st_context * st,struct gl_texture_object * texObj,bool get_reference)571 st_get_buffer_sampler_view_from_stobj(struct st_context *st,
572                                       struct gl_texture_object *texObj,
573                                       bool get_reference)
574 {
575    struct st_sampler_view *sv;
576    struct gl_buffer_object *stBuf =
577       texObj->BufferObject;
578 
579    if (!stBuf || !stBuf->buffer)
580       return NULL;
581 
582    sv = st_texture_get_current_sampler_view(st, texObj);
583 
584    struct pipe_resource *buf = stBuf->buffer;
585 
586    if (sv) {
587       struct pipe_sampler_view *view = sv->view;
588 
589       if (view->texture == buf) {
590          /* Debug check: make sure that the sampler view's parameters are
591           * what they're supposed to be.
592           */
593          assert(st_mesa_format_to_pipe_format(st,
594                                               texObj->_BufferObjectFormat)
595              == view->format);
596          assert(view->target == PIPE_BUFFER);
597          ASSERTED unsigned base = texObj->BufferOffset;
598          ASSERTED unsigned size = MIN2(buf->width0 - base,
599                            (unsigned) texObj->BufferSize);
600          assert(view->u.buf.offset == base);
601          assert(view->u.buf.size == size);
602          if (get_reference)
603             view = get_sampler_view_reference(sv, view);
604          return view;
605       }
606    }
607 
608    unsigned base = texObj->BufferOffset;
609 
610    if (base >= buf->width0)
611       return NULL;
612 
613    unsigned size = buf->width0 - base;
614    size = MIN2(size, (unsigned)texObj->BufferSize);
615    if (!size)
616       return NULL;
617 
618    /* Create a new sampler view. There is no need to clear the entire
619     * structure (consider CPU overhead).
620     */
621    struct pipe_sampler_view templ;
622 
623    templ.is_tex2d_from_buf = false;
624    templ.format =
625       st_mesa_format_to_pipe_format(st, texObj->_BufferObjectFormat);
626    templ.target = PIPE_BUFFER;
627    templ.swizzle_r = PIPE_SWIZZLE_X;
628    templ.swizzle_g = PIPE_SWIZZLE_Y;
629    templ.swizzle_b = PIPE_SWIZZLE_Z;
630    templ.swizzle_a = PIPE_SWIZZLE_W;
631    templ.u.buf.offset = base;
632    templ.u.buf.size = size;
633 
634    struct pipe_sampler_view *view =
635       st->pipe->create_sampler_view(st->pipe, buf, &templ);
636 
637    view = st_texture_set_sampler_view(st, texObj, view, false, false,
638                                       get_reference, false);
639 
640    return view;
641 }
642