2 * Copyright © 2014-2017 Broadcom
3 * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 #include "pipe/p_state.h"
26 #include "util/u_format.h"
27 #include "util/u_inlines.h"
28 #include "util/u_math.h"
29 #include "util/u_memory.h"
30 #include "util/u_half.h"
31 #include "util/u_helpers.h"
33 #include "vc5_context.h"
34 #include "vc5_tiling.h"
35 #include "broadcom/common/v3d_macros.h"
36 #include "broadcom/cle/v3dx_pack.h"
39 vc5_generic_cso_state_create(const void *src
, uint32_t size
)
41 void *dst
= calloc(1, size
);
44 memcpy(dst
, src
, size
);
49 vc5_generic_cso_state_delete(struct pipe_context
*pctx
, void *hwcso
)
55 vc5_set_blend_color(struct pipe_context
*pctx
,
56 const struct pipe_blend_color
*blend_color
)
58 struct vc5_context
*vc5
= vc5_context(pctx
);
59 vc5
->blend_color
.f
= *blend_color
;
60 for (int i
= 0; i
< 4; i
++) {
61 vc5
->blend_color
.hf
[i
] =
62 util_float_to_half(blend_color
->color
[i
]);
64 vc5
->dirty
|= VC5_DIRTY_BLEND_COLOR
;
68 vc5_set_stencil_ref(struct pipe_context
*pctx
,
69 const struct pipe_stencil_ref
*stencil_ref
)
71 struct vc5_context
*vc5
= vc5_context(pctx
);
72 vc5
->stencil_ref
= *stencil_ref
;
73 vc5
->dirty
|= VC5_DIRTY_STENCIL_REF
;
77 vc5_set_clip_state(struct pipe_context
*pctx
,
78 const struct pipe_clip_state
*clip
)
80 struct vc5_context
*vc5
= vc5_context(pctx
);
82 vc5
->dirty
|= VC5_DIRTY_CLIP
;
86 vc5_set_sample_mask(struct pipe_context
*pctx
, unsigned sample_mask
)
88 struct vc5_context
*vc5
= vc5_context(pctx
);
89 vc5
->sample_mask
= sample_mask
& ((1 << VC5_MAX_SAMPLES
) - 1);
90 vc5
->dirty
|= VC5_DIRTY_SAMPLE_MASK
;
94 float_to_187_half(float f
)
100 vc5_create_rasterizer_state(struct pipe_context
*pctx
,
101 const struct pipe_rasterizer_state
*cso
)
103 struct vc5_rasterizer_state
*so
;
105 so
= CALLOC_STRUCT(vc5_rasterizer_state
);
111 /* Workaround: HW-2726 PTB does not handle zero-size points (BCM2835,
114 so
->point_size
= MAX2(cso
->point_size
, .125f
);
116 if (cso
->offset_tri
) {
117 so
->offset_units
= float_to_187_half(cso
->offset_units
);
118 so
->offset_factor
= float_to_187_half(cso
->offset_scale
);
124 /* Blend state is baked into shaders. */
126 vc5_create_blend_state(struct pipe_context
*pctx
,
127 const struct pipe_blend_state
*cso
)
129 return vc5_generic_cso_state_create(cso
, sizeof(*cso
));
133 translate_stencil_op(enum pipe_stencil_op op
)
136 case PIPE_STENCIL_OP_KEEP
: return V3D_STENCIL_OP_KEEP
;
137 case PIPE_STENCIL_OP_ZERO
: return V3D_STENCIL_OP_ZERO
;
138 case PIPE_STENCIL_OP_REPLACE
: return V3D_STENCIL_OP_REPLACE
;
139 case PIPE_STENCIL_OP_INCR
: return V3D_STENCIL_OP_INCR
;
140 case PIPE_STENCIL_OP_DECR
: return V3D_STENCIL_OP_DECR
;
141 case PIPE_STENCIL_OP_INCR_WRAP
: return V3D_STENCIL_OP_INCWRAP
;
142 case PIPE_STENCIL_OP_DECR_WRAP
: return V3D_STENCIL_OP_DECWRAP
;
143 case PIPE_STENCIL_OP_INVERT
: return V3D_STENCIL_OP_INVERT
;
145 unreachable("bad stencil op");
149 vc5_create_depth_stencil_alpha_state(struct pipe_context
*pctx
,
150 const struct pipe_depth_stencil_alpha_state
*cso
)
152 struct vc5_depth_stencil_alpha_state
*so
;
154 so
= CALLOC_STRUCT(vc5_depth_stencil_alpha_state
);
160 if (cso
->depth
.enabled
) {
161 switch (cso
->depth
.func
) {
163 case PIPE_FUNC_LEQUAL
:
164 so
->ez_state
= VC5_EZ_LT_LE
;
166 case PIPE_FUNC_GREATER
:
167 case PIPE_FUNC_GEQUAL
:
168 so
->ez_state
= VC5_EZ_GT_GE
;
170 case PIPE_FUNC_NEVER
:
171 case PIPE_FUNC_EQUAL
:
172 so
->ez_state
= VC5_EZ_UNDECIDED
;
175 so
->ez_state
= VC5_EZ_DISABLED
;
179 /* If stencil is enabled and it's not a no-op, then it would
182 if (cso
->stencil
[0].enabled
&&
183 (cso
->stencil
[0].zfail_op
!= PIPE_STENCIL_OP_KEEP
||
184 cso
->stencil
[0].func
!= PIPE_FUNC_ALWAYS
||
185 (cso
->stencil
[1].enabled
&&
186 (cso
->stencil
[1].zfail_op
!= PIPE_STENCIL_OP_KEEP
&&
187 cso
->stencil
[1].func
!= PIPE_FUNC_ALWAYS
)))) {
188 so
->ez_state
= VC5_EZ_DISABLED
;
192 const struct pipe_stencil_state
*front
= &cso
->stencil
[0];
193 const struct pipe_stencil_state
*back
= &cso
->stencil
[1];
195 if (front
->enabled
) {
196 v3dx_pack(&so
->stencil_front
, STENCIL_CONFIG
, config
) {
197 config
.front_config
= true;
198 /* If !back->enabled, then the front values should be
199 * used for both front and back-facing primitives.
201 config
.back_config
= !back
->enabled
;
203 config
.stencil_write_mask
= front
->writemask
;
204 config
.stencil_test_mask
= front
->valuemask
;
206 config
.stencil_test_function
= front
->func
;
207 config
.stencil_pass_op
=
208 translate_stencil_op(front
->zpass_op
);
209 config
.depth_test_fail_op
=
210 translate_stencil_op(front
->zfail_op
);
211 config
.stencil_test_fail_op
=
212 translate_stencil_op(front
->fail_op
);
216 v3dx_pack(&so
->stencil_back
, STENCIL_CONFIG
, config
) {
217 config
.front_config
= false;
218 config
.back_config
= true;
220 config
.stencil_write_mask
= back
->writemask
;
221 config
.stencil_test_mask
= back
->valuemask
;
223 config
.stencil_test_function
= back
->func
;
224 config
.stencil_pass_op
=
225 translate_stencil_op(back
->zpass_op
);
226 config
.depth_test_fail_op
=
227 translate_stencil_op(back
->zfail_op
);
228 config
.stencil_test_fail_op
=
229 translate_stencil_op(back
->fail_op
);
237 vc5_set_polygon_stipple(struct pipe_context
*pctx
,
238 const struct pipe_poly_stipple
*stipple
)
240 struct vc5_context
*vc5
= vc5_context(pctx
);
241 vc5
->stipple
= *stipple
;
242 vc5
->dirty
|= VC5_DIRTY_STIPPLE
;
246 vc5_set_scissor_states(struct pipe_context
*pctx
,
248 unsigned num_scissors
,
249 const struct pipe_scissor_state
*scissor
)
251 struct vc5_context
*vc5
= vc5_context(pctx
);
253 vc5
->scissor
= *scissor
;
254 vc5
->dirty
|= VC5_DIRTY_SCISSOR
;
258 vc5_set_viewport_states(struct pipe_context
*pctx
,
260 unsigned num_viewports
,
261 const struct pipe_viewport_state
*viewport
)
263 struct vc5_context
*vc5
= vc5_context(pctx
);
264 vc5
->viewport
= *viewport
;
265 vc5
->dirty
|= VC5_DIRTY_VIEWPORT
;
269 vc5_set_vertex_buffers(struct pipe_context
*pctx
,
270 unsigned start_slot
, unsigned count
,
271 const struct pipe_vertex_buffer
*vb
)
273 struct vc5_context
*vc5
= vc5_context(pctx
);
274 struct vc5_vertexbuf_stateobj
*so
= &vc5
->vertexbuf
;
276 util_set_vertex_buffers_mask(so
->vb
, &so
->enabled_mask
, vb
,
278 so
->count
= util_last_bit(so
->enabled_mask
);
280 vc5
->dirty
|= VC5_DIRTY_VTXBUF
;
284 vc5_blend_state_bind(struct pipe_context
*pctx
, void *hwcso
)
286 struct vc5_context
*vc5
= vc5_context(pctx
);
288 vc5
->dirty
|= VC5_DIRTY_BLEND
;
292 vc5_rasterizer_state_bind(struct pipe_context
*pctx
, void *hwcso
)
294 struct vc5_context
*vc5
= vc5_context(pctx
);
295 vc5
->rasterizer
= hwcso
;
296 vc5
->dirty
|= VC5_DIRTY_RASTERIZER
;
300 vc5_zsa_state_bind(struct pipe_context
*pctx
, void *hwcso
)
302 struct vc5_context
*vc5
= vc5_context(pctx
);
304 vc5
->dirty
|= VC5_DIRTY_ZSA
;
308 vc5_vertex_state_create(struct pipe_context
*pctx
, unsigned num_elements
,
309 const struct pipe_vertex_element
*elements
)
311 struct vc5_context
*vc5
= vc5_context(pctx
);
312 struct vc5_vertex_stateobj
*so
= CALLOC_STRUCT(vc5_vertex_stateobj
);
317 memcpy(so
->pipe
, elements
, sizeof(*elements
) * num_elements
);
318 so
->num_elements
= num_elements
;
320 for (int i
= 0; i
< so
->num_elements
; i
++) {
321 const struct pipe_vertex_element
*elem
= &elements
[i
];
322 const struct util_format_description
*desc
=
323 util_format_description(elem
->src_format
);
324 uint32_t r_size
= desc
->channel
[0].size
;
326 const uint32_t size
=
327 cl_packet_length(GL_SHADER_STATE_ATTRIBUTE_RECORD
);
329 v3dx_pack(&so
->attrs
[i
* size
],
330 GL_SHADER_STATE_ATTRIBUTE_RECORD
, attr
) {
331 /* vec_size == 0 means 4 */
332 attr
.vec_size
= desc
->nr_channels
& 3;
333 attr
.signed_int_type
= (desc
->channel
[0].type
==
334 UTIL_FORMAT_TYPE_SIGNED
);
336 attr
.normalized_int_type
= desc
->channel
[0].normalized
;
337 attr
.read_as_int_uint
= desc
->channel
[0].pure_integer
;
338 attr
.instance_divisor
= MIN2(elem
->instance_divisor
,
341 switch (desc
->channel
[0].type
) {
342 case UTIL_FORMAT_TYPE_FLOAT
:
344 attr
.type
= ATTRIBUTE_FLOAT
;
346 assert(r_size
== 16);
347 attr
.type
= ATTRIBUTE_HALF_FLOAT
;
351 case UTIL_FORMAT_TYPE_SIGNED
:
352 case UTIL_FORMAT_TYPE_UNSIGNED
:
355 attr
.type
= ATTRIBUTE_INT
;
358 attr
.type
= ATTRIBUTE_SHORT
;
361 attr
.type
= ATTRIBUTE_INT2_10_10_10
;
364 attr
.type
= ATTRIBUTE_BYTE
;
368 "format %s unsupported\n",
370 attr
.type
= ATTRIBUTE_BYTE
;
377 "format %s unsupported\n",
384 /* Set up the default attribute values in case any of the vertex
387 so
->default_attribute_values
= vc5_bo_alloc(vc5
->screen
,
390 "default attributes");
391 uint32_t *attrs
= vc5_bo_map(so
->default_attribute_values
);
392 for (int i
= 0; i
< VC5_MAX_ATTRIBUTES
; i
++) {
393 attrs
[i
* 4 + 0] = 0;
394 attrs
[i
* 4 + 1] = 0;
395 attrs
[i
* 4 + 2] = 0;
396 if (i
< so
->num_elements
&&
397 util_format_is_pure_integer(so
->pipe
[i
].src_format
)) {
398 attrs
[i
* 4 + 3] = 1;
400 attrs
[i
* 4 + 3] = fui(1.0);
408 vc5_vertex_state_bind(struct pipe_context
*pctx
, void *hwcso
)
410 struct vc5_context
*vc5
= vc5_context(pctx
);
412 vc5
->dirty
|= VC5_DIRTY_VTXSTATE
;
416 vc5_set_constant_buffer(struct pipe_context
*pctx
, uint shader
, uint index
,
417 const struct pipe_constant_buffer
*cb
)
419 struct vc5_context
*vc5
= vc5_context(pctx
);
420 struct vc5_constbuf_stateobj
*so
= &vc5
->constbuf
[shader
];
422 util_copy_constant_buffer(&so
->cb
[index
], cb
);
424 /* Note that the state tracker can unbind constant buffers by
428 so
->enabled_mask
&= ~(1 << index
);
429 so
->dirty_mask
&= ~(1 << index
);
433 so
->enabled_mask
|= 1 << index
;
434 so
->dirty_mask
|= 1 << index
;
435 vc5
->dirty
|= VC5_DIRTY_CONSTBUF
;
439 vc5_set_framebuffer_state(struct pipe_context
*pctx
,
440 const struct pipe_framebuffer_state
*framebuffer
)
442 struct vc5_context
*vc5
= vc5_context(pctx
);
443 struct pipe_framebuffer_state
*cso
= &vc5
->framebuffer
;
448 for (i
= 0; i
< framebuffer
->nr_cbufs
; i
++)
449 pipe_surface_reference(&cso
->cbufs
[i
], framebuffer
->cbufs
[i
]);
450 for (; i
< vc5
->framebuffer
.nr_cbufs
; i
++)
451 pipe_surface_reference(&cso
->cbufs
[i
], NULL
);
453 cso
->nr_cbufs
= framebuffer
->nr_cbufs
;
455 pipe_surface_reference(&cso
->zsbuf
, framebuffer
->zsbuf
);
457 cso
->width
= framebuffer
->width
;
458 cso
->height
= framebuffer
->height
;
460 vc5
->swap_color_rb
= 0;
461 vc5
->blend_dst_alpha_one
= 0;
462 for (int i
= 0; i
< vc5
->framebuffer
.nr_cbufs
; i
++) {
463 struct pipe_surface
*cbuf
= vc5
->framebuffer
.cbufs
[i
];
467 const struct util_format_description
*desc
=
468 util_format_description(cbuf
->format
);
470 /* For BGRA8 formats (DRI window system default format), we
471 * need to swap R and B, since the HW's format is RGBA8.
473 if (desc
->swizzle
[0] == PIPE_SWIZZLE_Z
&&
474 cbuf
->format
!= PIPE_FORMAT_B5G6R5_UNORM
) {
475 vc5
->swap_color_rb
|= 1 << i
;
478 if (desc
->swizzle
[3] == PIPE_SWIZZLE_1
)
479 vc5
->blend_dst_alpha_one
|= 1 << i
;
482 vc5
->dirty
|= VC5_DIRTY_FRAMEBUFFER
;
485 static struct vc5_texture_stateobj
*
486 vc5_get_stage_tex(struct vc5_context
*vc5
, enum pipe_shader_type shader
)
489 case PIPE_SHADER_FRAGMENT
:
490 vc5
->dirty
|= VC5_DIRTY_FRAGTEX
;
491 return &vc5
->fragtex
;
493 case PIPE_SHADER_VERTEX
:
494 vc5
->dirty
|= VC5_DIRTY_VERTTEX
;
495 return &vc5
->verttex
;
498 fprintf(stderr
, "Unknown shader target %d\n", shader
);
503 static uint32_t translate_wrap(uint32_t pipe_wrap
, bool using_nearest
)
506 case PIPE_TEX_WRAP_REPEAT
:
508 case PIPE_TEX_WRAP_CLAMP_TO_EDGE
:
510 case PIPE_TEX_WRAP_MIRROR_REPEAT
:
512 case PIPE_TEX_WRAP_CLAMP_TO_BORDER
:
514 case PIPE_TEX_WRAP_CLAMP
:
515 return (using_nearest
? 1 : 3);
517 unreachable("Unknown wrap mode");
523 vc5_create_sampler_state(struct pipe_context
*pctx
,
524 const struct pipe_sampler_state
*cso
)
526 MAYBE_UNUSED
struct vc5_context
*vc5
= vc5_context(pctx
);
527 struct vc5_sampler_state
*so
= CALLOC_STRUCT(vc5_sampler_state
);
532 memcpy(so
, cso
, sizeof(*cso
));
534 bool either_nearest
=
535 (cso
->mag_img_filter
== PIPE_TEX_MIPFILTER_NEAREST
||
536 cso
->min_img_filter
== PIPE_TEX_MIPFILTER_NEAREST
);
538 #if V3D_VERSION >= 40
539 so
->bo
= vc5_bo_alloc(vc5
->screen
, cl_packet_length(SAMPLER_STATE
),
541 void *map
= vc5_bo_map(so
->bo
);
543 v3dx_pack(map
, SAMPLER_STATE
, sampler
) {
544 sampler
.wrap_i_border
= false;
546 sampler
.wrap_s
= translate_wrap(cso
->wrap_s
, either_nearest
);
547 sampler
.wrap_t
= translate_wrap(cso
->wrap_t
, either_nearest
);
548 sampler
.wrap_r
= translate_wrap(cso
->wrap_r
, either_nearest
);
550 sampler
.fixed_bias
= cso
->lod_bias
;
551 sampler
.depth_compare_function
= cso
->compare_func
;
553 sampler
.min_filter_nearest
=
554 cso
->min_img_filter
== PIPE_TEX_FILTER_NEAREST
;
555 sampler
.mag_filter_nearest
=
556 cso
->mag_img_filter
== PIPE_TEX_FILTER_NEAREST
;
557 sampler
.mip_filter_nearest
=
558 cso
->min_mip_filter
!= PIPE_TEX_MIPFILTER_LINEAR
;
560 sampler
.min_level_of_detail
= MIN2(MAX2(0, cso
->min_lod
),
562 sampler
.max_level_of_detail
= MIN2(cso
->max_lod
, 15);
564 if (cso
->min_mip_filter
== PIPE_TEX_MIPFILTER_NONE
) {
565 sampler
.min_level_of_detail
= 0;
566 sampler
.max_level_of_detail
= 0;
569 if (cso
->max_anisotropy
) {
570 sampler
.anisotropy_enable
= true;
572 if (cso
->max_anisotropy
> 8)
573 sampler
.maximum_anisotropy
= 3;
574 else if (cso
->max_anisotropy
> 4)
575 sampler
.maximum_anisotropy
= 2;
576 else if (cso
->max_anisotropy
> 2)
577 sampler
.maximum_anisotropy
= 1;
580 sampler
.border_colour_mode
= V3D_BORDER_COLOUR_FOLLOWS
;
581 /* XXX: The border colour field is in the TMU blending format
582 * (32, f16, or i16), and we need to customize it based on
585 * XXX: for compat alpha formats, we need the alpha field to
586 * be in the red channel.
588 sampler
.border_colour_red
=
589 util_float_to_half(cso
->border_color
.f
[0]);
590 sampler
.border_colour_green
=
591 util_float_to_half(cso
->border_color
.f
[1]);
592 sampler
.border_colour_blue
=
593 util_float_to_half(cso
->border_color
.f
[2]);
594 sampler
.border_colour_alpha
=
595 util_float_to_half(cso
->border_color
.f
[3]);
598 #else /* V3D_VERSION < 40 */
599 v3dx_pack(&so
->p0
, TEXTURE_UNIFORM_PARAMETER_0_CFG_MODE1
, p0
) {
600 p0
.s_wrap_mode
= translate_wrap(cso
->wrap_s
, either_nearest
);
601 p0
.t_wrap_mode
= translate_wrap(cso
->wrap_t
, either_nearest
);
602 p0
.r_wrap_mode
= translate_wrap(cso
->wrap_r
, either_nearest
);
605 v3dx_pack(&so
->texture_shader_state
, TEXTURE_SHADER_STATE
, tex
) {
606 tex
.depth_compare_function
= cso
->compare_func
;
607 tex
.fixed_bias
= cso
->lod_bias
;
609 #endif /* V3D_VERSION < 40 */
614 vc5_sampler_states_bind(struct pipe_context
*pctx
,
615 enum pipe_shader_type shader
, unsigned start
,
616 unsigned nr
, void **hwcso
)
618 struct vc5_context
*vc5
= vc5_context(pctx
);
619 struct vc5_texture_stateobj
*stage_tex
= vc5_get_stage_tex(vc5
, shader
);
625 for (i
= 0; i
< nr
; i
++) {
628 stage_tex
->samplers
[i
] = hwcso
[i
];
631 for (; i
< stage_tex
->num_samplers
; i
++) {
632 stage_tex
->samplers
[i
] = NULL
;
635 stage_tex
->num_samplers
= new_nr
;
639 vc5_sampler_state_delete(struct pipe_context
*pctx
,
642 struct pipe_sampler_state
*psampler
= hwcso
;
643 struct vc5_sampler_state
*sampler
= vc5_sampler_state(psampler
);
645 vc5_bo_unreference(&sampler
->bo
);
649 #if V3D_VERSION >= 40
651 translate_swizzle(unsigned char pipe_swizzle
)
653 switch (pipe_swizzle
) {
662 return 2 + pipe_swizzle
;
664 unreachable("unknown swizzle");
669 static struct pipe_sampler_view
*
670 vc5_create_sampler_view(struct pipe_context
*pctx
, struct pipe_resource
*prsc
,
671 const struct pipe_sampler_view
*cso
)
673 struct vc5_context
*vc5
= vc5_context(pctx
);
674 struct vc5_screen
*screen
= vc5
->screen
;
675 struct vc5_sampler_view
*so
= CALLOC_STRUCT(vc5_sampler_view
);
676 struct vc5_resource
*rsc
= vc5_resource(prsc
);
683 pipe_reference(NULL
, &prsc
->reference
);
685 /* Compute the sampler view's swizzle up front. This will be plugged
686 * into either the sampler (for 16-bit returns) or the shader's
687 * texture key (for 32)
689 uint8_t view_swizzle
[4] = {
695 const uint8_t *fmt_swizzle
=
696 vc5_get_format_swizzle(&screen
->devinfo
, so
->base
.format
);
697 util_format_compose_swizzles(fmt_swizzle
, view_swizzle
, so
->swizzle
);
699 so
->base
.texture
= prsc
;
700 so
->base
.reference
.count
= 1;
701 so
->base
.context
= pctx
;
703 int msaa_scale
= prsc
->nr_samples
> 1 ? 2 : 1;
705 #if V3D_VERSION >= 40
706 so
->bo
= vc5_bo_alloc(vc5
->screen
, cl_packet_length(SAMPLER_STATE
),
708 void *map
= vc5_bo_map(so
->bo
);
710 v3dx_pack(map
, TEXTURE_SHADER_STATE
, tex
) {
711 #else /* V3D_VERSION < 40 */
712 v3dx_pack(&so
->texture_shader_state
, TEXTURE_SHADER_STATE
, tex
) {
715 tex
.image_width
= prsc
->width0
* msaa_scale
;
716 tex
.image_height
= prsc
->height0
* msaa_scale
;
718 #if V3D_VERSION >= 40
719 /* On 4.x, the height of a 1D texture is redefined to be the
720 * upper 14 bits of the width (which is only usable with txf).
722 if (prsc
->target
== PIPE_TEXTURE_1D
||
723 prsc
->target
== PIPE_TEXTURE_1D_ARRAY
) {
724 tex
.image_height
= tex
.image_width
>> 14;
728 if (prsc
->target
== PIPE_TEXTURE_3D
) {
729 tex
.image_depth
= prsc
->depth0
;
731 tex
.image_depth
= (cso
->u
.tex
.last_layer
-
732 cso
->u
.tex
.first_layer
) + 1;
735 tex
.srgb
= util_format_is_srgb(cso
->format
);
737 tex
.base_level
= cso
->u
.tex
.first_level
;
738 #if V3D_VERSION >= 40
739 tex
.max_level
= cso
->u
.tex
.last_level
;
740 /* Note that we don't have a job to reference the texture's sBO
741 * at state create time, so any time this sampler view is used
742 * we need to add the texture to the job.
744 tex
.texture_base_pointer
= cl_address(NULL
,
746 rsc
->slices
[0].offset
),
748 tex
.swizzle_r
= translate_swizzle(so
->swizzle
[0]);
749 tex
.swizzle_g
= translate_swizzle(so
->swizzle
[1]);
750 tex
.swizzle_b
= translate_swizzle(so
->swizzle
[2]);
751 tex
.swizzle_a
= translate_swizzle(so
->swizzle
[3]);
753 tex
.array_stride_64_byte_aligned
= rsc
->cube_map_stride
/ 64;
755 if (prsc
->nr_samples
> 1) {
756 /* Using texture views to reinterpret formats on our
757 * MSAA textures won't work, because we don't lay out
758 * the bits in memory as it's expected -- for example,
759 * RGBA8 and RGB10_A2 are compatible in the
760 * ARB_texture_view spec, but in HW we lay them out as
761 * 32bpp RGBA8 and 64bpp RGBA16F. Just assert for now
764 assert(util_format_linear(cso
->format
) ==
765 util_format_linear(prsc
->format
));
766 uint32_t output_image_format
=
767 vc5_get_rt_format(&screen
->devinfo
, cso
->format
);
768 uint32_t internal_type
;
769 uint32_t internal_bpp
;
770 vc5_get_internal_type_bpp_for_output_format(&screen
->devinfo
,
775 switch (internal_type
) {
776 case V3D_INTERNAL_TYPE_8
:
777 tex
.texture_type
= TEXTURE_DATA_FORMAT_RGBA8
;
779 case V3D_INTERNAL_TYPE_16F
:
780 tex
.texture_type
= TEXTURE_DATA_FORMAT_RGBA16F
;
783 unreachable("Bad MSAA texture type");
786 /* sRGB was stored in the tile buffer as linear and
787 * would have been encoded to sRGB on resolved tile
788 * buffer store. Note that this means we would need
789 * shader code if we wanted to read an MSAA sRGB
790 * texture without sRGB decode.
794 tex
.texture_type
= vc5_get_tex_format(&screen
->devinfo
,
798 /* Since other platform devices may produce UIF images even
799 * when they're not big enough for V3D to assume they're UIF,
800 * we force images with level 0 as UIF to be always treated
803 tex
.level_0_is_strictly_uif
= (rsc
->slices
[0].tiling
==
804 VC5_TILING_UIF_XOR
||
805 rsc
->slices
[0].tiling
==
806 VC5_TILING_UIF_NO_XOR
);
807 tex
.level_0_xor_enable
= (rsc
->slices
[0].tiling
==
810 if (tex
.level_0_is_strictly_uif
)
811 tex
.level_0_ub_pad
= rsc
->slices
[0].ub_pad
;
813 #if V3D_VERSION >= 40
814 if (tex
.uif_xor_disable
||
815 tex
.level_0_is_strictly_uif
) {
818 #endif /* V3D_VERSION >= 40 */
825 vc5_sampler_view_destroy(struct pipe_context
*pctx
,
826 struct pipe_sampler_view
*psview
)
828 struct vc5_sampler_view
*sview
= vc5_sampler_view(psview
);
830 vc5_bo_unreference(&sview
->bo
);
831 pipe_resource_reference(&psview
->texture
, NULL
);
836 vc5_set_sampler_views(struct pipe_context
*pctx
,
837 enum pipe_shader_type shader
,
838 unsigned start
, unsigned nr
,
839 struct pipe_sampler_view
**views
)
841 struct vc5_context
*vc5
= vc5_context(pctx
);
842 struct vc5_texture_stateobj
*stage_tex
= vc5_get_stage_tex(vc5
, shader
);
848 for (i
= 0; i
< nr
; i
++) {
851 pipe_sampler_view_reference(&stage_tex
->textures
[i
], views
[i
]);
854 for (; i
< stage_tex
->num_textures
; i
++) {
855 pipe_sampler_view_reference(&stage_tex
->textures
[i
], NULL
);
858 stage_tex
->num_textures
= new_nr
;
861 static struct pipe_stream_output_target
*
862 vc5_create_stream_output_target(struct pipe_context
*pctx
,
863 struct pipe_resource
*prsc
,
864 unsigned buffer_offset
,
865 unsigned buffer_size
)
867 struct pipe_stream_output_target
*target
;
869 target
= CALLOC_STRUCT(pipe_stream_output_target
);
873 pipe_reference_init(&target
->reference
, 1);
874 pipe_resource_reference(&target
->buffer
, prsc
);
876 target
->context
= pctx
;
877 target
->buffer_offset
= buffer_offset
;
878 target
->buffer_size
= buffer_size
;
884 vc5_stream_output_target_destroy(struct pipe_context
*pctx
,
885 struct pipe_stream_output_target
*target
)
887 pipe_resource_reference(&target
->buffer
, NULL
);
892 vc5_set_stream_output_targets(struct pipe_context
*pctx
,
893 unsigned num_targets
,
894 struct pipe_stream_output_target
**targets
,
895 const unsigned *offsets
)
897 struct vc5_context
*ctx
= vc5_context(pctx
);
898 struct vc5_streamout_stateobj
*so
= &ctx
->streamout
;
901 assert(num_targets
<= ARRAY_SIZE(so
->targets
));
903 for (i
= 0; i
< num_targets
; i
++)
904 pipe_so_target_reference(&so
->targets
[i
], targets
[i
]);
906 for (; i
< so
->num_targets
; i
++)
907 pipe_so_target_reference(&so
->targets
[i
], NULL
);
909 so
->num_targets
= num_targets
;
911 ctx
->dirty
|= VC5_DIRTY_STREAMOUT
;
915 v3dX(state_init
)(struct pipe_context
*pctx
)
917 pctx
->set_blend_color
= vc5_set_blend_color
;
918 pctx
->set_stencil_ref
= vc5_set_stencil_ref
;
919 pctx
->set_clip_state
= vc5_set_clip_state
;
920 pctx
->set_sample_mask
= vc5_set_sample_mask
;
921 pctx
->set_constant_buffer
= vc5_set_constant_buffer
;
922 pctx
->set_framebuffer_state
= vc5_set_framebuffer_state
;
923 pctx
->set_polygon_stipple
= vc5_set_polygon_stipple
;
924 pctx
->set_scissor_states
= vc5_set_scissor_states
;
925 pctx
->set_viewport_states
= vc5_set_viewport_states
;
927 pctx
->set_vertex_buffers
= vc5_set_vertex_buffers
;
929 pctx
->create_blend_state
= vc5_create_blend_state
;
930 pctx
->bind_blend_state
= vc5_blend_state_bind
;
931 pctx
->delete_blend_state
= vc5_generic_cso_state_delete
;
933 pctx
->create_rasterizer_state
= vc5_create_rasterizer_state
;
934 pctx
->bind_rasterizer_state
= vc5_rasterizer_state_bind
;
935 pctx
->delete_rasterizer_state
= vc5_generic_cso_state_delete
;
937 pctx
->create_depth_stencil_alpha_state
= vc5_create_depth_stencil_alpha_state
;
938 pctx
->bind_depth_stencil_alpha_state
= vc5_zsa_state_bind
;
939 pctx
->delete_depth_stencil_alpha_state
= vc5_generic_cso_state_delete
;
941 pctx
->create_vertex_elements_state
= vc5_vertex_state_create
;
942 pctx
->delete_vertex_elements_state
= vc5_generic_cso_state_delete
;
943 pctx
->bind_vertex_elements_state
= vc5_vertex_state_bind
;
945 pctx
->create_sampler_state
= vc5_create_sampler_state
;
946 pctx
->delete_sampler_state
= vc5_sampler_state_delete
;
947 pctx
->bind_sampler_states
= vc5_sampler_states_bind
;
949 pctx
->create_sampler_view
= vc5_create_sampler_view
;
950 pctx
->sampler_view_destroy
= vc5_sampler_view_destroy
;
951 pctx
->set_sampler_views
= vc5_set_sampler_views
;
953 pctx
->create_stream_output_target
= vc5_create_stream_output_target
;
954 pctx
->stream_output_target_destroy
= vc5_stream_output_target_destroy
;
955 pctx
->set_stream_output_targets
= vc5_set_stream_output_targets
;