Provides APU physical memory allocation.
HRESULT ApuAlloc(
void **virtualAddress,
APU_ADDRESS *physicalAddress,
UINT32 sizeInBytes,
UINT32 alignmentInBytes,
UINT32 flags
)
virtualAddress
Type: void **
[out] The virtual address.
physicalAddress
Type: APU_ADDRESS *
[out, optional] The physical address.
sizeInBytes
Type: UINT32
[in] Size of allocation in bytes. All allocation requests must be aligned to a power of two, with a minimum alignment of four bytes.
alignmentInBytes
Type: UINT32
[in] Alignment in bytes. This must be a power of 2, greater than or equal to 4. Accepts the flag SHAPE_XMA_INPUT_BUFFER_ALIGNMENT (2048).
flags
Type: UINT32
[in, optional] Allocation flags; one of APU_ALLOC_CACHED or APU_ALLOC_NONCACHED. The default is APU_ALLOC_CACHED. This allows a title to request memory from either the cached, or non-cached ACP heaps.
Type: HRESULT
Returns one of the values shown in the following table.
| Return code | Description |
|---|---|
| S_OK | Success. |
| E_INVALIDARG | The parameter virtualAddress is null, size is zero, alignment is 0, or (alignment & 0x3) != 0, (alignment & (alignment-1)) != 0. |
| E_OUTOFMEMORY | There has been a memory allocation failure. |
The virtual and physical addresses returned represent different views of the same address space. Freeing one invalidates the other.
The maximum physical memory available using this method matches the heap size declared using ApuCreateHeap . If no heap has been created, a 64 MB one is created by default the first time this, or another heap allocation method, is called.
For Xbox One, all DMA input and output buffers used with flowgraphs, and all XMA content submitted to a source buffer, must be allocated using the ApuAlloc method, and freed using the ApuFree method, as shown in the following code. Note the use of the SHAPE_XMA_INPUT_BUFFER_ALIGNMENT flag to ensure correct block alignment.
HRESULT ApuVirtualAllocate(void** virtualAddress,UINT32 sizeInBytes)
{
DWORD dwsize = sizeInBytes;
DWORD change = 0;
if(FixBlockAlign((DWORD*)&sizeInBytes,SHAPE_XMA_INPUT_BUFFER_SIZE_ALIGNMENT,&change)) // returns TRUE if alignemt was needed else FALSE
{
return E_INVALIDARG;
}
return ApuAlloc(virtualAddress,NULL,sizeInBytes,SHAPE_XMA_INPUT_BUFFER_ALIGNMENT);
}
void ApuVirtualFree(void* virtualAddress)
{
if(virtualAddress)
{
ApuFree(virtualAddress);
}
}
BOOL FixBlockAlign(DWORD* pBYTES,DWORD BLOCKALIGN,DWORD* pChange)
{
if(pBYTES && (BLOCKALIGN > 1))
{
DWORD bytes = (*pBYTES);
(*pBYTES) /= BLOCKALIGN;
(*pBYTES) *= BLOCKALIGN;
if(pChange)
{
(*pChange) = bytes - (*pBYTES);
if((*pChange) > 0)
{
return TRUE;
}
}
}
return FALSE;
}
Header: Declared in apu.h.
Library: Use acphal.lib.