Sign in to follow this  
EmperorXYZ

[VC++] DirectX10 Question on effect files

Recommended Posts

EmperorXYZ    100
Hi, first of all, I'm following Frank Luna's book for DirectX10 and it is mostly pretty clear. I'm at chapter 5 where the whole rendering process is explained. Individually, I think I understand them all. The vertex buffer is initialized and bound to an input slot to the pipeline at the Input Assembler Stage. The vertices in the vertex buffer is feed into the first shader which is the vertex shader and go through all sort of transformations. How I understood it is that most commands are there to set up the stage and prepare for the transformations to be applied. What I mean is for example, commands such as the one that set the rasterization state, set a constant buffer variable, bind a vertex buffer to an input slot, etc... all those commands are just preparing for the transformation.

My first question is, what is the command that actually runs the code inside the effect file? I used to think it was

pass->Apply(0);

where pass is an ID3D10EffectPass* interface, but after looking at the code, the buffer index is bound to the input slot after that command, so it can't be. Is it the command

md3dDevice->DrawIndexed(mNumFaces*3, 0, 0);

where md3dDevice is an ID3D10Device* interface. I just need to know when is the code in the effect file is situated chronologically if I only look at the code in VC++.

Second question, while where the input to the vertex shader comes from is unambiguous, where does the output of the effect file go? I mean for the input, you explicitly use

md3dDevice->IASetIndexBuffer(mIB, DXGI_FORMAT_R32_UINT, 0);

which makes the effect file know that I want to use vertex buffer mIB as the input for the effect file and not some other vertex buffer instead. My question is, once all the transformations have been done on those vertices, where does the result go? From the look of it, the result goes back to the same vertex buffer, but there doesn't seem like there is an explicit command that sets the location where the output is saved.

Share this post


Link to post
Share on other sites
MJP    19786
ID3D10EffectPass::Apply just sets pipeline state. So it will bind shaders used in the technique/pass, as well as constant buffers, rasterizer/sampler/depth-stencil states, and shader resources.

When you say "runs the code", I assume you mean the shader code? Shader code is executed when you draw primitives. So when you draw some triangles the vertex shader will run for all vertices in the triangles, and the pixel shader will run for all pixels drawn from those triangles (the geometry shader will also be run for all triangles, if you're using one).

Typically the only "output" from a Draw call is the pixels that are written to by the pixel shader. When vertices are transformed by the vertex shader they don't get put into a buffer, they just go right into the next stage of the pipeline. The only exception is when you use a geometry shader with stream out, in which case the geometry shader outputs vertices to a vertex buffer. But this is a special case thing, and doesn't happen for most normal drawing operations.

Share this post


Link to post
Share on other sites
EmperorXYZ    100
Okay, I think I understand now. Basically, the draw command says I want to draw using that vertex buffer, but after the vertices have been transformed by the shader code. I kept thinking before that we had to "run" the code in the shaders on the input, store the output somewhere and then call draw to use the output. Thanks

Share this post


Link to post
Share on other sites
yckx    1298
[quote name='EmperorXYZ' timestamp='1313561788' post='4850164']
Okay, I think I understand now. Basically, the draw command says I want to draw using that vertex buffer, but after the vertices have been transformed by the shader code.
[/quote]
eh, not quite. The draw doesn't happen after the vertices are transformed by the shader code. Rather, the vertex shader (which is generally where vertex transforms take place) is the first phase of the draw.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this