Browse Source

Updated Unity plugin API headers, with support for new D3D12 v8 interface

master
Nico de Poel 5 months ago
parent
commit
f79ad52483
  1. 6
      include/UnityPluginAPI/IUnityGraphics.h
  2. 84
      include/UnityPluginAPI/IUnityGraphicsD3D12.h
  3. 49
      include/UnityPluginAPI/IUnityGraphicsVulkan.h
  4. 4
      include/UnityPluginAPI/IUnityLog.h
  5. 11
      include/UnityPluginAPI/IUnityRenderingExtensions.h

6
include/UnityPluginAPI/IUnityGraphics.h

@ -14,7 +14,7 @@ typedef enum UnityGfxRenderer
//kUnityGfxRendererD3D9 = 1, // Direct3D 9, removed //kUnityGfxRendererD3D9 = 1, // Direct3D 9, removed
kUnityGfxRendererD3D11 = 2, // Direct3D 11 kUnityGfxRendererD3D11 = 2, // Direct3D 11
kUnityGfxRendererNull = 4, // "null" device (used in batch mode) kUnityGfxRendererNull = 4, // "null" device (used in batch mode)
kUnityGfxRendererOpenGLES20 = 8, // OpenGL ES 2.0
//kUnityGfxRendererOpenGLES20 = 8, // OpenGL ES 2.0, removed
kUnityGfxRendererOpenGLES30 = 11, // OpenGL ES 3.0 kUnityGfxRendererOpenGLES30 = 11, // OpenGL ES 3.0
//kUnityGfxRendererGXM = 12, // PlayStation Vita, removed //kUnityGfxRendererGXM = 12, // PlayStation Vita, removed
kUnityGfxRendererPS4 = 13, // PlayStation 4 kUnityGfxRendererPS4 = 13, // PlayStation 4
@ -28,7 +28,9 @@ typedef enum UnityGfxRenderer
kUnityGfxRendererGameCoreXboxOne = 24, // GameCore Xbox One kUnityGfxRendererGameCoreXboxOne = 24, // GameCore Xbox One
kUnityGfxRendererGameCoreXboxSeries = 25, // GameCore XboxSeries kUnityGfxRendererGameCoreXboxSeries = 25, // GameCore XboxSeries
kUnityGfxRendererPS5 = 26, // PS5 kUnityGfxRendererPS5 = 26, // PS5
kUnityGfxRendererPS5NGGC = 27 // PS5 NGGC
kUnityGfxRendererPS5NGGC = 27, // PS5 NGGC
kUnityGfxRendererReservedCFE = 29
} UnityGfxRenderer; } UnityGfxRenderer;
typedef enum UnityGfxDeviceEventType typedef enum UnityGfxDeviceEventType

84
include/UnityPluginAPI/IUnityGraphicsD3D12.h

