D3DKMTOpenResource function
The D3DKMTOpenResource function opens a shared resource.
Syntax
NTSTATUS D3DKMTOpenResource( _Inout_ D3DKMT_OPENRESOURCE *pData );
Parameters
- pData [in, out]
-
A pointer to a D3DKMT_OPENRESOURCE structure that contains parameters for opening a shared resource.
Return value
D3DKMTOpenResource returns one of the following values:
| Return code | Description |
|---|---|
|
The resource was successfully opened. |
|
The graphics adapter was stopped or the display device was reset. |
|
Parameters were validated and determined to be incorrect. |
This function might also return other NTSTATUS values.
Examples
The following code example demonstrates how an OpenGL ICD can use D3DKMTQueryResourceInfo and D3DKMTOpenResource to open a shared resource.
HRESULT OpenResource(HANDLE hDevice, D3DKMT_HANDLE hGlobalShare, D3DKMT_OPENRESOURCE* pOpenResource)
{
HRESULT hr = S_OK;
NTSTATUS ntStatus;
VOID* pTotalAllocPrivateDriverData = NULL;
VOID* pOpenAllocInfoArray = NULL;
VOID* pResPrivateDriverData = NULL;
D3DKMT_OPENRESOURCE OpenResource = {0};
D3DKMT_QUERYRESOURCEINFO QueryResInfo = {0};
D3DDDIARG_OPENRESOURCE DrvOpenResource;
UINT Idx;
// Call D3DKMTQueryResourceInfo() to get information about the runtime/driver
// private data
QueryResInfo.hDevice = hDevice;
QueryResInfo.hGlobalShare = hGlobalShare;
ntStatus = pfnKTQueryResourceInfo(&QueryResInfo);
if (!NT_SUCCESS(ntStatus))
{
return NTStatusToHResult(ntStatus);
}
// Allocate memory for driver private data structs for all the allocations
// associated with the resource
pTotalAllocPrivateDriverData = MemAlloc(QueryResInfo.TotalPrivateDriverDataSize);
if (pTotalAllocPrivateDriverData == NULL)
{
return E_OUTOFMEMORY;
}
// Allocate an array of D3DDDI_OPENALLOCATIONINFO structs
pOpenAllocInfoArray = MemAlloc(sizeof(D3DDDI_OPENALLOCATIONINFO) * QueryResInfo.NumAllocations);
if (pOpenAllocInfoArray == NULL)
{
hr = E_OUTOFMEMORY;
goto OpenResourceLH_Cleanup;
}
// Allocate memory for resource PrivateDriverData if it exists
if (QueryResInfo.ResourcePrivateDriverDataSize != 0)
{
pResPrivateDriverData = MemAlloc(QueryResInfo.ResourcePrivateDriverDataSize);
if (pResPrivateDriverData == NULL)
{
hr = E_OUTOFMEMORY;
goto OpenResourceLH_Cleanup;
}
}
// Call DxgkDdiOpenAllocation() to open the resource and obtain the driver
// private data for all the allocations
OpenResource.hDevice = hDevice;
OpenResource.hGlobalShare = (D3DKMT_HANDLE)(UINT_PTR)pSurf->hSharedHandle;
OpenResource.NumAllocations = QueryResInfo.NumAllocations;
OpenResource.pOpenAllocationInfo = (D3DDDI_OPENALLOCATIONINFO*)pOpenAllocInfoArray;
OpenResource.pTotalPrivateDriverDataBuffer = pTotalAllocPrivateDriverData;
OpenResource.TotalPrivateDriverDataBufferSize = QueryResInfo.TotalPrivateDriverDataSize;
OpenResource.pResourcePrivateDriverData = pResPrivateDriverData;
OpenResource.ResourcePrivateDriverDataSize = QueryResInfo.ResourcePrivateDriverDataSize;
ntStatus = pfnKTOpenResource(&OpenResource);
if (!NT_SUCCESS(ntStatus))
{
hr = NTStatusToHResult(ntStatus);
goto OpenResourceLH_Cleanup;
}
// Return the information to the caller
*pOpenResource = OpenResource;
OpenResourceLH_Cleanup:
if (pTotalAllocPrivateDriverData != NULL)
{
MemFree(pTotalAllocPrivateDriverData);
}
if (pOpenAllocInfoArray != NULL)
{
MemFree(pOpenAllocInfoArray);
}
if (pResPrivateDriverData != NULL)
{
MemFree(pResPrivateDriverData);
}
return hr;
}
Requirements
|
Version | Available in Windows Vista and later versions of the Windows operating systems. |
|---|---|
|
Header |
|
|
Library |
|
See also
Send comments about this topic to Microsoft
Build date: 11/29/2012
