static bool ValidateAllocateMemoryParameters(D3D12MA_ALLOCATION_DESC *pAllocDesc, D3D12_RESOURCE_ALLOCATION_INFO *pAllocInfo, D3D12MA_Allocation **ppAllocation)
 {
     return((pAllocDesc != null) &&
            (pAllocInfo != null) &&
            (ppAllocation != null) &&
            ((pAllocInfo->Alignment == 0) || (pAllocInfo->Alignment == D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT) || (pAllocInfo->Alignment == D3D12_DEFAULT_MSAA_RESOURCE_PLACEMENT_ALIGNMENT)) &&
            (pAllocInfo->SizeInBytes != 0) &&
            ((pAllocInfo->SizeInBytes % (64UL * 1024)) == 0));
 }
        public int CreateResource([NativeTypeName("const ALLOCATION_DESC*")] D3D12MA_ALLOCATION_DESC *pAllocDesc, [NativeTypeName("const D3D12_RESOURCE_DESC*")] D3D12_RESOURCE_DESC *pResourceDesc, D3D12_RESOURCE_STATES InitialResourceState, [NativeTypeName("const D3D12_CLEAR_VALUE*")] D3D12_CLEAR_VALUE *pOptimizedClearValue, D3D12MA_Allocation **ppAllocation, [NativeTypeName("REFIID")] Guid *riidResource, void **ppvResource)
        {
            if ((pAllocDesc == null) || (pResourceDesc == null) || (ppAllocation == null))
            {
                D3D12MA_ASSERT(false); // "Invalid arguments passed to Allocator::CreateResource."
                return(E_INVALIDARG);
            }

            using var debugGlobalMutexLock = D3D12MA_DEBUG_GLOBAL_MUTEX_LOCK();

            return(m_Pimpl->CreateResource(pAllocDesc, pResourceDesc, InitialResourceState, pOptimizedClearValue, ppAllocation, riidResource, ppvResource));
        }
        public int AllocateMemory1([NativeTypeName("const ALLOCATION_DESC*")] D3D12MA_ALLOCATION_DESC *pAllocDesc, [NativeTypeName("const D3D12_RESOURCE_ALLOCATION_INFO*")] D3D12_RESOURCE_ALLOCATION_INFO *pAllocInfo, ID3D12ProtectedResourceSession *pProtectedSession, D3D12MA_Allocation **ppAllocation)
        {
            if (!ValidateAllocateMemoryParameters(pAllocDesc, pAllocInfo, ppAllocation))
            {
                D3D12MA_ASSERT(false); // "Invalid arguments passed to Allocator::AllocateMemory1."
                return(E_INVALIDARG);
            }

            using var debugGlobalMutexLock = D3D12MA_DEBUG_GLOBAL_MUTEX_LOCK();

            return(m_Pimpl->AllocateMemory1(pAllocDesc, pAllocInfo, pProtectedSession, ppAllocation));
        }
Exemplo n.º 4
0
        public int CreateResource2([NativeTypeName("UINT64")] ulong size, [NativeTypeName("UINT64")] ulong alignment, [NativeTypeName("const D3D12MA_ALLOCATION_DESC&")] D3D12MA_ALLOCATION_DESC *allocDesc, [NativeTypeName("const D3D12_RESOURCE_DESC1&")] D3D12_RESOURCE_DESC1 *resourceDesc, D3D12_RESOURCE_STATES InitialResourceState, [NativeTypeName("const D3D12_CLEAR_VALUE&")] D3D12_CLEAR_VALUE *pOptimizedClearValue, ID3D12ProtectedResourceSession *pProtectedSession, D3D12MA_Allocation **ppAllocation, [NativeTypeName("REFIID")] Guid *riidResource, void **ppvResource)
        {
            D3D12MA_ASSERT((D3D12MA_DEBUG_LEVEL > 0) && (pProtectedSession == null)); // "Should never get here. pProtectedSession != NULL currently requires committed resources."

            ID3D12Device8 *device8 = m_hAllocator->GetDevice8();

            if (device8 == null)
            {
                return(E_NOINTERFACE);
            }

            HRESULT hr = Allocate(size, alignment, allocDesc, 1, ppAllocation);

            if (SUCCEEDED(hr))
            {
                ID3D12Resource *res = null;
                hr = device8->CreatePlacedResource1(
                    (*ppAllocation)->m_Placed.block->GetHeap(),
                    (*ppAllocation)->GetOffset(),
                    resourceDesc,
                    InitialResourceState,
                    pOptimizedClearValue,
                    __uuidof <ID3D12Resource>(), (void **)&res
                    );

                if (SUCCEEDED(hr))
                {
                    if (ppvResource != null)
                    {
                        hr = res->QueryInterface(riidResource, ppvResource);
                    }

                    if (SUCCEEDED(hr))
                    {
                        (*ppAllocation)->SetResource(res, resourceDesc);
                    }
                    else
                    {
                        res->Release();
                        SAFE_RELEASE(ref *ppAllocation);
                    }
                }
                else
                {
                    SAFE_RELEASE(ref *ppAllocation);
                }
            }

            return(hr);
        }
