• Announcements

GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Followers 0

8 posts in this topic

Hello,

after finally driving myself to getting started with DX11 (it isn't as hard switching from DX9 as I thought), I've already come across the shader reflection interface. This has already taken a lot of tedious work from me (figuring/hardcoding the input layout, size of cbuffers), however there is one feature I'm not sure if it is missing or I've just been overlooking it. Is it possible to figure out the b-register of a cbuffer? I'm using this code to get the cbuffer-description:

void Effect::CreateCBufferDummies(ID3D11ShaderReflection& reflection)
{

for(size_t i = 0; i < shaderDesc.ConstantBuffers; i++)
{

pConstantReflection->GetDesc(&desc);

m_cBuffer[i] = new d3d::ConstantBuffer(*m_pDevice, desc.Size);
}
}


However, the D3D11_SHADER_BUFFER_DESC doesn't seem to have any register-variable or anything similar, which means that if I have this code in my shader

cbuffer instance : register(b1)
{
matrix cWorld;
}

cbuffer stage : register(b4)
{
matrix cViewProj;
}


those c-buffers would be written to the first two "slots" in my effect class, though what I intend is to have a fixed amount of possible cbuffers (effect, material, instance, pass, stage), which should always be at the same positio, determined by the register. Is there any such possiblity with shader reflection?

Edited by Juliean
0

Share on other sites

I don't recall it off the top of my head, but I wrote up a short article on reflection a while back (2009!): http://members.gamedev.net/JasonZ/Heiroglyph/D3D11ShaderReflection.pdf

Thanks, your article was one of the first, but unfortunately few I read concerning this topic. The other one fortunately tackled just what I needed the most (automatic input layout), but there seems to be very little resources apart from that...

You need to use GetResourceBindingDesc (or GetResourceBindingDescByName) to get the information about how the cbuffer is bound to the shader. That gives you a D3D11_SHADER_INPUT_BIND_DESC, and that contains a BindPoint, which is the buffer register number.

Thanks, thats it! I was already starting to dig into the Hieroglyph 3 source code, but a direct solution is always faster

While we are at it, and as I mentioned I automated the input layout generation: Any chance to mark/read out the input channel, and/or instancing data in the shader? Say like if I was to split my meshes into different buffers for position, normal, texcoords, can I somehow read that out from the shader reflection too, or do I have to make a custom naming convention for this myself?

			void Effect::CreateInputLayout(ID3D11ShaderReflection& reflection, ID3DBlob& shaderBlob)
{

int byteOffset = 0;
std::vector<D3D11_INPUT_ELEMENT_DESC> inputLayoutDesc;
for ( size_t i=0; i< shaderDesc.InputParameters; i++ )
{
D3D11_SIGNATURE_PARAMETER_DESC paramDesc;
reflection.GetInputParameterDesc(i, &paramDesc );

// fill out input element desc
D3D11_INPUT_ELEMENT_DESC elementDesc;
elementDesc.SemanticName = paramDesc.SemanticName;
elementDesc.SemanticIndex = paramDesc.SemanticIndex;
elementDesc.InputSlot = 0; //???
elementDesc.AlignedByteOffset = byteOffset;
elementDesc.InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; //???
elementDesc.InstanceDataStepRate = 0;  //???

// determine DXGI format
if ( paramDesc.Mask == 1 )
{
if ( paramDesc.ComponentType == D3D_REGISTER_COMPONENT_UINT32 ) elementDesc.Format = DXGI_FORMAT_R32_UINT;
else if ( paramDesc.ComponentType == D3D_REGISTER_COMPONENT_SINT32 ) elementDesc.Format = DXGI_FORMAT_R32_SINT;
else if ( paramDesc.ComponentType == D3D_REGISTER_COMPONENT_FLOAT32 ) elementDesc.Format = DXGI_FORMAT_R32_FLOAT;
byteOffset += 4;
}
else if ( paramDesc.Mask <= 3 )
{
if ( paramDesc.ComponentType == D3D_REGISTER_COMPONENT_UINT32 ) elementDesc.Format = DXGI_FORMAT_R32G32_UINT;
else if ( paramDesc.ComponentType == D3D_REGISTER_COMPONENT_SINT32 ) elementDesc.Format = DXGI_FORMAT_R32G32_SINT;
else if ( paramDesc.ComponentType == D3D_REGISTER_COMPONENT_FLOAT32 ) elementDesc.Format = DXGI_FORMAT_R32G32_FLOAT;
byteOffset += 8;
}
else if ( paramDesc.Mask <= 7 )
{
if ( paramDesc.ComponentType == D3D_REGISTER_COMPONENT_UINT32 ) elementDesc.Format = DXGI_FORMAT_R32G32B32_UINT;
else if ( paramDesc.ComponentType == D3D_REGISTER_COMPONENT_SINT32 ) elementDesc.Format = DXGI_FORMAT_R32G32B32_SINT;
else if ( paramDesc.ComponentType == D3D_REGISTER_COMPONENT_FLOAT32 ) elementDesc.Format = DXGI_FORMAT_R32G32B32_FLOAT;
byteOffset += 12;
}
else if ( paramDesc.Mask <= 15 )
{
if ( paramDesc.ComponentType == D3D_REGISTER_COMPONENT_UINT32 ) elementDesc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
else if ( paramDesc.ComponentType == D3D_REGISTER_COMPONENT_SINT32 ) elementDesc.Format = DXGI_FORMAT_R32G32B32A32_SINT;
else if ( paramDesc.ComponentType == D3D_REGISTER_COMPONENT_FLOAT32 ) elementDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
byteOffset += 16;
}

//save element desc
inputLayoutDesc.push_back(elementDesc);
}

// Try to create Input Layout
m_pLayout = new d3d::InputLayout(*m_pDevice, &inputLayoutDesc[0], inputLayoutDesc.size(), shaderBlob);
}


I'll have a look again at Hieroglyph 3 again when I'm home, but if someone has another answer in the meantime, I'd be glad too

Edited by Juliean
0

Share on other sites

While we are at it, and as I mentioned I automated the input layout generation: Any chance to mark/read out the input channel, and/or instancing data in the shader? Say like if I was to split my meshes into different buffers for position, normal, texcoords, can I somehow read that out from the shader reflection too, or do I have to make a custom naming convention for this myself?
Unfortunately, no.  Since the input assembler puts together all of the vertices prior to them reaching the vertex shader, there isn't any info available there.  You can check the vertex elements and look for some of the system values, but those are really only hints since they don't tell you which other elements are part of instance data or which buffer they came from.  Basically your engine just has to ensure that you have an input assembler state (i.e. vertex buffers, index buffers, input layout, and topology) that when it is put together with a particular draw call that it will assemble the correct vertex layout that your shader is looking for.
0

Share on other sites

Unfortunately, no. Since the input assembler puts together all of the vertices prior to them reaching the vertex shader, there isn't any info available there. You can check the vertex elements and look for some of the system values, but those are really only hints since they don't tell you which other elements are part of instance data or which buffer they came from. Basically your engine just has to ensure that you have an input assembler state (i.e. vertex buffers, index buffers, input layout, and topology) that when it is put together with a particular draw call that it will assemble the correct vertex layout that your shader is looking for.

Whats the point of having to have a shader blob for creating an input layout then? I mean, thats one of the things that kinda/sorta annoyes me a bit about dx11, so I'm glad I found that code to at least take away some of the work from me. I mean, if everything "magically" has to match up anyway, why have the shader blob be mandatory for creating that input layout? So whats the normal procedure for this, do I really need to have some sort of reference shader for every type of primitive (terrain, mesh, ...) I create?

0

Share on other sites

Actually, I think it makes sense to be designed the way that it is.  If you think about the vertex shader blob as defining the input signature for the pipeline, and the input layout as defining the output layout for the input assembler, then requiring the blob to create the input layout lets you validate that they match.  You can choose whatever (valid) signature for your vertex shader that you want, and then you can use that shader with any input layout combination that ends up producing that signature.

So in effect, you can have a single vertex buffer, you can have a vertex and an instance buffer, and both can work with the same vertex shader - you just need to create a separate input layout object for each configuration (which you would have to do anyways for the input layout to work).  So it seems perfectly logical to me - do you see it differently?

As far as making this work in an engine, in Hieroglyph 3 I just keep a copy of the blob around with the vertex shader class.  Then when I go to bind the input assembler state, my geometry class keeps a map of vertex shaders (as the key) to input layouts (as the value).  If the input layout is already created, then I just use it.  Otherwise, I generate one and then store it for next time.  It seems like a PITA at first, but once you get a wrapper around the functionality then it isn't too much concern anymore.

One hint from my experiences with that system - you have to be careful when using multithreaded rendering (i.e. deferred contexts on multiple threads) in such a system, since you can end up with multiple threads writing to the map at the same time.  Either mutex them, or create the input layouts serially rather than in parallel!

1

Share on other sites

So in effect, you can have a single vertex buffer, you can have a vertex and an instance buffer, and both can work with the same vertex shader - you just need to create a separate input layout object for each configuration (which you would have to do anyways for the input layout to work). So it seems perfectly logical to me - do you see it differently?

Aside from that I can't really see how a shader would work for both normal and instanced meshes (I suppose that was just an example, or is there really a reasonable type of shader you can use both instanced and non-instanced? I don't see it very useful to store the WVP matrix in the vertex buffer for non-instanced meshes e.g...), it does make sense indeed that way, but not so much that you have to validate against the vertex shader you are targenting. I mean, you set up all the variables yourself anyway, so I see it a bit tedious that they force you to validate. I mean, maybe I don't need validation, maybe I trust myself enough to choose the right combination anyway, its surely nice to have the option, but why enforce this? Unless there is some serious gain in eigther performance or usability through simply checking whether the shaders fit on creation time, I unforunately fail to see the point (what happens if I bind the wrong layout to the wrong shader anyway? crash, error, or jus undefined behaviour)?

