glsl: lower mediump temporaries to 16 bits except structures (v2)
[mesa.git] / src / mesa / state_tracker / st_sampler_view.c
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_bufferobjects.h"
42 #include "st_cb_texture.h"
43
44
45 /**
46 * Set the given view as the current context's view for the texture.
47 *
48 * Overwrites any pre-existing view of the context.
49 *
50 * Takes ownership of the view (i.e., stores the view without incrementing the
51 * reference count).
52 *
53 * \return the view, or NULL on error. In case of error, the reference to the
54 * view is released.
55 */
56 static struct pipe_sampler_view *
57 st_texture_set_sampler_view(struct st_context *st,
58 struct st_texture_object *stObj,
59 struct pipe_sampler_view *view,
60 bool glsl130_or_later, bool srgb_skip_decode)
61 {
62 struct st_sampler_views *views;
63 struct st_sampler_view *free = NULL;
64 struct st_sampler_view *sv;
65 GLuint i;
66
67 simple_mtx_lock(&stObj->validate_mutex);
68 views = stObj->sampler_views;
69
70 for (i = 0; i < views->count; ++i) {
71 sv = &views->views[i];
72
73 /* Is the array entry used ? */
74 if (sv->view) {
75 /* check if the context matches */
76 if (sv->view->context == st->pipe) {
77 pipe_sampler_view_reference(&sv->view, NULL);
78 goto found;
79 }
80 } else {
81 /* Found a free slot, remember that */
82 free = sv;
83 }
84 }
85
86 /* Couldn't find a slot for our context, create a new one */
87 if (free) {
88 sv = free;
89 } else {
90 if (views->count >= views->max) {
91 /* Allocate a larger container. */
92 unsigned new_max = 2 * views->max;
93 unsigned new_size = sizeof(*views) + new_max * sizeof(views->views[0]);
94
95 if (new_max < views->max ||
96 new_max > (UINT_MAX - sizeof(*views)) / sizeof(views->views[0])) {
97 pipe_sampler_view_reference(&view, NULL);
98 goto out;
99 }
100
101 struct st_sampler_views *new_views = malloc(new_size);
102 if (!new_views) {
103 pipe_sampler_view_reference(&view, NULL);
104 goto out;
105 }
106
107 new_views->count = views->count;
108 new_views->max = new_max;
109 memcpy(&new_views->views[0], &views->views[0],
110 views->count * sizeof(views->views[0]));
111
112 /* Initialize the pipe_sampler_view pointers to zero so that we don't
113 * have to worry about racing against readers when incrementing
114 * views->count.
115 */
116 memset(&new_views->views[views->count], 0,
117 (new_max - views->count) * sizeof(views->views[0]));
118
119 /* Use memory release semantics to ensure that concurrent readers will
120 * get the correct contents of the new container.
121 *
122 * Also, the write should be atomic, but that's guaranteed anyway on
123 * all supported platforms.
124 */
125 p_atomic_set(&stObj->sampler_views, new_views);
126
127 /* We keep the old container around until the texture object is
128 * deleted, because another thread may still be reading from it. We
129 * double the size of the container each time, so we end up with
130 * at most twice the total memory allocation.
131 */
132 views->next = stObj->sampler_views_old;
133 stObj->sampler_views_old = views;
134
135 views = new_views;
136 }
137
138 sv = &views->views[views->count];
139
140 /* Since modification is guarded by the lock, only the write part of the
141 * increment has to be atomic, and that's already guaranteed on all
142 * supported platforms without using an atomic intrinsic.
143 */
144 views->count++;
145 }
146
147 found:
148 assert(sv->view == NULL);
149
150 sv->glsl130_or_later = glsl130_or_later;
151 sv->srgb_skip_decode = srgb_skip_decode;
152 sv->view = view;
153 sv->st = st;
154
155 out:
156 simple_mtx_unlock(&stObj->validate_mutex);
157 return view;
158 }
159
160
161 /**
162 * Return the most-recently validated sampler view for the texture \p stObj
163 * in the given context, if any.
164 *
165 * Performs no additional validation.
166 */
167 const struct st_sampler_view *
168 st_texture_get_current_sampler_view(const struct st_context *st,
169 const struct st_texture_object *stObj)
170 {
171 const struct st_sampler_views *views = p_atomic_read(&stObj->sampler_views);
172
173 for (unsigned i = 0; i < views->count; ++i) {
174 const struct st_sampler_view *sv = &views->views[i];
175 if (sv->view && sv->view->context == st->pipe)
176 return sv;
177 }
178
179 return NULL;
180 }
181
182
183 /**
184 * For the given texture object, release any sampler views which belong
185 * to the calling context. This is used to free any sampler views
186 * which belong to the context before the context is destroyed.
187 */
188 void
189 st_texture_release_context_sampler_view(struct st_context *st,
190 struct st_texture_object *stObj)
191 {
192 GLuint i;
193
194 simple_mtx_lock(&stObj->validate_mutex);
195 struct st_sampler_views *views = stObj->sampler_views;
196 for (i = 0; i < views->count; ++i) {
197 struct pipe_sampler_view **sv = &views->views[i].view;
198
199 if (*sv && (*sv)->context == st->pipe) {
200 pipe_sampler_view_reference(sv, NULL);
201 break;
202 }
203 }
204 simple_mtx_unlock(&stObj->validate_mutex);
205 }
206
207
208 /**
209 * Release all sampler views attached to the given texture object, regardless
210 * of the context. This is called fairly frequently. For example, whenever
211 * the texture's base level, max level or swizzle change.
212 */
213 void
214 st_texture_release_all_sampler_views(struct st_context *st,
215 struct st_texture_object *stObj)
216 {
217 /* TODO: This happens while a texture is deleted, because the Driver API
218 * is asymmetric: the driver allocates the texture object memory, but
219 * mesa/main frees it.
220 */
221 if (!stObj->sampler_views)
222 return;
223
224 simple_mtx_lock(&stObj->validate_mutex);
225 struct st_sampler_views *views = stObj->sampler_views;
226 for (unsigned i = 0; i < views->count; ++i) {
227 struct st_sampler_view *stsv = &views->views[i];
228 if (stsv->view) {
229 if (stsv->st && stsv->st != st) {
230 /* Transfer this reference to the zombie list. It will
231 * likely be freed when the zombie list is freed.
232 */
233 st_save_zombie_sampler_view(stsv->st, stsv->view);
234 stsv->view = NULL;
235 } else {
236 pipe_sampler_view_reference(&stsv->view, NULL);
237 }
238 }
239 }
240 views->count = 0;
241 simple_mtx_unlock(&stObj->validate_mutex);
242 }
243
244
245 /*
246 * Delete the texture's sampler views and st_sampler_views containers.
247 * This is to be called just before a texture is deleted.
248 */
249 void
250 st_delete_texture_sampler_views(struct st_context *st,
251 struct st_texture_object *stObj)
252 {
253 st_texture_release_all_sampler_views(st, stObj);
254
255 /* Free the container of the current per-context sampler views */
256 assert(stObj->sampler_views->count == 0);
257 free(stObj->sampler_views);
258 stObj->sampler_views = NULL;
259
260 /* Free old sampler view containers */
261 while (stObj->sampler_views_old) {
262 struct st_sampler_views *views = stObj->sampler_views_old;
263 stObj->sampler_views_old = views->next;
264 free(views);
265 }
266 }
267
268
269 /**
270 * Return swizzle1(swizzle2)
271 */
272 static unsigned
273 swizzle_swizzle(unsigned swizzle1, unsigned swizzle2)
274 {
275 unsigned i, swz[4];
276
277 if (swizzle1 == SWIZZLE_XYZW) {
278 /* identity swizzle, no change to swizzle2 */
279 return swizzle2;
280 }
281
282 for (i = 0; i < 4; i++) {
283 unsigned s = GET_SWZ(swizzle1, i);
284 switch (s) {
285 case SWIZZLE_X:
286 case SWIZZLE_Y:
287 case SWIZZLE_Z:
288 case SWIZZLE_W:
289 swz[i] = GET_SWZ(swizzle2, s);
290 break;
291 case SWIZZLE_ZERO:
292 swz[i] = SWIZZLE_ZERO;
293 break;
294 case SWIZZLE_ONE:
295 swz[i] = SWIZZLE_ONE;
296 break;
297 default:
298 assert(!"Bad swizzle term");
299 swz[i] = SWIZZLE_X;
300 }
301 }
302
303 return MAKE_SWIZZLE4(swz[0], swz[1], swz[2], swz[3]);
304 }
305
306
307 /**
308 * Given a user-specified texture base format, the actual gallium texture
309 * format and the current GL_DEPTH_MODE, return a texture swizzle.
310 *
311 * Consider the case where the user requests a GL_RGB internal texture
312 * format the driver actually uses an RGBA format. The A component should
313 * be ignored and sampling from the texture should always return (r,g,b,1).
314 * But if we rendered to the texture we might have written A values != 1.
315 * By sampling the texture with a ".xyz1" swizzle we'll get the expected A=1.
316 * This function computes the texture swizzle needed to get the expected
317 * values.
318 *
319 * In the case of depth textures, the GL_DEPTH_MODE state determines the
320 * texture swizzle.
321 *
322 * This result must be composed with the user-specified swizzle to get
323 * the final swizzle.
324 */
325 static unsigned
326 compute_texture_format_swizzle(GLenum baseFormat, GLenum depthMode,
327 bool glsl130_or_later)
328 {
329 switch (baseFormat) {
330 case GL_RGBA:
331 return SWIZZLE_XYZW;
332 case GL_RGB:
333 return MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_ONE);
334 case GL_RG:
335 return MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_ZERO, SWIZZLE_ONE);
336 case GL_RED:
337 return MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_ZERO,
338 SWIZZLE_ZERO, SWIZZLE_ONE);
339 case GL_ALPHA:
340 return MAKE_SWIZZLE4(SWIZZLE_ZERO, SWIZZLE_ZERO,
341 SWIZZLE_ZERO, SWIZZLE_W);
342 case GL_LUMINANCE:
343 return MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_X, SWIZZLE_X, SWIZZLE_ONE);
344 case GL_LUMINANCE_ALPHA:
345 return MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_X, SWIZZLE_X, SWIZZLE_W);
346 case GL_INTENSITY:
347 return SWIZZLE_XXXX;
348 case GL_STENCIL_INDEX:
349 case GL_DEPTH_STENCIL:
350 case GL_DEPTH_COMPONENT:
351 /* Now examine the depth mode */
352 switch (depthMode) {
353 case GL_LUMINANCE:
354 return MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_X, SWIZZLE_X, SWIZZLE_ONE);
355 case GL_INTENSITY:
356 return MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_X, SWIZZLE_X, SWIZZLE_X);
357 case GL_ALPHA:
358 /* The texture(sampler*Shadow) functions from GLSL 1.30 ignore
359 * the depth mode and return float, while older shadow* functions
360 * and ARB_fp instructions return vec4 according to the depth mode.
361 *
362 * The problem with the GLSL 1.30 functions is that GL_ALPHA forces
363 * them to return 0, breaking them completely.
364 *
365 * A proper fix would increase code complexity and that's not worth
366 * it for a rarely used feature such as the GL_ALPHA depth mode
367 * in GL3. Therefore, change GL_ALPHA to GL_INTENSITY for all
368 * shaders that use GLSL 1.30 or later.
369 *
370 * BTW, it's required that sampler views are updated when
371 * shaders change (check_sampler_swizzle takes care of that).
372 */
373 if (glsl130_or_later)
374 return SWIZZLE_XXXX;
375 else
376 return MAKE_SWIZZLE4(SWIZZLE_ZERO, SWIZZLE_ZERO,
377 SWIZZLE_ZERO, SWIZZLE_X);
378 case GL_RED:
379 return MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_ZERO,
380 SWIZZLE_ZERO, SWIZZLE_ONE);
381 default:
382 assert(!"Unexpected depthMode");
383 return SWIZZLE_XYZW;
384 }
385 default:
386 assert(!"Unexpected baseFormat");
387 return SWIZZLE_XYZW;
388 }
389 }
390
391
392 static unsigned
393 get_texture_format_swizzle(const struct st_context *st,
394 const struct st_texture_object *stObj,
395 bool glsl130_or_later)
396 {
397 GLenum baseFormat = _mesa_base_tex_image(&stObj->base)->_BaseFormat;
398 unsigned tex_swizzle;
399 GLenum depth_mode = stObj->base.DepthMode;
400
401 /* In ES 3.0, DEPTH_TEXTURE_MODE is expected to be GL_RED for textures
402 * with depth component data specified with a sized internal format.
403 */
404 if (_mesa_is_gles3(st->ctx) &&
405 (baseFormat == GL_DEPTH_COMPONENT ||
406 baseFormat == GL_DEPTH_STENCIL ||
407 baseFormat == GL_STENCIL_INDEX)) {
408 const struct gl_texture_image *firstImage =
409 _mesa_base_tex_image(&stObj->base);
410 if (firstImage->InternalFormat != GL_DEPTH_COMPONENT &&
411 firstImage->InternalFormat != GL_DEPTH_STENCIL &&
412 firstImage->InternalFormat != GL_STENCIL_INDEX)
413 depth_mode = GL_RED;
414 }
415 tex_swizzle = compute_texture_format_swizzle(baseFormat,
416 depth_mode,
417 glsl130_or_later);
418
419 /* Combine the texture format swizzle with user's swizzle */
420 return swizzle_swizzle(stObj->base._Swizzle, tex_swizzle);
421 }
422
423
424 /**
425 * Return TRUE if the texture's sampler view swizzle is not equal to
426 * the texture's swizzle.
427 *
428 * \param stObj the st texture object,
429 */
430 ASSERTED static boolean
431 check_sampler_swizzle(const struct st_context *st,
432 const struct st_texture_object *stObj,
433 const struct pipe_sampler_view *sv,
434 bool glsl130_or_later)
435 {
436 unsigned swizzle = get_texture_format_swizzle(st, stObj, glsl130_or_later);
437
438 return ((sv->swizzle_r != GET_SWZ(swizzle, 0)) ||
439 (sv->swizzle_g != GET_SWZ(swizzle, 1)) ||
440 (sv->swizzle_b != GET_SWZ(swizzle, 2)) ||
441 (sv->swizzle_a != GET_SWZ(swizzle, 3)));
442 }
443
444
445 static unsigned
446 last_level(const struct st_texture_object *stObj)
447 {
448 unsigned ret = MIN2(stObj->base.MinLevel + stObj->base._MaxLevel,
449 stObj->pt->last_level);
450 if (stObj->base.Immutable)
451 ret = MIN2(ret, stObj->base.MinLevel + stObj->base.NumLevels - 1);
452 return ret;
453 }
454
455
456 static unsigned
457 last_layer(const struct st_texture_object *stObj)
458 {
459 if (stObj->base.Immutable && stObj->pt->array_size > 1)
460 return MIN2(stObj->base.MinLayer + stObj->base.NumLayers - 1,
461 stObj->pt->array_size - 1);
462 return stObj->pt->array_size - 1;
463 }
464
465
466 /**
467 * Determine the format for the texture sampler view.
468 */
469 static enum pipe_format
470 get_sampler_view_format(struct st_context *st,
471 const struct st_texture_object *stObj,
472 bool srgb_skip_decode)
473 {
474 enum pipe_format format;
475
476 GLenum baseFormat = _mesa_base_tex_image(&stObj->base)->_BaseFormat;
477 format = stObj->surface_based ? stObj->surface_format : stObj->pt->format;
478
479 if (baseFormat == GL_DEPTH_COMPONENT ||
480 baseFormat == GL_DEPTH_STENCIL ||
481 baseFormat == GL_STENCIL_INDEX) {
482 if (stObj->base.StencilSampling || baseFormat == GL_STENCIL_INDEX)
483 format = util_format_stencil_only(format);
484
485 return format;
486 }
487
488 /* If sRGB decoding is off, use the linear format */
489 if (srgb_skip_decode)
490 format = util_format_linear(format);
491
492 /* if resource format matches then YUV wasn't lowered */
493 if (format == stObj->pt->format)
494 return format;
495
496 /* Use R8_UNORM for video formats */
497 switch (format) {
498 case PIPE_FORMAT_NV12:
499 case PIPE_FORMAT_IYUV:
500 format = PIPE_FORMAT_R8_UNORM;
501 break;
502 case PIPE_FORMAT_P010:
503 case PIPE_FORMAT_P016:
504 format = PIPE_FORMAT_R16_UNORM;
505 break;
506 case PIPE_FORMAT_YUYV:
507 case PIPE_FORMAT_UYVY:
508 format = PIPE_FORMAT_R8G8_UNORM;
509 break;
510 case PIPE_FORMAT_AYUV:
511 format = PIPE_FORMAT_RGBA8888_UNORM;
512 break;
513 case PIPE_FORMAT_XYUV:
514 format = PIPE_FORMAT_RGBX8888_UNORM;
515 break;
516 default:
517 break;
518 }
519 return format;
520 }
521
522
523 static struct pipe_sampler_view *
524 st_create_texture_sampler_view_from_stobj(struct st_context *st,
525 struct st_texture_object *stObj,
526 enum pipe_format format,
527 bool glsl130_or_later)
528 {
529 /* There is no need to clear this structure (consider CPU overhead). */
530 struct pipe_sampler_view templ;
531 unsigned swizzle = get_texture_format_swizzle(st, stObj, glsl130_or_later);
532
533 templ.format = format;
534
535 if (stObj->level_override >= 0) {
536 templ.u.tex.first_level = templ.u.tex.last_level = stObj->level_override;
537 } else {
538 templ.u.tex.first_level = stObj->base.MinLevel + stObj->base.BaseLevel;
539 templ.u.tex.last_level = last_level(stObj);
540 }
541 if (stObj->layer_override >= 0) {
542 templ.u.tex.first_layer = templ.u.tex.last_layer = stObj->layer_override;
543 } else {
544 templ.u.tex.first_layer = stObj->base.MinLayer;
545 templ.u.tex.last_layer = last_layer(stObj);
546 }
547 assert(templ.u.tex.first_layer <= templ.u.tex.last_layer);
548 assert(templ.u.tex.first_level <= templ.u.tex.last_level);
549 templ.target = gl_target_to_pipe(stObj->base.Target);
550
551 templ.swizzle_r = GET_SWZ(swizzle, 0);
552 templ.swizzle_g = GET_SWZ(swizzle, 1);
553 templ.swizzle_b = GET_SWZ(swizzle, 2);
554 templ.swizzle_a = GET_SWZ(swizzle, 3);
555
556 return st->pipe->create_sampler_view(st->pipe, stObj->pt, &templ);
557 }
558
559
560 struct pipe_sampler_view *
561 st_get_texture_sampler_view_from_stobj(struct st_context *st,
562 struct st_texture_object *stObj,
563 const struct gl_sampler_object *samp,
564 bool glsl130_or_later,
565 bool ignore_srgb_decode)
566 {
567 const struct st_sampler_view *sv;
568 bool srgb_skip_decode = false;
569
570 if (!ignore_srgb_decode && samp->sRGBDecode == GL_SKIP_DECODE_EXT)
571 srgb_skip_decode = true;
572
573 sv = st_texture_get_current_sampler_view(st, stObj);
574
575 if (sv &&
576 sv->glsl130_or_later == glsl130_or_later &&
577 sv->srgb_skip_decode == srgb_skip_decode) {
578 /* Debug check: make sure that the sampler view's parameters are
579 * what they're supposed to be.
580 */
581 struct pipe_sampler_view *view = sv->view;
582 assert(stObj->pt == view->texture);
583 assert(!check_sampler_swizzle(st, stObj, view, glsl130_or_later));
584 assert(get_sampler_view_format(st, stObj, srgb_skip_decode) == view->format);
585 assert(gl_target_to_pipe(stObj->base.Target) == view->target);
586 assert(stObj->level_override >= 0 ||
587 stObj->base.MinLevel + stObj->base.BaseLevel == view->u.tex.first_level);
588 assert(stObj->level_override >= 0 || last_level(stObj) == view->u.tex.last_level);
589 assert(stObj->layer_override >= 0 || stObj->base.MinLayer == view->u.tex.first_layer);
590 assert(stObj->layer_override >= 0 || last_layer(stObj) == view->u.tex.last_layer);
591 assert(stObj->layer_override < 0 ||
592 (stObj->layer_override == view->u.tex.first_layer &&
593 stObj->layer_override == view->u.tex.last_layer));
594 return view;
595 }
596
597 /* create new sampler view */
598 enum pipe_format format = get_sampler_view_format(st, stObj,
599 srgb_skip_decode);
600 struct pipe_sampler_view *view =
601 st_create_texture_sampler_view_from_stobj(st, stObj, format,
602 glsl130_or_later);
603
604 view = st_texture_set_sampler_view(st, stObj, view,
605 glsl130_or_later, srgb_skip_decode);
606
607 return view;
608 }
609
610
611 struct pipe_sampler_view *
612 st_get_buffer_sampler_view_from_stobj(struct st_context *st,
613 struct st_texture_object *stObj)
614 {
615 const struct st_sampler_view *sv;
616 struct st_buffer_object *stBuf =
617 st_buffer_object(stObj->base.BufferObject);
618
619 if (!stBuf || !stBuf->buffer)
620 return NULL;
621
622 sv = st_texture_get_current_sampler_view(st, stObj);
623
624 struct pipe_resource *buf = stBuf->buffer;
625
626 if (sv) {
627 struct pipe_sampler_view *view = sv->view;
628
629 if (view->texture == buf) {
630 /* Debug check: make sure that the sampler view's parameters are
631 * what they're supposed to be.
632 */
633 assert(st_mesa_format_to_pipe_format(st,
634 stObj->base._BufferObjectFormat)
635 == view->format);
636 assert(view->target == PIPE_BUFFER);
637 ASSERTED unsigned base = stObj->base.BufferOffset;
638 ASSERTED unsigned size = MIN2(buf->width0 - base,
639 (unsigned) stObj->base.BufferSize);
640 assert(view->u.buf.offset == base);
641 assert(view->u.buf.size == size);
642 return view;
643 }
644 }
645
646 unsigned base = stObj->base.BufferOffset;
647
648 if (base >= buf->width0)
649 return NULL;
650
651 unsigned size = buf->width0 - base;
652 size = MIN2(size, (unsigned)stObj->base.BufferSize);
653 if (!size)
654 return NULL;
655
656 /* Create a new sampler view. There is no need to clear the entire
657 * structure (consider CPU overhead).
658 */
659 struct pipe_sampler_view templ;
660
661 templ.format =
662 st_mesa_format_to_pipe_format(st, stObj->base._BufferObjectFormat);
663 templ.target = PIPE_BUFFER;
664 templ.swizzle_r = PIPE_SWIZZLE_X;
665 templ.swizzle_g = PIPE_SWIZZLE_Y;
666 templ.swizzle_b = PIPE_SWIZZLE_Z;
667 templ.swizzle_a = PIPE_SWIZZLE_W;
668 templ.u.buf.offset = base;
669 templ.u.buf.size = size;
670
671 struct pipe_sampler_view *view =
672 st->pipe->create_sampler_view(st->pipe, buf, &templ);
673
674 view = st_texture_set_sampler_view(st, stObj, view, false, false);
675
676 return view;
677 }