Dx12 Vertex Buffer incorrect I'm playing around with directX 12 and I'm having some problems loading geometry in. I have a std::vector vertices definition and I do exactly what the dx12 template does with it.

  const UINT vertexBufferSize = sizeof(vertices);

  // Create the vertex buffer resource in the GPU's default heap and copy vertex data into it using the upload heap.
  // The upload resource must not be released until after the GPU has finished using it.
  Microsoft::WRL::ComPtr&lt;ID3D12Resource&gt; vertexBufferUpload;

  CD3DX12_HEAP_PROPERTIES defaultHeapProperties(D3D12_HEAP_TYPE_DEFAULT);
  CD3DX12_RESOURCE_DESC vertexBufferDesc = CD3DX12_RESOURCE_DESC::Buffer(vertexBufferSize);
  DX::ThrowIfFailed(d3dDevice-&gt;CreateCommittedResource(
     &amp;defaultHeapProperties,
     D3D12_HEAP_FLAG_NONE,
     &amp;vertexBufferDesc,
     D3D12_RESOURCE_STATE_COPY_DEST,
     nullptr,
     IID_PPV_ARGS(&amp;mVertexBuffer)));

  CD3DX12_HEAP_PROPERTIES uploadHeapProperties(D3D12_HEAP_TYPE_UPLOAD);
  DX::ThrowIfFailed(d3dDevice-&gt;CreateCommittedResource(
     &amp;uploadHeapProperties,
     D3D12_HEAP_FLAG_NONE,
     &amp;vertexBufferDesc,
     D3D12_RESOURCE_STATE_GENERIC_READ,
     nullptr,
     IID_PPV_ARGS(&amp;vertexBufferUpload)));

  mVertexBuffer-&gt;SetName(L"Vertex Buffer Resource");
  vertexBufferUpload-&gt;SetName(L"Vertex Buffer Upload Resource");

  // Upload the vertex buffer to the GPU.
  {
     D3D12_SUBRESOURCE_DATA vertexData = {};
     vertexData.pData = reinterpret_cast&lt;BYTE*&gt;(vertices.data());
     vertexData.RowPitch = vertexBufferSize;
     vertexData.SlicePitch = vertexData.RowPitch;

     UpdateSubresources(mCommandList.Get(), mVertexBuffer.Get(), vertexBufferUpload.Get(), 0, 0, 1, &amp;vertexData);

     CD3DX12_RESOURCE_BARRIER vertexBufferResourceBarrier =
        CD3DX12_RESOURCE_BARRIER::Transition(mVertexBuffer.Get(), D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER);
     mCommandList-&gt;ResourceBarrier(1, &amp;vertexBufferResourceBarrier);
  }


But this is what I get in the graphics debugger when it was suppossed to be a sphere. I can confirm that the data in vertices is correct.


If I change vertices to be what the template code had it works and renders the default cube. The only real difference mine is using a vector instead of an array.

VertexPositionColor cubeVertices[] =
{
    { XMFLOAT3(-0.5f, -0.5f, -0.5f), XMFLOAT3(0.0f, 0.0f, 0.0f) },
    { XMFLOAT3(-0.5f, -0.5f,  0.5f), XMFLOAT3(0.0f, 0.0f, 1.0f) },
    { XMFLOAT3(-0.5f,  0.5f, -0.5f), XMFLOAT3(0.0f, 1.0f, 0.0f) },
    { XMFLOAT3(-0.5f,  0.5f,  0.5f), XMFLOAT3(0.0f, 1.0f, 1.0f) },
    { XMFLOAT3(0.5f, -0.5f, -0.5f), XMFLOAT3(1.0f, 0.0f, 0.0f) },
    { XMFLOAT3(0.5f, -0.5f,  0.5f), XMFLOAT3(1.0f, 0.0f, 1.0f) },
    { XMFLOAT3(0.5f,  0.5f, -0.5f), XMFLOAT3(1.0f, 1.0f, 0.0f) },
    { XMFLOAT3(0.5f,  0.5f,  0.5f), XMFLOAT3(1.0f, 1.0f, 1.0f) },
};
Vector has a few different semantics from static arrays. For one it's a struct containing a pointer a capacity and a length (at the very least). That means that sizeof will not reflect how much data is actually stored in there (that only works on static arrays).

If you need to get the size in bytes of the data then you need

const UINT vertexBufferSize = sizeof(vertices::value_type) * vertices.size();