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 // gfdInterface.h
14 //
15 // Interface for Grafhics File Formats.
16
17 #ifndef _CAFE_GFD_INTERFACE_H_
18 #define _CAFE_GFD_INTERFACE_H_
19
20 #ifdef __cplusplus
21 extern "C"
22 {
23 #endif // __cplusplus
24
25 /// @addtogroup GFDInterfaceGroup
26 /// @{
27
28 /// \brief Swap byte order in a 16-bit int.
29 #define GFD_SWAP_8_IN_16(x) (((x)>>8)|((x)<<8))
30
31 /// \brief Swap byte order in a 32-bit int.
32 #define GFD_SWAP_8_IN_32(x) ((((x)>>24)&0xff)|(((x)>>8)&0xff00)|(((x)<<8)&0xff0000)|(((x)<<24)&0xff000000))
33
34 /// \brief Endian swap in 16-bit int buffer.
35 ///
36 /// \param pData Input data to swap
37 /// \param numberElements Number of elements
38 ///
39 /// \donotcall \threadsafe \enddonotcall
40 ///
GFDEndianSwap8in16(u16 * pData,u32 numberElements)41 inline void GFDEndianSwap8in16(u16 *pData, u32 numberElements)
42 {
43 for(u32 i = 0; i < numberElements; i++)
44 {
45 *pData = GFD_SWAP_8_IN_16(*pData);
46 pData++;
47 }
48 }
49
50 /// \brief Endian swap in 32-bit int buffer.
51 ///
52 /// \param pData Input data to swap
53 /// \param numberElements Number of elements
54 ///
55 /// \donotcall \threadsafe \enddonotcall
56 ///
GFDEndianSwap8in32(u32 * pData,u32 numberElements)57 inline void GFDEndianSwap8in32(u32 *pData, u32 numberElements)
58 {
59 for(u32 i = 0; i < numberElements; i++)
60 {
61 *pData = GFD_SWAP_8_IN_32(*pData);
62 pData++;
63 }
64 }
65
66 /// \brief Endian Swap
67 ///
68 /// \param pData Input data to swap
69 /// \param numberElements Number of elements
70 /// \param elemSize Size of element
71 ///
72 /// \donotcall \threadsafe \enddonotcall
73 ///
GFDEndianSwap(void * pData,u32 numberElements,GFDElementSize elemSize)74 inline void GFDEndianSwap(void *pData, u32 numberElements, GFDElementSize elemSize)
75 {
76 switch (elemSize)
77 {
78 case GFD_ELEMENT_SIZE_8:
79 break;
80 case GFD_ELEMENT_SIZE_16:
81 GFDEndianSwap8in16((u16*)pData, numberElements);
82 break;
83 case GFD_ELEMENT_SIZE_32:
84 GFDEndianSwap8in32((u32*)pData, numberElements);
85 break;
86 default:
87 break;
88 }
89 }
90
91 /// \brief Get align mode of GX2 shader file (.gsh) or texture file (.gtx).
92 ///
93 /// Given raw data loaded from shader file (.gsh) or texture file (.gtx),
94 /// returns \ref GFDAlignMode which was used in creating the file with tool.
95 ///
96 /// \param pData Input data, mapped from GX2 shader file (.gsh) or texture file (.gtx).
97 /// \retval Align mode of the file.
98 ///
99 /// \donotcall \threadsafe \enddonotcall
100 ///
101 GFDAlignMode GFDGetAlignMode(const void *pData);
102
103 //
104 // For Shader binary file (gsh)
105 //
106
107 /// \brief Get the number of Vertex shaders in GX2 shader file (.gsh)
108 ///
109 /// Given a buffer of raw data loaded from GX2 shader file (.gsh),
110 /// returns the number of Vertex Shaders it contains.
111 /// Will return TRUE and set output parameters to zero if the file is valid format, but contains no shaders of a specified type.
112 ///
113 /// \param pData Input data, mapped from a GX2 shader file (.gsh).
114 /// \retval Returns Counts of Vertex Shader in the file. 0 means no vertex shader.
115 ///
116 /// \donotcall \threadsafe \enddonotcall
117 ///
118 u32 GFDGetVertexShaderCount(const void *pData);
119
120 /// \brief Get size to allocate a Vertex Shader Header from a block of memory loaded from GX2 shader file (.gsh)
121 ///
122 /// This returns the size to allocate for a vertex shader header.
123 ///
124 /// \param index Index which vertex shader to extract.
125 /// \param pData Input data, mapped from a GX2 shader file (.gsh).
126 /// \retval Returns size of memory to allocate for the shader header. 0 means no vertex shader header.
127 ///
128 /// \donotcall \threadsafe \enddonotcall
129 ///
130 u32 GFDGetVertexShaderHeaderSize(u32 index, const void *pData);
131
132 /// \brief Get size to allocate a Vertex Shader from a block of memory loaded from GX2 shader file (.gsh)
133 ///
134 /// This returns the size to allocate for a vertex shader program.
135 ///
136 /// \param index Index which vertex shader to extract.
137 /// \param pData Input data, mapped from a GX2 shader file (.gsh).
138 /// \retval Returns size of memory to allocate for the shader program. 0 means no vertex shader program.
139 ///
140 /// \donotcall \threadsafe \enddonotcall
141 ///
142 u32 GFDGetVertexShaderProgramSize(u32 index, const void *pData);
143
144 /// \brief Get a GX2VertexShader with actual shader data from a block of memory loaded from GX2 shader file (.gsh)
145 ///
146 /// Given raw data loaded from .gsh shader file, and an initialized GX2VertexShader structure,
147 /// this fills the GX2VertexShader structure with data from the nth vertex shader in the file.
148 ///
149 /// \param pHeader Pointer to GX2VertexShader structure
150 /// \param pProgram Pointer to shader program. Must be aligned on 256 byte boundary.
151 /// \param index Index of vertex shader to extract.
152 /// \param pData Input data, mapped from GX2 shader file (.gsh).
153 /// \retval True on success, or false if data is invalid or index is out of range.
154 ///
155 /// \donotcall \threadsafe \enddonotcall
156 ///
157 BOOL GFDGetVertexShader(GX2VertexShader *pHeader, void *pProgram, u32 index, const void *pData);
158
159 /// \brief Get a GX2VertexShader pointer with actual shader data in a block of memory loaded from an aligned GX2 shader file (.gsh)
160 ///
161 /// Given specific aligned data buffer loaded from aligned .gtx file,
162 /// this fills the GX2VertexShader structure with data for the nth shader in the file, and return the pointer.
163 ///
164 /// \param index Which shader to extract.
165 /// \param pData Input data, mapped from GX2 shader file (.gsh).
166 /// \retval GX2VertexShader pointer with actual shader data in a block of memory
167 ///
168 /// \donotcall \threadsafe \enddonotcall
169 ///
170 GX2VertexShader *GFDGetVertexShaderPointer(u32 index, const void *pData);
171
172
173 /// \brief Get the number of Pixel shaders in GX2 shader file (.gsh)
174 ///
175 /// Given a buffer of raw data loaded from GX2 shader file (.gsh),
176 /// returns the number of Pixel Shaders it contains.
177 /// Will return TRUE and set output parameters to zero if the file is valid format, but contains no shaders of a specified type.
178 ///
179 /// \param pData Input data, mapped from a GX2 shader file (.gsh).
180 /// \retval Returns Counts of Pixel Shader in the file. Returns 0 means no pixel shader header.
181 ///
182 /// \donotcall \threadsafe \enddonotcall
183 ///
184 u32 GFDGetPixelShaderCount(const void *pData);
185
186 /// \brief Get size to allocate a Pixel Shader Header from a block of memory loaded from GX2 shader file (.gsh)
187 ///
188 /// This returns the size to allocate for a pixel shader header.
189 ///
190 /// \param index Index which pixel shader to extract.
191 /// \param pData Input data, mapped from a GX2 shader file (.gsh).
192 /// \retval Returns size of memory to allocate for the shader header. 0 means no pixel shader header.
193 ///
194 /// \donotcall \threadsafe \enddonotcall
195 ///
196 u32 GFDGetPixelShaderHeaderSize(u32 index, const void *pData);
197
198 /// \brief Get size to allocate a Pixel Shader from a block of memory loaded from GX2 shader file (.gsh)
199 ///
200 /// This returns the size to allocate for a Pixel shader.
201 ///
202 /// \param index Index which pixel shader to extract.
203 /// \param pData Input data, mapped from a GX2 shader file (.gsh).
204 /// \retval Returns size of memory to allocate for the shader program. Returns 0 means no pixel shader program.
205 ///
206 /// \donotcall \threadsafe \enddonotcall
207 ///
208 u32 GFDGetPixelShaderProgramSize(u32 index, const void *pData);
209
210 /// \brief Get a GX2PixelShader with actual shader data from a block of memory loaded from GX2 shader file (.gsh)
211 ///
212 /// Given raw data loaded from .gsh shader file, and an initialized GX2PixelShader structure,
213 /// this fills the GX2PixelShader structure with data from the nth pixel shader in the file.
214 ///
215 /// \param pHeader Pointer to GX2PixelShader structure to fill
216 /// \param pProgram Pointer to shader program. Must be aligned on 256 byte boundary.
217 /// \param index Index of pixel shader to extract.
218 /// \param pData Input data, mapped from GX2 shader file (.gsh).
219 /// \retval True on success, or false if data is invalid or index is out of range.
220 ///
221 /// \donotcall \threadsafe \enddonotcall
222 ///
223 BOOL GFDGetPixelShader(GX2PixelShader *pHeader, void *pProgram, u32 index, const void *pData);
224
225 /// \brief Get a GX2PixelShader pointer with actual shader data in a block of memory loaded from an aligned GX2 shader file (.gsh)
226 ///
227 /// Given specific aligned data buffer loaded from aligned .gtx file,
228 /// this fills the GX2PixelShader structure with data for the nth shader in the file, and return the pointer.
229 ///
230 /// \param index Which shader to extract.
231 /// \param pData Input data, mapped from GX2 shader file (.gsh).
232 /// \retval GX2PixelShader pointer with actual shader data in a block of memory
233 ///
234 /// \donotcall \threadsafe \enddonotcall
235 ///
236 GX2PixelShader *GFDGetPixelShaderPointer(u32 index, const void *pData);
237
238 /// \brief Get the number of Geometry shaders in GX2 shader file (.gsh)
239 ///
240 /// Given a buffer of raw data loaded from GX2 shader file (.gsh),
241 /// returns the number of Geometry Shaders it contains.
242 /// Will return TRUE and set output parameters to zero if the file is valid format, but contains no shaders of a specified type.
243 ///
244 /// \param pData Input data, mapped from a GX2 shader file (.gsh).
245 /// \retval Returns Counts of Geometry Shader in the file. Returns 0 means no geometry shader header.
246 ///
247 /// \donotcall \threadsafe \enddonotcall
248 ///
249 u32 GFDGetGeometryShaderCount(const void *pData);
250
251 /// \brief Get size to allocate a Geometry Shader Header from a block of memory loaded from GX2 shader file (.gsh)
252 ///
253 /// This returns the size to allocate for a geometry shader header.
254 ///
255 /// \param index Index which geometry shader to extract.
256 /// \param pData Input data, mapped from a GX2 shader file (.gsh).
257 /// \retval Returns size of memory to allocate for the shader header. 0 means no geometry shader header.
258 ///
259 /// \donotcall \threadsafe \enddonotcall
260 ///
261 u32 GFDGetGeometryShaderHeaderSize(u32 index, const void *pData);
262
263 /// \brief Get size to allocate a Geometry Shader from a block of memory loaded from GX2 shader file (.gsh)
264 ///
265 /// This returns the size to allocate for a Geometry shader.
266 ///
267 /// \param index Index which Geometry shader to extract.
268 /// \param pData Input data, mapped from a GX2 shader file (.gsh).
269 /// \retval Returns size of memory to allocate for the shader program. Returns 0 means no geometry shader program.
270 ///
271 /// \donotcall \threadsafe \enddonotcall
272 ///
273 u32 GFDGetGeometryShaderProgramSize(u32 index, const void *pData);
274
275 /// \brief Get size to allocate a Geometry Shader from a block of memory loaded from GX2 shader file (.gsh)
276 ///
277 /// This returns the size to allocate for a Geometry copy shader.
278 ///
279 /// \param index Index which Geometry shader to extract.
280 /// \param pData Input data, mapped from a GX2 shader file (.gsh).
281 /// \retval Returns size of memory to allocate for the copy shader program. Returns 0 means no geometry shader program.
282 ///
283 /// \donotcall \threadsafe \enddonotcall
284 ///
285 u32 GFDGetGeometryShaderCopyProgramSize(u32 index, const void *pData);
286
287 /// \brief Get a GX2GeometryShader with actual shader data from a block of memory loaded from GX2 shader file (.gsh)
288 ///
289 /// Given raw data loaded from .gsh shader file, and an initialized GX2GeometryShader structure,
290 /// this fills the GX2GeometryShader structure with data from the nth geometry shader in the file.
291 ///
292 /// \param pHeader Pointer to GX2GeometryShader structure to fill
293 /// \param pProgram Pointer to shader program. Must be aligned on 256 byte boundary.
294 /// \param pCopyProgram Pointer to copy shader program. Must be aligned on 256 byte boundary.
295 /// \param index Index of geometry shader to extract.
296 /// \param pData Input data, mapped from GX2 shader file (.gsh).
297 /// \retval True on success, or false if data is invalid or index is out of range.
298 ///
299 /// \donotcall \threadsafe \enddonotcall
300 ///
301 BOOL GFDGetGeometryShader(GX2GeometryShader *pHeader, void *pProgram, void *pCopyProgram, u32 index, const void *pData);
302
303 /// \brief Get a GX2GeometryShader pointer with actual shader data in a block of memory loaded from an aligned GX2 shader file (.gsh)
304 ///
305 /// Given specific aligned data buffer loaded from aligned .gtx file,
306 /// this fills the GX2GeometryShader structure with data for the nth shader in the file, and return the pointer.
307 ///
308 /// \param index Which shader to extract.
309 /// \param pData Input data, mapped from GX2 shader file (.gsh).
310 /// \retval GX2GeometryShader pointer with actual shader data in a block of memory
311 ///
312 /// \donotcall \threadsafe \enddonotcall
313 ///
314 GX2GeometryShader *GFDGetGeometryShaderPointer(u32 index, const void *pData);
315
316 /// \brief Get the number of Compute shaders in GX2 shader file (.gsh)
317 ///
318 /// Given a buffer of raw data loaded from GX2 shader file (.gsh),
319 /// returns the number of Compute Shaders it contains.
320 /// Will return TRUE and set output parameters to zero if the file is in valid a format, but contains no shaders of a specified type.
321 ///
322 /// \param pData Input data, mapped from a GX2 shader file (.gsh).
323 /// \retval Returns Counts of Compute Shader in the file. 0 means no compute shader.
324 ///
325 /// \donotcall \threadsafe \enddonotcall
326 ///
327 u32 GFDGetComputeShaderCount(const void *pData);
328
329 /// \brief Get size to allocate a Compute Shader Header from a block of memory loaded from GX2 shader file (.gsh)
330 ///
331 /// This returns the size to allocate for a compute shader header.
332 ///
333 /// \param index Index which compute shader to extract.
334 /// \param pData Input data, mapped from a GX2 shader file (.gsh).
335 /// \retval Returns size of memory to allocate for the shader header. 0 means no compute shader header.
336 ///
337 /// \donotcall \threadsafe \enddonotcall
338 ///
339 u32 GFDGetComputeShaderHeaderSize(u32 index, const void *pData);
340
341 /// \brief Get size to allocate a Compute Shader from a block of memory loaded from GX2 shader file (.gsh)
342 ///
343 /// This returns the size to allocate for a compute shader program.
344 ///
345 /// \param index Index which compute shader to extract.
346 /// \param pData Input data, mapped from a GX2 shader file (.gsh).
347 /// \retval Returns size of memory to allocate for the shader program. 0 means no compute shader program.
348 ///
349 /// \donotcall \threadsafe \enddonotcall
350 ///
351 u32 GFDGetComputeShaderProgramSize(u32 index, const void *pData);
352
353 /// \brief Get a GX2ComputeShader with actual shader data from a block of memory loaded from GX2 shader file (.gsh)
354 ///
355 /// Given raw data loaded from .gsh shader file, and an initialized GX2ComputeShader structure,
356 /// this fills the GX2ComputeShader structure with data from the nth compute shader in the file.
357 ///
358 /// \param pHeader Pointer to GX2ComputeShader structure
359 /// \param pProgram Pointer to shader program. Must be aligned on a 256 byte boundary.
360 /// \param index Index of compute shader to extract.
361 /// \param pData Input data, mapped from GX2 shader file (.gsh).
362 /// \retval True on success, or false if data is invalid or index is out of range.
363 ///
364 /// \donotcall \threadsafe \enddonotcall
365 ///
366 BOOL GFDGetComputeShader(GX2ComputeShader *pHeader, void *pProgram, u32 index, const void *pData);
367
368 /// \brief Get a GX2ComputeShader pointer with actual shader data in a block of memory loaded from an aligned GX2 shader file (.gsh)
369 ///
370 /// Given a specific, aligned data buffer loaded from an aligned .gtx file,
371 /// this fills the GX2ComputeShader structure with data for the nth shader in the file, and returns the pointer.
372 ///
373 /// \param index Which shader to extract.
374 /// \param pData Input data, mapped from GX2 shader file (.gsh).
375 /// \retval GX2ComputeShader pointer with actual shader data in a block of memory
376 ///
377 /// \donotcall \threadsafe \enddonotcall
378 ///
379 GX2ComputeShader *GFDGetComputeShaderPointer(u32 index, const void *pData);
380
381
382 //
383 // For Texture binary file (gtx)
384 //
385
386 /// \brief Get the number of Textures in GX2 texture file (.gtx)
387 ///
388 /// Given a buffer of raw data loaded from GX2 texture file (.gtx),
389 /// returns the number of Textures it contains.
390 /// Will return TRUE and set output parameters to zero if the file is valid format, but contains no texture of a specified type.
391 ///
392 /// \param pData Input data, mapped from a GX2 texture file (.gtx).
393 /// \retval Returns Counts of Texture in the file.
394 ///
395 /// \donotcall \threadsafe \enddonotcall
396 ///
397 u32 GFDGetTextureCount(const void *pData);
398
399 /// \brief Get size to allocate a Texture Header from a block of memory loaded from GX2 texture file (.gtx)
400 ///
401 /// This returns the size to allocate for a texture header.
402 ///
403 /// \param index Index which texture to extract.
404 /// \param pData Input data, mapped from a GX2 texture file (.gtx).
405 /// \retval Returns size of memory to allocate for the texture header. 0 means no texture header.
406 ///
407 /// \donotcall \threadsafe \enddonotcall
408 ///
409 u32 GFDGetTextureHeaderSize(u32 index, const void *pData);
410
411 /// \brief Get Alignment size for allocating a Texture from a block of memory loaded from GX2 texture file (.gtx)
412 ///
413 /// This returns the alignment size to allocate for a texture Image Data.
414 ///
415 /// \param index Index which texture to extract.
416 /// \param pData Input data, mapped from a GX2 texture file (.gtx).
417 /// \retval Returns alignment size to allocate for the texture image data. Returns 0 means no image data.
418 ///
419 /// \donotcall \threadsafe \enddonotcall
420 ///
421 u32 GFDGetTextureAlignmentSize(u32 index, const void *pData);
422
423 /// \brief Get size to allocate a Texture from a block of memory loaded from GX2 texture file (.gtx)
424 ///
425 /// This returns the size to allocate for a texture Image Data.
426 ///
427 /// \param index Index which texture to extract.
428 /// \param pData Input data, mapped from a GX2 texture file (.gtx).
429 /// \retval Returns size of memory to allocate for the texture image data. Returns 0 means no image data.
430 ///
431 /// \donotcall \threadsafe \enddonotcall
432 ///
433 u32 GFDGetTextureImageSize(u32 index, const void *pData);
434
435 /// \brief Get size to allocate a Texture from a block of memory loaded from GX2 texture file (.gtx)
436 ///
437 /// This returns the size to allocate for a texture Mipmap Image Data.
438 ///
439 /// \param index Index which texture to extract.
440 /// \param pData Input data, mapped from a GX2 texture file (.gtx).
441 /// \retval Returns size of memory to allocate for the texture mipmap image data. Returns 0 means no mip image data.
442 ///
443 /// \donotcall \threadsafe \enddonotcall
444 ///
445 u32 GFDGetTextureMipImageSize(u32 index, const void *pData);
446
447 /// \brief Get a GX2Texture with actual texture data from a block of memory loaded from a GX2 texture file (.gtx)
448 ///
449 /// Given raw data loaded from .gtx texture file, and an initialized GX2Texture structure,
450 /// this fills the GX2Texture structure with data for the nth texture in the file.
451 /// \note This function does not call \ref GX2Invalidate on the surface
452 ///
453 /// \param pHeader Pointer to GX2Texture Structure to fill
454 /// \param pImage Pointer to image data
455 /// \param pMipImage Pointer to mipmap image data
456 /// \param index Which texture to extract.
457 /// \param pData Input data, mapped from GX2 texture file (.gtx).
458 /// \retval True on success, or false if data is invalid or index is out of range.
459 ///
460 /// \donotcall \threadsafe \enddonotcall
461 ///
462 BOOL GFDGetTexture(GX2Texture *pHeader, void *pImage, void *pMipImage, u32 index, const void *pData);
463
464 /// \brief As per \ref GFDGetTexture but the surface is created with \ref GX2RCreateSurface.
465 /// \note Surface data will be invalidated after loading
466 ///
467 /// \donotcall \gx2_typical \userheap \enddonotcall
468 ///
469 BOOL GFDGetGX2RTexture(GX2Texture *pHeader, u32 index, const void *pData);
470
471 /// \brief Get a GX2Texture pointer with actual texture data in a block of memory loaded from an aligned GX2 texture file (.gtx)
472 ///
473 /// Given specific aligned data buffer loaded from aligned .gtx file,
474 /// this fills the GX2Texture structure with data for the nth texture in the file, and returns the pointer.
475 /// \note This function does not call \ref GX2Invalidate on the surface
476 ///
477 /// \param index Which texture to extract.
478 /// \param pData Input data, mapped from GX2 texture file (.gtx).
479 /// \retval GX2Texture pointer with actual texture data in a block of memory
480 ///
481 /// \donotcall \threadsafe \enddonotcall
482 ///
483 GX2Texture *GFDGetTexturePointer(u32 index, const void *pData);
484
485 /// \brief As per \ref GFDGetTexturePointer but the surface is wrapped with \ref GX2RCreateSurfaceUserMemory.
486 /// \note Surface data will be invalidated after loading
487 ///
488 /// \donotcall \gx2_typical \enddonotcall
489 ///
490 GX2Texture *GFDGetGX2RTexturePointer(u32 index, const void *pData);
491
492
493 /// @}
494
495 #ifdef __cplusplus
496 }
497 #endif // __cplusplus
498
499 #endif // _CAFE_GFD_SHADER_H_
500