Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shader Printf in HLSL and DX12 #14

Open
utterances-bot opened this issue Jan 11, 2024 · 6 comments
Open

Shader Printf in HLSL and DX12 #14

utterances-bot opened this issue Jan 11, 2024 · 6 comments

Comments

@utterances-bot
Copy link

Shader Printf in HLSL and DX12

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

Copy link

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

Copy link

mateeeeeee commented Jan 14, 2024

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.

Copy link

gevahn commented Jan 15, 2024

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;
		}
	}
}

Copy link
Owner

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

Copy link
Owner

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

@mateeeeeee
Copy link

mateeeeeee commented Jan 16, 2024

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants