Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4084174
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:24:22+00:00 2026-05-20T18:24:22+00:00

We’ve one pixel shader in HLSL which is used for slightly different things in

  • 0

We’ve one pixel shader in HLSL which is used for slightly different things in a few places, and as such has several conditional blocks meaning that complex functionality is omitted in some cases. As well, this means we pass textures as sampler parameters which may not always be used.

I have no idea how much of a performance hit these two things add but especially since we support SM2.0 on integrated graphics chips, inefficiencies are an issue. So, does passing a texture in and not using it mean any extra overhead? And does using an if simply act to add a couple of instructions or can it drastically affect things due to stalls and so on like when doing CPU optimization?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:24:23+00:00Added an answer on May 20, 2026 at 6:24 pm

    Setting a texture on the GPU takes some CPU time, but it is reasonably small in comparison to the actual batch cost. More importantly, it should have no impact at all on the actual shader execution, if the shader never references it.

    Now, there are three ways that branching can be handled:

    First of all, if the branch condition is always going to be the same thing (if it only depends on compile-time constants), then one side of the branch can be inlined out entirely. In many cases it can be preferable to compile multiple versions of your shader if it makes it possible to eliminate significant branches this way.

    The second technique is that the shader can evaluate both sides of the branch and then select the correct result based on the conditional, all without actually branching (it does it arithmetically). This is best when the code in the branch is small.

    And finally, it can actually use branching instructions. First of all the branch instructions have modest instruction count costs. And then there is the pipeline. The x86 has a long serial pipeline, which you can easily stall. The GPU has a completely different, parallel pipeline.

    The GPU evaluates groups of fragments (pixels) in parallel, executing the fragment program once for multiple fragments at a time. If all the fragments in a group take the same branch, then you only have that branch’s execution cost. If they take two (or more) branches, then the shader must be executed multiple times, for that group of fragments, to cover all the branches.

    Because the fragment groups have on-screen locality, it helps if your branches have similar on-screen locality. See this diagram:


    (source: nvidia.com)

    Now, the shader compiler generally does a very good job of selecting which of the last two methods to use (for the first method, the compiler will inline for you, but you have to make multiple shader versions yourself). But if you’re optimising performance, it can be useful to see the actual output of the compiler. To this end, use fxc.exe in the DirectX SDK Utilities, with the /Fc <file> option, to get a disassembly view of the compiled shader.

    (As this is performance advice: remember to always measure your performance, figure out what limits you’re hitting, and then worry about optimising it. No point in optimising your shader branches if you’re texture-fetch bound, for example.)

    Additional reference: GPU Gems 2: Chapter 34. GPU Flow-Control Idioms.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I am reading a book about Javascript and jQuery and using one of the
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.