DXGI_ERROR_ACCESS_DENIED when trying to draw a triangle with DirectX 12
So, I'm currently working on drawing a triangle with DirectX 12 and making some helper functions for myself, but CreateCommitedResource keeps failing with DXGI_ERROR_DEVICE_REMOVED and the removal reason being DXGI_ERROR_ACCESS_DENIED. I've been debugging for 3 hours at this point, and I'm at a stalemate. Anyone have any ideas?
Function:
bool Window::draw(System::Shape shape, System::Color color, System::Vector2 vector)
{
if (shape.shape == System::Shape::type::triangle) {
Vertex triangleVertices[] =
{
{ { 0.0f, 0.25f * 1049088, 0.0f }, { 1.0f, 0.0f, 0.0f, 1.0f } },
{ { 0.25f, -0.25f * 1049088, 0.0f }, { 0.0f, 1.0f, 0.0f, 1.0f } },
{ { -0.25f, -0.25f * 1049088, 0.0f }, { 0.0f, 0.0f, 1.0f, 1.0f } }
};
const UINT vertexBufferSize = sizeof(triangleVertices);
ID3D12Resource* vertexBuffer = nullptr;
D3D12_HEAP_PROPERTIES heapProperties = {};
heapProperties.Type = D3D12_HEAP_TYPE_UPLOAD;
heapProperties.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
heapProperties.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
heapProperties.VisibleNodeMask = 1;
D3D12_RESOURCE_DESC resourceDesc = {};
resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
resourceDesc.Alignment = 0;
resourceDesc.Width = vertexBufferSize;
resourceDesc.Height = 1;
resourceDesc.DepthOrArraySize = 1;
resourceDesc.MipLevels = 1;
resourceDesc.Format = DXGI_FORMAT_UNKNOWN;
resourceDesc.SampleDesc.Count = 1;
resourceDesc.SampleDesc.Quality = 0;
resourceDesc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
resourceDesc.Flags = D3D12_RESOURCE_FLAG_NONE;
pImpl->device->CreateCommittedResource(
&heapProperties,
D3D12_HEAP_FLAG_NONE,
&resourceDesc,
D3D12_RESOURCE_STATE_GENERIC_READ,
nullptr,
IID_PPV_ARGS(&vertexBuffer)
);
UINT8* pVertexDataBegin;
D3D12_RANGE readRange;
readRange.Begin = 0;
readRange.End = vertexBufferSize;
vertexBuffer->Map(0, &readRange, reinterpret_cast<void**>(&pVertexDataBegin));
memcpy(pVertexDataBegin, triangleVertices, sizeof(triangleVertices));
vertexBuffer->Unmap(0, nullptr);
D3D12_VERTEX_BUFFER_VIEW vertexBufferView;
vertexBufferView.BufferLocation = vertexBuffer->GetGPUVirtualAddress();
vertexBufferView.StrideInBytes = sizeof(Vertex);
vertexBufferView.SizeInBytes = vertexBufferSize;
pImpl->commandList->Reset(pImpl->commandAllocator, nullptr);
D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle = pImpl->rtvHeap->GetCPUDescriptorHandleForHeapStart();
pImpl->commandList->OMSetRenderTargets(1, &rtvHandle, FALSE, nullptr);
pImpl->commandList->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
pImpl->commandList->IASetVertexBuffers(0, 1, &vertexBufferView);
pImpl->commandList->DrawInstanced(3, 1, 0, 0);
pImpl->commandList->Close();
ID3D12CommandList* ppCommandLists[] = { pImpl->commandList };
pImpl->commandQueue->ExecuteCommandLists(_countof(ppCommandLists), ppCommandLists);
pImpl->swapChain->Present(1, 0);
const UINT64 fence = pImpl->fenceValue;
pImpl->commandQueue->Signal(pImpl->fence, fence);
pImpl->fenceValue++;
if (pImpl->fence->GetCompletedValue() < fence) {
pImpl->fence->SetEventOnCompletion(fence, pImpl->fenceEvent);
WaitForSingleObject(pImpl->fenceEvent, INFINITE);
}
pImpl->frameIndex = pImpl->swapChain->GetCurrentBackBufferIndex();
return true;
}
return false;
}
I have a RTX 3090 and I'm running this on a Windows 11 PC.