2 * Copyright 2012 Nouveau Project
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 in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * Authors: Christoph Bumiller
25 #include "nvc0_context.h"
26 #include "nve4_compute.h"
28 #include "nv50/codegen/nv50_ir_driver.h"
30 static void nve4_compute_dump_launch_desc(const struct nve4_cp_launch_desc
*);
34 nve4_screen_compute_setup(struct nvc0_screen
*screen
,
35 struct nouveau_pushbuf
*push
)
37 struct nouveau_device
*dev
= screen
->base
.device
;
38 struct nouveau_object
*chan
= screen
->base
.channel
;
43 switch (dev
->chipset
& 0xf0) {
45 obj_class
= NVF0_COMPUTE_CLASS
; /* GK110 */
48 obj_class
= NVE4_COMPUTE_CLASS
; /* GK104 */
51 NOUVEAU_ERR("unsupported chipset: NV%02x\n", dev
->chipset
);
55 ret
= nouveau_object_new(chan
, 0xbeef00c0, obj_class
, NULL
, 0,
58 NOUVEAU_ERR("Failed to allocate compute object: %d\n", ret
);
62 ret
= nouveau_bo_new(dev
, NOUVEAU_BO_VRAM
, 0, NVE4_CP_PARAM_SIZE
, NULL
,
67 BEGIN_NVC0(push
, SUBC_COMPUTE(NV01_SUBCHAN_OBJECT
), 1);
68 PUSH_DATA (push
, screen
->compute
->oclass
);
70 BEGIN_NVC0(push
, NVE4_COMPUTE(TEMP_ADDRESS_HIGH
), 2);
71 PUSH_DATAh(push
, screen
->tls
->offset
);
72 PUSH_DATA (push
, screen
->tls
->offset
);
73 /* No idea why there are 2. Divide size by 2 to be safe.
74 * Actually this might be per-MP TEMP size and looks like I'm only using
75 * 2 MPs instead of all 8.
77 BEGIN_NVC0(push
, NVE4_COMPUTE(TEMP_SIZE_HIGH(0)), 3);
78 PUSH_DATAh(push
, screen
->tls_size
/ 2);
79 PUSH_DATA (push
, screen
->tls_size
/ 2);
80 PUSH_DATA (push
, 0xff);
81 BEGIN_NVC0(push
, NVE4_COMPUTE(TEMP_SIZE_HIGH(1)), 3);
82 PUSH_DATAh(push
, screen
->tls_size
/ 2);
83 PUSH_DATA (push
, screen
->tls_size
/ 2);
84 PUSH_DATA (push
, 0xff);
86 /* Unified address space ? Who needs that ? Certainly not OpenCL.
88 * FATAL: Buffers with addresses inside [0x1000000, 0x3000000] will NOT be
89 * accessible. We cannot prevent that at the moment, so expect failure.
91 BEGIN_NVC0(push
, NVE4_COMPUTE(LOCAL_BASE
), 1);
92 PUSH_DATA (push
, 1 << 24);
93 BEGIN_NVC0(push
, NVE4_COMPUTE(SHARED_BASE
), 1);
94 PUSH_DATA (push
, 2 << 24);
96 BEGIN_NVC0(push
, NVE4_COMPUTE(CODE_ADDRESS_HIGH
), 2);
97 PUSH_DATAh(push
, screen
->text
->offset
);
98 PUSH_DATA (push
, screen
->text
->offset
);
100 BEGIN_NVC0(push
, SUBC_COMPUTE(0x0310), 1);
101 PUSH_DATA (push
, (obj_class
>= NVF0_COMPUTE_CLASS
) ? 0x400 : 0x300);
103 /* NOTE: these do not affect the state used by the 3D object */
104 BEGIN_NVC0(push
, NVE4_COMPUTE(TIC_ADDRESS_HIGH
), 3);
105 PUSH_DATAh(push
, screen
->txc
->offset
);
106 PUSH_DATA (push
, screen
->txc
->offset
);
107 PUSH_DATA (push
, NVC0_TIC_MAX_ENTRIES
- 1);
108 BEGIN_NVC0(push
, NVE4_COMPUTE(TSC_ADDRESS_HIGH
), 3);
109 PUSH_DATAh(push
, screen
->txc
->offset
+ 65536);
110 PUSH_DATA (push
, screen
->txc
->offset
+ 65536);
111 PUSH_DATA (push
, NVC0_TSC_MAX_ENTRIES
- 1);
113 if (obj_class
>= NVF0_COMPUTE_CLASS
) {
114 BEGIN_NVC0(push
, SUBC_COMPUTE(0x0248), 1);
115 PUSH_DATA (push
, 0x100);
116 BEGIN_NIC0(push
, SUBC_COMPUTE(0x0248), 63);
117 for (i
= 63; i
>= 1; --i
)
118 PUSH_DATA(push
, 0x38000 | i
);
119 IMMED_NVC0(push
, SUBC_COMPUTE(NV50_GRAPH_SERIALIZE
), 0);
120 IMMED_NVC0(push
, SUBC_COMPUTE(0x518), 0);
123 BEGIN_NVC0(push
, NVE4_COMPUTE(TEX_CB_INDEX
), 1);
124 PUSH_DATA (push
, 0); /* does not interefere with 3D */
126 if (obj_class
>= NVF0_COMPUTE_CLASS
)
127 IMMED_NVC0(push
, SUBC_COMPUTE(0x02c4), 1);
129 /* MS sample coordinate offsets: these do not work with _ALT modes ! */
130 BEGIN_NVC0(push
, NVE4_COMPUTE(UPLOAD_ADDRESS_HIGH
), 2);
131 PUSH_DATAh(push
, screen
->parm
->offset
+ NVE4_CP_INPUT_MS_OFFSETS
);
132 PUSH_DATA (push
, screen
->parm
->offset
+ NVE4_CP_INPUT_MS_OFFSETS
);
133 BEGIN_NVC0(push
, NVE4_COMPUTE(UPLOAD_SIZE
), 2);
134 PUSH_DATA (push
, 64);
135 PUSH_DATA (push
, NVE4_COMPUTE_UPLOAD_UNK0184_UNKVAL
);
136 BEGIN_1IC0(push
, NVE4_COMPUTE(UPLOAD_EXEC
), 17);
137 PUSH_DATA (push
, NVE4_COMPUTE_UPLOAD_EXEC_UNKVAL_DATA
);
138 PUSH_DATA (push
, 0); /* 0 */
140 PUSH_DATA (push
, 1); /* 1 */
142 PUSH_DATA (push
, 0); /* 2 */
144 PUSH_DATA (push
, 1); /* 3 */
146 PUSH_DATA (push
, 2); /* 4 */
148 PUSH_DATA (push
, 3); /* 5 */
150 PUSH_DATA (push
, 2); /* 6 */
152 PUSH_DATA (push
, 3); /* 7 */
156 BEGIN_NVC0(push
, NVE4_COMPUTE(UPLOAD_ADDRESS_HIGH
), 2);
157 PUSH_DATAh(push
, screen
->parm
->offset
+ NVE4_CP_INPUT_TRAP_INFO_PTR
);
158 PUSH_DATA (push
, screen
->parm
->offset
+ NVE4_CP_INPUT_TRAP_INFO_PTR
);
159 BEGIN_NVC0(push
, NVE4_COMPUTE(UPLOAD_SIZE
), 2);
160 PUSH_DATA (push
, 28);
161 PUSH_DATA (push
, NVE4_COMPUTE_UPLOAD_UNK0184_UNKVAL
);
162 BEGIN_1IC0(push
, NVE4_COMPUTE(UPLOAD_EXEC
), 8);
163 PUSH_DATA (push
, NVE4_COMPUTE_UPLOAD_EXEC_UNKVAL_DATA
);
164 PUSH_DATA (push
, screen
->parm
->offset
+ NVE4_CP_PARAM_TRAP_INFO
);
165 PUSH_DATAh(push
, screen
->parm
->offset
+ NVE4_CP_PARAM_TRAP_INFO
);
166 PUSH_DATA (push
, screen
->tls
->offset
);
167 PUSH_DATAh(push
, screen
->tls
->offset
);
168 PUSH_DATA (push
, screen
->tls
->size
/ 2); /* MP TEMP block size */
169 PUSH_DATA (push
, screen
->tls
->size
/ 2 / 64); /* warp TEMP block size */
170 PUSH_DATA (push
, 0); /* warp cfstack size */
173 BEGIN_NVC0(push
, NVE4_COMPUTE(FLUSH
), 1);
174 PUSH_DATA (push
, NVE4_COMPUTE_FLUSH_CB
);
181 nve4_compute_validate_surfaces(struct nvc0_context
*nvc0
)
183 struct nvc0_screen
*screen
= nvc0
->screen
;
184 struct nouveau_pushbuf
*push
= nvc0
->base
.pushbuf
;
185 struct nv50_surface
*sf
;
186 struct nv04_resource
*res
;
189 const unsigned t
= 1;
191 mask
= nvc0
->surfaces_dirty
[t
];
197 * NVE4's surface load/store instructions receive all the information
198 * directly instead of via binding points, so we have to supply them.
200 BEGIN_NVC0(push
, NVE4_COMPUTE(UPLOAD_ADDRESS_HIGH
), 2);
201 PUSH_DATAh(push
, screen
->parm
->offset
+ NVE4_CP_INPUT_SUF(i
));
202 PUSH_DATA (push
, screen
->parm
->offset
+ NVE4_CP_INPUT_SUF(i
));
203 BEGIN_NVC0(push
, NVE4_COMPUTE(UPLOAD_SIZE
), 2);
204 PUSH_DATA (push
, 64);
205 PUSH_DATA (push
, NVE4_COMPUTE_UPLOAD_UNK0184_UNKVAL
);
206 BEGIN_1IC0(push
, NVE4_COMPUTE(UPLOAD_EXEC
), 17);
207 PUSH_DATA (push
, NVE4_COMPUTE_UPLOAD_EXEC_UNKVAL_DATA
);
209 nve4_set_surface_info(push
, nvc0
->surfaces
[t
][i
], screen
);
211 sf
= nv50_surface(nvc0
->surfaces
[t
][i
]);
213 res
= nv04_resource(sf
->base
.texture
);
215 if (sf
->base
.writable
)
216 BCTX_REFN(nvc0
->bufctx_cp
, CP_SUF
, res
, RDWR
);
218 BCTX_REFN(nvc0
->bufctx_cp
, CP_SUF
, res
, RD
);
221 if (nvc0
->surfaces_dirty
[t
]) {
222 BEGIN_NVC0(push
, NVE4_COMPUTE(FLUSH
), 1);
223 PUSH_DATA (push
, NVE4_COMPUTE_FLUSH_CB
);
226 /* re-reference non-dirty surfaces */
227 mask
= nvc0
->surfaces_valid
[t
] & ~nvc0
->surfaces_dirty
[t
];
232 sf
= nv50_surface(nvc0
->surfaces
[t
][i
]);
233 res
= nv04_resource(sf
->base
.texture
);
235 if (sf
->base
.writable
)
236 BCTX_REFN(nvc0
->bufctx_cp
, CP_SUF
, res
, RDWR
);
238 BCTX_REFN(nvc0
->bufctx_cp
, CP_SUF
, res
, RD
);
241 nvc0
->surfaces_dirty
[t
] = 0;
245 /* Thankfully, textures with samplers follow the normal rules. */
247 nve4_compute_validate_samplers(struct nvc0_context
*nvc0
)
249 boolean need_flush
= nve4_validate_tsc(nvc0
, 5);
251 BEGIN_NVC0(nvc0
->base
.pushbuf
, NVE4_COMPUTE(TSC_FLUSH
), 1);
252 PUSH_DATA (nvc0
->base
.pushbuf
, 0);
255 /* (Code duplicated at bottom for various non-convincing reasons.
256 * E.g. we might want to use the COMPUTE subchannel to upload TIC/TSC
257 * entries to avoid a subchannel switch.
258 * Same for texture cache flushes.
259 * Also, the bufctx differs, and more IFs in the 3D version looks ugly.)
261 static void nve4_compute_validate_textures(struct nvc0_context
*);
264 nve4_compute_set_tex_handles(struct nvc0_context
*nvc0
)
266 struct nouveau_pushbuf
*push
= nvc0
->base
.pushbuf
;
268 const unsigned s
= nvc0_shader_stage(PIPE_SHADER_COMPUTE
);
270 uint32_t dirty
= nvc0
->textures_dirty
[s
] | nvc0
->samplers_dirty
[s
];
275 n
= util_logbase2(dirty
) + 1 - i
;
278 address
= nvc0
->screen
->parm
->offset
+ NVE4_CP_INPUT_TEX(i
);
280 BEGIN_NVC0(push
, NVE4_COMPUTE(UPLOAD_ADDRESS_HIGH
), 2);
281 PUSH_DATAh(push
, address
);
282 PUSH_DATA (push
, address
);
283 BEGIN_NVC0(push
, NVE4_COMPUTE(UPLOAD_SIZE
), 2);
284 PUSH_DATA (push
, n
* 4);
285 PUSH_DATA (push
, 0x1);
286 BEGIN_1IC0(push
, NVE4_COMPUTE(UPLOAD_EXEC
), 1 + n
);
287 PUSH_DATA (push
, NVE4_COMPUTE_UPLOAD_EXEC_UNKVAL_DATA
);
288 PUSH_DATAp(push
, &nvc0
->tex_handles
[s
][i
], n
);
290 BEGIN_NVC0(push
, NVE4_COMPUTE(FLUSH
), 1);
291 PUSH_DATA (push
, NVE4_COMPUTE_FLUSH_CB
);
293 nvc0
->textures_dirty
[s
] = 0;
294 nvc0
->samplers_dirty
[s
] = 0;
299 nve4_compute_validate_program(struct nvc0_context
*nvc0
)
301 struct nvc0_program
*prog
= nvc0
->compprog
;
306 if (!prog
->translated
) {
307 prog
->translated
= nvc0_program_translate(
308 prog
, nvc0
->screen
->base
.device
->chipset
);
309 if (!prog
->translated
)
312 if (unlikely(!prog
->code_size
))
315 if (likely(prog
->code_size
)) {
316 if (nvc0_program_upload_code(nvc0
, prog
)) {
317 struct nouveau_pushbuf
*push
= nvc0
->base
.pushbuf
;
318 BEGIN_NVC0(push
, NVE4_COMPUTE(FLUSH
), 1);
319 PUSH_DATA (push
, NVE4_COMPUTE_FLUSH_CODE
);
328 nve4_compute_state_validate(struct nvc0_context
*nvc0
)
330 if (!nve4_compute_validate_program(nvc0
))
332 if (nvc0
->dirty_cp
& NVC0_NEW_CP_TEXTURES
)
333 nve4_compute_validate_textures(nvc0
);
334 if (nvc0
->dirty_cp
& NVC0_NEW_CP_SAMPLERS
)
335 nve4_compute_validate_samplers(nvc0
);
336 if (nvc0
->dirty_cp
& (NVC0_NEW_CP_TEXTURES
| NVC0_NEW_CP_SAMPLERS
))
337 nve4_compute_set_tex_handles(nvc0
);
338 if (nvc0
->dirty_cp
& NVC0_NEW_CP_SURFACES
)
339 nve4_compute_validate_surfaces(nvc0
);
340 if (nvc0
->dirty_cp
& NVC0_NEW_CP_GLOBALS
)
341 nvc0_validate_global_residents(nvc0
,
342 nvc0
->bufctx_cp
, NVC0_BIND_CP_GLOBAL
);
344 nvc0_bufctx_fence(nvc0
, nvc0
->bufctx_cp
, FALSE
);
346 nouveau_pushbuf_bufctx(nvc0
->base
.pushbuf
, nvc0
->bufctx_cp
);
347 if (unlikely(nouveau_pushbuf_validate(nvc0
->base
.pushbuf
)))
349 if (unlikely(nvc0
->state
.flushed
))
350 nvc0_bufctx_fence(nvc0
, nvc0
->bufctx_cp
, TRUE
);
357 nve4_compute_upload_input(struct nvc0_context
*nvc0
, const void *input
,
358 const uint
*block_layout
,
359 const uint
*grid_layout
)
361 struct nvc0_screen
*screen
= nvc0
->screen
;
362 struct nouveau_pushbuf
*push
= nvc0
->base
.pushbuf
;
363 struct nvc0_program
*cp
= nvc0
->compprog
;
366 BEGIN_NVC0(push
, NVE4_COMPUTE(UPLOAD_ADDRESS_HIGH
), 2);
367 PUSH_DATAh(push
, screen
->parm
->offset
);
368 PUSH_DATA (push
, screen
->parm
->offset
);
369 BEGIN_NVC0(push
, NVE4_COMPUTE(UPLOAD_SIZE
), 2);
370 PUSH_DATA (push
, cp
->parm_size
);
371 PUSH_DATA (push
, 0x1);
372 BEGIN_1IC0(push
, NVE4_COMPUTE(UPLOAD_EXEC
), 1 + (cp
->parm_size
/ 4));
373 PUSH_DATA (push
, NVE4_COMPUTE_UPLOAD_EXEC_UNKVAL_DATA
);
374 PUSH_DATAp(push
, input
, cp
->parm_size
/ 4);
376 BEGIN_NVC0(push
, NVE4_COMPUTE(UPLOAD_ADDRESS_HIGH
), 2);
377 PUSH_DATAh(push
, screen
->parm
->offset
+ NVE4_CP_INPUT_GRID_INFO(0));
378 PUSH_DATA (push
, screen
->parm
->offset
+ NVE4_CP_INPUT_GRID_INFO(0));
379 BEGIN_NVC0(push
, NVE4_COMPUTE(UPLOAD_SIZE
), 2);
380 PUSH_DATA (push
, 7 * 4);
381 PUSH_DATA (push
, 0x1);
382 BEGIN_1IC0(push
, NVE4_COMPUTE(UPLOAD_EXEC
), 1 + 7);
383 PUSH_DATA (push
, NVE4_COMPUTE_UPLOAD_EXEC_UNKVAL_DATA
);
384 PUSH_DATAp(push
, block_layout
, 3);
385 PUSH_DATAp(push
, grid_layout
, 3);
388 BEGIN_NVC0(push
, NVE4_COMPUTE(FLUSH
), 1);
389 PUSH_DATA (push
, NVE4_COMPUTE_FLUSH_CB
);
392 static INLINE
uint8_t
393 nve4_compute_derive_cache_split(struct nvc0_context
*nvc0
, uint32_t shared_size
)
395 if (shared_size
> (32 << 10))
396 return NVC0_3D_CACHE_SPLIT_48K_SHARED_16K_L1
;
397 if (shared_size
> (16 << 10))
398 return NVE4_3D_CACHE_SPLIT_32K_SHARED_32K_L1
;
399 return NVC1_3D_CACHE_SPLIT_16K_SHARED_48K_L1
;
403 nve4_compute_setup_launch_desc(struct nvc0_context
*nvc0
,
404 struct nve4_cp_launch_desc
*desc
,
406 const uint
*block_layout
,
407 const uint
*grid_layout
)
409 const struct nvc0_screen
*screen
= nvc0
->screen
;
410 const struct nvc0_program
*cp
= nvc0
->compprog
;
413 nve4_cp_launch_desc_init_default(desc
);
415 desc
->entry
= nvc0_program_symbol_offset(cp
, label
);
417 desc
->griddim_x
= grid_layout
[0];
418 desc
->griddim_y
= grid_layout
[1];
419 desc
->griddim_z
= grid_layout
[2];
420 desc
->blockdim_x
= block_layout
[0];
421 desc
->blockdim_y
= block_layout
[1];
422 desc
->blockdim_z
= block_layout
[2];
424 desc
->shared_size
= align(cp
->cp
.smem_size
, 0x100);
425 desc
->local_size_p
= align(cp
->cp
.lmem_size
, 0x10);
426 desc
->local_size_n
= 0;
427 desc
->cstack_size
= 0x800;
428 desc
->cache_split
= nve4_compute_derive_cache_split(nvc0
, cp
->cp
.smem_size
);
430 desc
->gpr_alloc
= cp
->num_gprs
;
431 desc
->bar_alloc
= cp
->num_barriers
;
433 for (i
= 0; i
< 7; ++i
) {
434 const unsigned s
= 5;
435 if (nvc0
->constbuf
[s
][i
].u
.buf
)
436 nve4_cp_launch_desc_set_ctx_cb(desc
, i
+ 1, &nvc0
->constbuf
[s
][i
]);
438 nve4_cp_launch_desc_set_cb(desc
, 0, screen
->parm
, 0, NVE4_CP_INPUT_SIZE
);
441 static INLINE
struct nve4_cp_launch_desc
*
442 nve4_compute_alloc_launch_desc(struct nouveau_context
*nv
,
443 struct nouveau_bo
**pbo
, uint64_t *pgpuaddr
)
445 uint8_t *ptr
= nouveau_scratch_get(nv
, 512, pgpuaddr
, pbo
);
448 if (*pgpuaddr
& 255) {
449 unsigned adj
= 256 - (*pgpuaddr
& 255);
453 return (struct nve4_cp_launch_desc
*)ptr
;
457 nve4_launch_grid(struct pipe_context
*pipe
,
458 const uint
*block_layout
, const uint
*grid_layout
,
462 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
463 struct nouveau_pushbuf
*push
= nvc0
->base
.pushbuf
;
464 struct nve4_cp_launch_desc
*desc
;
465 uint64_t desc_gpuaddr
;
466 struct nouveau_bo
*desc_bo
;
469 desc
= nve4_compute_alloc_launch_desc(&nvc0
->base
, &desc_bo
, &desc_gpuaddr
);
472 BCTX_REFN_bo(nvc0
->bufctx_cp
, CP_DESC
, NOUVEAU_BO_GART
| NOUVEAU_BO_RD
,
475 ret
= !nve4_compute_state_validate(nvc0
);
479 nve4_compute_setup_launch_desc(nvc0
, desc
, label
, block_layout
, grid_layout
);
480 nve4_compute_dump_launch_desc(desc
);
482 nve4_compute_upload_input(nvc0
, input
, block_layout
, grid_layout
);
484 /* upload descriptor and flush */
486 BEGIN_NVC0(push
, NVE4_COMPUTE(UPLOAD_ADDRESS_HIGH
), 2);
487 PUSH_DATAh(push
, desc_gpuaddr
);
488 PUSH_DATA (push
, desc_gpuaddr
);
489 BEGIN_NVC0(push
, NVE4_COMPUTE(UPLOAD_SIZE
), 2);
490 PUSH_DATA (push
, 256);
491 PUSH_DATA (push
, NVE4_COMPUTE_UPLOAD_UNK0184_UNKVAL
);
492 BEGIN_1IC0(push
, NVE4_COMPUTE(UPLOAD_EXEC
), 1 + (256 / 4));
493 PUSH_DATA (push
, NVE4_COMPUTE_UPLOAD_EXEC_UNKVAL_DESC
);
494 PUSH_DATAp(push
, (const uint32_t *)desc
, 256 / 4);
495 BEGIN_NVC0(push
, NVE4_COMPUTE(FLUSH
), 1);
496 PUSH_DATA (push
, NVE4_COMPUTE_FLUSH_CB
| NVE4_COMPUTE_FLUSH_CODE
);
498 BEGIN_NVC0(push
, NVE4_COMPUTE(LAUNCH_DESC_ADDRESS
), 1);
499 PUSH_DATA (push
, desc_gpuaddr
>> 8);
500 BEGIN_NVC0(push
, NVE4_COMPUTE(LAUNCH
), 1);
501 PUSH_DATA (push
, 0x3);
502 BEGIN_NVC0(push
, SUBC_COMPUTE(NV50_GRAPH_SERIALIZE
), 1);
507 NOUVEAU_ERR("Failed to launch grid !\n");
508 nouveau_scratch_done(&nvc0
->base
);
509 nouveau_bufctx_reset(nvc0
->bufctx_cp
, NVC0_BIND_CP_DESC
);
513 #define NVE4_TIC_ENTRY_INVALID 0x000fffff
516 nve4_compute_validate_textures(struct nvc0_context
*nvc0
)
518 struct nouveau_bo
*txc
= nvc0
->screen
->txc
;
519 struct nouveau_pushbuf
*push
= nvc0
->base
.pushbuf
;
520 const unsigned s
= 5;
522 uint32_t commands
[2][NVE4_CP_INPUT_TEX_MAX
];
523 unsigned n
[2] = { 0, 0 };
525 for (i
= 0; i
< nvc0
->num_textures
[s
]; ++i
) {
526 struct nv50_tic_entry
*tic
= nv50_tic_entry(nvc0
->textures
[s
][i
]);
527 struct nv04_resource
*res
;
528 const boolean dirty
= !!(nvc0
->textures_dirty
[s
] & (1 << i
));
531 nvc0
->tex_handles
[s
][i
] |= NVE4_TIC_ENTRY_INVALID
;
534 res
= nv04_resource(tic
->pipe
.texture
);
537 tic
->id
= nvc0_screen_tic_alloc(nvc0
->screen
, tic
);
539 PUSH_SPACE(push
, 16);
540 BEGIN_NVC0(push
, NVE4_COMPUTE(UPLOAD_ADDRESS_HIGH
), 2);
541 PUSH_DATAh(push
, txc
->offset
+ (tic
->id
* 32));
542 PUSH_DATA (push
, txc
->offset
+ (tic
->id
* 32));
543 BEGIN_NVC0(push
, NVE4_COMPUTE(UPLOAD_SIZE
), 2);
544 PUSH_DATA (push
, 32);
545 PUSH_DATA (push
, NVE4_COMPUTE_UPLOAD_UNK0184_UNKVAL
);
546 BEGIN_1IC0(push
, NVE4_COMPUTE(UPLOAD_EXEC
), 9);
547 PUSH_DATA (push
, NVE4_COMPUTE_UPLOAD_EXEC_UNKVAL_DATA
);
548 PUSH_DATAp(push
, &tic
->tic
[0], 8);
550 commands
[0][n
[0]++] = (tic
->id
<< 4) | 1;
552 if (res
->status
& NOUVEAU_BUFFER_STATUS_GPU_WRITING
) {
553 commands
[1][n
[1]++] = (tic
->id
<< 4) | 1;
555 nvc0
->screen
->tic
.lock
[tic
->id
/ 32] |= 1 << (tic
->id
% 32);
557 res
->status
&= ~NOUVEAU_BUFFER_STATUS_GPU_WRITING
;
558 res
->status
|= NOUVEAU_BUFFER_STATUS_GPU_READING
;
560 nvc0
->tex_handles
[s
][i
] &= ~NVE4_TIC_ENTRY_INVALID
;
561 nvc0
->tex_handles
[s
][i
] |= tic
->id
;
563 BCTX_REFN(nvc0
->bufctx_cp
, CP_TEX(i
), res
, RD
);
565 for (; i
< nvc0
->state
.num_textures
[s
]; ++i
)
566 nvc0
->tex_handles
[s
][i
] |= NVE4_TIC_ENTRY_INVALID
;
569 BEGIN_NIC0(push
, NVE4_COMPUTE(TIC_FLUSH
), n
[0]);
570 PUSH_DATAp(push
, commands
[0], n
[0]);
573 BEGIN_NIC0(push
, NVE4_COMPUTE(TEX_CACHE_CTL
), n
[1]);
574 PUSH_DATAp(push
, commands
[1], n
[1]);
577 nvc0
->state
.num_textures
[s
] = nvc0
->num_textures
[s
];
581 static const char *nve4_cache_split_name(unsigned value
)
584 case NVC1_3D_CACHE_SPLIT_16K_SHARED_48K_L1
: return "16K_SHARED_48K_L1";
585 case NVE4_3D_CACHE_SPLIT_32K_SHARED_32K_L1
: return "32K_SHARED_32K_L1";
586 case NVC0_3D_CACHE_SPLIT_48K_SHARED_16K_L1
: return "48K_SHARED_16K_L1";
593 nve4_compute_dump_launch_desc(const struct nve4_cp_launch_desc
*desc
)
595 const uint32_t *data
= (const uint32_t *)desc
;
597 boolean zero
= FALSE
;
599 debug_printf("COMPUTE LAUNCH DESCRIPTOR:\n");
601 for (i
= 0; i
< sizeof(*desc
); i
+= 4) {
603 debug_printf("[%x]: 0x%08x\n", i
, data
[i
/ 4]);
607 debug_printf("...\n");
612 debug_printf("entry = 0x%x\n", desc
->entry
);
613 debug_printf("grid dimensions = %ux%ux%u\n",
614 desc
->griddim_x
, desc
->griddim_y
, desc
->griddim_z
);
615 debug_printf("block dimensions = %ux%ux%u\n",
616 desc
->blockdim_x
, desc
->blockdim_y
, desc
->blockdim_z
);
617 debug_printf("s[] size: 0x%x\n", desc
->shared_size
);
618 debug_printf("l[] size: -0x%x / +0x%x\n",
619 desc
->local_size_n
, desc
->local_size_p
);
620 debug_printf("stack size: 0x%x\n", desc
->cstack_size
);
621 debug_printf("barrier count: %u\n", desc
->bar_alloc
);
622 debug_printf("$r count: %u\n", desc
->gpr_alloc
);
623 debug_printf("cache split: %s\n", nve4_cache_split_name(desc
->cache_split
));
625 for (i
= 0; i
< 8; ++i
) {
627 uint32_t size
= desc
->cb
[i
].size
;
628 boolean valid
= !!(desc
->cb_mask
& (1 << i
));
630 address
= ((uint64_t)desc
->cb
[i
].address_h
<< 32) | desc
->cb
[i
].address_l
;
632 if (!valid
&& !address
&& !size
)
634 debug_printf("CB[%u]: address = 0x%"PRIx64
", size 0x%x%s\n",
635 i
, address
, size
, valid
? "" : " (invalid)");
640 nve4_compute_trap_info(struct nvc0_context
*nvc0
)
642 struct nvc0_screen
*screen
= nvc0
->screen
;
643 struct nouveau_bo
*bo
= screen
->parm
;
645 volatile struct nve4_mp_trap_info
*info
;
648 ret
= nouveau_bo_map(bo
, NOUVEAU_BO_RDWR
, nvc0
->base
.client
);
651 map
= (uint8_t *)bo
->map
;
652 info
= (volatile struct nve4_mp_trap_info
*)(map
+ NVE4_CP_PARAM_TRAP_INFO
);
655 debug_printf("trapstat = %08x\n", info
->trapstat
);
656 debug_printf("warperr = %08x\n", info
->warperr
);
657 debug_printf("PC = %x\n", info
->pc
);
658 debug_printf("tid = %u %u %u\n",
659 info
->tid
[0], info
->tid
[1], info
->tid
[2]);
660 debug_printf("ctaid = %u %u %u\n",
661 info
->ctaid
[0], info
->ctaid
[1], info
->ctaid
[2]);
662 for (i
= 0; i
<= 63; ++i
)
663 debug_printf("$r%i = %08x\n", i
, info
->r
[i
]);
664 for (i
= 0; i
<= 6; ++i
)
665 debug_printf("$p%i = %i\n", i
, (info
->flags
>> i
) & 1);
666 debug_printf("$c = %x\n", info
->flags
>> 12);