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 _CAFE_GX2R_BUFFER_H_
14 #define _CAFE_GX2R_BUFFER_H_
15 
16 
17 #ifdef __cplusplus
18 extern "C"
19 {
20 #endif // __cplusplus
21 
22 
23 /// @addtogroup GX2RGroup
24 /// @{
25 
26 
27 
28 /// \brief \ref GX2RDestroyBuffer but with GX2R_OPTION flags (see \ref GX2RResourceFlags)
29 ///
30 /// \donotcall \gx2_typical \userheap \enddonotcall
31 ///
32 void GX2API GX2RDestroyBufferEx(GX2RBuffer* gx2Buffer, GX2RResourceFlags optionFlags);
33 
34 /// \brief \ref GX2RLockBuffer but with GX2R_OPTION flags (see \ref GX2RResourceFlags)
35 ///
36 /// \donotcall \fgonly \notthreadsafe \notinterrupt \notexception \devonly \enddonotcall
37 ///
38 void* GX2API GX2RLockBufferEx(const GX2RBuffer* gx2Buffer, GX2RResourceFlags optionFlags);
39 
40 /// \brief \ref GX2RLockBufferRegion but with GX2R_OPTION flags (see \ref GX2RResourceFlags)
41 /// ***UNIMPLEMENTED in this release***
42 ///
43 /// \donotcall \threadsafe \devonly \enddonotcall
44 ///
45 void* GX2API GX2RLockBufferRegionEx(const GX2RBuffer* gx2Buffer, u32 byteOffset, u32 byteCount, GX2RResourceFlags optionFlags);
46 
47 /// \brief \ref GX2RUnlockBuffer but with GX2R_OPTION flags (see \ref GX2RResourceFlags)
48 ///
49 /// \donotcall \gx2_typical \enddonotcall
50 ///
51 /// \writesgpu
52 /// \writesgpu{if the buffer resource usage is any GPU usable type (e.g. \ref GX2R_BIND_VERTEX_BUFFER)}
53 ///
54 void GX2API GX2RUnlockBufferEx(const GX2RBuffer* gx2Buffer, GX2RResourceFlags optionFlags);
55 
56 /// \brief Create a buffer object.
57 ///
58 /// \param      gx2Buffer Address of a filled-in \ref GX2RBuffer struct.
59 /// \return     GX2_TRUE if creation succeeds, GX2_FALSE otherwise
60 ///
61 /// \note This function will allocate the memory via the allocator callback (see \ref GX2RSetAllocator).
62 /// If \ref GX2R_USAGE_GPU_WRITE or \ref GX2R_USAGE_DMA_WRITE is specified, DCInvalidateRange() will be called
63 /// to clear any CPU cache lines which could unexpectedly overwrite the data.
64 /// If the allocator callback writes to the memory, e.g. a debug fill value, the cache must be flushed
65 /// with GX2Invalidate(GX2_INVALIDATE_CPU).
66 /// No GPU cache invalidation is performed - this is done in \ref GX2RUnlockBuffer.
67 /// Consider using the GXUT helper functions to create common types.
68 ///
69 /// \donotcall \gx2_typical \userheap \enddonotcall
70 ///
71 GX2Boolean GX2API GX2RCreateBuffer(GX2RBuffer* gx2Buffer);
72 
73 /// \brief Create a buffer object from user supplied memory.
74 ///
75 /// \param gx2Buffer     Address of a filled-in \ref GX2RBuffer struct.
76 /// \param pUserMem      Pointer to existing memory for the buffer.
77 /// \param userByteCount Size of the user memory block, must be >= the required size for the buffer (see \ref GX2RGetBufferAllocationSize)
78 /// \return GX2_TRUE if creation succeeds, GX2_FALSE otherwise
79 ///
80 /// \note \ref GX2RCreateBuffer should be used in preference to this version except where absolutely necessary.
81 /// Cache invalidation behavior is the same as \ref GX2RCreateBuffer.
82 /// Although the memory pointer is accessible without using Lock/Unlock, these should still be used as they provide important
83 /// hooks for debugging and profiling. Lock/Unlock will also manage CPU and GPU cache invalidation, although
84 /// this can be suppressed per buffer or per call with the \ref GX2R_OPTION_NO_CPU_INVALIDATE and \ref GX2R_OPTION_NO_GPU_INVALIDATE flags,
85 /// in which case \ref GX2RInvalidateBuffer, \ref GX2RInvalidateMemory or \ref GX2Invalidate should be used.
86 /// \ref GX2RDestroyBuffer must still be called for user memory buffers.
87 ///
88 /// \donotcall \fgonly \notthreadsafe \notinterrupt \notexception \devonly \enddonotcall
89 ///
90 GX2Boolean GX2API GX2RCreateBufferUserMemory(GX2RBuffer* gx2Buffer, void* pUserMem, u32 userByteCount);
91 
92 /// \brief Destroy a GX2R buffer object.
93 ///
94 /// \param gx2Buffer Address of a \ref GX2RBuffer struct.
95 ///
96 /// \note Memory will be freed via the default allocator or user callback.
97 /// If the buffer was created from user memory via \ref GX2RCreateBufferUserMemory this function is
98 /// still necessary to mark the buffer as deleted.
99 /// Destroying a buffer that was never created or has already been destroyed is not an error.
100 ///
101 /// \donotcall \gx2_typical \userheap \enddonotcall
102 ///
GX2RDestroyBuffer(GX2RBuffer * gx2Buffer)103 GX2_INLINE void GX2RDestroyBuffer(GX2RBuffer* gx2Buffer)
104 {
105     GX2RDestroyBufferEx(gx2Buffer, GX2R_OPTION_NONE);
106 }
107 
108 /// \brief  Lock a GX2R buffer object and return a pointer to the memory.
109 ///
110 /// \param  gx2Buffer Address of a \ref GX2RBuffer struct.
111 /// \return Memory address of the start of the buffer
112 ///
113 /// \note The returned buffer memory may be read or written by the CPU or via DMA transfer (or even the GPU),
114 /// however it is imperative the correct usage flags are set in \ref GX2RResourceFlags to ensure cache coherency.
115 /// \ref GX2RUnlockBuffer must be called before the buffer object is used by any other GX2R APIs.
116 ///
117 /// \donotcall \fgonly \notthreadsafe \notinterrupt \notexception \devonly \enddonotcall
118 ///
GX2RLockBuffer(const GX2RBuffer * gx2Buffer)119 GX2_INLINE void* GX2RLockBuffer(const GX2RBuffer* gx2Buffer)
120 {
121     return GX2RLockBufferEx(gx2Buffer, GX2R_OPTION_NONE);
122 }
123 
124 /// \brief  Lock a subrange of a GX2R buffer object and return a pointer to the memory.
125 ///
126 /// \param  gx2Buffer   Address of a \ref GX2RBuffer struct.
127 /// \param  byteOffset  Start offset of the region to lock
128 /// \param  byteCount   Size of the region to lock
129 /// \return Memory address of the locked buffer region
130 ///
131 /// \note See \ref GX2RLockBuffer for more info.
132 /// ***UNIMPLEMENTED in this release***
133 ///
134 /// \donotcall \threadsafe \devonly \enddonotcall
135 ///
GX2RLockBufferRegion(const GX2RBuffer * gx2Buffer,u32 byteOffset,u32 byteCount)136 GX2_INLINE void* GX2RLockBufferRegion(const GX2RBuffer* gx2Buffer, u32 byteOffset, u32 byteCount)
137 {
138     return GX2RLockBufferRegionEx(gx2Buffer, byteOffset, byteCount, GX2R_OPTION_NONE);
139 }
140 
141 
142 /// \brief Unlock a GX2R buffer object.
143 ///
144 /// \param gx2Buffer Address of a \ref GX2RBuffer struct.
145 ///
146 /// \note This function will perform any necessary CPU and GPU cache invalidation.
147 /// Cache invalidation can be controlled with \ref GX2R_OPTION_NO_CPU_INVALIDATE and GX2R_OPTION_NO_GPU_INVALIDATE,
148 /// either per buffer in the resourceFlags, or per call when passed to \ref GX2RUnlockBufferEx.
149 /// It is recommended to let the API handle correct CPU and GPU cache invalidation almost always, however
150 /// in some cases it can be more efficient to do manual invalidation, e.g. updating a large
151 /// number of objects and invalidating the GPU over the entire range once only.
152 /// See \ref GX2RInvalidateBuffer, \ref GX2RInvalidateMemory and \ref GX2Invalidate.
153 /// The buffer memory pointer must not be used after the buffer is unlocked.
154 ///
155 /// \donotcall \gx2_typical \enddonotcall
156 ///
157 /// \writesgpu
158 /// \writesgpu{if the buffer resource usage is any GPU usable type (e.g. \ref GX2R_BIND_VERTEX_BUFFER)}
159 ///
GX2RUnlockBuffer(const GX2RBuffer * gx2Buffer)160 GX2_INLINE void GX2RUnlockBuffer(const GX2RBuffer* gx2Buffer)
161 {
162     GX2RUnlockBufferEx(gx2Buffer, GX2R_OPTION_NONE);
163 }
164 
165 
166 /// \brief Returns true if the buffer has memory allocated, that is, created but not yet destroyed
167 /// \param gx2Buffer Address of a \ref GX2RBuffer struct.
168 ///
169 /// \donotcall \threadsafe \devonly \enddonotcall
170 ///
171 GX2Boolean GX2API GX2RBufferExists(const GX2RBuffer* gx2Buffer);
172 
173 /// \brief Give the buffer a meaningful name for debug and profiling.
174 ///
175 /// \param gx2Buffer Address of a \ref GX2RBuffer struct.
176 /// \param name Name string. Copied into the API.
177 ///
178 /// \note Ignored in release builds.
179 /// Buffer must have memory allocated (i.e. \ref GX2RBufferExists is true) when this is called.
180 ///
181 /// \donotcall \fgonly \notthreadsafe \notinterrupt \notexception \devonly \enddonotcall
182 ///
183 void GX2API GX2RSetBufferName(GX2RBuffer* gx2Buffer, const char* name);
184 
185 /// \brief Get buffer debug name - see \ref GX2RSetBufferName
186 ///
187 /// \param gx2Buffer Address of a \ref GX2RBuffer struct.
188 ///
189 /// \donotcall \fgonly \notthreadsafe \notinterrupt \notexception \devonly \enddonotcall
190 ///
191 const char* GX2API GX2RGetBufferName(const GX2RBuffer* gx2Buffer);
192 
193 
194 
195 /// \brief Set the attribute buffer
196 ///
197 /// \param vertexBuffer Buffer object created with \ref GX2R_BIND_VERTEX_BUFFER flag.
198 /// \param slot Which shader attribute slot to bind to.
199 /// \param stride Stride in bytes between the start of one vertex and the next
200 /// \param byteOffset Offset in bytes from the start of the buffer to the first vertex
201 ///
202 /// \note The offset parameter can be used when several attribute streams are interleaved into
203 /// a single array-of-vertex buffer, and/or to pack several geometry elements into a single buffer.
204 /// Stride of 0 is valid (TODO: check this)
205 /// Use \ref GX2UTSetAttributeBuffer in the common case that stride==vertexBuffer->elementSize
206 ///
207 /// \donotcall \gx2_typical \enddonotcall
208 ///
209 /// \writesgpu
210 /// \alwayswritesgpu
211 ///
212 void GX2API GX2RSetAttributeBuffer(const GX2RBuffer* vertexBuffer, u32 slot, u32 stride, u32 byteOffset);
213 
214 
215 
216 /// \brief Set a Uniform Block buffer for the Vertex Shader
217 ///
218 /// Use in \ref GX2_SHADER_MODE_UNIFORM_BLOCK or \ref GX2_SHADER_MODE_GEOMETRY_SHADER only.
219 ///
220 /// \param uniformBlock Buffer object created with \ref GX2R_BIND_UNIFORM_BLOCK
221 /// \param location Hardware location of uniform block (\ref GX2UniformBlock)
222 /// \param byteOffset Offset in bytes from the start of the buffer to the first element
223 ///
224 /// \donotcall \gx2_typical \enddonotcall
225 ///
226 /// \writesgpu
227 /// \alwayswritesgpu
228 ///
229 void GX2API GX2RSetVertexUniformBlock(const GX2RBuffer* uniformBlock, u32 location, u32 byteOffset);
230 
231 /// \brief Set a Uniform Block buffer for the Geometry Shader
232 ///
233 /// Use in \ref GX2_SHADER_MODE_UNIFORM_BLOCK or \ref GX2_SHADER_MODE_GEOMETRY_SHADER only.
234 ///
235 /// \param uniformBlock Buffer object created with \ref GX2R_BIND_UNIFORM_BLOCK
236 /// \param location Hardware location of uniform block (\ref GX2UniformBlock)
237 /// \param byteOffset Offset in bytes from the start of the buffer to the first element
238 ///
239 /// \donotcall \gx2_typical \enddonotcall
240 ///
241 /// \writesgpu
242 /// \alwayswritesgpu
243 ///
244 void GX2API GX2RSetGeometryUniformBlock(const GX2RBuffer* uniformBlock, u32 location, u32 byteOffset);
245 
246 /// \brief Set a Uniform Block buffer for the Pixel Shader
247 ///
248 /// Use in \ref GX2_SHADER_MODE_UNIFORM_BLOCK or \ref GX2_SHADER_MODE_GEOMETRY_SHADER only.
249 ///
250 /// \param uniformBlock Buffer object created with \ref GX2R_BIND_UNIFORM_BLOCK
251 /// \param location Hardware location of uniform block (\ref GX2UniformBlock)
252 /// \param byteOffset Offset in bytes from the start of the buffer to the first element
253 ///
254 /// \donotcall \gx2_typical \enddonotcall
255 ///
256 /// \writesgpu
257 /// \alwayswritesgpu
258 ///
259 void GX2API GX2RSetPixelUniformBlock(const GX2RBuffer* uniformBlock, u32 location, u32 byteOffset);
260 
261 
262 
263 /// \brief Set the stream out buffer to be used as the given stream out target
264 ///
265 /// \param soTarget      The stream out target to setup
266 /// \param streamOutBuffer Pointer to stream out buffer structure to use
267 /// \note The GX2RStreamOutBuffer must be initialized with a GX2RBuffer, and the dataPtr field must be NULL.
268 /// You can call \ref GX2SetStreamOutBuffer() directly as it will detect dataPtr==NULL and use the buffer, however this API
269 /// provides some extra validation.
270 ///
271 /// \donotcall \gx2_typical \enddonotcall
272 ///
273 /// \writesgpu
274 /// \alwayswritesgpu
275 ///
276 void GX2API GX2RSetStreamOutBuffer(u32 soTarget, const GX2StreamOutBuffer* streamOutBuffer);
277 
278 
279 
280 /// \brief Draw indexed primitives
281 ///
282 /// \param primitiveType    Type of primitive to draw
283 /// \param indexBuffer      Buffer of type \ref GX2R_BIND_INDEX_BUFFER holding indices
284 /// \param indexFormat      Specifies if indices are 16-bit or 32-bit
285 /// \param indexCount       How many vertices to draw
286 /// \param startIndex       Which index in the index buffer is considered first
287 /// \param startVertex      Which vertex in vertex buffers is considered first
288 /// \param numInstances     How many instances to draw
289 ///
290 /// \note startVertex does not apply to attributes indexed by instance ID
291 /// \note See also \ref GX2UTDrawIndexed() to draw with common default parameters
292 ///
293 /// \donotcall \gx2_typical \enddonotcall
294 ///
295 /// \writesgpu
296 /// \alwayswritesgpu
297 ///
298 void GX2API GX2RDrawIndexed(GX2PrimitiveType primitiveType, const GX2RBuffer* indexBuffer, GX2IndexFormat indexFormat, u32 indexCount, u32 startIndex, u32 startVertex, u32 numInstances);
299 
300 /// \brief Draw indexed primitives copying indices into the command buffer.
301 /// This is the same as \ref GX2RDrawIndexed() except indexBuffer need not continue to exist as indices are copied
302 /// \note See also \ref GX2UTDrawIndexedImmediate() to draw with common default parameters
303 ///
304 /// \donotcall \gx2_typical \enddonotcall
305 ///
306 /// \writesgpu
307 /// \alwayswritesgpu
308 ///
309 void GX2API GX2RDrawIndexedImmediate(GX2PrimitiveType primitiveType, const GX2RBuffer* indexBuffer, GX2IndexFormat indexFormat, u32 indexCount, u32 startIndex, u32 startVertex, u32 numInstances);
310 
311 
312 
313 /// \brief Begin recording a display list that can be executed later.
314 /// \param displayList      Buffer of type \ref GX2R_BIND_DISPLAY_LIST
315 /// \param enableProfiling  Initial profiling state for the display list
316 /// \param optionFlags      Option to suppress CPU cache invalidation
317 /// \note The profiling state is stored with the state context so if GX2SetContextState is called
318 ///       within the display list the profiling state (enabled or disabled) may change.
319 ///       If GX2SetContextState() is not called in the display list the correct context state
320 ///       (with respect to profiling) must be set before calling GX2RCallDisplayList() or
321 ///       GX2RDirectCallDisplayList() to execute the display list.
322 /// Note this API will perform the necessary cache invalidation on the buffer, unless suppressed with optionFlags
323 ///
324 /// \donotcall \gx2_dl \enddonotcall
325 ///
326 void GX2API GX2RBeginDisplayListEx(const GX2RBuffer* displayList, GX2Boolean enableProfiling, GX2RResourceFlags optionFlags);
327 
328 /// \brief Begin recording a display list that can be executed later.
329 /// \param displayList Buffer of type \ref GX2R_BIND_DISPLAY_LIST
330 /// \note HW Profiling will be enabled for the Display list.
331 /// Note this API will perform the necessary cache invalidation on the buffer
332 ///
333 /// \donotcall \gx2_dl \enddonotcall
334 ///
GX2RBeginDisplayList(const GX2RBuffer * displayList)335 GX2_INLINE void GX2RBeginDisplayList(const GX2RBuffer* displayList)
336 {
337     GX2RBeginDisplayListEx(displayList, GX2_ENABLE, GX2R_OPTION_NONE);
338 }
339 
340 /// \brief End the display list generation.
341 ///
342 /// \param displayList Buffer of type \ref GX2R_BIND_DISPLAY_LIST previously set in \ref GX2RBeginDisplayList
343 /// \return the actual size of the display list in bytes.
344 /// Note this API will assert if the display list has overrun the buffer size.
345 ///
346 /// \donotcall \gx2_typical \enddonotcall
347 ///
348 u32 GX2API GX2REndDisplayList(const GX2RBuffer* displayList);
349 
350 /// \brief  Execute the displaylist by adding it to the current display list or command buffer.
351 ///
352 /// \param  displayList Buffer of type \ref GX2R_BIND_DISPLAY_LIST
353 /// \param  byteSize Actual size of the display list, as returned by \ref GX2REndDisplayList()
354 /// \note   A display list referenced in this call cannot call another display list (no nesting).
355 ///
356 /// \donotcall \gx2_typical \enddonotcall
357 ///
358 /// \writesgpu
359 /// \alwayswritesgpu
360 ///
361 void GX2API GX2RCallDisplayList(const GX2RBuffer* displayList, u32 byteSize);
362 
363 /// \brief  Execute the displaylist by adding it directly to the graphics ring buffer.
364 ///
365 /// \param  displayList Buffer of type \ref GX2R_BIND_DISPLAY_LIST
366 /// \param  byteSize Actual size of the display list, as returned by \ref GX2REndDisplayList()
367 /// \note   This function can only be called from the main thread.
368 ///
369 /// \donotcall \nomulticore \gx2_dl \enddonotcall
370 ///
371 /// \writesgpu
372 /// \alwayswritesgpu
373 ///
374 void GX2API GX2RDirectCallDisplayList(const GX2RBuffer* displayList, u32 byteSize);
375 
376 
377 
378 /// \brief Set a ring buffer for geometry shader input (VS output)
379 ///
380 /// \param ringInBuffer Buffer of type \ref GX2R_BIND_GS_RING
381 ///
382 /// \note This function invokes a full pipeline flush.
383 /// Buffer size must be calculated with GX2CalcGeometryShaderInputRingBufferSize(),
384 /// or else see \ref GX2UTCreateGeometryShaderInputRingBuffer()
385 /// See also \ref GX2UTSetGeometryShaderRingBuffers()
386 ///
387 /// \donotcall \gx2_typical \enddonotcall
388 ///
389 /// \writesgpu
390 /// \alwayswritesgpu
391 ///
392 void GX2API GX2RSetGeometryShaderInputRingBuffer(const GX2RBuffer* ringInBuffer);
393 
394 /// \brief Set a ring buffer for geometry shader output (PS input)
395 ///
396 /// \param ringOutBuffer Buffer of type \ref GX2R_BIND_GS_RING
397 ///
398 /// \note This function invokes a full pipeline flush.
399 /// Buffer size must be calculated with \ref GX2CalcGeometryShaderOutputRingBufferSize(),
400 /// or else see \ref GX2UTCreateGeometryShaderOutputRingBuffer()
401 /// See also \ref GX2UTSetGeometryShaderRingBuffers()
402 ///
403 /// \donotcall \gx2_typical \enddonotcall
404 ///
405 /// \writesgpu
406 /// \alwayswritesgpu
407 ///
408 void GX2API GX2RSetGeometryShaderOutputRingBuffer(const GX2RBuffer* ringOutBuffer);
409 
410 
411 
412 /// \brief Create a fetch shader based on the given attribute stream list.
413 ///
414 /// \param fetchShader      User-allocated instance of \ref GX2FetchShader structure
415 /// \param shaderProgram    Buffer of type GX2R_BIND_SHADER_PROGRAM for the fetch shader binary code
416 /// \param attribCount      Number of attribute streams
417 /// \param attribStreams    User-allocated array of \ref GX2AttribStream structures containing information about all attribute streams
418 /// \param type             The type of fetch shader to generate
419 /// \param tessMode         Tessellation mode, only valid if type is not GX2_FETCH_SHADER_TESSELATION_NONE
420 ///
421 /// \note See also GX2UTInitFetchShader()
422 /// ***UNIMPLEMENTED in this release***
423 ///
424 /// \donotcall \threadsafe \devonly \enddonotcall
425 ///
426 void GX2API GX2RInitFetchShader(GX2FetchShader* fetchShader, const GX2RBuffer* shaderProgram, u32 attribCount, const GX2AttribStream* attribStreams, GX2FetchShaderType type, GX2TessellationMode tessMode);
427 
428 
429 /// \brief Utility function for custom allocator or user memory buffer to get the correct alignment for the given buffer type
430 /// \note Useful for custom allocators or user memory APIs.
431 /// Only works with buffers types - for surfaces use GX2CalcSurfaceSizeAndAlignment()
432 ///
433 /// \donotcall \threadsafe \devonly \enddonotcall
434 ///
435 u32 GX2API GX2RGetBufferAlignment(GX2RResourceFlags resourceFlags);
436 
437 /// \brief Utility function for custom allocator or user memory buffer to get the correct size for the given buffer
438 ///
439 /// \param gx2Buffer Address of a \ref GX2RBuffer struct.
440 ///
441 /// \note This is not simply elementSize*elementCount as the end of the block may be rounded up to a 64-byte boundary.
442 /// The CPU cache prefetching is in 64-byte granularity, so without this alignment it may read into adjacent memory.
443 /// If that memory is written to by the GPU, then read by the CPU, the first 32 bytes will be incorrect.
444 /// Useful for custom allocators or user memory APIs.
445 /// Note this is a calculation of the required size based on the parameters, not necessarily the actual allocation size
446 /// if a custom allocator or user memory was employed.
447 /// The actual allocation size will also be greater if GX2R_DEBUG_GUARD_BANDS_ENABLED debug option is set - see \ref GX2RGetBufferGuardBandSize.
448 ///
449 /// \donotcall \threadsafe \devonly \enddonotcall
450 ///
451 u32 GX2API GX2RGetBufferAllocationSize(const GX2RBuffer* gx2Buffer);
452 
453 /// \brief Utility function to perform correct cache invalidation for user memory
454 /// \param resourceFlags    Type/semantics/options for the data referenced by pMem
455 /// \param pMem             User memory pointer to buffer data
456 /// \param byteCount        Size of data at pMem
457 ///
458 /// \note Typically when using the GX2R APIs this will not be necessary, however this function is useful when using user memory
459 /// via \ref GX2RCreateBufferUserMemory and \ref GX2RResourceFlags to suppress invalidation within the API.
460 /// See also \ref GX2RInvalidateBuffer
461 ///
462 /// \donotcall \gx2_typical \enddonotcall
463 ///
464 /// \writesgpu
465 /// \writesgpu{if the buffer resource usage is any GPU usable type (e.g. \ref GX2R_BIND_VERTEX_BUFFER)}
466 ///
467 void GX2API GX2RInvalidateMemory(GX2RResourceFlags resourceFlags, void *pMem, u32 byteCount);
468 
469 /// \brief Utility function to perform correct cache invalidation for the given buffer
470 ///
471 /// \param gx2Buffer    Address of a \ref GX2RBuffer struct.
472 /// \param optionFlags  The OPTION values are used instead of buffer resourceFlags (i.e. buffer NO_INVALIDATE flags will be ignored)
473 ///
474 /// \note Typically when using the GX2R APIs this will not be necessary, however it is useful when using \ref GX2RResourceFlags
475 /// to suppress invalidation within the API.
476 /// See also \ref GX2RInvalidateMemory
477 ///
478 /// \donotcall \gx2_typical \enddonotcall
479 ///
480 /// \writesgpu
481 /// \writesgpu{if the buffer resource usage is any GPU usable type (e.g. \ref GX2R_BIND_VERTEX_BUFFER)}
482 ///
483 void GX2API GX2RInvalidateBuffer(const GX2RBuffer* gx2Buffer, GX2RResourceFlags optionFlags);
484 
485 
486 /// \brief Get the size of the guard bands required for a buffer with the specified flags.
487 /// \param resourceFlags    Type/semantics/options for the data referenced by pMem
488 ///
489 /// \note This function is a static calculation and does not take into account whether guard bands are currently enabled - if required
490 /// that can be queried with \ref GX2RGetDebugOptions.
491 /// If the resourceFlags are from a buffer created with \ref GX2RCreateBufferUserMemory the return value will be zero.
492 /// To ignore the user memory status, mask out the GX2R_RESOURCE_FLAG_RESERVED bits.
493 ///
494 /// \donotcall \threadsafe \devonly \enddonotcall
495 ///
496 u32 GX2API GX2RGetBufferGuardBandSize(GX2RResourceFlags resourceFlags);
497 
498 
499 /// @}
500 
501 #ifdef __cplusplus
502 }
503 #endif // __cplusplus
504 
505 #endif // _CAFE_GX2R_BUFFER_H_
506