1 /*---------------------------------------------------------------------------*
2
3 Copyright 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 _GX2UTRESOLVE_H_
14 #define _GX2UTRESOLVE_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 #include <cafe/gx2.h>
19
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23
24 /// @addtogroup GX2UTCopyAndConvertGroup
25 /// @{
26
27 /// \brief Setup all of the constant render state needed for \ref GX2UTResolveAAColorBuffer.
28 ///
29 /// \param enable Enable or disable the state
30 ///
31 /// This enables and disables the state used by \ref GX2UTResolveAAColorBuffer.
32 /// After finishing all resolve operations, it is necessary to call
33 /// this function to disable the resolve state and set any changed state
34 /// back to the GX2 default state. A smaller yet equivalent routine can be
35 /// written using knowledge of the application's desired state.
36 /// To customize the state that is restored, refer to the library source
37 /// (src/lib/gx2ut/gx2utResolve.cpp).
38 ///
39 /// \donotcall \gx2_typical \enddonotcall
40 ///
41 /// \clobberstate
42 ///
43 /// \writesgpu
44 /// \alwayswritesgpu
45 ///
46 void GX2UTSetResolveAAColorState(GX2Boolean enable);
47
48 /// \brief Resolves a MSAA color buffer to a single-sampled surface.
49 ///
50 /// \param cb Pointer to color buffer surface structure
51 /// \param dstSurface Destination color/texture surface.
52 /// \param dstMip Destination mipmap level for dstSurface.
53 /// \param dstSlice Destination slice for dstSurface.
54 /// \param subRect Pointer to the region to resolve.
55 ///
56 /// This function assumes \ref GX2UTSetResolveAAColorState
57 /// (or comparable state setup function) has been called to setup required
58 /// render state.
59 ///
60 /// This resolves a MSAA color buffer to a single-sampled surface in the same
61 /// way as \ref GX2ResolveAAColorBuffer. It modifies the current GX2 state for
62 /// all shaders, GX2_RENDER_TARGET0, GX2_RENDER_TARGET1, and Scissor/Viewport
63 /// settings.
64 ///
65 /// Resolves a region from one surface to a region of another surface. Setting
66 /// the rectangular regions to a top-left of (0,0) and a bottom-right of (width,
67 /// height) will resolve the entire surface without any flipping (the right and
68 /// bottom are exclusive).
69 ///
70 /// The subRect dimensions should be relative to the mipmap level dimensions,
71 /// not the base level dimensions. The subRect origin (left, top) must be
72 /// aligned on a 2x2 pixel boundary.
73 ///
74 /// \note It is not necessary to call \ref GX2Invalidate on the
75 /// source/destination buffer. This is done internally.
76 ///
77 /// \note This routine has the same limitations as \ref GX2ResolveAAColorBuffer.
78 /// \ref GX2IsResolveSupported can be used to determine if a source
79 /// GX2ColorBuffer can be resolved.
80 ///
81 /// \note This resolve, as it is, will be impacted by the toss stage
82 /// (\ref GX2TossStageSect) setup at GX2Init time. To avoid this, call
83 /// this function from a separate state context with profiling disabled.
84 /// See \ref GX2SetupContextStateEx for more information.
85 ///
86 /// \warning The color buffer must not be an AA buffer and the destination
87 /// surface must be a non-AA color/texture surface.
88 ///
89 /// \clobberstate
90 ///
91 /// \donotcall \gx2_typical \enddonotcall
92 ///
93 /// \writesgpu
94 /// \alwayswritesgpu
95 ///
96 void GX2UTResolveAAColorBufferRectOp(const GX2ColorBuffer *cb,
97 GX2Surface *dstSurface,
98 u32 dstMip, u32 dstSlice,
99 GX2UTRect * subRect);
100
101 /// \brief Resolves a MSAA color buffer to a single-sampled surface.
102 ///
103 /// \param cb Pointer to color buffer surface structure
104 /// \param dstSurface Destination color/texture surface.
105 /// \param dstMip Destination mipmap level for dstSurface.
106 /// \param dstSlice Destination slice for dstSurface.
107 ///
108 /// This function assumes \ref GX2UTSetResolveAAColorState
109 /// (or comparable state setup function) has been called to setup required
110 /// render state.
111 ///
112 /// This resolves a MSAA color buffer to a single-sampled surface in the same
113 /// way as \ref GX2ResolveAAColorBuffer. It modifies the current GX2 state for
114 /// all shaders, GX2_RENDER_TARGET0, GX2_RENDER_TARGET1, and Scissor/Viewport
115 /// settings.
116 ///
117 /// \note It is not necessary to call \ref GX2Invalidate on the
118 /// source/destination buffer. This is done internally.
119 ///
120 /// \note This routine has the same limitations as \ref GX2ResolveAAColorBuffer.
121 /// \ref GX2IsResolveSupported can be used to determine if a source
122 /// GX2ColorBuffer can be resolved.
123 ///
124 /// \note This resolve, as it is, will be impacted by the toss stage
125 /// (\ref GX2TossStageSect) setup at GX2Init time. To avoid this, call
126 /// this function from a separate state context with profiling disabled.
127 /// See \ref GX2SetupContextStateEx for more information.
128 ///
129 /// \warning The color buffer must not be an AA buffer and the destination
130 /// surface must be a non-AA color/texture surface.
131 ///
132 /// \clobberstate
133 ///
134 /// \donotcall \gx2_typical \enddonotcall
135 ///
136 /// \writesgpu
137 /// \alwayswritesgpu
138 ///
GX2UTResolveAAColorBufferOp(const GX2ColorBuffer * cb,GX2Surface * dstSurface,u32 dstMip,u32 dstSlice)139 GX2_INLINE void GX2UTResolveAAColorBufferOp(const GX2ColorBuffer *cb,
140 GX2Surface *dstSurface, u32 dstMip,
141 u32 dstSlice)
142 {
143 GX2UTRect subRect = {0};
144
145 subRect.right = GX2Max(1, dstSurface->width >> dstMip);
146 subRect.bottom = GX2Max(1, dstSurface->height >> dstMip);
147
148 GX2UTDebugTagIndent(__func__);
149
150 GX2UTResolveAAColorBufferRectOp(cb, dstSurface, dstMip, dstSlice, &subRect);
151
152 GX2UTDebugTagUndent();
153 }
154
155
156 /// \brief Resolves a MSAA color buffer to a single-sampled surface.
157 ///
158 /// \param cb Pointer to color buffer surface structure
159 /// \param dstSurface Destination color/texture surface.
160 /// \param dstMip Destination mipmap level for dstSurface.
161 /// \param dstSlice Destination slice for dstSurface.
162 ///
163 /// This function mimics the behavior of GX2 and is intended to be an optimized
164 /// replacement for \ref GX2ResolveAAColorBuffer.
165 ///
166 /// \note This API changes rendering states and disables state shadowing.
167 /// If you are using state shadowing, you must call
168 /// \ref GX2SetContextState() afterward.
169 ///
170 /// \note This routine has the same limitations as \ref GX2ResolveAAColorBuffer.
171 /// \ref GX2IsResolveSupported can be used to determine if a source
172 /// GX2ColorBuffer can be resolved.
173 ///
174 /// \warning Better performing alternatives exist. Please see
175 /// \ref GX2UTAdvancedGX2ReplacementAPISect.
176 ///
177 /// \clobberstate
178 /// \disablesstateshadow
179 ///
180 /// \donotcall \gx2_typical \enddonotcall
181 ///
182 /// \writesgpu
183 /// \alwayswritesgpu
184 ///
GX2UTResolveAAColorBuffer(const GX2ColorBuffer * cb,GX2Surface * dstSurface,u32 dstMip,u32 dstSlice)185 GX2_INLINE void GX2UTResolveAAColorBuffer(const GX2ColorBuffer *cb,
186 GX2Surface *dstSurface, u32 dstMip,
187 u32 dstSlice)
188 {
189 GX2UTDebugTagIndent(__func__);
190
191 // Disable state shadowing. If your app is using state shadowing,
192 // you will need to restore the context after calling this function.
193 GX2SetContextState(NULL);
194
195 // Setup all of the constant render state needed for the color resolve.
196 GX2UTSetResolveAAColorState(GX2_ENABLE);
197
198 // Setup parameter specific render state and color resolve.
199 GX2UTResolveAAColorBufferOp(cb, dstSurface, dstMip, dstSlice);
200
201 // Disable special hardware state and set state back to GX2 default
202 GX2UTSetResolveAAColorState(GX2_DISABLE);
203
204 GX2UTDebugTagUndent();
205 }
206
207
208 /// @}
209
210 #ifdef __cplusplus
211 }
212 #endif // __cplusplus
213
214 #endif // _GX2UTRESOLVE_H_
215