Condividi tramite


Funzione D3DKMTCreateAllocation2 (d3dkmthk.h)

La funzione D3DKMTCreateAllocation2 crea o aggiunge allocazioni di memoria di sistema o video.

Sintassi

NTSTATUS D3DKMTCreateAllocation2(
  D3DKMT_CREATEALLOCATION *unnamedParam1
);

Parametri

unnamedParam1

[in, out] pData: puntatore a una struttura D3DKMT_CREATEALLOCATION che contiene informazioni per la creazione di allocazioni.

Valore restituito

D3DKMTCreateAllocation2 restituisce STATUS_SUCCESS se l'operazione ha esito positivo. In caso contrario, potrebbe restituire un codice NTSTATUS , ad esempio uno dei valori seguenti:

Codice restituito Descrizione
STATUS_DEVICE_REMOVED La scheda grafica è stata arrestata o il dispositivo di visualizzazione è stato reimpostato.
STATUS_INVALID_PARAMETER I parametri sono stati convalidati e sono stati determinati come non corretti.
STATUS_NO_MEMORY Impossibile completare questa routine a causa di memoria di sistema insufficiente.
STATUS_NO_VIDEO_MEMORY Questa routine non è stata completata a causa di memoria video insufficiente. La gestione memoria video tenta di virtualizzare la memoria video. Tuttavia, se la virtualizzazione non riesce, ad esempio quando si esaurisce lo spazio indirizzi virtuale, la gestione memoria potrebbe restituire questo codice di errore.

Commenti

Un client grafico in modalità utente può chiamare D3DKMTCreateAllocation2 per creare allocazioni e risorse. Un'allocazione può essere associata a una risorsa oppure può essere autonoma.

D3DKMTCreateAllocation2 può anche essere chiamato per aggiungere allocazioni aggiuntive a una risorsa in qualsiasi momento. Le uniche restrizioni sono che tutte le allocazioni condivise devono essere associate a una risorsa e non è possibile aggiungere allocazioni aggiuntive a una risorsa condivisa esistente.

Esempio

Creazione di un'allocazione autonoma nella memoria video non associata a una risorsa

L'esempio di codice seguente illustra come un client grafico in modalità utente può usare D3DKMTCreateAllocation2 per creare un'allocazione autonoma nella memoria video non associata a una risorsa.

D3DKMT_HANDLE CreateStandAloneAllocation(D3DKMT_HANDLE hDevice, VOID* pPrivateAllocationInfo, UINT Size)
{
    D3DKMT_CREATEALLOCATION CreateAllocation;
    D3DDDI_ALLOCATIONINFO2 AllocationInfo;

    memset(&CreateAllocation, 0, sizeof(CreateAllocation));
    CreateAllocation.hDevice = hDevice;
    CreateAllocation.NumAllocations = 1;
    CreateAllocation.pAllocationInfo2 = &AllocationInfo;

    AllocationInfo.hAllocation = NULL;
    AllocationInfo.pSystemMem = NULL;  // Vidmem allocation
    AllocationInfo.pPrivateDriverData = pPrivateAllocationInfo;  // Contains format, size, and so on.
    AllocationInfo.PrivateDriverDataSize = Size;

    if (NT_SUCCESS((*pfnKTCreateAllocation)(&CreateAllocation))) {
        return AllocationInfo.hAllocation;
    }
    return 0;
}

Creazione di una risorsa con un'allocazione di memoria di sistema singola

L'esempio di codice seguente illustra come un client grafico in modalità utente può usare D3DKMTCreateAllocation2 per creare una risorsa con un'allocazione di memoria di sistema singola.

HRESULT CreateSysmemResource(D3DKMT_HANDLE hDevice, 
                             UINT AllocationSize, 
                             VOID* pResourceData, 
                             UINT ResourceDataSize,
                             VOID* pAllocationData, 
                             UINT AllocationDataSize,
                             D3DKMT_HANDLE* phResource,
                             D3DKMT_HANDLE* phAllocation)
{
    D3DKMT_CREATEALLOCATION CreateAllocation;
    D3DDDI_ALLOCATIONINFO2 AllocationInfo;
    VOID* pSysMem;

    *phResource = NULL;
    *phAllocation = NULL;

    // For a sysmem allocation, preallocate the memory.
    pSysMem = MemAlloc(AllocationSize);
    if (pSysMem == NULL) {
        return E_OUTOFMEMORY;
    }
 
    memset(&CreateAllocation, 0, sizeof(CreateAllocation));
    CreateAllocation.hDevice = hDevice;
    CreateAllocation.Flags.CreateResource = TRUE;
    CreateAllocation.pPrivateDriverData = pResourceData;
    CreateAllocation.PrivateDriverDataSize = ResourceDataSize;
    CreateAllocation.NumAllocations = 1;
    CreateAllocation.pAllocationInfo = &AllocationInfo;

    AllocationInfo.hAllocation = NULL;
    AllocationInfo.pSystemMem = pSysMem;
    AllocationInfo.pPrivateDriverData = pAllocationData;
    AllocationInfo.PrivateDriverDataSize = AllocationDataSize;

    if (NT_SUCCESS((*pfnKTCreateAllocation)(&CreateAllocation))) {
        *phResource = CreateAllocation.hResource;
        *phAllocation = AllocationInfo.hAllocation;
        return S_OK;
    }
    MemFree(pSysMem);
    return E_FAIL;
}

Requisiti

Requisito Valore
Client minimo supportato Windows 7
Piattaforma di destinazione Universale
Intestazione d3dkmthk.h (include D3dkmthk.h)
Libreria Gdi32.lib
DLL Gdi32.dll

Vedi anche

D3DKMT_CREATEALLOCATION