I'm trying to learn graphics programming and DirectX11.
I'm trying to learn how to minimize CPU-GPU transfer and graphics programming in general.
I have a question that I have been unable to answer myself from online resources:
Which of the D3D methods actually sends the data to the GPU(and, equivalently, for a static mesh does ALL the vertex data get passed to the GPU every frame, or only once)?
Code follows:
(simplified for stackexchange)
In my "mesh" class, I have a vertex buffer:
ID3D11Buffer *m_pVBuffer;
In my mesh's constructor, I set some vertices to the vertex buffer:
D3D11_MAPPED_SUBRESOURCE ms;
devcon->Map(m_pVBuffer, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &ms);
memcpy(ms.pData, &vertices[0], sizeof(VERTEX) * vertices.size());
devcon->Unmap(m_pVBuffer, NULL);
Then in my mesh's "render" method, I do this:
UINT stride = sizeof(VERTEX);
UINT offset = 0;
devcon->IASetVertexBuffers(0, 1, &m_pVBuffer, &stride, &offset);
devcon->IASetIndexBuffer(m_pIBuffer, DXGI_FORMAT_R32_UINT, 0);
devcon->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
devcon->DrawIndexed(m_num_indices, 0, 0);
To repeat: Is the data uploaded to the GPU when I Map, memcpy and Unmap the vertex buffer, or is it uploaded every frame, when I call IASetVertexBuffers?