4 ms·
Their shaders contain a peculiar construction: if (condition) { while (true) { } } condition is always false, but the compiler doesn’t
by jandrese 2y ago
Their shaders contain a peculiar construction:
if (condition) {
while (true) { }
}
condition is always false, but the compiler doesn’t know that.
What is the purpose of this other than to be a poison pill for people writing compliant shader compilers?
- tombh 2y agoIs this how shaders "panic"?
- zamadatix 2y agoIsn't the main point of tests to be poison pills for people writing compilers so they can ensure any shaders passed to the compiler don't break it? I.e. it's not that the specific code is useful as is in practice but if a chunk of a shader ends up functionally simplifying to something like this in a particular instance your shader compiler still needs to handle it right even though it could be written better at that point.
- JakaJancar 2y agoMaybe an edge-case in some codegen?
- nsajko 2y agoThe purpose of the construction could be to inform the compiler of the fact that the condition is always false, so as to enable the compiler optimizer more. Take a look at these features in C++, LLVM or Rust if you're not familiar with the concept: * https://en.cppreference.com/w/cpp/utility/unreachable https://en.cppreference.com/w/cpp/utility/unreachable * https://en.cppreference.com/w/cpp/language/attributes/assume https://en.cppreference.com/w/cpp/language/attributes/assume * https://en.cppreference.com/w/cpp/memory/assume_aligned https://en.cppreference.com/w/cpp/memory/assume_aligned * https://llvm.org/docs/LangRef.html#unreachable-instruction https://llvm.org/docs/LangRef.html#unreachable-instruction * https://llvm.org/docs/LangRef.html#llvm-assume-intrinsic https://llvm.org/docs/LangRef.html#llvm-assume-intrinsic * https://doc.rust-lang.org/std/hint/fn.unreachable_unchecked.html https://doc.rust-lang.org/std/hint/fn.unreachable_unchecked.... * https://doc.rust-lang.org/std/hint/fn.assert_unchecked.html https://doc.rust-lang.org/std/hint/fn.assert_unchecked.html The infinite loop is effectively an unreachable instruction (reaching it is not allowed), and an unreachable instruction behind a branch effectively becomes an assume instruction.
- SomeoneFromCA 2y agoNo, it cannot, as while (true) {} is not UB and should not be optimized out. EDIT: oops, yes you are right, it is not c++ after all.