-1
\$\begingroup\$

What is the best way to buffer Vertex Shaders, Pixel Shaders, etc into the Device/Device Context without having to reload them from the filesystem every time?

ID3D11Device::CreateVertexShader http://msdn.microsoft.com/en-us/library/windows/desktop/ff476524(v=vs.85).aspx

ID3D11DeviceContext::VSSetShader http://msdn.microsoft.com/en-us/library/windows/desktop/ff476493(v=vs.85).aspx

Does Device::CreateVertexShader buffer a single instance of the shader in System, (not GPU), memory? Can I buffer more than 1?

DeviceContext::CreateVertexShader buffer a single instance of the shader in the GPU, (not System), memory? Can I buffer more than 1?

What are the recommended methods for buffering shaders within the system?

Thanks!

\$\endgroup\$
3
\$\begingroup\$

I'm not 100% certain that I fully understand the thinking behind your question, but this should cover everything:

ID3D11VertexShader *vs1;
ID3D11VertexShader *vs2;

device->CreateVertexShader (..., &vs1);
device->CreateVertexShader (..., &vs2);

We now have two vertex shaders, and this only needs to be done once, during startup.

context->VSSetshader (vs1, ...);

We're now using vertex shader 1; no need to call CreateVertexShader again, no need to load it from the filesystem again.

context->VSSetshader (vs2, ...);

And we're now using vertex shader 2; no need to call CreateVertexShader again, no need to load it from the filesystem again.

\$\endgroup\$
  • \$\begingroup\$ Are you saying that CreateVertexShader is moving the filedata of the .cso and loading it to the GPU, and keeping it there? Then VSSetShader, etc, are just making one of those active? Does Shader.Release() then remove it from the GPU? Thanks! Is this the same for buffers? When you CreateBuffer(), does this move the buffer data to the GPU? I had been thinking that "Set" is what moves it to the GPU. Thanks for the help. \$\endgroup\$ – Wind And Flame Feb 1 '13 at 19:10
  • \$\begingroup\$ That's roundabout correct, yes. The shader/buffer/whatever may be kept on the CPU and only moved to the GPU on the first "Set" call, but subsequent "Set"s will always use the on-the-GPU copy (unless the driver has a valid reason for moving it back to CPU-side); this is something that you really don't need to worry about - the driver understands the hardware better than you do and can do a better job of managing resources than you can. \$\endgroup\$ – Maximus Minimus Feb 2 '13 at 1:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.