GraphicsDevice
класс в UnityEngine.AMD
Выполнено в:UnityEngine.AMDModule
Описание
Обеспечивает основную точку входа для модуля AMD. Используйте ее для взаимодействия с функцией FSR2.
GraphicsDevice включает интерфейс для создания контекстов возможностей и управления ими, выполнения команд FSR2, а также служебные методы управления разрешением для режимов качества.GraphicsDevice необходимо для реализации FSR2 вне встроенной интеграции с HDRP Динамическое разрешение.
Перед использованием GraphicsDevice, обеспечивают AMDUnityPlugin загружается и устройство инициализируется через GraphicsDevice.CreateGraphicsDevice.
Дополнительные ресурсы: AMDUnityPlugin, FSR2Context, FSR2TextureTable, FSR2CommandInitializationData, FSR2CommandExecutionData
using UnityEngine; using UnityEngine.Rendering; using UnityEngine.Rendering.HighDefinition; using UnityEngine.AMD;
// Example HDRP custom pass public class CustomFSRPass : CustomPass { public static bool EnsureAMDPluginLoaded() { if (!AMDUnityPlugin.IsLoaded()) { Debug.Log("AMDUnityPlugin is not loaded!"); if (!AMDUnityPlugin.Load()) { Debug.LogError("Unable to load AMDUnityPlugin"); return false; } } Debug.Log("AMDUnityPlugin is successfully loaded!"); return true; }
void InitializeAMDDevice() { if (!EnsureAMDPluginLoaded()) return;
// AMDUnityPlugin initialization will handle device creation for us. // In case the device is not created, we call the static method GraphicsDevice.CreateGraphicsDevice(). amdDevice = GraphicsDevice.device == null ? GraphicsDevice.CreateGraphicsDevice() : GraphicsDevice.device;
Debug.LogFormat("AMD.GraphicsDevice initialized w/ version {0}", GraphicsDevice.version); }
protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd) { if (amdDevice == null) { InitializeAMDDevice(); } float scalingRatio = fsr2Context == null ? 1.0f : amdDevice.GetUpscaleRatioFromQualityMode(m_Quality); fsr2OutputColorBuffer = RTHandles.Alloc( new Vector2(scalingRatio, scalingRatio), dimension: TextureDimension.Tex2D, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, name: "fsr2OutputColorBuffer", enableRandomWrite: true );
// other pass setup code }
protected override void Execute(CustomPassContext ctx) { bool initializeFsr2Context = fsr2Context == null || HasInputResolutionChanged(ctx) || HasOutputResolutionChanged(ctx); if (initializeFsr2Context) { if (fsr2Context != null) { amdDevice.DestroyFeature(ctx.cmd, fsr2Context); fsr2Context = null; }
FSR2CommandInitializationData initData = new FSR2CommandInitializationData(); // populate initData fsr2Context = amdDevice.CreateFeature(ctx.cmd, initData); }
fsr2Context.executeData.enableSharpening = m_EnableSharpening ? 1 : 0; // populate rest of fsr2Context.executeData FSR2TextureTable fsr2TextureTable = new FSR2TextureTable() { // populate texture table };
amdDevice.ExecuteFSR2(ctx.cmd, fsr2Context, fsr2TextureTable); }
protected override void Cleanup() { // pass cleanup code
// No explicit clean up is necessary for AMD.GraphicsDevice, all handled internally }
private GraphicsDevice amdDevice = null; private FSR2Context fsr2Context = null; private RTHandle fsr2OutputColorBuffer; // other member variables }
Статические свойства
| Свойство | Описание |
|---|---|
| device | Получает устройство, созданное GraphicsDevice.CreateGraphicsDevice. Если устройство не было создано, это свойство оценивается как null. |
| version | Получает версию, соответствующую хост-плагину Unity, который управляет официальной библиотекой AMD.AMDUnityPlugin. |
Открытые методы
| Метод | Описание |
|---|---|
| CreateFeature | Создает объект FSR2Context. |
| DestroyFeature | Уничтожает определенный FSR2Context, созданный с помощью GraphicsDevice.CreateFeature. |
| ExecuteFSR2 | Записывает выполнение прохода FSR2 в буфер команды рендеринга. Этот вызов не выполняет буфер команды, он только добавляет в него пользовательские команды. |
| GetRenderResolutionFromQualityMode | Запрос конфигурации разрешения из указанной предварительной настройки режима качества. |
| GetUpscaleRatioFromQualityMode | Получает предварительно рассчитанный коэффициент масштабирования на основе предварительно установленного параметра качества. |
Статические методы
| Метод | Описание |
|---|---|
| CreateGraphicsDevice | Создает главный объект API. Этот метод можно вызвать только один раз в приложении. |