Using input layout in DirectX

Started by
1 comment, last by Deft 11 years, 7 months ago
Hello all again!

I'm interested in working with DirectX, but during researching this wonderful library I've got so much questions. At now first of questions is working with input layout and switching between different layouts for rendering difference game objects.
I can explain my question with example (very-very abstract example):

  1. Let assume that I want to render player object at first pass. During player rendering I use shadows and lightning, and may be another graphics improvements;
  2. Then I want to render road with using of tessellation;
  3. After that I want to spawn game world NPCs.

So, at first pass I use something like:
[source lang="cpp"]// Compiling shaders
context->IASetInputLayout(...); // Setting input layout with using custom vertex shader
// Rendering an object[/source]
Then I go to render road. And stop... Road isn't like a player. Let assume that I want to render it fast, without shadows and with tessellation. For doing such thing, I need to switch input layout - load and compile hull/domain shaders, change vertex shader and reset my input layout to new state for using new shader group.
After doing that I need return to shader from first pass to render NPCs. So, I call context->IASetInputLayout again... And so on, and so on.

Is it normal to switch between different input layouts during object rendering? Or may be I need to improve rendering sequence? Or I doing something wrong and input layout does not need to be switched during such rendering actions?

Hope for any answer smile.png With regards.
// Sorry for my English.
Advertisement
Everytime you switch there's some data validation going on, so it's best to do less switching to save CPU power.
I assume your player and other NPCs most likely use same shader (it's just skinning afterall), so render them all. Then change shader and render all roads, etc.

However, you shouldn't create input layout or shaders during rendering, it should be part of resource loading. Shader compilation takes a lot time, so better create them all when application starts, outside of mainloop.
Thank you a lot. Now I understand what to do smile.png

This topic is closed to new replies.

Advertisement