• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      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.
Sign in to follow this  
Followers 0
schupf

Not enough PS input registers

10 posts in this topic

Hello,

I am using DX9 and targeting Shader Model 2.

All my shader files include a common shader file, which looks like this:
[CODE]

float4x4 auWorldMat : register(c0);
float4x4 auWorldInvTransMat : register(c4);
float4x4 auViewMat : register(c8);
float4x4 auProjMat : register(c12);
float4x4 auViewProjMat : register(c16);
float3 auCameraPosition : register(c20);
float auTimeDt : register(c21);
float auTimeAbs : register(c22);

float4 auMat_EmissiveColor : register(c23);
float4 auMat_AmbientColor : register(c24);
float4 auMat_DiffuseColor : register(c25);
float4 auMat_SpecularColor : register(c26);

float3 auLight0_Position : register(c30);
float3 auLight0_Direction : register(c31);
float4 auLight0_AttenAndRange : register(c32);
float4 auLight0_AmbientColor : register(c33);
float4 auLight0_DiffuseColor : register(c34);
etc...
[/CODE]

My engine sets these values every frame per SetVertexShaderConstantF or SetPixelShaderConstantF().
Unfortunately I just run into the following problem:
I have a pixel shader, that reads auLight0_DiffuseColor, which gives the following compile error:
[quote]error X5200: (Second source param) Invalid register number: 34. Max allowed for this type is 31.
, which apparently only has 32 c# input registers.[/quote]
Apparently SM2.0 PS only support 32 c# input registers.

So what would be the best way to fix this problem?
Upgrade to SM3.0 (my game should also run on old hardware (Win XP). Is SM3.0 standard even for old machines?)

Or should I put all values that are read exclusively by the PS into the first c# registers and move Vertex Shader specific variables (like
world matrix, proj matrix etc.) into the higher registers?

Thanks!
0

Share this post


Link to post
Share on other sites
Each of these registers can hold 4 floats, so you can put some of those single float parameters into the same register. This is slightly less convenient, but is pretty much the only way of using registers more efficiently

Example:
[CODE]
float4 auTime : register(c22);

main(...)
{
auTimeDt = auTime.x;
auTimeAbs = auTime.y;
// we've got space for two more floats here...
}
[/CODE]



As for your question about SM 3.0 being standard on "old" hardware, depends on what you define as "old" hardware.

If you don't want to target SM 2.0 cards, then move to SM 3.0...
0

Share this post


Link to post
Share on other sites
Normally you'd let the hlsl compiler do the constant register allocation and it will return you a constant table to tell you where it's allocated them. The downside of that approach is that you'll have to set all the constants up every time you switch shader, because the register numbers can change.

If you don't want to do that then you should definitely reuse the same register numbers for both the pixel and vertex shader - they won't conflict.

By the way almost all PS 2.0 cards I know of are Intel motherboard integrated ones, and are rather slow.
0

Share this post


Link to post
Share on other sites
[quote name='Adam_42' timestamp='1326045358' post='4900681']

If you don't want to do that then you should definitely reuse the same register numbers for both the pixel and vertex shader - they won't conflict.
[/quote]
I already use some of these uniforms for VS and PS. For example all material and lighting uniforms are set for the PS and VS (per SetVertexShaderConstant/SetPixelShaderConstant).
Wouldn't it be the best idea to put all PS uniforms into register C0-C31 and all pure VS uniforms (viewmatrix, projMatrix etc) into Registers C31+?
0

Share this post


Link to post
Share on other sites
[quote name='schupf' timestamp='1326049990' post='4900715']
Wouldn't it be the best idea to put all PS uniforms into register C0-C31 and all pure VS uniforms (viewmatrix, projMatrix etc) into Registers C31+?
[/quote]

If you don't want to make full use of the available vertex shader registers then you could do that.
0

Share this post


Link to post
Share on other sites
[quote name='Adam_42' timestamp='1326119799' post='4900947']
[quote name='schupf' timestamp='1326049990' post='4900715']
Wouldn't it be the best idea to put all PS uniforms into register C0-C31 and all pure VS uniforms (viewmatrix, projMatrix etc) into Registers C31+?
[/quote]

If you don't want to make full use of the available vertex shader registers then you could do that.
[/quote]
Uhm, what do you mean with "vertex shader registers"? I thought the c# registers are shared between PS and VS, arent they? Are there additional registers (writable by the C++ host code) specific for the VS?
0

Share this post


Link to post
Share on other sites
The pixel shader and vertex shader constant registers are completely separate.

That is SetVertexShaderConstant(0, foo); SetPixelShaderConstant(0, bar); will set two independent values for the first constant - one for the vertex shader and one for the pixel shader.
0

Share this post


Link to post
Share on other sites
I did not know this.

I thought the only registers that are available from the C++ Host code are the c# registers and I thought [color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left]SetVertexShaderConstant and [/left][/size][/font][/color][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left]SetPixelShaderConstant() set these c# registersdi[/left][/size][/font][/color]
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left]If PS and VS have different registers: How are they called? Which register is set if I call [/left][/size][/font][/color][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left]SetVertexShaderConstant and which one is set by calling [/left][/size][/font][/color][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left]SetPixelShaderConstant[/left][/size][/font][/color][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left]?[/left][/size][/font][/color]

[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left]On this site: [/left][/size][/font][/color][url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb172961(v=vs.85).aspx"]http://msdn.microsoft.com/en-us/library/windows/desktop/bb172961(v=vs.85).aspx[/url] are the register types. Which one can be set from C++ Host code?
0

Share this post


Link to post
Share on other sites
[quote name='schupf' timestamp='1326399974' post='4902094']

[left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3]If PS and VS have different registers: How are they called? Which register is set if I call [/size][/font][/color][/left]
[left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3]SetVertexShaderConstant and which one is set by calling [/size][/font][/color][/left]
[left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3]SetPixelShaderConstant[/size][/font][/color][/left]
[left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3]?[/size][/font][/color][/left]
[/quote]

SetVertexShaderConstantF will set the vertex shader constant registers (c# in the msdn link).
SetPixelShaderConstantF will set the pixel shader constant register (c# in the [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb172918(v=vs.85).aspx"]pixel shader version of your link[/url])

There are also integer and boolean versions of the above (same as above but with I and B instead of F, and i# / b# on the msdn pages).

The pixel and vertex shaders both have their own float, integer, and boolean constant registers. They are completely separate, the pixel shader cannot access data in a vertex shader constant and vice versa.
0

Share this post


Link to post
Share on other sites
Ah, I see.

In my first posting I showed part of my common shader file that declared all my variables that might be used by pixel or vertex shaders. I included this file in ALL my pixel and vertex shader source files. Since PS and VS have their own c# registers I guess it would make more sense to split this file into a common shader file for all pixel shaders and one for all vertex shaders?
0

Share this post


Link to post
Share on other sites
Yes, exactly. What you were doing was redundantly defining the constants in both the pixel and vertex shaders, roughly halving your number of registers.
0

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  
Followers 0