Exemplo n.º 5
0
        public int CreateResource([NativeTypeName("UINT64")] ulong size, [NativeTypeName("UINT64")] ulong alignment, [NativeTypeName("const D3D12MA_ALLOCATION_DESC&")] D3D12MA_ALLOCATION_DESC *allocDesc, [NativeTypeName("const D3D12_RESOURCE_DESC&")] D3D12_RESOURCE_DESC *resourceDesc, D3D12_RESOURCE_STATES InitialResourceState, [NativeTypeName("const D3D12_CLEAR_VALUE&")] D3D12_CLEAR_VALUE *pOptimizedClearValue, D3D12MA_Allocation **ppAllocation, [NativeTypeName("REFIID")] Guid *riidResource, void **ppvResource)
        {
            HRESULT hr = Allocate(size, alignment, allocDesc, 1, ppAllocation);

            if (SUCCEEDED(hr))
            {
                ID3D12Resource *res = null;
                hr = m_hAllocator->GetDevice()->CreatePlacedResource(
                    (*ppAllocation)->m_Placed.block->GetHeap(),
                    (*ppAllocation)->GetOffset(),
                    resourceDesc,
                    InitialResourceState,
                    pOptimizedClearValue,
                    __uuidof <ID3D12Resource>(), (void **)&res
                    );

                if (SUCCEEDED(hr))
                {
                    if (ppvResource != null)
                    {
                        hr = res->QueryInterface(riidResource, ppvResource);
                    }

                    if (SUCCEEDED(hr))
                    {
                        (*ppAllocation)->SetResource(res, resourceDesc);
                    }
                    else
                    {
                        res->Release();
                        SAFE_RELEASE(ref *ppAllocation);
                    }
                }
                else
                {
                    SAFE_RELEASE(ref *ppAllocation);
                }
            }

            return(hr);
        }
Exemplo n.º 6
0
        public int Allocate([NativeTypeName("UINT64")] ulong size, [NativeTypeName("UINT64")] ulong alignment, [NativeTypeName("const D3D12MA_ALLOCATION_DESC&")] D3D12MA_ALLOCATION_DESC *allocDesc, [NativeTypeName("size_t")] nuint allocationCount, D3D12MA_Allocation **pAllocations)
        {
            nuint allocIndex;

            HRESULT hr = S_OK;

            using (var @lock = new D3D12MA_MutexLockWrite(ref m_Mutex, m_hAllocator->UseMutex()))
            {
                for (allocIndex = 0; allocIndex < allocationCount; ++allocIndex)
                {
                    hr = AllocatePage(size, alignment, allocDesc, pAllocations + allocIndex);

                    if (FAILED(hr))
                    {
                        break;
                    }
                }
            }

            if (FAILED(hr))
            {
                // Free all already created allocations.
                while (unchecked (allocIndex-- != 0))
                {
                    Free(pAllocations[allocIndex]);
                }

                ZeroMemory(pAllocations, (nuint)sizeof(D3D12MA_Allocation *) * allocationCount);
            }

            return(hr);
        }