0
votes

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!

1
Where did you get the idea that you could only create one vertex shader at a time?Nicol Bolas

1 Answers

2
votes

When you use ID3D11Device::CreateVertexShader, you retrieve a reference to them, will represents your vertex shader in gpu, so if you have 3 vertex shaders you do:

ID3D11VertexShader* vsref1;
ID3D11VertexShader* vsref2;
ID3D11VertexShader* vsref3;

CreateVertexShader(bytecode1,sizeofbytecode1,NULL,&vsref1);
CreateVertexShader(bytecode2,sizeofbytecode2,NULL,&vsref2);
CreateVertexShader(bytecode3,sizeofbytecode3,NULL,&vsref3);

Make sure you keep track of vsref1,2 and 3 (like as class members). Once created they are uploaded to your gpu, no need to do it again, VSSetShader is then called to select which one you want to use.

Then you can assign your vertex shader to the pipeline anytime using:

VSSetShader(vsref1,NULL,0);

or

VSSetShader(vsref2,NULL,0); 

That doesn't cause an upload, it's just to tell your gpu which Vertex Shader you want to use for the next Draw call.