Jump to content
  • Advertisement
Sign in to follow this  
Quat

d3d11 Shaders Copying vertex data to arrays fast?

This topic is 2417 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

For a multi-layer terrain texturing implementation, I am packing transformed texture coordinates and blending weights into float4 and output from vertex shader. For example, blend weights for 4 layers are packed into one float4, and two 2D texture coordinates are packed into one float4.

In the pixel shader, I want to be able to do a loop for each layer, so let's say I had 8 blend layers, I do:

float blendWeights[8] = {
pixel.LayerWeights0.x, pixel.LayerWeights0.y, pixel.LayerWeights0.z, pixel.LayerWeights0.w,
pixel.LayerWeights1.x, pixel.LayerWeights1.y, pixel.LayerWeights1.z, pixel.LayerWeights1.w
};

Then I can loop from i=0; i < 8;

My question is, should I worry about the performance of copying the data into the scalar array? I can't really think of a clean way to do the loop otherwise.

Share this post


Link to post
Share on other sites
Advertisement
I would almost assume that the compiler will take what you have specified there and unroll the loop to just use the input attribute registers. Of course I don't know for sure, but you should be able to check this with FXC assembly output.

Is there any alternative to doing it this way?

Share this post


Link to post
Share on other sites
You are probably right. I'll check the assembly. It's not really a true loop anyway, but is looping on a compile time constant (using the effects framework to generate a shader to support terrain meshes with 1-16 layers), so it should be unrolled.

Share this post


Link to post
Share on other sites
You can always force it to unroll with the [unroll] attribute.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!