ShaderReflection; stripping information from an Effect
#21 Members - Reputation: 2045
Posted 11 October 2012 - 12:01 PM
This also means that you can have 'shared' constant buffers or shared helper functions.
You could also just define your constant buffers in an include file and include them in all of the shader files which need them, the compiler will do the rest.
#22 Members - Reputation: 551
Posted 11 October 2012 - 12:10 PM
You don't have to create a separate file for each shader if you want to reuse data, the D3D compiler requires entry points for each shader which are the 'shader functions' you talked about. This means you can have multiple shaders in a file and the compiler will compile the correct one based on the entry point you passed it.
This also means that you can have 'shared' constant buffers or shared helper functions.
You could also just define your constant buffers in an include file and include them in all of the shader files which need them, the compiler will do the rest.
Bingo... that's the type of answer I was hoping for. Wow, that will make things FAR easier... If I do it that way, what file format/extension do I have to use? Can I continue using .fx format, or do I have to use ____ ?
CEO & Lead Developer at ATCWARE™
"Project X-1"; a 100% managed, platform-agnostic game & simulation engine
Please visit our new forums and help us test them and break the ice!
___________________________________________________________________________________
#24 Members - Reputation: 551
Posted 11 October 2012 - 01:25 PM
The file extension doesn't play any role, so use whatever you want
Sweet... I thought it did for some reason, but perhaps I'm just thinking of FX Composer... That's another thing... I'm wondering how difficult its going to be to use FXC now that I'm not using the standard "Effects" way of doing things... But oh well, that's the least of my concerns right now. Right now I'm writing a mini-game from scratch to get used to shaders without the Effects Framework... I'll pop up here again if I have any trouble...
CEO & Lead Developer at ATCWARE™
"Project X-1"; a 100% managed, platform-agnostic game & simulation engine
Please visit our new forums and help us test them and break the ice!
___________________________________________________________________________________
#25 Members - Reputation: 554
Posted 11 October 2012 - 02:51 PM
Each specific shader will have some information on how that resource is bound to the pipeline though (e.g. the bindpoint - its index in XXXSetConstantBuffers()). That would be found in the InputBindingDescription that you'd query from your shader reflection object.
Edited by Starnick, 11 October 2012 - 02:54 PM.
Starnick
Tesla Graphics Engine | AssimpNet | DevILNet |
#26 Members - Reputation: 551
Posted 11 October 2012 - 04:32 PM
CEO & Lead Developer at ATCWARE™
"Project X-1"; a 100% managed, platform-agnostic game & simulation engine
Please visit our new forums and help us test them and break the ice!
___________________________________________________________________________________
#27 Members - Reputation: 551
Posted 12 October 2012 - 11:35 AM
// HLSL file:
var var1;
var var2;
var var2;
PS_INPUT someVertexShader( VS_INPUT input );
float4 somePixelShader( PS_INPUT input);
...and I compile each shader:
[source lang="csharp"]var psByteCode = ShaderByteCode.Compile( ... );var vsByteCode = ShaderByteCode.Compile( ... );[/source]
...does setting the constant buffer(s) of one shader instance effect the other? Or does the two only share a duplicate of the same constant buffers, and the values must be written to both individually?
CEO & Lead Developer at ATCWARE™
"Project X-1"; a 100% managed, platform-agnostic game & simulation engine
Please visit our new forums and help us test them and break the ice!
___________________________________________________________________________________
#29 Moderators - Reputation: 5419
Posted 12 October 2012 - 05:15 PM
cbuffer Constants : register(b0)
{
float4x4 World;
float4x4 ViewProjection;
}
When you compile a shader with this code, there's no allocation of resources for that constant buffer or anything like that. All that code says is "when this shader runs, I expect that constant buffer with 128 bytes (32 floats * 4 bytes) should be bound to slot 0 of the appropriate shader stage". It's then your application code's responsibility to actually create a constant buffer using the Buffer class with the appropriate size and binding flags, fill that that buffer with the data needed by the shader, and then bind that buffer to the appropriate slot using DeviceContext.<ShaderType>.SetConstantBuffer. If you do that correctly, your shader will pull the data from your Buffer and use it.
Now let's say you have two vertex shaders that you compile, and both use the same constant buffer layout in both shaders. In this case there is no "duplication" or anything like that, since it's your responsibility to allocate and manage constant buffer resources. So if you wanted to, it's possible to share the same Buffer between draw calls using your two different shaders. You could bind the buffer, draw with shader A, and then draw with shader B, and both shaders will pull the same data from the buffer. Or if you wanted, you could set new data into the buffer after drawing with shader A, and then shader B will use the new contents of the buffer. Or if you wanted you could create two buffers of the same size, and bind one buffer for shader A and bind the other for shader B.
An interesting consequence of this setup is that you don't necessarily need the exact same constant buffer layout in two shaders in order to shader a constant buffer. For instance shader B could just have this:
cbuffer Constants : register(b0)
{
float4x4 World;
}
In that case it would be okay to still use the same constant buffer as shader A, since the size of the buffer expected by shader B is still less than or equal to the size of the constant buffer that was bound. But it's up to you to make sure that in all cases the right data gets to the right shader. In practice I wouldn't really recommend doing something like I just mentioned, since it can easily lead to bugs if you update a constant buffer layout in one shader but forget to do it in another. Instead I would recommend defining shared layouts in a header file, and then using #include to share it between different shaders.