@ -13,59 +13,111 @@
struct RenderSurfaceBase; struct RenderSurfaceBase;
typedef struct RenderSurfaceBase* UnityRenderBuffer; typedef struct RenderSurfaceBase* UnityRenderBuffer;
typedef struct UnityGraphicsD3D12ResourceState UnityGraphicsD3D12ResourceState;
struct UnityGraphicsD3D12ResourceState
typedef struct UnityGraphicsD3D12ResourceState
{ {
ID3D12Resource* resource; // Resource to barrier. ID3D12Resource* resource; // Resource to barrier.
D3D12_RESOURCE_STATES expected; // Expected resource state before this command list is executed. D3D12_RESOURCE_STATES expected; // Expected resource state before this command list is executed.
D3D12_RESOURCE_STATES current; // State this resource will be in after this command list is executed. D3D12_RESOURCE_STATES current; // State this resource will be in after this command list is executed.
};
}UnityGraphicsD3D12ResourceState;
struct UnityGraphicsD3D12RecordingState
typedef struct UnityGraphicsD3D12RecordingState
{ {
ID3D12GraphicsCommandList* commandList; // D3D12 command list that is currently recorded by Unity ID3D12GraphicsCommandList* commandList; // D3D12 command list that is currently recorded by Unity
};
}UnityGraphicsD3D12RecordingState;
enum UnityD3D12GraphicsQueueAccess
typedef enum UnityD3D12GraphicsQueueAccess
{ {
// No queue acccess, no work must be submitted to UnityD3D12Instance::graphicsQueue from the plugin event callback
// Enables access to CommandRecordingState and disables access to GetCommandQueue. When using this plugin callbacks
// will be called from the render thread. When accessing the command queue from GetCommandQueue it is hihgly likely
// that submission thread will be using at the same time and it will cause issues.
kUnityD3D12GraphicsQueueAccess_DontCare, kUnityD3D12GraphicsQueueAccess_DontCare,
// Make sure that Unity worker threads don't access the D3D12 graphics queue
// This disables access to the current Unity command buffer
// Enables access to GetCommandQueue and disables access to CommandRecordingState. When using this plugin callbacks
// will be called from the submission thread. When accessing the commmand list from CommandRecordingState it is highly
// likely that the render thread will be accessing it at the same time and it will cause issues.
kUnityD3D12GraphicsQueueAccess_Allow, kUnityD3D12GraphicsQueueAccess_Allow,
};
}UnityD3D12GraphicsQueueAccess;
enum UnityD3D12EventConfigFlagBits
typedef enum UnityD3D12EventConfigFlagBits
{ {
kUnityD3D12EventConfigFlag_EnsurePreviousFrameSubmission = (1 << 0), // default: (NOT SUPPORTED) kUnityD3D12EventConfigFlag_EnsurePreviousFrameSubmission = (1 << 0), // default: (NOT SUPPORTED)
kUnityD3D12EventConfigFlag_FlushCommandBuffers = (1 << 1), // submit existing command buffers, default: not set kUnityD3D12EventConfigFlag_FlushCommandBuffers = (1 << 1), // submit existing command buffers, default: not set
kUnityD3D12EventConfigFlag_SyncWorkerThreads = (1 << 2), // wait for worker threads to finish, default: not set kUnityD3D12EventConfigFlag_SyncWorkerThreads = (1 << 2), // wait for worker threads to finish, default: not set
kUnityD3D12EventConfigFlag_ModifiesCommandBuffersState = (1 << 3), // should be set when descriptor set bindings, vertex buffer bindings, etc are changed (default: set) kUnityD3D12EventConfigFlag_ModifiesCommandBuffersState = (1 << 3), // should be set when descriptor set bindings, vertex buffer bindings, etc are changed (default: set)
};
}UnityD3D12EventConfigFlagBits;
struct UnityD3D12PluginEventConfig
typedef struct UnityD3D12PluginEventConfig
{ {
UnityD3D12GraphicsQueueAccess graphicsQueueAccess; UnityD3D12GraphicsQueueAccess graphicsQueueAccess;
UINT32 flags; // UnityD3D12EventConfigFlagBits to be used when invoking a native plugin UINT32 flags; // UnityD3D12EventConfigFlagBits to be used when invoking a native plugin
bool ensureActiveRenderTextureIsBound; // If true, the actively bound render texture will be bound prior the execution of the native plugin method. bool ensureActiveRenderTextureIsBound; // If true, the actively bound render texture will be bound prior the execution of the native plugin method.
};
}UnityD3D12PluginEventConfig;
typedef struct UnityGraphicsD3D12PhysicalVideoMemoryControlValues UnityGraphicsD3D12PhysicalVideoMemoryControlValues;
struct UnityGraphicsD3D12PhysicalVideoMemoryControlValues // all absolute values in bytes
typedef struct UnityGraphicsD3D12PhysicalVideoMemoryControlValues // all absolute values in bytes
{ {
UINT64 reservation; // Minimum required physical memory for an application [default = 64MB]. UINT64 reservation; // Minimum required physical memory for an application [default = 64MB].
UINT64 systemMemoryThreshold; // If free physical video memory drops below this threshold, resources will be allocated in system memory. [default = 64MB] UINT64 systemMemoryThreshold; // If free physical video memory drops below this threshold, resources will be allocated in system memory. [default = 64MB]
UINT64 residencyHysteresisThreshold; // Minimum free physical video memory needed to start bringing evicted resources back after shrunken video memory budget expands again. [default = 128MB] UINT64 residencyHysteresisThreshold; // Minimum free physical video memory needed to start bringing evicted resources back after shrunken video memory budget expands again. [default = 128MB]
float nonEvictableRelativeThreshold; // The relative proportion of the video memory budget that must be kept available for non-evictable resources. [default = 0.25] float nonEvictableRelativeThreshold; // The relative proportion of the video memory budget that must be kept available for non-evictable resources. [default = 0.25]
}UnityGraphicsD3D12PhysicalVideoMemoryControlValues;
// Should only be used on the rendering/submission thread.
UNITY_DECLARE_INTERFACE(IUnityGraphicsD3D12v8)
{
ID3D12Device* (UNITY_INTERFACE_API * GetDevice)();
// Swap chain is only accessible when using the unity player.
// When using the editor GetSwapChain will return nullptr.
IDXGISwapChain* (UNITY_INTERFACE_API * GetSwapChain)();
// These are also only accessible when using the player,
// both of these return 0 when editor is used.
UINT32(UNITY_INTERFACE_API * GetSyncInterval)();
UINT(UNITY_INTERFACE_API * GetPresentFlags)();
ID3D12Fence* (UNITY_INTERFACE_API * GetFrameFence)();
// Returns the value set on the frame fence once the current frame completes or the GPU is flushed
UINT64(UNITY_INTERFACE_API * GetNextFrameFenceValue)();
// Executes a given command list on a worker thread. The command list type must be D3D12_COMMAND_LIST_TYPE_DIRECT.
// [Optional] Declares expected and post-execution resource states.
// Returns the fence value. The value will be set once the current frame completes or the GPU is flushed.
UINT64(UNITY_INTERFACE_API * ExecuteCommandList)(ID3D12GraphicsCommandList * commandList, int stateCount, UnityGraphicsD3D12ResourceState * states);
void(UNITY_INTERFACE_API * SetPhysicalVideoMemoryControlValues)(const UnityGraphicsD3D12PhysicalVideoMemoryControlValues * memInfo);
ID3D12CommandQueue* (UNITY_INTERFACE_API * GetCommandQueue)();
ID3D12Resource* (UNITY_INTERFACE_API * TextureFromRenderBuffer)(UnityRenderBuffer rb);
ID3D12Resource* (UNITY_INTERFACE_API * TextureFromNativeTexture)(UnityTextureID texture);
// Change the precondition for a specific user-defined event
// Should be called during initialization
void(UNITY_INTERFACE_API * ConfigureEvent)(int eventID, const UnityD3D12PluginEventConfig * pluginEventConfig);
bool(UNITY_INTERFACE_API * CommandRecordingState)(UnityGraphicsD3D12RecordingState * outCommandRecordingState);
// Ask the state of a resource to be the requested state in the active command list. Adds barriers if needed.
void(UNITY_INTERFACE_API * RequestResourceState)(ID3D12Resource * resource, D3D12_RESOURCE_STATES state);
// Notify Unity about the state of a resource in the active command list.
// Needs to be called after adding commands to command recording state if they change the state of any resource,
// so that the graphics backend can add necessary barriers for any further commands.
void(UNITY_INTERFACE_API * NotifyResourceState)(ID3D12Resource * resource, D3D12_RESOURCE_STATES state, bool UAVAccess);
}; };
UNITY_REGISTER_INTERFACE_GUID(0x9d303045d00d4cfdULL, 0x8febb42968b423b6ULL, IUnityGraphicsD3D12v8) // TODO: Get proper values
// Should only be used on the rendering/submission thread. // Should only be used on the rendering/submission thread.
UNITY_DECLARE_INTERFACE(IUnityGraphicsD3D12v7) UNITY_DECLARE_INTERFACE(IUnityGraphicsD3D12v7)
{ {
ID3D12Device* (UNITY_INTERFACE_API * GetDevice)(); ID3D12Device* (UNITY_INTERFACE_API * GetDevice)();
// Swap chain is only accessible when using the unity player.
// When using the editor GetSwapChain will return nullptr.
IDXGISwapChain* (UNITY_INTERFACE_API * GetSwapChain)(); IDXGISwapChain* (UNITY_INTERFACE_API * GetSwapChain)();
// These are also only accessible when using the player,
// both of these return 0 when editor is used.
UINT32(UNITY_INTERFACE_API * GetSyncInterval)(); UINT32(UNITY_INTERFACE_API * GetSyncInterval)();
UINT(UNITY_INTERFACE_API * GetPresentFlags)(); UINT(UNITY_INTERFACE_API * GetPresentFlags)();

49
include/UnityPluginAPI/IUnityGraphicsVulkan.h

@ -6,6 +6,7 @@
#pragma once #pragma once
#include "IUnityInterface.h" #include "IUnityInterface.h"
#include <stdbool.h>
#ifndef UNITY_VULKAN_HEADER #ifndef UNITY_VULKAN_HEADER
#define UNITY_VULKAN_HEADER <vulkan/vulkan.h> #define UNITY_VULKAN_HEADER <vulkan/vulkan.h>
@ -13,7 +14,7 @@
#include UNITY_VULKAN_HEADER #include UNITY_VULKAN_HEADER
struct UnityVulkanInstance
typedef struct UnityVulkanInstance
{ {
VkPipelineCache pipelineCache; // Unity's pipeline cache is serialized to disk VkPipelineCache pipelineCache; // Unity's pipeline cache is serialized to disk
VkInstance instance; VkInstance instance;
@ -24,9 +25,9 @@ struct UnityVulkanInstance
unsigned int queueFamilyIndex; unsigned int queueFamilyIndex;
void* reserved[8]; void* reserved[8];
};
}UnityVulkanInstance;
struct UnityVulkanMemory
typedef struct UnityVulkanMemory
{ {
VkDeviceMemory memory; // Vulkan memory handle VkDeviceMemory memory; // Vulkan memory handle
VkDeviceSize offset; // offset within memory VkDeviceSize offset; // offset within memory
@ -36,9 +37,9 @@ struct UnityVulkanMemory
unsigned int memoryTypeIndex; // index into VkPhysicalDeviceMemoryProperties::memoryTypes unsigned int memoryTypeIndex; // index into VkPhysicalDeviceMemoryProperties::memoryTypes
void* reserved[4]; void* reserved[4];
};
}UnityVulkanMemory;
enum UnityVulkanResourceAccessMode
typedef enum UnityVulkanResourceAccessMode
{ {
// Does not imply any pipeline barriers, should only be used to query resource attributes // Does not imply any pipeline barriers, should only be used to query resource attributes
kUnityVulkanResourceAccess_ObserveOnly, kUnityVulkanResourceAccess_ObserveOnly,
@ -48,9 +49,9 @@ enum UnityVulkanResourceAccessMode
// Recreates the backing resource (VkBuffer/VkImage) but keeps the previous one alive if it's in use // Recreates the backing resource (VkBuffer/VkImage) but keeps the previous one alive if it's in use
kUnityVulkanResourceAccess_Recreate, kUnityVulkanResourceAccess_Recreate,
};
}UnityVulkanResourceAccessMode;
struct UnityVulkanImage
typedef struct UnityVulkanImage
{ {
UnityVulkanMemory memory; // memory that backs the image UnityVulkanMemory memory; // memory that backs the image
VkImage image; // Vulkan image handle VkImage image; // Vulkan image handle
@ -66,9 +67,9 @@ struct UnityVulkanImage
int mipCount; int mipCount;
void* reserved[4]; void* reserved[4];
};
}UnityVulkanImage;
struct UnityVulkanBuffer
typedef struct UnityVulkanBuffer
{ {
UnityVulkanMemory memory; // memory that backs the buffer UnityVulkanMemory memory; // memory that backs the buffer
VkBuffer buffer; // Vulkan buffer handle VkBuffer buffer; // Vulkan buffer handle
@ -76,9 +77,9 @@ struct UnityVulkanBuffer
VkBufferUsageFlags usage; VkBufferUsageFlags usage;
void* reserved[4]; void* reserved[4];
};
}UnityVulkanBuffer;
struct UnityVulkanRecordingState
typedef struct UnityVulkanRecordingState
{ {
VkCommandBuffer commandBuffer; // Vulkan command buffer that is currently recorded by Unity VkCommandBuffer commandBuffer; // Vulkan command buffer that is currently recorded by Unity
VkCommandBufferLevel commandBufferLevel; VkCommandBufferLevel commandBufferLevel;
@ -91,9 +92,9 @@ struct UnityVulkanRecordingState
unsigned long long safeFrameNumber; // all resources that were used in this frame (or before) are safe to be released unsigned long long safeFrameNumber; // all resources that were used in this frame (or before) are safe to be released
void* reserved[4]; void* reserved[4];
};
}UnityVulkanRecordingState;
enum UnityVulkanEventRenderPassPreCondition
typedef enum UnityVulkanEventRenderPassPreCondition
{ {
// Don't care about the state on Unity's current command buffer // Don't care about the state on Unity's current command buffer
// This is the default precondition // This is the default precondition
@ -110,9 +111,9 @@ enum UnityVulkanEventRenderPassPreCondition
// Ends the current render pass (and resumes it afterwards if needed) // Ends the current render pass (and resumes it afterwards if needed)
// If used in combination with the SRP RenderPass API the resuls is undefined. // If used in combination with the SRP RenderPass API the resuls is undefined.
kUnityVulkanRenderPass_EnsureOutside kUnityVulkanRenderPass_EnsureOutside
};
}UnityVulkanEventRenderPassPreCondition;
enum UnityVulkanGraphicsQueueAccess
typedef enum UnityVulkanGraphicsQueueAccess
{ {
// No queue acccess, no work must be submitted to UnityVulkanInstance::graphicsQueue from the plugin event callback // No queue acccess, no work must be submitted to UnityVulkanInstance::graphicsQueue from the plugin event callback
kUnityVulkanGraphicsQueueAccess_DontCare, kUnityVulkanGraphicsQueueAccess_DontCare,
@ -120,22 +121,22 @@ enum UnityVulkanGraphicsQueueAccess
// Make sure that Unity worker threads don't access the Vulkan graphics queue // Make sure that Unity worker threads don't access the Vulkan graphics queue
// This disables access to the current Unity command buffer // This disables access to the current Unity command buffer
kUnityVulkanGraphicsQueueAccess_Allow, kUnityVulkanGraphicsQueueAccess_Allow,
};
}UnityVulkanGraphicsQueueAccess;
enum UnityVulkanEventConfigFlagBits
typedef enum UnityVulkanEventConfigFlagBits
{ {
kUnityVulkanEventConfigFlag_EnsurePreviousFrameSubmission = (1 << 0), // default: set kUnityVulkanEventConfigFlag_EnsurePreviousFrameSubmission = (1 << 0), // default: set
kUnityVulkanEventConfigFlag_FlushCommandBuffers = (1 << 1), // submit existing command buffers, default: not set kUnityVulkanEventConfigFlag_FlushCommandBuffers = (1 << 1), // submit existing command buffers, default: not set
kUnityVulkanEventConfigFlag_SyncWorkerThreads = (1 << 2), // wait for worker threads to finish, default: not set kUnityVulkanEventConfigFlag_SyncWorkerThreads = (1 << 2), // wait for worker threads to finish, default: not set
kUnityVulkanEventConfigFlag_ModifiesCommandBuffersState = (1 << 3), // should be set when descriptor set bindings, vertex buffer bindings, etc are changed (default: set) kUnityVulkanEventConfigFlag_ModifiesCommandBuffersState = (1 << 3), // should be set when descriptor set bindings, vertex buffer bindings, etc are changed (default: set)
};
}UnityVulkanEventConfigFlagBits;
struct UnityVulkanPluginEventConfig
typedef struct UnityVulkanPluginEventConfig
{ {
UnityVulkanEventRenderPassPreCondition renderPassPrecondition; UnityVulkanEventRenderPassPreCondition renderPassPrecondition;
UnityVulkanGraphicsQueueAccess graphicsQueueAccess; UnityVulkanGraphicsQueueAccess graphicsQueueAccess;
uint32_t flags; uint32_t flags;
};
}UnityVulkanPluginEventConfig;
// Constant that can be used to reference the whole image // Constant that can be used to reference the whole image
const VkImageSubresource* const UnityVulkanWholeImage = NULL; const VkImageSubresource* const UnityVulkanWholeImage = NULL;
@ -143,16 +144,16 @@ const VkImageSubresource* const UnityVulkanWholeImage = NULL;
// callback function, see InterceptInitialization // callback function, see InterceptInitialization
typedef PFN_vkGetInstanceProcAddr(UNITY_INTERFACE_API * UnityVulkanInitCallback)(PFN_vkGetInstanceProcAddr getInstanceProcAddr, void* userdata); typedef PFN_vkGetInstanceProcAddr(UNITY_INTERFACE_API * UnityVulkanInitCallback)(PFN_vkGetInstanceProcAddr getInstanceProcAddr, void* userdata);
enum UnityVulkanSwapchainMode
typedef enum UnityVulkanSwapchainMode
{ {
kUnityVulkanSwapchainMode_Default, kUnityVulkanSwapchainMode_Default,
kUnityVulkanSwapchainMode_Offscreen kUnityVulkanSwapchainMode_Offscreen
};
}UnityVulkanSwapchainMode;
struct UnityVulkanSwapchainConfiguration
typedef struct UnityVulkanSwapchainConfiguration
{ {
UnityVulkanSwapchainMode mode; UnityVulkanSwapchainMode mode;
};
}UnityVulkanSwapchainConfiguration;
enum enum
{ {

4
include/UnityPluginAPI/IUnityLog.h

@ -8,7 +8,7 @@
#include "IUnityInterface.h" #include "IUnityInterface.h"
/// The type of the log message /// The type of the log message
enum UnityLogType
typedef enum UnityLogType
{ {
/// UnityLogType used for Errors. /// UnityLogType used for Errors.
kUnityLogTypeError = 0, kUnityLogTypeError = 0,
@ -18,7 +18,7 @@ enum UnityLogType
kUnityLogTypeLog = 3, kUnityLogTypeLog = 3,
/// UnityLogType used for Exceptions. /// UnityLogType used for Exceptions.
kUnityLogTypeException = 4, kUnityLogTypeException = 4,
};
}UnityLogType;
#define UNITY_WRAP_CODE(CODE_) do { CODE_; } while (0) #define UNITY_WRAP_CODE(CODE_) do { CODE_; } while (0)
#define UNITY_LOG(PTR_, MSG_) UNITY_WRAP_CODE((PTR_)->Log(kUnityLogTypeLog, MSG_, __FILE__, __LINE__)) #define UNITY_LOG(PTR_, MSG_) UNITY_WRAP_CODE((PTR_)->Log(kUnityLogTypeLog, MSG_, __FILE__, __LINE__))

11
include/UnityPluginAPI/IUnityRenderingExtensions.h

@ -8,6 +8,7 @@
#include "IUnityGraphics.h" #include "IUnityGraphics.h"
#include <stdbool.h>
/* /*
Low-level Native Plugin Rendering Extensions Low-level Native Plugin Rendering Extensions
@ -290,13 +291,13 @@ typedef enum UnityRenderingExtTextureFormat
// Video formats // Video formats
kUnityRenderingExtFormatYUV2, kUnityRenderingExtFormatYUV2,
// Automatic formats, back-end decides
kUnityRenderingExtFormatDepthAuto_removed_donotuse,
kUnityRenderingExtFormatShadowAuto_removed_donotuse,
kUnityRenderingExtFormatVideoAuto_removed_donotuse,
// Obsoleted
//kUnityRenderingExtFormatDepthAuto_removed_donotuse = 142,
//kUnityRenderingExtFormatShadowAuto_removed_donotuse = 143,
//kUnityRenderingExtFormatVideoAuto_removed_donotuse = 144,
// ASTC hdr profile // ASTC hdr profile
kUnityRenderingExtFormatRGBA_ASTC4X4_UFloat,
kUnityRenderingExtFormatRGBA_ASTC4X4_UFloat = 145,
kUnityRenderingExtFormatRGBA_ASTC5X5_UFloat, kUnityRenderingExtFormatRGBA_ASTC5X5_UFloat,
kUnityRenderingExtFormatRGBA_ASTC6X6_UFloat, kUnityRenderingExtFormatRGBA_ASTC6X6_UFloat,
kUnityRenderingExtFormatRGBA_ASTC8X8_UFloat, kUnityRenderingExtFormatRGBA_ASTC8X8_UFloat,

Loading…
Cancel
Save