2 * Copyright (C) 2008-2009 Advanced Micro Devices, Inc.
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 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 * Richard Li <RichardZ.Li@amd.com>, <richardradeon@gmail.com>
25 * CooperYuan <cooper.yuan@amd.com>, <cooperyuan@gmail.com>
28 #include "main/glheader.h"
29 #include "main/state.h"
30 #include "main/imports.h"
31 #include "main/enums.h"
32 #include "main/macros.h"
33 #include "main/context.h"
35 #include "main/simple_list.h"
36 #include "main/api_arrayelt.h"
37 #include "swrast/swrast.h"
38 #include "swrast_setup/swrast_setup.h"
42 #include "tnl/t_vp_build.h"
43 #include "tnl/t_context.h"
44 #include "tnl/t_vertex.h"
45 #include "tnl/t_pipeline.h"
47 #include "r600_context.h"
48 #include "r600_cmdbuf.h"
52 #include "r700_vertprog.h"
53 #include "r700_fragprog.h"
54 #include "r700_state.h"
56 void r700WaitForIdle(context_t
*context
);
57 void r700WaitForIdleClean(context_t
*context
);
58 void r700Start3D(context_t
*context
);
59 GLboolean
r700SendTextureState(context_t
*context
);
60 static unsigned int r700PrimitiveType(int prim
);
61 void r600UpdateTextureState(GLcontext
* ctx
);
62 GLboolean
r700SyncSurf(context_t
*context
,
63 struct radeon_bo
*pbo
,
65 uint32_t write_domain
,
68 void r700WaitForIdle(context_t
*context
)
70 BATCH_LOCALS(&context
->radeon
);
71 BEGIN_BATCH_NO_AUTOSTATE(3);
73 R600_OUT_BATCH(CP_PACKET3(R600_IT_SET_CONFIG_REG
, 1));
74 R600_OUT_BATCH(mmWAIT_UNTIL
- ASIC_CONFIG_BASE_INDEX
);
75 R600_OUT_BATCH(WAIT_3D_IDLE_bit
);
81 void r700WaitForIdleClean(context_t
*context
)
83 BATCH_LOCALS(&context
->radeon
);
84 BEGIN_BATCH_NO_AUTOSTATE(5);
86 R600_OUT_BATCH(CP_PACKET3(R600_IT_EVENT_WRITE
, 0));
87 R600_OUT_BATCH(CACHE_FLUSH_AND_INV_EVENT
);
89 R600_OUT_BATCH(CP_PACKET3(R600_IT_SET_CONFIG_REG
, 1));
90 R600_OUT_BATCH(mmWAIT_UNTIL
- ASIC_CONFIG_BASE_INDEX
);
91 R600_OUT_BATCH(WAIT_3D_IDLE_bit
| WAIT_3D_IDLECLEAN_bit
);
97 void r700Start3D(context_t
*context
)
99 BATCH_LOCALS(&context
->radeon
);
100 if (context
->radeon
.radeonScreen
->chip_family
< CHIP_FAMILY_RV770
)
102 BEGIN_BATCH_NO_AUTOSTATE(2);
103 R600_OUT_BATCH(CP_PACKET3(R600_IT_START_3D_CMDBUF
, 0));
108 BEGIN_BATCH_NO_AUTOSTATE(3);
109 R600_OUT_BATCH(CP_PACKET3(R600_IT_CONTEXT_CONTROL
, 1));
110 R600_OUT_BATCH(0x80000000);
111 R600_OUT_BATCH(0x80000000);
116 r700WaitForIdleClean(context
);
119 static GLboolean
r700SetupShaders(GLcontext
* ctx
)
121 context_t
*context
= R700_CONTEXT(ctx
);
123 R700_CHIP_CONTEXT
*r700
= (R700_CHIP_CONTEXT
*)(&context
->hw
);
127 r700
->ps
.SQ_PGM_RESOURCES_PS
.u32All
= 0;
128 r700
->vs
.SQ_PGM_RESOURCES_VS
.u32All
= 0;
130 SETbit(r700
->ps
.SQ_PGM_RESOURCES_PS
.u32All
, PGM_RESOURCES__PRIME_CACHE_ON_DRAW_bit
);
131 SETbit(r700
->vs
.SQ_PGM_RESOURCES_VS
.u32All
, PGM_RESOURCES__PRIME_CACHE_ON_DRAW_bit
);
133 r700SetupVertexProgram(ctx
);
135 r700SetupFragmentProgram(ctx
);
137 exportCount
= (r700
->ps
.SQ_PGM_EXPORTS_PS
.u32All
& EXPORT_MODE_mask
) / (1 << EXPORT_MODE_shift
);
138 r700
->CB_SHADER_CONTROL
.u32All
= (1 << exportCount
) - 1;
140 r600UpdateTextureState(ctx
);
145 GLboolean
r700SyncSurf(context_t
*context
,
146 struct radeon_bo
*pbo
,
147 uint32_t read_domain
,
148 uint32_t write_domain
,
151 BATCH_LOCALS(&context
->radeon
);
152 uint32_t cp_coher_size
;
157 if (pbo
->size
== 0xffffffff)
158 cp_coher_size
= 0xffffffff;
160 cp_coher_size
= ((pbo
->size
+ 255) >> 8);
162 BEGIN_BATCH_NO_AUTOSTATE(5);
163 R600_OUT_BATCH(CP_PACKET3(R600_IT_SURFACE_SYNC
, 3));
164 R600_OUT_BATCH(sync_type
);
165 R600_OUT_BATCH(cp_coher_size
);
166 R600_OUT_BATCH_RELOC(0,
169 read_domain
, write_domain
, 0); // ???
178 static unsigned int r700PrimitiveType(int prim
)
180 switch (prim
& PRIM_MODE_MASK
)
183 return DI_PT_POINTLIST
;
186 return DI_PT_LINELIST
;
189 return DI_PT_LINESTRIP
;
192 return DI_PT_LINELOOP
;
195 return DI_PT_TRILIST
;
197 case GL_TRIANGLE_STRIP
:
198 return DI_PT_TRISTRIP
;
200 case GL_TRIANGLE_FAN
:
204 return DI_PT_QUADLIST
;
207 return DI_PT_QUADSTRIP
;
210 return DI_PT_POLYGON
;
219 static void r700RunRenderPrimitive(GLcontext
* ctx
, int start
, int end
, int prim
)
221 context_t
*context
= R700_CONTEXT(ctx
);
222 BATCH_LOCALS(&context
->radeon
);
223 int type
, i
, total_emit
;
224 int num_indices
= end
- start
;
225 uint32_t vgt_draw_initiator
= 0;
226 uint32_t vgt_index_type
= 0;
227 uint32_t vgt_primitive_type
= 0;
228 uint32_t vgt_num_indices
= 0;
230 type
= r700PrimitiveType(prim
);
232 if (type
< 0 || num_indices
<= 0)
235 total_emit
= 3 /* VGT_PRIMITIVE_TYPE */
236 + 2 /* VGT_INDEX_TYPE */
237 + 2 /* NUM_INSTANCES */
238 + num_indices
+ 3; /* DRAW_INDEX_IMMD */
240 BEGIN_BATCH_NO_AUTOSTATE(total_emit
);
242 SETfield(vgt_primitive_type
, type
,
243 VGT_PRIMITIVE_TYPE__PRIM_TYPE_shift
, VGT_PRIMITIVE_TYPE__PRIM_TYPE_mask
);
244 R600_OUT_BATCH(CP_PACKET3(R600_IT_SET_CONFIG_REG
, 1));
245 R600_OUT_BATCH(mmVGT_PRIMITIVE_TYPE
- ASIC_CONFIG_BASE_INDEX
);
246 R600_OUT_BATCH(vgt_primitive_type
);
249 SETfield(vgt_index_type
, DI_INDEX_SIZE_32_BIT
, INDEX_TYPE_shift
, INDEX_TYPE_mask
);
250 R600_OUT_BATCH(CP_PACKET3(R600_IT_INDEX_TYPE
, 0));
251 R600_OUT_BATCH(vgt_index_type
);
254 R600_OUT_BATCH(CP_PACKET3(R600_IT_NUM_INSTANCES
, 0));
258 vgt_num_indices
= num_indices
;
259 SETfield(vgt_draw_initiator
, DI_SRC_SEL_IMMEDIATE
, SOURCE_SELECT_shift
, SOURCE_SELECT_mask
);
260 SETfield(vgt_draw_initiator
, DI_MAJOR_MODE_0
, MAJOR_MODE_shift
, MAJOR_MODE_mask
);
262 R600_OUT_BATCH(CP_PACKET3(R600_IT_DRAW_INDEX_IMMD
, (num_indices
+ 1)));
263 R600_OUT_BATCH(vgt_num_indices
);
264 R600_OUT_BATCH(vgt_draw_initiator
);
266 for (i
= start
; i
< end
; i
++) {
274 void r700EmitState(GLcontext
* ctx
)
276 context_t
*context
= R700_CONTEXT(ctx
);
278 rcommonEnsureCmdBufSpace(&context
->radeon
,
279 context
->radeon
.hw
.max_state_size
, __FUNCTION__
);
281 r700Start3D(context
);
282 r700SendSQConfig(context
);
283 r700SendFSState(context
); // FIXME just a place holder for now
284 r700SendPSState(context
);
285 r700SendVSState(context
);
287 r700SendTextureState(context
);
288 r700SetupStreams(ctx
);
290 r700SendUCPState(context
);
291 r700SendContextStates(context
);
292 r700SendViewportState(context
, 0);
293 r700SendRenderTargetState(context
, 0);
294 r700SendDepthTargetState(context
);
298 static GLboolean
r700RunRender(GLcontext
* ctx
,
299 struct tnl_pipeline_stage
*stage
)
301 context_t
*context
= R700_CONTEXT(ctx
);
303 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
304 struct vertex_buffer
*vb
= &tnl
->vb
;
306 r700UpdateShaders(ctx
);
307 r700SetScissor(context
);
308 r700SetupShaders(ctx
);
310 r700SetRenderTarget(context
, 0);
311 r700SetDepthTarget(context
);
315 /* richard test code */
316 for (i
= 0; i
< vb
->PrimitiveCount
; i
++) {
317 GLuint prim
= _tnl_translate_prim(&vb
->Primitive
[i
]);
318 GLuint start
= vb
->Primitive
[i
].start
;
319 GLuint end
= vb
->Primitive
[i
].start
+ vb
->Primitive
[i
].count
;
320 r700RunRenderPrimitive(ctx
, start
, end
, prim
);
323 /* Flush render op cached for last several quads. */
324 r700WaitForIdleClean(context
);
326 radeonReleaseArrays(ctx
, ~0);
328 rcommonFlushCmdBuf( &context
->radeon
, __FUNCTION__
);
333 static GLboolean
r700RunNonTCLRender(GLcontext
* ctx
,
334 struct tnl_pipeline_stage
*stage
) /* -------------------- */
336 GLboolean bRet
= GL_TRUE
;
341 static GLboolean
r700RunTCLRender(GLcontext
* ctx
, /*----------------------*/
342 struct tnl_pipeline_stage
*stage
)
344 GLboolean bRet
= GL_FALSE
;
346 /* TODO : sw fallback */
349 * Ensure all enabled and complete textures are uploaded along with any buffers being used.
351 if(!r600ValidateBuffers(ctx
))
356 bRet
= r700RunRender(ctx
, stage
);
359 //GL_FALSE will stop to do other pipe stage in _tnl_run_pipeline
360 //The render here DOES finish the whole pipe, so GL_FALSE should be returned for success.
363 const struct tnl_pipeline_stage _r700_render_stage
= {
364 "r700 Hardware Rasterization",
372 const struct tnl_pipeline_stage _r700_tcl_stage
= {
373 "r700 Hardware Transform, Clipping and Lighting",
381 const struct tnl_pipeline_stage
*r700_pipeline
[] =
384 &_tnl_vertex_transform_stage
,
385 &_tnl_normal_transform_stage
,
386 &_tnl_lighting_stage
,
387 &_tnl_fog_coordinate_stage
,
389 &_tnl_texture_transform_stage
,
390 &_tnl_vertex_program_stage
,