Adding more then two cubes DirectX12

0

What am I understanding currently:

  1. Create device: access the video adapter(got that)
  2. Create swap chain: create render surface and back buffers that will swap(got that)
  3. Command queue, command list, fence etc: as far as I understand, it a list of actions video card will do each iteration(didn’t get yet)
  4. Pipeline state object(got that):

    4.4. Root signature: parameters we will pass to shaders functions

    4.5. Compile existing shaders: seems to be clear

    4.6. Input layout: explain video card what my vertex structure is

    4.7. Set PSO using the device method(too long to write)(set to command list, maybe)

  5. Vertices and indexes list: create array of structures(respectively to that we sent to PSO) and store them, and there I confused: I need to store it in GPU memory - default heap, but only GPU has access to that memory. So I create a default heap(how if I dont have access?) then create an upload heap, store the resource(vertices) there, and add a command to command list to copy from upload heap to default heap. That’s how I understand it.

  6. Create depth/stencil buffer: stuff seems to be not really important, plus I am too lazy even to translate “stencil” from English(so, just copied code from example)

  7. Creating the objects. Here I am facing an issue. Code:

``

for (int i = 0;i<frameBufferCount;  i++) 
   { 

  hr = device->CreateCommittedResource(             &CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD),      
  // this heap will be used to upload the constant buffer data 
        D3D12_HEAP_FLAG_NONE,           // no flags 

          &CD3DX12_RESOURCE_DESC::Buffer(1024 * 64), // 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(&constantBufferUploadHeaps[i])); 

          constantBufferUploadHeaps[i]->SetName(L"Constant Buffer Upload Resource Heap"); 

    ZeroMemory(&cbPerObject, sizeof(cbPerObject)); 

    CD3DX12_RANGE readRange(0, 0);    // We do not intend to read from this resource on the CPU. (so end is less than or equal to begin)                                    // map the resource heap to get a gpu virtual address to the beginning of the heap 


    hr = constantBufferUploadHeaps[i]->Map(0, &readRange, reinterpret_cast<void**>(&cbvGPUAddress[i])); 

    // Because of the constant read alignment requirements, constant buffer views must be 256 bit aligned. Our buffers are smaller than 256 bits, 

    // so we need to add spacing between the two buffers, so that the second buffer starts at 256 bits from the beginning of the resource heap. 

    for (int ii = 0; ii < 1000;ii++) 
    memcpy(cbvGPUAddress[i] + ConstantBufferPerObjectAlignedSize*ii, &cbPerObject, sizeof(cbPerObject)); 
} 

// Now we execute the command list to upload the initial assets (triangle data) 
commandList->Close(); 
ID3D12CommandList* ppCommandLists[] = { commandList }; 
commandQueue->ExecuteCommandLists(_countof(ppCommandLists), ppCommandLists);

When I make ii less then 100 for example all works fine, but with 1000 program throws exception at memcpy call:

0xC0000005: access violation while trying to write address 0x1B31A008 

In Update() I also has the same loop, and in UpdatePipeline() I has the loop with DrawIndexedInstanced calls.


Please, figure me, if me understanding of things wrong, and explain why I am getting exception?


Learn from here

c++
directx
directx-12
asked on Stack Overflow Mar 28, 2020 by Artur • edited Mar 28, 2020 by Artur

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0