Hi !
I am trying to create a constant buffer for my shader and the variable “constantBufferUploadHeap”
is nullptr after the "CreateCommittedResource" instruction
with an error for “invalid parameter(s)”. I don't know if it comes from the alignment of data and if I have to add padding or not.
Here is my code :
struct VS_CONSTANT_BUFFER_G_BUFFER
{
XMFLOAT4X4A viewWorld;
XMFLOAT4X4A projViewWorld;
bool normalMappingEnabled;
bool padding[127];//in order to align data to 256 bytes
};
D3D12_HEAP_PROPERTIES heapProperties;
heapProperties.Type = D3D12_HEAP_TYPE_UPLOAD;
heapProperties.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
heapProperties.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
heapProperties.CreationNodeMask = 1;
heapProperties.VisibleNodeMask = 1;
D3D12_RESOURCE_DESC resourceDesc;
resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
resourceDesc.Alignment = D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT;// D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT;// ;
resourceDesc.Width = sizeof(VS_CONSTANT_BUFFER_G_BUFFER);
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;
HRESULT hr = deviceDX12->CreateCommittedResource(
&heapProperties, // this heap will be used to upload the constant buffer data
D3D12_HEAP_FLAG_NONE, // no flags
&resourceDesc, // size of the resource heap. Must be a multiple of 64KB for single-textures and constant buffers
D3D12_RESOURCE_STATE_GENERIC_READ, // will be data that is read from so we keep it in the generic read state
nullptr, // we do not have use an optimized clear value for constant buffers
IID_PPV_ARGS(&constantBufferUploadHeap));
HRESULT hr2 = deviceDX12->GetDeviceRemovedReason();
if (FAILED(hr))
cout << "CreateCommittedResource failed " << endl;
constantBufferUploadHeap->SetName(L"Constant Buffer Upload Resource Heap");
D3D12_CONSTANT_BUFFER_VIEW_DESC constantBufferGBufferMatrices;
constantBufferGBufferMatrices.BufferLocation = constantBufferUploadHeap->GetGPUVirtualAddress();
constantBufferGBufferMatrices.SizeInBytes = sizeof(VS_CONSTANT_BUFFER_G_BUFFER);
deviceDX12->CreateConstantBufferView(&constantBufferGBufferMatrices, mainDescriptorHeap->GetCPUDescriptorHandleForHeapStart());