1 /*---------------------------------------------------------------------------*
2
3 Copyright 2010-2014 Nintendo. All rights reserved.
4
5 These coded instructions, statements, and computer programs contain
6 proprietary information of Nintendo of America Inc. and/or Nintendo
7 Company Ltd., and are protected by Federal copyright law. They may
8 not be disclosed to third parties or copied or duplicated in any form,
9 in whole or in part, without the prior written consent of Nintendo.
10
11 *---------------------------------------------------------------------------*/
12
13 #ifndef _GX2UTCLEAR_H_
14 #define _GX2UTCLEAR_H_
15
16 // Note: Currently this header depends on gx2.h being included first to define
17 // types like s32 and structures like GX2Surface.
18
19 // Need GX2UTRect struct; this pulls in gx2.h also
20 #include "gx2utCopy.h"
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26 /// @addtogroup GX2UTClearSurfaceGroup
27 /// @{
28
29 /// \brief Setup all of the constant render state needed for GX2UT clears
30 ///
31 /// \param enable Enable or disable the state
32 ///
33 /// This enables and disables the state used by \ref GX2UTClearRectOp and
34 /// \ref GX2UTClearRectOp. After finishing all clear operations, it is
35 /// necessary to call this function to disable the clear state and set any
36 /// changed state to the GX2 default state. A smaller yet equivalent routine
37 /// can be written using knowledge of the application's desired state. To
38 /// customize the state that is restored, refer to the library source
39 /// (src/lib/gx2ut/gx2utClear.cpp).
40 ///
41 /// \donotcall \gx2_typical \enddonotcall
42 ///
43 /// \clobberstate
44 ///
45 /// \writesgpu
46 /// \alwayswritesgpu
47 ///
48 void GX2UTSetClearState(GX2Boolean enable);
49
50 /// \brief Performs a sub-rectangle clear operation on the buffers.
51 ///
52 /// \param colorBuffer Color buffer to clear (can be NULL).
53 /// \param depthBuffer Depth buffer to clear (can be NULL).
54 /// \param r Red color component of clear value
55 /// \param g Green color component of clear value
56 /// \param b Blue color component of clear value
57 /// \param a Alpha color component of clear value
58 /// \param depthBuffer Pointer to depth buffer to clear
59 /// \param depthClear Depth clear value (from 0.0 to 1.0)
60 /// \param stencilClear Stencil clear value (from 0 to 255)
61 /// \param clearFlags Indicates if depth and/or stencil buffer should be cleared
62 /// \param hiStencil pointer to HiStencil pretest states
63 /// \param dstRect Pointer to the destination region to clear.
64 ///
65 /// This function assumes \ref GX2UTSetClearState()
66 /// (or comparable state setup function) has been called to setup required
67 /// render state.
68 ///
69 /// Clears a region of a surface as specified by dstRect. The rect dimensions
70 /// should be relative to the mipmap level dimensions, not the base level
71 /// dimensions.
72 ///
73 /// This clears a color/depth buffer in the same way as \ref GX2ClearColor
74 /// and \ref GX2ClearDepthStencil. It modifies the current GX2State for all
75 /// shaders, GX2_RENDER_TARGET0, depth buffer, and Scissor/Viewport
76 /// settings.
77 ///
78 /// \note It is not necessary to call \ref GX2Invalidate on the color/depth
79 /// buffer being cleared. This is done internally.
80 ///
81 /// \note This clear, as it is, will be impacted by the toss stage
82 /// (\ref GX2TossStageSect) setup at GX2Init() time. To avoid this,
83 /// call this clear function from a separate state context with
84 /// profiling disabled. See \ref GX2SetupContextStateEx() for more
85 /// information.
86 ///
87 /// \donotcall \gx2_typical \enddonotcall
88 ///
89 /// \clobberstate
90 ///
91 /// \writesgpu
92 /// \alwayswritesgpu
93 ///
94 void GX2UTClearRectOp(GX2ColorBuffer *colorBuffer, GX2DepthBuffer *depthBuffer,
95 f32 r, f32 g, f32 b, f32 a, f32 depthClear, u8 stencilClear,
96 GX2ClearMode clearFlags, GX2HiStencilInfo *hiStencil, GX2UTRect *dstRect);
97
98 /// \brief Performs a clear operation on the buffers.
99 ///
100 /// \param colorBuffer Color buffer to clear (can be NULL).
101 /// \param depthBuffer Depth buffer to clear (can be NULL).
102 /// \param r Red color component of clear value
103 /// \param g Green color component of clear value
104 /// \param b Blue color component of clear value
105 /// \param a Alpha color component of clear value
106 /// \param depthBuffer Pointer to depth buffer to clear
107 /// \param depthClear Depth clear value (from 0.0 to 1.0)
108 /// \param stencilClear Stencil clear value (from 0 to 255)
109 /// \param clearFlags Indicates if depth and/or stencil buffer should be cleared
110 /// \param hiStencil pointer to HiStencil pretest states
111 ///
112 /// This function assumes \ref GX2UTSetClearState()
113 /// (or comparable state setup function) has been called to setup required
114 /// render state.
115 ///
116 /// This clears a color/depth buffer in the same way as \ref GX2ClearColor
117 /// and \ref GX2ClearDepthStencil. It modifies the current GX2State for all
118 /// shaders, GX2_RENDER_TARGET0, depth buffer, and Scissor/Viewport
119 /// settings.
120 ///
121 /// \note It is not necessary to call \ref GX2Invalidate on the color/depth
122 /// buffer being cleared. This is done internally.
123 ///
124 /// \note This clear, as it is, will be impacted by the toss stage
125 /// (\ref GX2TossStageSect) setup at GX2Init() time. To avoid this,
126 /// call this clear function from a separate state context with
127 /// profiling disabled. See \ref GX2SetupContextStateEx() for more
128 /// information.
129 ///
130 /// \donotcall \gx2_typical \enddonotcall
131 ///
132 /// \clobberstate
133 ///
134 /// \writesgpu
135 /// \alwayswritesgpu
136 ///
GX2UTClearOp(GX2ColorBuffer * colorBuffer,GX2DepthBuffer * depthBuffer,f32 r,f32 g,f32 b,f32 a,f32 depthClear,u8 stencilClear,GX2ClearMode clearFlags,GX2HiStencilInfo * hiStencil)137 GX2_INLINE void GX2UTClearOp(GX2ColorBuffer *colorBuffer,
138 GX2DepthBuffer *depthBuffer,
139 f32 r, f32 g, f32 b, f32 a,
140 f32 depthClear, u8 stencilClear,
141 GX2ClearMode clearFlags,
142 GX2HiStencilInfo *hiStencil)
143 {
144 GX2UTRect dstRect = {0};
145
146 ASSERT(colorBuffer || depthBuffer);
147
148 if (colorBuffer)
149 {
150 dstRect.right = GX2Max(1, colorBuffer->surface.width >> colorBuffer->viewMip);
151 dstRect.bottom = GX2Max(1, colorBuffer->surface.height >> colorBuffer->viewMip);
152 }
153 else
154 {
155 dstRect.right = GX2Max(1, depthBuffer->surface.width >> depthBuffer->viewMip);
156 dstRect.bottom = GX2Max(1, depthBuffer->surface.height >> depthBuffer->viewMip);
157 }
158
159 GX2UTDebugTagIndent(__func__);
160
161 GX2UTClearRectOp(colorBuffer, depthBuffer, r, g, b, a,
162 depthClear, stencilClear, clearFlags, hiStencil, &dstRect);
163
164 GX2UTDebugTagUndent();
165 }
166
167 /// \brief Setup parameter specific render state and clear the specified dest surface.
168 ///
169 /// \param dstSurface Pointer to destination surface structure
170 /// \param dstMip Mip level of dest surface to write (0 typically)
171 /// \param dstSlice Slice to write for array & 3D (0 typically)
172 /// \param dstRect Pointer to the destination region to clear.
173 /// \param dstAuxPtr Destination MSAA auxPtr for AA buffer or NULL for non-AA buffers.
174 /// \param dstAuxSize Destination MSAA auxSize for AA buffers or NULL for non-AA buffers.
175 /// \param r Red color component of clear value
176 /// \param g Green color component of clear value
177 /// \param b Blue color component of clear value
178 /// \param a Alpha color component of clear value
179 /// \param depthBuffer Pointer to depth buffer to clear
180 /// \param depthClear Depth clear value (from 0.0 to 1.0)
181 /// \param stencilClear Stencil clear value (from 0 to 255)
182 /// \param clearFlags Indicates if depth and/or stencil buffer should be cleared
183 /// \param hiStencil pointer to HiStencil pretest states
184 ///
185 /// This function assumes \ref GX2UTSetClearState()
186 /// (or comparable state setup function) has been called to setup required
187 /// render state.
188 ///
189 /// Clears a region of a surface as specified by dstRect. The rect dimensions
190 /// should be relative to the mipmap level dimensions, not the base level
191 /// dimensions.
192 ///
193 /// This clears a color/depth buffer in the same way as \ref GX2ClearColor
194 /// and \ref GX2ClearDepthStencil. It modifies the current GX2State for all
195 /// shaders, GX2_RENDER_TARGET0, depth buffer, and Scissor/Viewport
196 /// settings.
197 ///
198 /// \note It is not necessary to call \ref GX2Invalidate on the color/depth
199 /// buffer being cleared. This is done internally.
200 ///
201 /// \note This clear, as it is, will be impacted by the toss stage
202 /// (\ref GX2TossStageSect) setup at GX2Init() time. To avoid this,
203 /// call this clear function from a separate state context with
204 /// profiling disabled. See \ref GX2SetupContextStateEx() for more
205 /// information.
206 ///
207 /// \warning The behavior of this routine has changed from SDK 2.12.00!
208 /// It now disables state shadowing and requires
209 /// \ref GX2SetContextState afterward. To avoid this, please use
210 /// \ref GX2UTClearRectOp instead.
211 ///
212 /// \clobberstate
213 /// \disablesstateshadow
214 ///
215 /// \donotcall \gx2_typical \enddonotcall
216 ///
217 /// \writesgpu
218 /// \alwayswritesgpu
219 ///
GX2UTClearSurfaceRect(GX2Surface * dstSurface,u32 dstMip,u32 dstSlice,GX2UTRect * dstRect,void * dstAuxPtr,u32 dstAuxSize,f32 r,f32 g,f32 b,f32 a,GX2DepthBuffer * depthBuffer,f32 depthClear,u8 stencilClear,GX2ClearMode clearFlags,GX2HiStencilInfo * hiStencil)220 GX2_INLINE void GX2UTClearSurfaceRect(GX2Surface *dstSurface, u32 dstMip, u32 dstSlice,
221 GX2UTRect *dstRect, void* dstAuxPtr, u32 dstAuxSize,
222 f32 r, f32 g, f32 b, f32 a,
223 GX2DepthBuffer *depthBuffer, f32 depthClear,
224 u8 stencilClear, GX2ClearMode clearFlags,
225 GX2HiStencilInfo *hiStencil)
226 {
227 GX2ColorBuffer *cbPtr = NULL;
228 GX2DepthBuffer *dbPtr = NULL;
229 GX2ColorBuffer cb;
230 GX2DepthBuffer db;
231
232 GX2UTDebugTagIndent(__func__);
233
234 if ( dstSurface )
235 {
236 cb.viewMip = dstMip;
237 cb.viewFirstSlice = dstSlice;
238 cb.viewNumSlices = 1;
239 cb.auxPtr = dstAuxPtr;
240 cb.auxSize = dstAuxSize;
241 cb.surface = *dstSurface;
242 GX2InitColorBufferRegs(&cb);
243 cbPtr = &cb;
244 }
245
246 if ( depthBuffer )
247 {
248 db = *depthBuffer;
249 db.viewMip = dstMip;
250 db.viewFirstSlice = dstSlice;
251 db.viewNumSlices = 1;
252 GX2InitDepthBufferRegs(&db);
253
254 dbPtr = &db;
255 }
256
257 // Disable state shadowing
258 GX2SetContextState(NULL);
259
260 // Setup clear
261 GX2UTSetClearState(GX2_ENABLE);
262
263 // Just clear a single slice at the given mip level
264 GX2UTClearRectOp(cbPtr, dbPtr, r, g, b, a, depthClear, stencilClear,
265 clearFlags, hiStencil, dstRect);
266
267 // Disable clear state
268 GX2UTSetClearState(GX2_DISABLE);
269
270 GX2UTDebugTagUndent();
271 }
272
273 /// \brief Clear a color and/or depth/stencil surface with Hi-Stencil.
274 ///
275 /// \deprecated This API has been deprecated and may not be available in future
276 /// releases. Please use \ref GX2UTClearSurfaceRect instead.
277 ///
278 /// \param dstSurface Pointer to destination surface structure
279 /// \param dstMip Mip level of dest surface to write (0 typically)
280 /// \param dstSlice Slice to write for array & 3D (0 typically)
281 /// \param dstRect Pointer to the destination region to clear.
282 /// \param dstAuxPtr Destination MSAA auxPtr for AA buffer or NULL for non-AA buffers.
283 /// \param dstAuxSize Destination MSAA auxSize for AA buffers or NULL for non-AA buffers.
284 /// \param r Red color component of clear value
285 /// \param g Green color component of clear value
286 /// \param b Blue color component of clear value
287 /// \param a Alpha color component of clear value
288 /// \param depthBuffer Pointer to depth buffer to clear
289 /// \param depthClear Depth clear value (from 0.0 to 1.0)
290 /// \param stencilClear Stencil clear value (from 0 to 255)
291 /// \param clearFlags Indicates if depth and/or stencil buffer should be cleared
292 /// \param hiStencil pointer to HiStencil pretest states
293 ///
294 /// \note This API changes rendering states and disables state shadowing.
295 /// If you are using state shadowing, you must call
296 /// \ref GX2SetContextState() afterward.
297 ///
298 /// \warning Better performing alternatives exist. Please see
299 /// \ref GX2UTAdvancedGX2ReplacementAPISect.
300 ///
301 /// \donotcall \gx2_typical \enddonotcall
302 ///
303 /// \clobberstate
304 /// \disablesstateshadow
305 ///
306 /// \writesgpu
307 /// \alwayswritesgpu
308 ///
GX2UTSetAndClearSurfaceRect(GX2Surface * dstSurface,u32 dstMip,u32 dstSlice,GX2UTRect * dstRect,void * dstAuxPtr,u32 dstAuxSize,f32 r,f32 g,f32 b,f32 a,GX2DepthBuffer * depthBuffer,f32 depthClear,u8 stencilClear,GX2ClearMode clearFlags,GX2HiStencilInfo * hiStencil)309 GX2_INLINE void GX2UTSetAndClearSurfaceRect(
310 GX2Surface *dstSurface, u32 dstMip, u32 dstSlice, GX2UTRect *dstRect,
311 void* dstAuxPtr, u32 dstAuxSize, f32 r, f32 g, f32 b, f32 a,
312 GX2DepthBuffer *depthBuffer, f32 depthClear, u8 stencilClear,
313 GX2ClearMode clearFlags, GX2HiStencilInfo *hiStencil)
314 {
315 GX2UTDebugTagIndent(__func__);
316
317 // Setup parameter specific render state and clear.
318 GX2UTClearSurfaceRect(dstSurface, dstMip, dstSlice, dstRect,
319 dstAuxPtr, dstAuxSize, r, g, b, a,
320 depthBuffer, depthClear, stencilClear,
321 clearFlags, hiStencil);
322
323 GX2UTDebugTagUndent();
324 }
325
326 /// \brief Setup parameter specific render state and clear the specified dest surface.
327 ///
328 /// \param dstSurface Pointer to destination surface structure
329 /// \param dstMip Mip level of dest surface to write (0 typically)
330 /// \param dstSlice Slice to write for array & 3D (0 typically)
331 /// \param r Red color component of clear value
332 /// \param g Green color component of clear value
333 /// \param b Blue color component of clear value
334 /// \param a Alpha color component of clear value
335 /// \param depthBuffer Pointer to depth buffer to clear
336 /// \param depthClear Depth clear value (from 0.0 to 1.0)
337 /// \param stencilClear Stencil clear value (from 0 to 255)
338 /// \param clearFlags Indicates if depth and/or stencil buffer should be cleared
339 /// \param hiStencil pointer to HiStencil pretest states
340 ///
341 /// This routine is a convenience function for \ref GX2UTClearOp.
342 ///
343 /// Clears a region of a surface as specified by dstRect. The rect dimensions
344 /// should be relative to the mipmap level dimensions, not the base level
345 /// dimensions.
346 ///
347 /// This clears a color/depth buffer in the same way as \ref GX2ClearColor
348 /// and \ref GX2ClearDepthStencil. It modifies the current GX2State for all
349 /// shaders, GX2_RENDER_TARGET0, depth buffer, and Scissor/Viewport
350 /// settings.
351 ///
352 /// To specify a region within the surface to be cleared, use
353 /// \ref GX2UTClearSurfaceRect instead.
354 ///
355 /// \note It is not necessary to call \ref GX2Invalidate on the color/depth
356 /// buffer being cleared. This is done internally.
357 ///
358 /// \note This clear, as it is, will be impacted by the toss stage
359 /// (\ref GX2TossStageSect) setup at GX2Init() time. To avoid this,
360 /// call this clear function from a separate state context with
361 /// profiling disabled. See \ref GX2SetupContextStateEx() for more
362 /// information.
363 ///
364 /// \warning Better performing alternatives exist. Please see
365 /// \ref GX2UTAdvancedGX2ReplacementAPISect.
366 ///
367 /// \warning This routine does not work when dstSurface.aa != GX2_AA_MODE_1X.
368 /// Use \ref GX2UTClearSurfaceRect instead. Otherwise memory corruption
369 /// will occur.
370 ///
371 /// \warning The behavior of this routine has changed from SDK 2.12.00!
372 /// It now disables state shadowing and requires
373 /// \ref GX2SetContextState afterward. To avoid this, please use
374 /// \ref GX2UTClearOp instead.
375 ///
376 /// \clobberstate
377 /// \disablesstateshadow
378 ///
379 /// \donotcall \gx2_typical \enddonotcall
380 ///
381 /// \writesgpu
382 /// \alwayswritesgpu
383 ///
GX2UTClearSurface(GX2Surface * dstSurface,u32 dstMip,u32 dstSlice,f32 r,f32 g,f32 b,f32 a,GX2DepthBuffer * depthBuffer,f32 depthClear,u8 stencilClear,GX2ClearMode clearFlags,GX2HiStencilInfo * hiStencil)384 GX2_INLINE void GX2UTClearSurface(GX2Surface *dstSurface, u32 dstMip, u32 dstSlice,
385 f32 r, f32 g, f32 b, f32 a,
386 GX2DepthBuffer *depthBuffer,
387 f32 depthClear, u8 stencilClear,
388 GX2ClearMode clearFlags,
389 GX2HiStencilInfo *hiStencil)
390 {
391 GX2UTRect dstRect;
392
393 GX2UTDebugTagIndent(__func__);
394
395 ASSERT(dstSurface != NULL || depthBuffer != NULL);
396
397 if (dstSurface)
398 {
399 //We need to adjust rectangles based on the mip level
400 dstRect.left = 0;
401 dstRect.top = 0;
402 dstRect.right = GX2Max(1, dstSurface->width >> dstMip);
403 dstRect.bottom = GX2Max(1, dstSurface->height >> dstMip);
404 }
405 else
406 {
407 //Use depthBuffer for dimensions
408 dstRect.left = 0;
409 dstRect.top = 0;
410 dstRect.right = GX2Max(1, depthBuffer->surface.width);
411 dstRect.bottom = GX2Max(1, depthBuffer->surface.height);
412 }
413
414 GX2UTClearSurfaceRect(dstSurface, dstMip, dstSlice, &dstRect,
415 NULL, 0, r, g, b, a,
416 depthBuffer, depthClear, stencilClear, clearFlags, hiStencil);
417
418 GX2UTDebugTagUndent();
419 }
420
421 /// \brief Clears the given render target and depth/stencil surface.
422 ///
423 /// \param colorBuffer pointer to color buffer to clear
424 /// \param depthBuffer pointer to depth/stencil buffer to clear
425 /// \param r Red color component of clear value
426 /// \param g Green color component of clear value
427 /// \param b Blue color component of clear value
428 /// \param a Alpha color component of clear value
429 /// \param depthValue Depth clear value (from 0.0 to 1.0)
430 /// \param stencilValue Stencil clear value (from 0 to 255)
431 /// \param clearFlags Indicates if depth and/or stencil buffer should be cleared
432 ///
433 /// This function mimics the behavior of GX2 and is intended to be an optimized
434 /// replacement for \ref GX2ClearBuffersEx.
435 ///
436 /// \note This clear, as it is, will be impacted by the toss stage (GX2TossStage)
437 /// setup at GX2Init() time. To avoid this, call this clear function from
438 /// a separate state context with profiling disabled. See
439 /// \ref GX2SetupContextStateEx() for more information.
440 ///
441 /// \warning Better performing alternatives exist. Please see
442 /// \ref GX2UTAdvancedGX2ReplacementAPISect.
443 ///
444 /// \clobberstate
445 /// \disablesstateshadow
446 ///
447 /// \donotcall \gx2_typical \enddonotcall
448 ///
449 /// \writesgpu
450 /// \alwayswritesgpu
451 ///
GX2UTClearBuffersEx(GX2ColorBuffer * colorBuffer,GX2DepthBuffer * depthBuffer,f32 r,f32 g,f32 b,f32 a,f32 depthValue,u8 stencilValue,GX2ClearMode clearFlags)452 GX2_INLINE void GX2UTClearBuffersEx(GX2ColorBuffer *colorBuffer,
453 GX2DepthBuffer *depthBuffer,
454 f32 r, f32 g, f32 b, f32 a,
455 f32 depthValue, u8 stencilValue,
456 GX2ClearMode clearFlags)
457 {
458 GX2UTRect dstRect;
459
460 ASSERT(colorBuffer || depthBuffer);
461
462 GX2UTDebugTagIndent(__func__);
463
464 if ( colorBuffer )
465 {
466 // We need to adjust rectangles based on the mip level
467 dstRect.left = 0;
468 dstRect.top = 0;
469 dstRect.right = GX2Max(1, colorBuffer->surface.width >> colorBuffer->viewMip);
470 dstRect.bottom = GX2Max(1, colorBuffer->surface.height >> colorBuffer->viewMip);
471 }
472 else
473 {
474 // We need to adjust rectangles based on the mip level
475 dstRect.left = 0;
476 dstRect.top = 0;
477 dstRect.right = GX2Max(1, depthBuffer->surface.width >> depthBuffer->viewMip);
478 dstRect.bottom = GX2Max(1, depthBuffer->surface.height >> depthBuffer->viewMip);
479 }
480
481 //Disable state shadowing. If your app is using state shadowing,
482 //you will need to restore the context after calling this function.
483 GX2SetContextState(NULL);
484
485 // Setup all of the constant render state needed for the clear.
486 GX2UTSetClearState(GX2_ENABLE);
487
488 // Clear the rectangle
489 GX2UTClearRectOp(colorBuffer, depthBuffer, r, g, b, a,
490 depthValue, stencilValue, clearFlags,
491 NULL, &dstRect);
492
493 // Disable special hardware state and set state back to GX2 default
494 GX2UTSetClearState(GX2_DISABLE);
495
496 GX2UTDebugTagUndent();
497 }
498
499 /// \brief Clears the given render target to the specified color.
500 ///
501 /// \param colorBuffer pointer to color buffer to clear
502 /// \param r Red color component of clear value
503 /// \param g Green color component of clear value
504 /// \param b Blue color component of clear value
505 /// \param a Alpha color component of clear value
506 ///
507 /// This function mimics the behavior of GX2 and is intended to be an optimized
508 /// replacement for \ref GX2ClearColor.
509 ///
510 /// \note This API changes rendering states and disables state shadowing.
511 /// If you are using state shadowing, you must call
512 /// \ref GX2SetContextState() afterward.
513 ///
514 /// \note This function clears only the single miplevel specified by
515 /// colorBuffer->viewMip. This function clears the number of slices
516 /// specified by colorBuffer->viewNumSlices starting with slice number
517 /// colorBuffer->viewFirstSlice.
518 ///
519 /// \warning Better performing alternatives exist. Please see
520 /// \ref GX2UTAdvancedGX2ReplacementAPISect.
521 ///
522 /// \clobberstate
523 /// \disablesstateshadow
524 ///
525 /// \donotcall \gx2_typical \enddonotcall
526 ///
527 /// \writesgpu
528 /// \alwayswritesgpu
529 ///
GX2UTClearColor(GX2ColorBuffer * colorBuffer,f32 r,f32 g,f32 b,f32 a)530 GX2_INLINE void GX2UTClearColor(GX2ColorBuffer *colorBuffer,
531 f32 r, f32 g, f32 b, f32 a)
532 {
533 GX2UTDebugTagIndent(__func__);
534
535 GX2UTClearBuffersEx(colorBuffer, NULL, r, g, b, a, 0.0f, 0u, GX2_CLEAR_NONE);
536
537 GX2UTDebugTagUndent();
538 }
539
540 /// \brief Clear the depth/stencil surface with saved depth and stencil values.
541 ///
542 /// \param depthBuffer pointer to depth/stencil buffer to clear
543 /// \param clearFlags Indicates if depth and/or stencil buffer should be cleared
544 ///
545 /// This function mimics the behavior of GX2 and is intended to be an optimized
546 /// replacement for \ref GX2ClearDepthStencil.
547 ///
548 /// \note This API changes rendering states and disables state shadowing.
549 /// If you are using state shadowing, you must call
550 /// \ref GX2SetContextState() afterward
551 /// (when (clearFlags & (GX2_CLEAR_DEPTH|GX2_CLEAR_STENCIL)) != 0).
552 ///
553 /// \note This API will use the current clearDepth and clearStencil values
554 /// from the \ref GX2DepthBuffer.
555 ///
556 /// \note This function clears only the single miplevel specified by
557 /// depthBuffer->viewMip. This function clears the number of slices
558 /// specified by depthBuffer->viewNumSlices starting with slice number
559 /// depthBuffer->viewFirstSlice.
560 ///
561 /// \note To generate valuable HiStencil pretest results while clearing the
562 /// stencil buffer, please see \ref GX2UTClearRectOp.
563 ///
564 /// \warning Better performing alternatives exist. Please see
565 /// \ref GX2UTAdvancedGX2ReplacementAPISect.
566 ///
567 /// \clobberstate
568 /// \disablesstateshadow
569 ///
570 /// \donotcall \gx2_typical \enddonotcall
571 ///
572 /// \writesgpu
573 /// \alwayswritesgpu
574 ///
GX2UTClearDepthStencil(GX2DepthBuffer * depthBuffer,GX2ClearMode clearFlags)575 GX2_INLINE void GX2UTClearDepthStencil(GX2DepthBuffer *depthBuffer, GX2ClearMode clearFlags)
576 {
577 ASSERT(depthBuffer);
578
579 GX2UTDebugTagIndent(__func__);
580
581 GX2UTClearBuffersEx(NULL, depthBuffer, 0.0f, 0.0f, 0.0f, 0.0f, depthBuffer->clearDepth, depthBuffer->clearStencil, clearFlags);
582
583 GX2UTDebugTagUndent();
584 }
585
586 /// \brief Clear the depth/stencil surface with given depth and stencil values.
587 ///
588 /// \param depthBuffer pointer to depth/stencil buffer to clear
589 /// \param depthValue Depth clear value (from 0.0 to 1.0)
590 /// \param stencilValue Stencil clear value (from 0 to 255)
591 /// \param clearFlags Indicates if depth and/or stencil buffer should be cleared
592 ///
593 /// This function mimics the behavior of GX2 and is intended to be an optimized
594 /// replacement for \ref GX2ClearDepthStencilEx.
595 ///
596 /// \note This function clears only the single miplevel specified by
597 /// depthBuffer->viewMip. This function clears the number of slices
598 /// specified by depthBuffer->viewNumSlices starting with slice number
599 /// depthBuffer->viewFirstSlice.
600 ///
601 /// \warning Better performing alternatives exist. Please see
602 /// \ref GX2UTAdvancedGX2ReplacementAPISect.
603 ///
604 /// \clobberstate
605 /// \disablesstateshadow
606 ///
607 /// \donotcall \gx2_typical \enddonotcall
608 ///
609 /// \writesgpu
610 /// \alwayswritesgpu
611 ///
GX2UTClearDepthStencilEx(GX2DepthBuffer * depthBuffer,f32 depthValue,u8 stencilValue,GX2ClearMode clearFlags)612 GX2_INLINE void GX2UTClearDepthStencilEx(GX2DepthBuffer *depthBuffer,
613 f32 depthValue, u8 stencilValue,
614 GX2ClearMode clearFlags)
615 {
616 GX2UTDebugTagIndent(__func__);
617
618 GX2UTClearBuffersEx(NULL, depthBuffer, 0.0f, 0.0f, 0.0f, 0.0f, depthValue, stencilValue, clearFlags);
619
620 GX2UTDebugTagUndent();
621 }
622
623 /// \brief Clears the given render target and depth/stencil surface.
624 ///
625 /// \param colorBuffer pointer to color buffer to clear
626 /// \param depthBuffer pointer to depth/stencil buffer to clear
627 /// \param r Red color component of clear value
628 /// \param g Green color component of clear value
629 /// \param b Blue color component of clear value
630 /// \param a Alpha color component of clear value
631 /// \param clearFlags Indicates if depth and/or stencil buffer should be cleared
632 ///
633 /// This function mimics the behavior of GX2 and is intended to be an optimized
634 /// replacement for \ref GX2ClearBuffers.
635 ///
636 /// \note This API changes rendering states and disables state shadowing.
637 /// If you are using state shadowing, you must call
638 /// \ref GX2SetContextState() afterward.
639 ///
640 /// \warning Better performing alternatives exist. Please see
641 /// \ref GX2UTAdvancedGX2ReplacementAPISect.
642 ///
643 /// \clobberstate
644 /// \disablesstateshadow
645 ///
646 /// \donotcall \gx2_typical \enddonotcall
647 ///
648 /// \writesgpu
649 /// \alwayswritesgpu
650 ///
GX2UTClearBuffers(GX2ColorBuffer * colorBuffer,GX2DepthBuffer * depthBuffer,f32 r,f32 g,f32 b,f32 a,GX2ClearMode clearFlags)651 GX2_INLINE void GX2UTClearBuffers(GX2ColorBuffer *colorBuffer, GX2DepthBuffer *depthBuffer,
652 f32 r, f32 g, f32 b, f32 a, GX2ClearMode clearFlags)
653 {
654 ASSERT(depthBuffer);
655
656 GX2UTDebugTagIndent(__func__);
657
658 GX2UTClearBuffersEx(colorBuffer, depthBuffer, r, g, b, a, depthBuffer->clearDepth, depthBuffer->clearStencil, clearFlags);
659
660 GX2UTDebugTagUndent();
661 }
662
663 /// \brief Clear a color and/or depth/stencil surface with Hi-Stencil.
664 ///
665 /// \deprecated This API has been deprecated and may not be available in future
666 /// releases. Please use \ref GX2UTCopySurfaceEx instead.
667 ///
668 /// \param dstSurface Pointer to destination surface structure
669 /// \param dstMip Mip level of dest surface to write (0 typically)
670 /// \param dstSlice Slice to write for array & 3D (0 typically)
671 /// \param r Red color component of clear value
672 /// \param g Green color component of clear value
673 /// \param b Blue color component of clear value
674 /// \param a Alpha color component of clear value
675 /// \param depthBuffer Pointer to depth buffer to clear
676 /// \param depthClear Depth clear value (from 0.0 to 1.0)
677 /// \param stencilClear Stencil clear value (from 0 to 255)
678 /// \param clearFlags Indicates if depth and/or stencil buffer should be cleared
679 /// \param hiStencil pointer to HiStencil pretest states
680 ///
681 /// \note It is not necessary to call \ref GX2Invalidate on the color/depth
682 /// buffer being cleared. This is done internally.
683 ///
684 /// \note This API changes rendering states and disables state shadowing.
685 /// If you are using state shadowing, you must call
686 /// \ref GX2SetContextState() afterward.
687 ///
688 /// \warning Better performing alternatives exist. Please see
689 /// \ref GX2UTAdvancedGX2ReplacementAPISect.
690 ///
691 /// \clobberstate
692 /// \disablesstateshadow
693 ///
694 /// \donotcall \gx2_typical \enddonotcall
695 ///
696 /// \writesgpu
697 /// \alwayswritesgpu
698 ///
GX2UTSetAndClearSurface(GX2Surface * dstSurface,u32 dstMip,u32 dstSlice,f32 r,f32 g,f32 b,f32 a,GX2DepthBuffer * depthBuffer,f32 depthClear,u8 stencilClear,GX2ClearMode clearFlags,GX2HiStencilInfo * hiStencil)699 GX2_INLINE void GX2UTSetAndClearSurface(GX2Surface *dstSurface, u32 dstMip, u32 dstSlice,
700 f32 r, f32 g, f32 b, f32 a,
701 GX2DepthBuffer *depthBuffer, f32 depthClear, u8 stencilClear,
702 GX2ClearMode clearFlags, GX2HiStencilInfo *hiStencil)
703 {
704 GX2UTDebugTagIndent(__func__);
705
706 // Setup parameter specific render state and clear.
707 GX2UTClearSurface(dstSurface, dstMip, dstSlice, r, g, b, a, depthBuffer,
708 depthClear, stencilClear, clearFlags, hiStencil);
709
710 GX2UTDebugTagUndent();
711 }
712
713 /// \brief A function to invalidate the HiStencil pretest results.
714 ///
715 /// \param dstRect Pointer to the destination region to clear.
716 /// \param depthBuffer Pointer to depth buffer to clear
717 ///
718 /// This routine clears the HiStencil pretest results without clearing the
719 /// actual stencil buffer. This should be invoked if the HiStencil pretest
720 /// states need to be changed during a frame. This is faster than clearing
721 /// and regenerating the actual stencil buffer.
722 ///
723 /// \note Must be invoked when changing the HiStencil state within a frame. In
724 /// other words, always invoke this function in combination with
725 /// \ref GX2SetHiStencilInfo. Never invoke one without the other or
726 /// HiStencil buffer corruption will occur.
727 ///
728 /// \clobberstate
729 /// \disablesstateshadow
730 ///
731 /// \donotcall \gx2_typical \enddonotcall
732 ///
733 /// \writesgpu
734 /// \alwayswritesgpu
735 ///
736 void GX2UTInvalidateHiStencilRect(GX2UTRect *dstRect, GX2DepthBuffer *depthBuffer);
737
738 /// \brief Clears the MSAA color buffer auxPtr.
739 ///
740 /// This clears the \ref GX2ColorBuffer.auxPtr to
741 /// \ref GX2_AUX_BUFFER_CLEAR_VALUE using the graphics pipeline.
742 ///
743 /// \param colorBuffer MSAA Color buffer to clear
744 ///
745 /// \clobberstate
746 ///
747 /// \donotcall \gx2_typical \enddonotcall
748 ///
749 /// \writesgpu
750 /// \alwayswritesgpu
751 ///
752 void GX2UTSetupColorAuxBufferOp(GX2ColorBuffer *colorBuffer);
753
754 /// \brief Clears the MSAA color buffer auxPtr.
755 ///
756 /// This clears the \ref GX2ColorBuffer.auxPtr to
757 /// \ref GX2_AUX_BUFFER_CLEAR_VALUE using the graphics pipeline.
758 ///
759 /// \param colorBuffer MSAA Color buffer to clear
760 ///
761 /// \warning Better performing alternative exists. Please see
762 /// \ref GX2UTSetupColorAuxBufferOp and \ref GX2UTSetClearState.
763 ///
764 /// \clobberstate
765 /// \disablesstateshadow
766 ///
767 /// \donotcall \gx2_typical \enddonotcall
768 ///
769 /// \writesgpu
770 /// \alwayswritesgpu
771 ///
GX2UTSetupColorAuxBuffer(GX2ColorBuffer * colorBuffer)772 GX2_INLINE void GX2UTSetupColorAuxBuffer(GX2ColorBuffer *colorBuffer)
773 {
774 // Disable state shadowing
775 GX2SetContextState(NULL);
776
777 // Setup clear
778 GX2UTSetClearState(GX2_ENABLE);
779
780 // Just clear a single slice at the given mip level
781 GX2UTSetupColorAuxBufferOp(colorBuffer);
782
783 // Disable clear state
784 GX2UTSetClearState(GX2_DISABLE);
785
786
787 }
788
789 /// @}
790
791 #ifdef __cplusplus
792 }
793 #endif // __cplusplus
794
795 #endif // _GX2UTCLEAR_H_
796