Caricamenti della visualizzazione di accesso non ordinato (UAV) tipizzata

Caricamento tipizzato UAV (Unordered Access View) consente a uno shader di leggere da un UAV con un DXGI_FORMAT specifico.

Panoramica

Una visualizzazione di accesso non ordinato (UAV) è una visualizzazione di una risorsa di accesso non ordinata (che può includere buffer, trame e matrici di trame, anche se senza più campionamento). Un UAV consente l'accesso in lettura/scrittura non ordinato temporale da più thread. Ciò significa che questo tipo di risorsa può essere letto/scritto simultaneamente da più thread senza generare conflitti di memoria. Questo accesso simultaneo viene gestito tramite l'uso di Funzioni Atomic.

D3D12 (e D3D11.3) si espande sull'elenco dei formati che possono essere usati con caricamenti UAV tipizzato.

Formati supportati e chiamate API

In precedenza, i tre formati seguenti supportavano i caricamenti UAV tipizzato ed erano necessari per l'hardware D3D11.0. Sono supportati per tutti gli hardware D3D11.3 e D3D12.

  • R32_FLOAT
  • R32_UINT
  • R32_SINT

I formati seguenti sono supportati come set nell'hardware D3D12 o D3D11.3, quindi, se ne è supportata una, tutte sono supportate.

  • R32G32B32A32_FLOAT
  • R32G32B32A32_UINT
  • R32G32B32A32_SINT
  • R16G16B16A16_FLOAT
  • R16G16B16A16_UINT
  • R16G16B16A16_SINT
  • R8G8B8A8_UNORM
  • R8G8B8A8_UINT
  • R8G8B8A8_SINT
  • R16_FLOAT
  • R16_UINT
  • R16_SINT
  • R8_UNORM
  • R8_UINT
  • R8_SINT

I formati seguenti sono facoltativamente e supportati singolarmente nell'hardware D3D12 e D3D11.3, quindi è necessario eseguire una singola query su ogni formato per testare il supporto.

  • R16G16B16A16_UNORM
  • R16G16B16A16_SNORM
  • R32G32_FLOAT
  • R32G32_UINT
  • R32G32_SINT
  • R10G10B10A2_UNORM
  • R10G10B10A2_UINT
  • R11G11B10_FLOAT
  • R8G8B8A8_SNORM
  • R16G16_FLOAT
  • R16G16_UNORM
  • R16G16_UINT
  • R16G16_SNORM
  • R16G16_SINT
  • R8G8_UNORM
  • R8G8_UINT
  • R8G8_SNORM
  • R8G8_SINT
  • R16_UNORM
  • R16_SNORM
  • R8_SNORM
  • A8_UNORM
  • B5G6R5_UNORM
  • B5G5R5A1_UNORM
  • B4G4R4A4_UNORM

Per determinare il supporto per eventuali formati aggiuntivi, chiamare CheckFeatureSupport con la struttura D3D12_FEATURE_DATA_D3D12_OPTIONS come primo parametro (fare riferimento a Capability Querying). Il campo TypedUAVLoadAdditionalFormats verrà impostato se è supportato l'elenco "supportato come set". Effettuare una seconda chiamata a CheckFeatureSupport usando una struttura di D3D12_FEATURE_DATA_FORMAT_SUPPORT (verificando la struttura restituita sul membro D3D12_FORMAT_SUPPORT2_UAV_TYPED_LOAD dell'enumerazione D3D12_FORMAT_SUPPORT2 ) per determinare il supporto nell'elenco dei formati facoltativamente supportati elencati sopra, ad esempio:

D3D12_FEATURE_DATA_D3D12_OPTIONS FeatureData;
ZeroMemory(&FeatureData, sizeof(FeatureData));
HRESULT hr = pDevice->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &FeatureData, sizeof(FeatureData));
if (SUCCEEDED(hr))
{
    // TypedUAVLoadAdditionalFormats contains a Boolean that tells you whether the feature is supported or not
    if (FeatureData.TypedUAVLoadAdditionalFormats)
    {
        // Can assume “all-or-nothing” subset is supported (e.g. R32G32B32A32_FLOAT)
        // Cannot assume other formats are supported, so we check:
        D3D12_FEATURE_DATA_FORMAT_SUPPORT FormatSupport = {DXGI_FORMAT_R32G32_FLOAT, D3D12_FORMAT_SUPPORT1_NONE, D3D12_FORMAT_SUPPORT2_NONE};
        hr = pDevice->CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &FormatSupport, sizeof(FormatSupport));
        if (SUCCEEDED(hr) && (FormatSupport.Support2 & D3D12_FORMAT_SUPPORT2_UAV_TYPED_LOAD) != 0)
        {
            // DXGI_FORMAT_R32G32_FLOAT supports UAV Typed Load!
        }
    }
}

Uso di caricamenti UAV tipizzato da HLSL

Per gli UAV tipizzato, il flag HLSL è D3D_SHADER_REQUIRES_TYPED_UAV_LOAD_ADDITIONAL_FORMATS.

Di seguito è riportato un esempio di codice shader per elaborare un caricamento UAV tipizzato:

RWTexture2D<float4> uav1;
uint2 coord;
float4 main() : SV_Target
{
  return uav1.Load(coord);
}

Uso di UAV tipizzato UNORM e SNORM da HLSL

Quando si usa un UAV tipizzato viene caricato per leggere da una risorsa UNORM o SNORM, è necessario dichiarare correttamente il tipo di elemento dell'oggetto HLSL come unorm o snorm. Viene specificato come comportamento non definito per la mancata corrispondenza del tipo di elemento dichiarato in HLSL con il tipo di dati della risorsa sottostante. Ad esempio, se si usa un UAV tipizzato in una risorsa buffer con dati R8_UNORM, è necessario dichiarare il tipo di elemento come unorm float:

RWBuffer<unorm float> uav;

Rendering

Associazione di risorse

Associazione di risorse in HLSL

Modello shader 5.1

Specifica delle firme radice in HLSL