As far as making this work in an engine, in Hieroglyph 3 I just keep a copy of the blob around with the vertex shader class. Then when I go to bind the input assembler state, my geometry class keeps a map of vertex shaders (as the key) to input layouts (as the value). If the input layout is already created, then I just use it. Otherwise, I generate one and then store it for next time. It seems like a PITA at first, but once you get a wrapper around the functionality then it isn't too much concern anymore.

So that effectively means that you have to bind the shader before the input layout, and keep the currently active vertex shader around somewhere? Hm, I quess that could work, I just have to ensure that the BindShader-command is always set before the input layout command in my render queue... but for now, to get things running again (I want to plug the new render and gfx api into my latest game without much hassle as primary goal) I think I'll just use a small naming convention in the shader for which buffer I suppose the input value should come from ("_v1" for vertex stream 1 e.g.), with some manual parsing on effect generation using the shader reflection. Once I've got things running again, I'll track back and optimize things based on what you suggested, thanks for that!

One hint from my experiences with that system - you have to be careful when using multithreaded rendering (i.e. deferred contexts on multiple threads) in such a system, since you can end up with multiple threads writing to the map at the same time. Either mutex them, or create the input layouts serially rather than in parallel!

Thanks, I'll keep that in mind too. Multithreaded rendering was one of the things I'm keen on trying out after I've got things running, I think a system of multithreaded instance assignement to the render queues, in combination with a deferred context for actually rendering those instances in the queue could aid quite a bit of performance.

