From efc507147e0beb1ac5b2f046bf8e4d902bca652c Mon Sep 17 00:00:00 2001 From: Reiko Asakura Date: Wed, 23 Sep 2020 13:03:51 -0400 Subject: Refactor SceGxmInternal headers --- include/user/gxm.h | 18 +++++++ include/user/gxm/context.h | 82 ++++++++++++++++++++++++++++ include/user/gxm/init.h | 53 ++++++++++++++++++ include/user/gxm/internal.h | 34 ------------ include/user/gxm/memory.h | 109 ++++++++++++++++++++++++++++++++++++++ include/user/gxm/render_target.h | 68 ++++++++++++++++++++++++ include/user/gxm/shader_patcher.h | 81 ++++++++++++++++++++++++++++ include/user/gxm/sync_object.h | 95 +++++++++++++++++++++++++++++++++ 8 files changed, 506 insertions(+), 34 deletions(-) create mode 100644 include/user/gxm.h create mode 100644 include/user/gxm/context.h create mode 100644 include/user/gxm/init.h delete mode 100644 include/user/gxm/internal.h create mode 100644 include/user/gxm/memory.h create mode 100644 include/user/gxm/render_target.h create mode 100644 include/user/gxm/shader_patcher.h create mode 100644 include/user/gxm/sync_object.h (limited to 'include') diff --git a/include/user/gxm.h b/include/user/gxm.h new file mode 100644 index 0000000..60f3e11 --- /dev/null +++ b/include/user/gxm.h @@ -0,0 +1,18 @@ +#ifndef _DOLCESDK_PSP2_GXM_INTERNAL_H_ +#define _DOLCESDK_PSP2_GXM_INTERNAL_H_ + +/** @file + + Helper include file that includes all public headers. +*/ + +#include + +#include +#include +#include +#include +#include +#include + +#endif /* _DOLCESDK_PSP2_GXM_INTERNAL_H_ */ diff --git a/include/user/gxm/context.h b/include/user/gxm/context.h new file mode 100644 index 0000000..06a35fe --- /dev/null +++ b/include/user/gxm/context.h @@ -0,0 +1,82 @@ +#ifndef _DOLCESDK_PSP2_GXM_CONTEXT_INTERNAL_H_ +#define _DOLCESDK_PSP2_GXM_CONTEXT_INTERNAL_H_ + +/** @file +*/ + +#include + +#ifdef __cplusplus +extern "C" { +#endif // def __cplusplus + +/** Updates a YUV color profile. The visibility buffers will be used for all fragment jobs + started after this function returns. + + This function is only supported on the immediate context, and it will return the + #SCE_GXM_ERROR_INVALID_VALUE error code if called using a deferred context. + + The cscIndex parameter defines whether the profile being set will be active for + textures that use YUV swizzles referencing CSC0 or CSC1. + + The default profile for CSC0 is #SCE_GXM_YUV_PROFILE_BT601_STANDARD, and the default profile for + CSC1 is #SCE_GXM_YUV_PROFILE_BT709_STANDARD. + + @param[in,out] immediateContext A pointer to the immediate context. + @param[in] cscIndex The CSC index (0 or 1). + @param[in] profile The YUV color profile. + + @retval + SCE_OK The operation was successful. + @retval + SCE_GXM_ERROR_INVALID_POINTER The operation failed because a parameter was unexpectedly NULL. + @retval + SCE_GXM_ERROR_INVALID_VALUE The operation failed due to an invalid input parameter, or because + the context is not an immediate context. + + @ingroup render +*/ +SceGxmErrorCode sceGxmSetFragmentJobYuvProfile( + SceGxmContext *immediateContext, + uint32_t cscIndex, + SceGxmYuvProfile profile); + +/** Updates the visibility buffers. The visibility buffers will be used for all fragment jobs + started after this function returns. + + This function is only supported on the immediate context, and it will return the + #SCE_GXM_ERROR_INVALID_VALUE error code if called using a deferred context. + + The visibility buffer must be mapped with read/write access for the GPU, or page faults will + occur. The mapped region must extend from bufferBase for #SCE_GXM_GPU_CORE_COUNT times + stridePerCore bytes. In addition, the visibility slot index must be no more than + stridePerCore/4 to ensure that the per-core buffers do not overlap. Both the base + address and stride must be aligned to #SCE_GXM_VISIBILITY_ALIGNMENT bytes. + + @param[in,out] immediateContext A pointer to the immediate context. + @param[in] bufferBase The base address of the visibility buffer. The address must + persist until fragment processing for the current scene has completed. + @param[in] stridePerCore The stride between cores through the visibility buffer. + + @retval + SCE_OK The operation was successful. + @retval + SCE_GXM_ERROR_INVALID_POINTER The operation failed because a parameter was unexpectedly NULL. + @retval + SCE_GXM_ERROR_INVALID_VALUE The operation failed because the context is not an immediate context. + @retval + SCE_GXM_ERROR_INVALID_ALIGNMENT The operation failed due to either the base address or + stride per core not being aligned to #SCE_GXM_VISIBILITY_ALIGNMENT bytes. + + @ingroup render +*/ +SceGxmErrorCode sceGxmSetFragmentJobVisibilityBuffer( + SceGxmContext *immediateContext, + void *bufferBase, + uint32_t stridePerCore); + +#ifdef __cplusplus +} +#endif // def __cplusplus + +#endif /* _DOLCESDK_PSP2_GXM_CONTEXT_INTERNAL_H_ */ diff --git a/include/user/gxm/init.h b/include/user/gxm/init.h new file mode 100644 index 0000000..6739e2a --- /dev/null +++ b/include/user/gxm/init.h @@ -0,0 +1,53 @@ +#ifndef _DOLCESDK_PSP2_GXM_INIT_INTERNAL_H_ +#define _DOLCESDK_PSP2_GXM_INIT_INTERNAL_H_ + +/** @file +*/ + +#include + +#ifdef __cplusplus +extern "C" { +#endif // def __cplusplus + +/** Initializes the libgxm library for shared sync objects. + + Internally this function will prepare this process for rendering, creating + the parameter buffer with the given size. + + This function must be called before any other libgxm object is created, such + as a context, or sync object. + + @param[in] params A pointer to a populated SceGxmInitializeParams structure. + + @retval + SCE_OK The operation completed successfully. + @retval + SCE_GXM_ERROR_INVALID_POINTER The SceGxmInitializeParams pointer was NULL. + @retval + SCE_GXM_ERROR_INVALID_VALUE One or more parameters were invalid. + @retval + SCE_GXM_ERROR_ALREADY_INITIALIZED The operation failed because libgxm is already initialized. + @retval + SCE_GXM_ERROR_OUT_OF_MEMORY There was no memory to perform the operation. + @retval + SCE_GXM_ERROR_DRIVER The operation failed due to a driver error. + + @ingroup render +*/ +SceGxmErrorCode sceGxmInitializeInternal(const SceGxmInitializeParams *params); + +/** Checks if the libgxm library was initialized for shared sync objects. + + @return + Returns true if the libgxm library was initialized for shared sync objects; otherwise false is returned. + + @ingroup render +*/ +bool sceGxmIsInitializedInternal(void); + +#ifdef __cplusplus +} +#endif // def __cplusplus + +#endif /* _DOLCESDK_PSP2_GXM_INIT_INTERNAL_H_ */ diff --git a/include/user/gxm/internal.h b/include/user/gxm/internal.h deleted file mode 100644 index 1be3fc9..0000000 --- a/include/user/gxm/internal.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef _DOLCESDK_PSP2_GXM_INTERNAL_H_ -#define _DOLCESDK_PSP2_GXM_INTERNAL_H_ - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -SceGxmErrorCode sceGxmInternalMapVertexUsseMemory(void *base, uint32_t size, uint32_t *offset); - -SceGxmErrorCode sceGxmInternalUnmapVertexUsseMemory(void *base); - -SceGxmErrorCode sceGxmInternalMapFragmentUsseMemory(void *base, uint32_t size, uint32_t *offset); - -SceGxmErrorCode sceGxmInternalUnmapFragmentUsseMemory(void *base); - -SceGxmErrorCode sceGxmInternalGetRenderTargetMemSize( - const SceGxmRenderTargetParams *params, - uint32_t* driverMemSize); - -SceGxmErrorCode sceGxmInternalCreateRenderTarget( - const SceGxmRenderTargetParams *params, - SceGxmRenderTarget **renderTarget); - -SceBool sceGxmInternalIsInitialized(void); - -#ifdef __cplusplus -} -#endif - -#endif /* _DOLCESDK_PSP2_GXM_INTERNAL_H_ */ diff --git a/include/user/gxm/memory.h b/include/user/gxm/memory.h new file mode 100644 index 0000000..fb33636 --- /dev/null +++ b/include/user/gxm/memory.h @@ -0,0 +1,109 @@ +#ifndef _DOLCESDK_PSP2_GXM_MEMORY_INTERNAL_H_ +#define _DOLCESDK_PSP2_GXM_MEMORY_INTERNAL_H_ + +/** @file + + Memory mapping API for the GPU. +*/ + +#include + +#ifdef __cplusplus +extern "C" { +#endif // def __cplusplus + +/** Maps memory for vertex USSE code usage. If successful, this mapping + operation returns a USSE offset to address the memory as vertex USSE code. + + @param[in] base A 4K-aligned base address of the region to map. + @param[in] size A 4K-aligned size in bytes of the region to map. This + cannot be greater than 8MB. + @param[in] offset A pointer to a 32-bit value to hold the USSE offset. + + @retval + SCE_OK The operation was completed successfully. + @retval + SCE_GXM_ERROR_UNINITIALIZED The operation failed because the library was not initialized. + @retval + SCE_GXM_ERROR_INVALID_POINTER The operation failed because a pointer was invalid. + @retval + SCE_GXM_ERROR_INVALID_VALUE The operation failed because a parameter was invalid. + @retval + SCE_GXM_ERROR_DRIVER The operation failed due to a driver error. + + @ingroup render +*/ +SceGxmErrorCode sceGxmMapVertexUsseMemoryInternal(void *base, uint32_t size, uint32_t *offset); + +/** Unmaps memory that was previously mapped as vertex USSE code. It is the + responsibility of the caller to ensure that the GPU no longer needs this + memory for rendering. This could be accomplished by calling #sceGxmFinish() + before unmapping. + + @param[in] base The base address of the region to unmap. This must match + the base address that was used when mapping the memory + using #sceGxmMapVertexUsseMemory(). + + @retval + SCE_OK The operation was completed successfully. + @retval + SCE_GXM_ERROR_UNINITIALIZED The operation failed because the library was not initialized. + @retval + SCE_GXM_ERROR_INVALID_POINTER The operation failed because a pointer was invalid. + @retval + SCE_GXM_ERROR_DRIVER The operation failed due to a driver error. + + @ingroup render +*/ +SceGxmErrorCode sceGxmUnmapVertexUsseMemoryInternal(void *base); + +/** Maps memory for fragment USSE code usage. If successful, this mapping + operation returns a USSE offset to address the memory as fragment USSE code. + + @param[in] base A 4K-aligned base address of the region to map. + @param[in] size A 4K-aligned size in bytes of the region to map. This + cannot be greater than 8MB. + @param[in] offset A pointer to a 32-bit value to hold the USSE offset. + + @retval + SCE_OK The operation was completed successfully. + @retval + SCE_GXM_ERROR_UNINITIALIZED The operation failed because the library was not initialized. + @retval + SCE_GXM_ERROR_INVALID_POINTER The operation failed because a pointer was invalid. + @retval + SCE_GXM_ERROR_INVALID_VALUE The operation failed because a parameter was invalid. + @retval + SCE_GXM_ERROR_DRIVER The operation failed due to a driver error. + + @ingroup render +*/ +SceGxmErrorCode sceGxmMapFragmentUsseMemoryInternal(void *base, uint32_t size, uint32_t *offset); + +/** Unmaps memory that was previously mapped as fragment USSE code. It is the + responsibility of the caller to ensure that the GPU no longer needs this + memory for rendering. This could be accomplished by calling #sceGxmFinish() + before unmapping. + + @param[in] base The base address of the region to unmap. This must match + the base address that was used when mapping the memory + using #sceGxmMapFragmentUsseMemory(). + + @retval + SCE_OK The operation was completed successfully. + @retval + SCE_GXM_ERROR_UNINITIALIZED The operation failed because the library was not initialized. + @retval + SCE_GXM_ERROR_INVALID_POINTER The operation failed because a pointer was invalid. + @retval + SCE_GXM_ERROR_DRIVER The operation failed due to a driver error. + + @ingroup render +*/ +SceGxmErrorCode sceGxmUnmapFragmentUsseMemoryInternal(void *base); + +#ifdef __cplusplus +} +#endif // def __cplusplus + +#endif /* _DOLCESDK_PSP2_GXM_MEMORY_INTERNAL_H_ */ diff --git a/include/user/gxm/render_target.h b/include/user/gxm/render_target.h new file mode 100644 index 0000000..44a38a3 --- /dev/null +++ b/include/user/gxm/render_target.h @@ -0,0 +1,68 @@ +#ifndef _DOLCESDK_PSP2_GXM_RENDER_TARGET_INTERNAL_H_ +#define _DOLCESDK_PSP2_GXM_RENDER_TARGET_INTERNAL_H_ + +/** @file +*/ + +#include + +#ifdef __cplusplus +extern "C" { +#endif // def __cplusplus + +/** Computes the driver memory size needed for the given set of render + target parameters. The memory will be used for render target GPU data structures should + be allocated as an uncached LPDDR memblock using sceKernelAllocMemBlock(). + + @param[in] params A pointer to render target parameters. + @param[out] driverMemSize A pointer to storage for the driver memory size. + + @retval + SCE_OK The operation was completed successfully. + @retval + SCE_GXM_ERROR_INVALID_VALUE The operation failed due to an invalid parameter value. + @retval + SCE_GXM_ERROR_INVALID_POINTER The operation failed due to a NULL pointer. + + @ingroup render +*/ +SceGxmErrorCode sceGxmGetRenderTargetMemSizeInternal( + const SceGxmRenderTargetParams *params, + uint32_t* driverMemSize); + +/** Creates a render target object. A render target defines the layout for tiled + rendering and is needed to start a scene and draw geometry. Render targets + should ideally be created at load time, since creating them requires resources + from the OS. + + Once the render target is no longer needed, call #sceGxmDestroyRenderTarget() + to destroy it. + + @param[in] params The creation parameters for the render target. + @param[out] renderTarget A pointer to storage for the render target pointer. + + @retval + SCE_OK The operation was successful. + @retval + SCE_GXM_ERROR_UNINITIALIZED The operation failed as libgxm is not initialized. + @retval + SCE_GXM_ERROR_INVALID_VALUE The operation failed due to an invalid parameter value. + @retval + SCE_GXM_ERROR_INVALID_POINTER The operation failed due to a NULL pointer. + @retval + SCE_GXM_ERROR_OUT_OF_RENDER_TARGETS The operation failed because the maximum number + of render targets have already been created. + @retval + SCE_GXM_ERROR_DRIVER The operation failed due to a driver error. + + @ingroup render +*/ +SceGxmErrorCode sceGxmCreateRenderTargetInternal( + const SceGxmRenderTargetParams *params, + SceGxmRenderTarget **renderTarget); + +#ifdef __cplusplus +} +#endif // def __cplusplus + +#endif /* _DOLCESDK_PSP2_GXM_RENDER_TARGET_INTERNAL_H_ */ diff --git a/include/user/gxm/shader_patcher.h b/include/user/gxm/shader_patcher.h new file mode 100644 index 0000000..7ae47dd --- /dev/null +++ b/include/user/gxm/shader_patcher.h @@ -0,0 +1,81 @@ +#ifndef _DOLCESDK_PSP2_GXM_SHADER_PATCHER_INTERNAL_H_ +#define _DOLCESDK_PSP2_GXM_SHADER_PATCHER_INTERNAL_H_ + +/** @file +*/ + +#include + +#ifdef __cplusplus +extern "C" { +#endif // def __cplusplus + +/** Finds or creates a final fragment program. + + The fragment program is constructed by appending the shader compiler output + with output register conversion and blending code. + + When this program is no longer needed, it should be released by calling + #sceGxmShaderPatcherReleaseFragmentProgram(). The caller is responsible for ensuring that + the GPU is no longer using this program before it is released. + + Blending/masking is only supported for the output register formats + #SCE_GXM_OUTPUT_REGISTER_FORMAT_UCHAR4 or #SCE_GXM_OUTPUT_REGISTER_FORMAT_HALF4. + If the blendInfo structure has an active blend or non-trivial mask when using + unsupported output register format, the error code #SCE_GXM_ERROR_UNSUPPORTED + will be returned. + + The parameter vertexProgram is only required to remap texture coordinates. If all + vertex programs that will be used with this fragment program write a contiguous range of + texture coordinates starting at TEXCOORD0 (or do not write texture coordinates), then the + vertexProgram parameter may be NULL. Any vertex program that uses texture coordinates + that either start at a non-zero binding (such as TEXCOORD1) or form a non-contiguous range + must be explicitly linked by passing the program as the vertexProgram parameter. + + The parameter texcoordMap can provide an explicit remapping of texture coordinates. + + @param[in,out] shaderPatcher A pointer to the shader patcher. + @param[in] programId The ID for a program registered with this shader patcher. + @param[in] outputFormat The format for the fragment program COLOR0 output. + @param[in] multisampleMode The multisample mode. + @param[in] blendInfo A pointer to the blend info structure or NULL. This + structure is copied by the function and therefore does not need to + persist after the call. + @param[in] vertexProgram A pointer to the vertex program or NULL. This + structure does not need to persist after the call. + @param[in] texcoordMap A pointer to explicit remapping of texture coordinates or NULL. + @param[out] fragmentProgram A pointer to storage for a fragment program pointer. + + @retval + SCE_OK The operation was successful. + @retval + SCE_GXM_ERROR_UNSUPPORTED Blending or masking is enabled for an unsupported + output register format. + @retval + SCE_GXM_ERROR_INVALID_POINTER The operation failed because one or more of the pointers supplied was NULL. + @retval + SCE_GXM_ERROR_INVALID_VALUE The operation failed due to an invalid input parameter. + @retval + SCE_GXM_ERROR_INVALID_ALIGNMENT The operation failed because some allocated memory did not have the required alignment. + @retval + SCE_GXM_ERROR_OUT_OF_HOST_MEMORY The operation failed because a host memory allocation failed. + @retval + SCE_GXM_ERROR_OUT_OF_FRAGMENT_USSE_MEMORY The operation failed because a fragment USSE memory allocation failed. + + @ingroup shaderpatcher +*/ +SceGxmErrorCode sceGxmShaderPatcherCreateFragmentProgramInternal( + SceGxmShaderPatcher *shaderPatcher, + SceGxmShaderPatcherId programId, + SceGxmOutputRegisterFormat outputFormat, + SceGxmMultisampleMode multisampleMode, + const SceGxmBlendInfo *blendInfo, + const SceGxmProgram *vertexProgram, + const uint32_t *texcoordMap, + SceGxmFragmentProgram **fragmentProgram); + +#ifdef __cplusplus +} +#endif // def __cplusplus + +#endif /* _DOLCESDK_PSP2_GXM_SHADER_PATCHER_INTERNAL_H_ */ diff --git a/include/user/gxm/sync_object.h b/include/user/gxm/sync_object.h new file mode 100644 index 0000000..811560c --- /dev/null +++ b/include/user/gxm/sync_object.h @@ -0,0 +1,95 @@ +#ifndef _DOLCESDK_PSP2_GXM_SYNC_OBJECT_INTERNAL_H_ +#define _DOLCESDK_PSP2_GXM_SYNC_OBJECT_INTERNAL_H_ + +/** @file +*/ + +#include + +#ifdef __cplusplus +extern "C" { +#endif // def __cplusplus + +/** Creates a shared sync object. Currently sync objects are used purely to + synchronize rendering with display operations in the display queue. + + @param[in] key The key for the shared sync object. + @param[out] syncObject A pointer to storage for a sync object pointer. + + @retval + SCE_OK The operation was completed successfully. + @retval + SCE_GXM_ERROR_UNINITIALIZED The operation failed as libgxm is not initialized, or not initialized to allow shared sync objects. + @retval + SCE_GXM_ERROR_INVALID_VALUE The operation failed as the key parameter was 0. + @retval + SCE_GXM_ERROR_INVALID_POINTER The operation failed as the sync object pointer was NULL. + @retval + SCE_GXM_ERROR_DRIVER The operation failed due to a driver error. + + @ingroup render +*/ +SceGxmErrorCode sceGxmSyncObjectCreateShared(uint32_t key, SceGxmSyncObject **syncObject); + +/** Deletes a shared sync object. + + @param[in] key The key for the shared sync object. + + @retval + SCE_OK The operation was completed successfully. + @retval + SCE_GXM_ERROR_UNINITIALIZED The operation failed as libgxm is not initialized. + @retval + SCE_GXM_ERROR_INVALID_VALUE The operation failed as the key parameter was 0. + @retval + SCE_GXM_ERROR_DRIVER The operation failed due to a driver error. + + @ingroup render +*/ +SceGxmErrorCode sceGxmSyncObjectDeleteShared(uint32_t key); + +/** Opens a shared sync object. + + @param[in] key The key for the shared sync object. + @param[out] syncObject A pointer to storage for a sync object pointer. + + @retval + SCE_OK The operation was completed successfully. + @retval + SCE_GXM_ERROR_UNINITIALIZED The operation failed as libgxm is not initialized, or not initialized to allow shared sync objects. + @retval + SCE_GXM_ERROR_INVALID_VALUE The operation failed as the key parameter was 0. + @retval + SCE_GXM_ERROR_INVALID_POINTER The operation failed as the sync object pointer was NULL, or the key parameter was invalid. + @retval + SCE_GXM_ERROR_DRIVER The operation failed due to a driver error. + + @ingroup render +*/ +SceGxmErrorCode sceGxmSyncObjectOpenShared(uint32_t key, SceGxmSyncObject **syncObject); + +/** Closes a shared sync object. + + @param[in] key The key for the shared sync object. + @param[in,out] syncObject A sync object pointer. + + @retval + SCE_OK The operation was completed successfully. + @retval + SCE_GXM_ERROR_UNINITIALIZED The operation failed as libgxm is not initialized. + @retval + SCE_GXM_ERROR_INVALID_VALUE The operation failed as the key parameter was 0. + @retval + SCE_GXM_ERROR_INVALID_POINTER The operation failed as the sync object pointer was NULL. + @retval + SCE_GXM_ERROR_DRIVER The operation failed due to a driver error. + + @ingroup render +*/ +SceGxmErrorCode sceGxmSyncObjectCloseShared(uint32_t key, SceGxmSyncObject *syncObject); + +#ifdef __cplusplus +} +#endif // def __cplusplus + +#endif /* _DOLCESDK_PSP2_GXM_SYNC_OBJECT_INTERNAL_H_ */ -- cgit v1.2.3