TheRealMJP / TheRealMJP.github.io

Backing repo for my blog
16 stars 1 forks source link

Shader Printf in HLSL and DX12 #14

Open utterances-bot opened 7 months ago

utterances-bot commented 7 months ago

Shader Printf in HLSL and DX12

https://therealmjp.github.io/posts/hlsl-printf/

XanderBert commented 7 months ago

Awesome write up! Definitely going to take a closer look into this!

mateeeeeee commented 7 months ago

Thanks for the article! I am trying to implement this in my engine, however I get compiler errors when trying to use indexing to string literal: bool b = ("Hello"[2] == 'l'); //error: type mismatch I was wondering what dxc version you are using because I tried with both latest official release (v1.7.2308) and with the latest successful build's artifacts from Github but it didnt work.

gevahn commented 7 months ago

Slightly less cursed(?) way to get the char code


template<typename T> int CharToUint(in T c) {
    int charCode = -1;
    uint charMapLen = StrLen("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
    for (int i = 0; i < charMapLen; i++) {
        if (c == "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i]) {
            charCode = LettersStart + i;
            return charCode;
        }
    }
}
TheRealMJP commented 7 months ago

Hey @mateeeeeee, yeah it looks like you need to pass the character to a templated function first for the comparison to work. I imagine that's a side effect of how char and other 8-bit types were disabled in clang/LLVM.

https://godbolt.org/z/asdc76coG

TheRealMJP commented 7 months ago

@gevahn ha nice, I didn't think of that! I guess that's at least more compact than what I came up with.

mateeeeeee commented 7 months ago

@TheRealMJP thanks for the answer. It seems my issue was using DXC_ARG_SKIP_OPTIMIZATIONS (-Od). MRE that shows the issue here Removing -Od will make it work. I've reported the issue to DXC.