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