Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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!

share|improve this question

1 Answer 1

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. –  Darth Satan Feb 2 '13 at 1:36

Your Answer

 
discard

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.