Git Product home page Git Product logo

Comments (5)

llvm-beanz avatar llvm-beanz commented on June 12, 2024 1

I did a quick investigation here. There is a silly bug in DXC's overload scoring which is probably not easy to fix without side-effects.

A distilled demonstration is:

void f(int I);
void f(float F);

void c(bool B) {
  f(B); // error call to `f` is ambiguous
}

Basically the overload scoring doesn't provide a sane score to conversions from bool. It should prefer bool->int over bool->float.

This seems to cause something funky when we add the overloads to the AST which I still don't fully understand, but somehow we come out only adding the float overload, so DXC resolves to that. All of this code is a big magic-voodoo.

from directxshadercompiler.

pow2clk avatar pow2clk commented on June 12, 2024

The example Chris showed pertains to how user-function overloads are resolved and does represent a real issue. Intrinsics are resolved a bit differently. The QuadReadAcrossX() overload is determined by the pseudo-type indicated here as is interpreted in Sema here. Because it is specified as numeric it doesn't include bool. Its close cousin WaveReadLaneAt uses any instead of numeric, which includes bool. Doing the same thing correctly produces dx.op.quadOp.i1. Unfortunately, the validator identifies this as an invalid overload. That means to fix this, we'd need to either determine that all relevant hardware can handle this anyway, which is possible, or change it in a new shader model.

from directxshadercompiler.

pow2clk avatar pow2clk commented on June 12, 2024

One note I have for @rnvannatta is that the description says that this fails to compile. It doesn't fail, it just uses a float overload. that's weird and probably not intended, but I wanted to confirm that we were considering the same issue: https://godbolt.org/z/GqKh9341d

from directxshadercompiler.

rnvannatta avatar rnvannatta commented on June 12, 2024

Yup you're correct. It's just using the wrong overload.

Sorry, I always compile with -Werror and just saw lots of compiler noise.

from directxshadercompiler.

llvm-beanz avatar llvm-beanz commented on June 12, 2024

@pow2clk, I think the example I pasted highlights exactly the bug that results in this behavior being wrong.

Because of a bug in how SemaHLSL scores Boolean conversions, MatchArguments returns “true” when evaluating the float overload, which signifies that the overload is an exact match. This causes the custom overload handling for built in functions to only provide one overload candidate in the overload set (the float one). See the code here: https://github.com/microsoft/DirectXShaderCompiler/blob/main/tools/clang/lib/Sema/SemaHLSL.cpp#L4936

We can talk about whether this specific case is a bug or not, based on what is set in gen_intrin_main, but that’s not the main problem here. The main problem is that we incorrectly score the overload, and that causes problems with other intrinsics too. Like WaveActiveSum, which shouldn’t have a bool overload, and definitely shouldn’t resolve to a float one.

If we didn’t incorrectly score the overload, rather than populating a single overload candidate, we would populate a full candidate set, and the overload would fail to resolve producing an error. That’s probably the intended behavior here, except for the bug in MatchArguments that says a book argument is an exact match for a float parameter (which is obviously a bug).

from directxshadercompiler.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.