Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

bjone

Fastest way to pass parameters/values to a shader...

This topic is 5125 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, i'm currently searching the fastest way to setup constants for my shaders. currently i'm doing in the HLSL side:
matrix WorldViewProject;
float3 LightVector;
float3 ViewPosition;

// PS 

texture BaseTexture;
texture BumpTexture;
texture SelfTexture;

struct  {	
	bool UseBaseTexture,UseBumpTexture,UseSelfTexture;
	vector Speculars[2];
	float3 AtmosphericLight;
} States;

....

pixelshader()
{
  if( States.UseBumpTexture )
     .....
}
et on the C/C++ side, i have a:
typedef struct  {
	BOOL UseBaseTexture,UseBumpTexture,UseSelfTexture;
	D3DXVECTOR4 Speculars[2];
	D3DXVECTOR3 AtmosphericLight;
} RenderState;

class myobject
{
public:
    RenderState States;
}

on draw:

...
Effect->SetValue("States", &myboject->States, sizeof RenderState );
...

Effect->Begin()
....
---------- Are there any cheaper way to pass states (bool constants, floats, vectors...) to shaders ? i'm looking for ID3DXEffect::BeginParameterBlock() familly, but i don't see the according function to delete a ParameterBlock :??: (bizarre ?) [edited by - bjone on May 7, 2004 12:16:14 PM] [edited by - bjone on May 7, 2004 3:58:27 PM]

Share this post


Link to post
Share on other sites
Advertisement
Most probably that''s because you didn''t use the [ source ][/ source ] (without the spaces between the angle brackets and text) for formatting the code
Please edit the message and do so, that''ll increase readability.

Anyway, what makes you think setting shader constants is your bottleneck? Don''t do premature optimization, use a profiler instead. (AMD''s CodeAnalyst is free)

Muhammad Haggag,
Optimize
Bitwise account: MHaggag -

Share this post


Link to post
Share on other sites
it''s clearly not a bottleneck, but i wanted just to know what should be considered as the best approach...

Share this post


Link to post
Share on other sites
The ID3DXEffect interface is the easiest (you''d have to migrate your shaders to effect format and everything, though), but maybe not the fastest right now. However, they are increasing it''s speed greatly in the next release with some pure optimizations and some new interfaces and techniques.


Dustin Franklin
Mircrosoft DirectX MVP

Share this post


Link to post
Share on other sites
Here you are some optimizations that may be useful for this shader:

1. Instead of using an array, You can pack the scalar data into a vector or vectors. this will reduce the number of constants, no of instructions and enable you to work around hardware limitations.
2. For conditional compilation, declare the Boolean constants as static, because when not declared as constants, both branches of the shader are evaluated.
For more about shader optimization, you can see the paper called "Dark secrets of shader development" of ati.


Mohammad Adel
Optimize

"If A is a success in life, then A equals X plus Y plus Z. Work is X; Y is play; and Z is keeping your mouth shut". Einstien

[edited by - mohamed adel on May 10, 2004 12:35:57 PM]

Share this post


Link to post
Share on other sites
for the second point (static bools), it will not help because i want to change these params at runtime...

Share this post


Link to post
Share on other sites
quote:
Original post by bjone
good..

you''re talking about the incoming dx9 release (summer 2004) ?
Yep, that release.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!