Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?



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?


share|improve this question
up vote 3 down vote accepted

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.

share|improve this answer
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. – Wind And Flame Feb 1 '13 at 19:10
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. – Le Comte du Merde-fou Feb 2 '13 at 1:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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