HLSL 中的 printf 函数有什么作用?

What does the printf function in HLSL do?

MSDN HLSL 参考说明了关于 printf 的内容:

"Submits a custom shader message to the information queue."

https://msdn.microsoft.com/en-us/library/windows/desktop/ff728755%28v=vs.85%29.aspx

什么是信息队列,如何查看着色器消息?这是否意味着在像素着色器中使用时会输出宽度*高度(屏幕像素)消息?

谢谢!

它基本上可以用于着色器跟踪。 D3D11_TRACE_STEP 结构可以帮助你从 HLSL 中获取 printf 传递的消息,一个例子如下,乍一看似乎没问题(虽然是用 D 写的):

https://github.com/evilrat666/directx-d/blob/master/src/directx/d3d11shadertracing.d

可以和这个接口一起使用来访问跟踪信息:

https://msdn.microsoft.com/en-us/library/windows/desktop/hh446840(v=vs.85).aspx

免责声明:这只是我在研究该主题时发现的,因此我无法提供实际的代码示例。对于调试着色器,我宁愿建议使用 Renderdoc 或 VS Graphics Debugger