0

Share on other sites

Aside from that I can't really see how a shader would work for both normal and instanced meshes (I suppose that was just an example, or is there really a reasonable type of shader you can use both instanced and non-instanced? I don't see it very useful to store the WVP matrix in the vertex buffer for non-instanced meshes e.g...), it does make sense indeed that way, but not so much that you have to validate against the vertex shader you are targenting. I mean, you set up all the variables yourself anyway, so I see it a bit tedious that they force you to validate. I mean, maybe I don't need validation, maybe I trust myself enough to choose the right combination anyway, its surely nice to have the option, but why enforce this? Unless there is some serious gain in eigther performance or usability through simply checking whether the shaders fit on creation time, I unforunately fail to see the point (what happens if I bind the wrong layout to the wrong shader anyway? crash, error, or jus undefined behaviour)?
My example was contrived, I give you that :)  But by doing it this way, the validation is done at creation time.  The previous generation (i.e. Pre-DX10) API had to do that checking at runtime when you bound the data.  Due to the large number of ways you can configure the pipeline to match that vertex shader input signature, that was lots of work to do - for every new pipeline configuration!  In addition, the implementations were also not very strict about their validation routines.  Some drivers would allow more flexibility when they shouldn't have, causing inconsistent behavior across GPU vendors and the reference device.  I think it was a good move to make the validation part of the API itself (reduced variation across implementations) and move the validation to a one time at creation (for performance).  Once the input layout is created, I'm sure they have some simple way to validate that it works with a given vertex shader at runtime.

