2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
29 #include "../radeon/r600_pipe_common.h"
31 #include "pipe/p_screen.h"
32 #include "pipe/p_context.h"
33 #include "util/u_format.h"
34 #include "util/u_math.h"
35 #include "util/u_slab.h"
37 #include "si_public.h"
39 #include "si_resource.h"
42 #ifdef PIPE_ARCH_BIG_ENDIAN
43 #define SI_BIG_ENDIAN 1
45 #define SI_BIG_ENDIAN 0
49 #define SI_TRACE_CS_DWORDS 6
51 #define SI_MAX_DRAW_CS_DWORDS 18
53 struct si_pipe_compute
;
56 struct r600_common_screen b
;
59 struct si_pipe_sampler_view
{
60 struct pipe_sampler_view base
;
61 struct r600_resource
*resource
;
63 uint32_t fmask_state
[8];
66 struct si_pipe_sampler_state
{
68 uint32_t border_color
[4];
71 struct si_cs_shader_state
{
72 struct si_pipe_compute
*program
;
75 struct si_textures_info
{
76 struct si_sampler_views views
;
77 struct si_pipe_sampler_state
*samplers
[NUM_TEX_UNITS
];
79 uint32_t depth_texture_mask
; /* which textures are depth */
80 uint32_t compressed_colortex_mask
;
84 #define SI_NUM_ATOMS(sctx) (sizeof((sctx)->atoms)/sizeof((sctx)->atoms.array[0]))
85 #define SI_NUM_SHADERS (PIPE_SHADER_FRAGMENT+1)
88 struct r600_common_context b
;
89 struct blitter_context
*blitter
;
90 void *custom_dsa_flush_depth_stencil
[8];
91 void *custom_dsa_flush_depth
[8];
92 void *custom_dsa_flush_stencil
[8];
93 void *custom_dsa_flush_inplace
;
94 void *custom_blend_resolve
;
95 void *custom_blend_decompress
;
96 struct si_screen
*screen
;
100 /* The order matters. */
101 struct r600_atom
*const_buffers
[SI_NUM_SHADERS
];
102 struct r600_atom
*sampler_views
[SI_NUM_SHADERS
];
103 struct r600_atom
*streamout_buffers
;
104 /* Caches must be flushed after resource descriptors are
105 * updated in memory. */
106 struct r600_atom
*cache_flush
;
107 struct r600_atom
*streamout_begin
;
109 struct r600_atom
*array
[0];
112 struct si_vertex_element
*vertex_elements
;
113 struct pipe_framebuffer_state framebuffer
;
114 unsigned fb_log_samples
;
115 unsigned fb_cb0_is_integer
;
116 unsigned fb_compressed_cb_mask
;
117 unsigned pa_sc_line_stipple
;
118 unsigned pa_su_sc_mode_cntl
;
119 /* for saving when using blitter */
120 struct pipe_stencil_ref stencil_ref
;
121 struct si_pipe_shader_selector
*ps_shader
;
122 struct si_pipe_shader_selector
*vs_shader
;
123 struct si_cs_shader_state cs_shader_state
;
124 /* shader information */
125 unsigned sprite_coord_enable
;
126 unsigned export_16bpc
;
127 struct si_buffer_resources const_buffers
[SI_NUM_SHADERS
];
128 struct si_buffer_resources streamout_buffers
;
129 struct si_textures_info samplers
[SI_NUM_SHADERS
];
130 struct r600_resource
*border_color_table
;
131 unsigned border_color_offset
;
133 unsigned default_ps_gprs
, default_vs_gprs
;
135 /* Below are variables from the old r600_context.
137 unsigned pm4_dirty_cdwords
;
139 /* Vertex and index buffers. */
140 bool vertex_buffers_dirty
;
141 struct pipe_index_buffer index_buffer
;
142 struct pipe_vertex_buffer vertex_buffer
[PIPE_MAX_ATTRIBS
];
143 unsigned nr_vertex_buffers
;
145 /* With rasterizer discard, there doesn't have to be a pixel shader.
146 * In that case, we bind this one: */
147 void *dummy_pixel_shader
;
148 struct r600_atom cache_flush
;
149 struct pipe_constant_buffer null_const_buf
; /* used for set_constant_buffer(NULL) on CIK */
151 /* SI state handling */
152 union si_state queued
;
153 union si_state emitted
;
157 void si_init_blit_functions(struct si_context
*sctx
);
158 void si_flush_depth_textures(struct si_context
*sctx
,
159 struct si_textures_info
*textures
);
160 void si_decompress_color_textures(struct si_context
*sctx
,
161 struct si_textures_info
*textures
);
163 /* si_hw_context.c */
164 void si_context_flush(struct si_context
*ctx
, unsigned flags
);
165 void si_begin_new_cs(struct si_context
*ctx
);
166 void si_need_cs_space(struct si_context
*ctx
, unsigned num_dw
, boolean count_draw_in
);
169 void si_flush(struct pipe_context
*ctx
, struct pipe_fence_handle
**fence
,
173 void si_trace_emit(struct si_context
*sctx
);
177 void si_init_compute_functions(struct si_context
*sctx
);
180 struct pipe_video_codec
*si_uvd_create_decoder(struct pipe_context
*context
,
181 const struct pipe_video_codec
*templ
);
183 struct pipe_video_buffer
*si_video_buffer_create(struct pipe_context
*pipe
,
184 const struct pipe_video_buffer
*tmpl
);
189 static INLINE
uint32_t S_FIXED(float value
, uint32_t frac_bits
)
191 return value
* (1 << frac_bits
);
193 #define ALIGN_DIVUP(x, y) (((x) + (y) - 1) / (y))
195 static INLINE
unsigned si_map_swizzle(unsigned swizzle
)
198 case UTIL_FORMAT_SWIZZLE_Y
:
199 return V_008F0C_SQ_SEL_Y
;
200 case UTIL_FORMAT_SWIZZLE_Z
:
201 return V_008F0C_SQ_SEL_Z
;
202 case UTIL_FORMAT_SWIZZLE_W
:
203 return V_008F0C_SQ_SEL_W
;
204 case UTIL_FORMAT_SWIZZLE_0
:
205 return V_008F0C_SQ_SEL_0
;
206 case UTIL_FORMAT_SWIZZLE_1
:
207 return V_008F0C_SQ_SEL_1
;
208 default: /* UTIL_FORMAT_SWIZZLE_X */
209 return V_008F0C_SQ_SEL_X
;
213 static inline unsigned si_tex_aniso_filter(unsigned filter
)
215 if (filter
<= 1) return 0;
216 if (filter
<= 2) return 1;
217 if (filter
<= 4) return 2;
218 if (filter
<= 8) return 3;
222 /* 12.4 fixed-point */
223 static INLINE
unsigned si_pack_float_12p4(float x
)
226 x
>= 4096 ? 0xffff : x
* 16;