"you can't debug print shaders" oh yeah? well check this shit out

that's right, a whole ass view matrix, served directly from the GPU

I'm using the R1 single-channel 1bpp 2D texture format for this one
A unity shader .cginc to draw numbers in the fragment shader - see the first comment below for example usage!

A unity shader .cginc to draw numbers in the fragment shader - see the first comment below for example usage! - GpuPrinter.cginc

Gist
@acegikmo Hoooo ! Neat ! I have been wanting to try this the other day in a shader.

@acegikmo Neat trick!

For printing to actual console did you explore maybe writing debug messages to a structured GPU buffer and reading back async on the CPU and then just displaying in normal tty console?

@acegikmo Also unreal has a funny shader graph node that basically displays the text on whatever model it's applied to using just its normal UVs, etc.
@boggo I could! but I didn't need it in this case, this was,, 90% made because I was curious what it would look like lol (but also to debug matrices GPU side)
@boggo @acegikmo Unity’s SRP libraries already have this functionality somewhere
@aras @boggo @acegikmo what?! Really?!!
Graphics/Packages/com.unity.render-pipelines.core/ShaderLibrary/ShaderDebugPrint.hlsl at master · Unity-Technologies/Graphics

Unity Graphics - Including Scriptable Render Pipeline - Unity-Technologies/Graphics

GitHub
@acegikmo Just to make sure I understand the code right, thats encoding the numbers such that each pixel's row corresponds to one of the dBits, and the col is the index of the bit in the number in dBit? (AKA the row is binary encoded?
@deef yep!
@acegikmo Is there any particular reason you encoded using decimal instead of 0b111010111111101 etc? (I *think* c# supported binary, hex, and oct literals, anyway)
@deef because it looks funnier that way! but also idk if hlsl supports binary literals? It started as a binary literal in C# though before I moved it to hlsl

@acegikmo Ah. I thought it was C#, not hlsl. my mistake. Dunno how it being for a shader didn't tip me off to that..., but I also should not have read float DrawDigit as func DrawDigit lol.

In any event, it appears no. binary for literals is not supported https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-appendix-grammar#integer-numbers Tho hex and oct are, so its odd its missing.

Grammar - Win32 apps

HLSL statements are constructed using the following rules for grammar.

@deef @acegikmo I think this may be the first time I've seen a somewhat legit use case for octal other than Unix permissions. (although it would still be less readable than binary)

Interestingly, binary is a late addition in many languages. C# didn't have it until version 7, and C++ until version 14.

@acegikmo 😍

In our engine we can printf from shaders, with extended format specifier syntax for vectors and matrices. We can also create debug primitives from shaders. Extremely helpful. It's often the first thing I implement when I start using a new engine, along with shader hot recompliation if it's not already there. Iteration time and ease of debugging are super important in my opinion.

@acegikmo galaxy brain level idea right here

@acegikmo

Thats some incredible html in the "gif"

@acegikmo this is really cool. But also, newest GDB can actually debug GPU code on AMD GPUs. You need a proprietary blob from and to do it tho =/

Also idk what Nvidia or Intel are doing, but I think there's chat about how to standardize debug info for GPU code so that we won't need the proprietary blob anymore and more GPUs could be supported

@GwenTheKween is that for ROCm only or can it also debug Vulkan or DX11/12 shaders?

@supersingular I don't know to be honest. I just see patches flying through every so often

It might be a ROCm specific feature, now that you mention it 

Vulkan-ValidationLayers/docs/debug_printf.md at main · KhronosGroup/Vulkan-ValidationLayers

Vulkan Validation Layers (VVL). Contribute to KhronosGroup/Vulkan-ValidationLayers development by creating an account on GitHub.

GitHub
@acegikmo sci Fi stuff right there!
GitHub - msqrt/shader-printf: Simple printf functionality for GLSL.

Simple printf functionality for GLSL. Contribute to msqrt/shader-printf development by creating an account on GitHub.

GitHub
@acegikmo Freya really just said "hold my vertex"
@acegikmo oh my god this is amazing
@acegikmo holy shit that's cool as fuck
@acegikmo galaxy-brain level stuff

@acegikmo GL_EXT_debug_printf would like to have a word with you...

But interactive on-screen debug visualizations are definitely nicer in a lot of cases than logging to stdout.

@acegikmo there's a similar minimal shader font for debug info in the vrchat audiolink package.. but it's overengineered to use sdfs: https://github.com/llealloo/audiolink/blob/master/Packages/com.llealloo.audiolink/Runtime/Shaders/SmoothPixelFont.cginc
audiolink/Packages/com.llealloo.audiolink/Runtime/Shaders/SmoothPixelFont.cginc at master · llealloo/audiolink

Audio reactive prefabs for VRChat. Contribute to llealloo/audiolink development by creating an account on GitHub.

GitHub