I'm not sure, but I think if you mismatch you get an error in the debug console and the draw call doesn't execute.

Regarding the implementation, I just have a series of 'state' objects that I use to represent my current pipeline state.  Then the object that is setting the input configuration can grab a reference to the vertex shader and check its input layouts.  It works pretty good, and I haven't found any situations where I really wanted something else (yet!).

0

Create an account

Register a new account

Followers 0

• Similar Content

• Hi Guys,
I am revisiting an old DX11 framework I was creating a while back and am scratching my head with a small issue.
I am trying to set the pixel shader resources and am getting the following error on every loop.
As you can see in the below code, I am clearing out the shader resources as per the documentation. (Even going overboard and doing it both sides of the main PSSet call). But I just can't get rid of the error. Which results in the render target not being drawn.
ID3D11ShaderResourceView* srv = { 0 }; d3dContext->PSSetShaderResources(0, 1, &srv); for (std::vector<RenderTarget>::iterator it = rtVector.begin(); it != rtVector.end(); ++it) { if (it->szName == name) { //std::cout << it->srv <<"\r\n"; d3dContext->PSSetShaderResources(0, 1, &it->srv); break; } } d3dContext->PSSetShaderResources(0, 1, &srv);
I am storing the RT's in a vector and setting them by name. I have tested the it->srv and am retrieving a valid pointer.
At this stage I am out of ideas.
Any help would be greatly appreciated

• hi, guys, how to understand the math used in CDXUTDirectionWidget ::UpdateLightDir
the  following code snippet is taken from MS DXTU source code

D3DXMATRIX mInvView;
D3DXMatrixInverse( &mInvView, NULL, &m_mView );
mInvView._41 = mInvView._42 = mInvView._43 = 0;
D3DXMATRIX mLastRotInv;
D3DXMatrixInverse( &mLastRotInv, NULL, &m_mRotSnapshot );
D3DXMATRIX mRot = *m_ArcBall.GetRotationMatrix();
m_mRotSnapshot = mRot;
// Accumulate the delta of the arcball's rotation in view space.
// Note that per-frame delta rotations could be problematic over long periods of time.
m_mRot *= m_mView * mLastRotInv * mRot * mInvView;
// Since we're accumulating delta rotations, we need to orthonormalize
// the matrix to prevent eventual matrix skew
D3DXVECTOR3* pXBasis = ( D3DXVECTOR3* )&m_mRot._11;
D3DXVECTOR3* pYBasis = ( D3DXVECTOR3* )&m_mRot._21;
D3DXVECTOR3* pZBasis = ( D3DXVECTOR3* )&m_mRot._31;
D3DXVec3Normalize( pXBasis, pXBasis );
D3DXVec3Cross( pYBasis, pZBasis, pXBasis );
D3DXVec3Normalize( pYBasis, pYBasis );
D3DXVec3Cross( pZBasis, pXBasis, pYBasis );

https://github.com/Microsoft/DXUT/blob/master/Optional/DXUTcamera.cpp
• By YixunLiu
Hi,
I have a surface mesh and I want to use a cone to cut a hole on the surface mesh.
Anybody know a fast method to calculate the intersected boundary of these two geometries?

Thanks.

YL

• By hiya83
Hi, I tried searching for this but either I failed or couldn't find anything. I know there's D11/D12 interop and there are extensions for GL/D11 (though not very efficient). I was wondering if there's any Vulkan/D11 or Vulkan/D12 interop?
Thanks!

• Hi Guys,
I am just wondering if it is possible to acquire the address of the backbuffer if an API (based on DX11) only exposes the 'device' and 'context' pointers?
Any advice would be greatly appreciated

• 19
• 14
• 23
• 11
• 28