Condividi tramite


Caricamento della visualizzazione di accesso non ordinato

Unrdered Access View (UAV) Typed Load è la possibilità di leggere uno shader da un UAV con un DXGI_FORMAT specifico.

Panoramica

Una visualizzazione di accesso non ordinata (UAV) è una visualizzazione di una risorsa di accesso non ordinata (che può includere buffer, trame e matrici di trame, anche se senza campionamento multi-campionamento). Un UAV consente l'accesso in lettura/scrittura cronologicamente non ordinato 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 nell'elenco di formati che possono essere usati con carichi UAV tipizzato.

Formati e chiamate API supportate

In precedenza, i tre formati supportati sono stati caricati dall'UAV tipizzato e sono stati 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 uno è supportato, tutti sono supportati.

  • 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
  • 8G8_SINT
  • R16_UNORM
  • R16_SNORM
  • R8_SNORM
  • A8_UNORM
  • B5G6R5_UNORM
  • B5G5R5A1_UNORM
  • B4G4R4A4_UNORM

Per determinare il supporto per eventuali formati aggiuntivi, chiamare ID3D11Device::CheckFeatureSupport con la struttura D3D11_FEATURE_DATA_D3D11_OPTIONS2 come primo parametro. Il TypedUAVLoadAdditionalFormats bit verrà impostato se è supportato l'elenco "supportato come set" precedente. Eseguire una seconda chiamata a CheckFeatureSupport usando una struttura D3D11_FEATURE_DATA_FORMAT_SUPPORT2 (verificando la struttura restituita rispetto al membro D3D12_FORMAT_SUPPORT2_UAV_TYPED_LOAD dell'enumerazione D3D11_FORMAT_SUPPORT2) per determinare il supporto nell'elenco dei formati supportati facoltativamente sopra, ad esempio:

D3D11_FEATURE_DATA_D3D11_OPTIONS2 FeatureData;
ZeroMemory(&FeatureData, sizeof(FeatureData));
HRESULT hr = pDevice->CheckFeatureSupport(D3D11_FEATURE_D3D11_OPTIONS2, &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:
        D3D11_FEATURE_DATA_FORMAT_SUPPORT2 FormatSupport;
        ZeroMemory(&FormatSupport, sizeof(FormatSupport));
        FormatSupport.InFormat = DXGI_FORMAT_R32G32_FLOAT;
        hr = pDevice->CheckFeatureSupport(D3D11_FEATURE_FORMAT_SUPPORT2, &FormatSupport, sizeof(FormatSupport));
        if (SUCCEEDED(hr) && (FormatSupport.OutFormatSupport2 & D3D11_FORMAT_SUPPORT2_UAV_TYPED_LOAD) != 0)
        {
            // DXGI_FORMAT_R32G32_FLOAT supports UAV Typed Load!
        }
    }
}

Uso dei carichi UAV tipizzato da HLSL

Per le UAV tipizzata, il flag HLSL è D3D_SHADER_REQUIRES_TYPED_UAV_LOAD_ADDITIONAL_FORMATS.

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

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

Funzionalità direct3D 11.3

Modello shader 5.1