简体   繁体   English

如何使用 Vulkan 编译 HLSL 着色器?

[英]How to compile HLSL shaders with Vulkan?

I'm current learning Vulkan API, it's time to create pipeline, I chose HLSL because in the future I want to reuse shaders in DirectX and when I get an RTX GPU I intend to bring ray tracing, I'm new in HLSL, I wrote a simple vertex shader:我目前正在学习 Vulkan API,是时候创建管道了,我选择了 HLSL,因为将来我想在 DirectX 中重用着色器,当我得到 RTX GPU 我打算带来光线追踪,我是 HLSL 的新手,我写了一个简单的顶点着色器:

float4 main(float2 pos : POSITIONT) : SV_POSITION
{
    return float4(pos, 0, 1);
}

Following this tutorial i try to compile: glslc.exe VertexShader.hlsl -o vertex.spv按照本教程,我尝试编译: glslc.exe VertexShader.hlsl -o vertex.spv

And i get this error: glslc: error: 'VertexShader.hlsl': .hlsl file encountered but no -fshader-stage specified ahead我得到这个错误: glslc: error: 'VertexShader.hlsl': .hlsl file encountered but no -fshader-stage specified ahead

So, how to compile HLSL in Vulkan?那么,如何在 Vulkan 中编译 HLSL?

The other option is to use the DXC compiler ( https://github.com/Microsoft/DirectXShaderCompiler ) which has a SPIR-V backend available.另一种选择是使用具有可用 SPIR-V 后端的 DXC 编译器 ( https://github.com/Microsoft/DirectXShaderCompiler )。 This would be the same compiler you end up using with DirectX as well.这也将与您最终与 DirectX 一起使用的编译器相同。

Solveld adding -fshader-stage=vertex求解添加 -fshader-stage=vertex

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM