Fonction D3DKMTCreateAllocation2 (d3dkmthk.h)
La fonction D3DKMTCreateAllocation2 crée ou ajoute des allocations de mémoire système ou vidéo.
Syntaxe
NTSTATUS D3DKMTCreateAllocation2(
D3DKMT_CREATEALLOCATION *unnamedParam1
);
Paramètres
unnamedParam1
[in, out] pData : pointeur vers une structure D3DKMT_CREATEALLOCATION qui contient des informations pour la création d’allocations.
Valeur retournée
D3DKMTCreateAllocation2 retourne STATUS_SUCCESS si l’opération réussit. Sinon, il peut renvoyer un code NTSTATUS tel qu’une des valeurs suivantes :
Code de retour | Description |
---|---|
STATUS_DEVICE_REMOVED | La carte graphique a été arrêtée ou le périphérique d’affichage a été réinitialisé. |
STATUS_INVALID_PARAMETER | Les paramètres ont été validés et déterminés comme incorrects. |
STATUS_NO_MEMORY | Cette routine n’a pas pu se terminer en raison d’une mémoire système insuffisante. |
STATUS_NO_VIDEO_MEMORY | Cette routine n’a pas pu se terminer en raison d’une mémoire vidéo insuffisante. Le gestionnaire de mémoire vidéo tente de virtualiser la mémoire vidéo. Toutefois, si la virtualisation échoue (par exemple, lorsque l’espace d’adressage virtuel est vide), le gestionnaire de mémoire peut renvoyer ce code d’erreur. |
Remarques
Un client graphique en mode utilisateur peut appeler D3DKMTCreateAllocation2 pour créer des allocations et des ressources. Une allocation peut être associée à une ressource ou elle peut être autonome.
D3DKMTCreateAllocation2 peut également être appelé pour ajouter des allocations supplémentaires à une ressource à tout moment. Les seules restrictions sont que toutes les allocations partagées doivent être associées à une ressource et que des allocations supplémentaires ne peuvent pas être ajoutées à une ressource partagée existante.
Exemples
Création d’une allocation autonome dans la mémoire vidéo qui n’est pas associée à une ressource
L’exemple de code suivant montre comment un client graphique en mode utilisateur peut utiliser D3DKMTCreateAllocation2 pour créer une allocation autonome dans la mémoire vidéo qui n’est pas associée à une ressource.
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;
}
Création d’une ressource avec une allocation de mémoire système unique
L’exemple de code suivant montre comment un client graphique en mode utilisateur peut utiliser D3DKMTCreateAllocation2 pour créer une ressource avec une allocation de mémoire système unique.
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;
}
Configuration requise
Condition requise | Valeur |
---|---|
Client minimal pris en charge | Windows 7 |
Plateforme cible | Universal |
En-tête | d3dkmthk.h (inclure D3dkmthk.h) |
Bibliothèque | Gdi32.lib |
DLL | Gdi32.dll |