2025-04-10 20:39:04 +08:00

106 lines
3.1 KiB
C++

#pragma once
#include "Unity/IUnityGraphics.h"
#include <array>
struct IUnityInterfaces;
enum GraphicsFeature
{
VRS_DRAW = 0,
VRS_PRIMITIVE,
VRS_ATTACHMENT,
HW_SPATIAL_SR,
METAL_VRR,
HW_AISR,
HW_ADAPTIVE_VRS,
HW_FG_INTERPOLATE,
HW_FG_EXTRAPOLATION,
METAL_FX_SPATIAL_SR,
METAL_FX_TEMPORAL_SR,
VIVO_TEMPORAL_SR,
QCOM_AFME,
MAX_CNT
};
struct SupportFeatureList
{
std::array<bool, GraphicsFeature::MAX_CNT> support_features = {0};
bool& operator[](GraphicsFeature feature)
{
return support_features[(int)feature];
}
};
struct AFMEParam
{
void* src;
void* data;
void* dst;
};
// Super-simple "graphics abstraction". This is nothing like how a proper platform abstraction layer would look like;
// all this does is a base interface for whatever our plugin sample needs. Which is only "draw some triangles"
// and "modify a texture" at this point.
//
// There are implementations of this base class for D3D9, D3D11, OpenGL etc.; see individual RenderAPI_* files.
class RenderAPI
{
public:
virtual ~RenderAPI() { }
// Process general event like initialization, shutdown, device loss/reset etc.
virtual void processDeviceEvent(UnityGfxDeviceEventType type, IUnityInterfaces* interfaces) = 0;
// Is the API using "reversed" (1.0 at near plane, 0.0 at far plane) depth buffer?
// Reversed Z is used on modern platforms, and improves depth buffer precision.
virtual bool getUsesReverseZ() = 0;
// Sets the underlying resource to unity RenderBuffer
// see https://docs.unity3d.com/ScriptReference/RenderBuffer.html
// setting rb to nullptr is used to signal the plugin that the
// previously set RenderBuffer is no longer valid
virtual void setRenderTextureResource(UnityRenderBuffer rb) {}
// This should return true when the plugin is used with the unity player
// and false when the editor is used. The editor uses multiple swap
// chains (for each window) so instead of choosing one of them nullptr is returned.
virtual bool isSwapChainAvailable() { return false; };
// These require the swap chain to be available to be functional.
// When the swap chain is not available these simply return 0
virtual unsigned int getPresentFlags() { return 0; }
virtual unsigned int getSyncInterval() { return 0; }
virtual unsigned int getBackbufferWidth() { return 0; }
virtual unsigned int getBackbufferHeight() { return 0; }
virtual void enableVRS(void* data) {}
virtual void disableVRS() {}
virtual void enableFGExtrapolation(void* data) {}
virtual void preFGExtrapolation() {}
// when renturn true present dst, data may matriaxs or texture
virtual bool doFGExtrapolation(void* src, void* data, void* dst) { return false;}
virtual void postFGExtrapolation() {}
virtual void disableFGExtrapolation() {}
virtual void spatialUpScale(void* data) {}
virtual bool getFeatureSupport(GraphicsFeature feature);
virtual void SetVKPSOHook(bool enable) {}
protected:
virtual void initSupportFeature() = 0;
SupportFeatureList support_features;
};
// Create a graphics API implementation instance for the given API type.
RenderAPI* createRenderAPI(UnityGfxRenderer apiType);