问题标签 [spir-v]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
2871 浏览

cmake - 为什么 Cmake 不构建我的 vulkan/spirv 着色器?

我目前正在通过关注这个网站来学习 Vulkan 。我目前正处于需要将我的 GLSL 着色器编译为 SPIR-V 的地步。与仅为着色器创建单独的编译脚本(例如使用 bash)的网站不同,我想在我的代码中完全使用 Cmake。

因为网站推荐的 SPIR-V/GLSL 编译器 glslc 安装在我的系统路径上(稍后我会担心可移植性。),我决定add_custom_command在一个 cmake 函数中使用 Cmake,它充当包装器以添加着色器要编译。

但是,当我尝试这样做时,就好像我根本没有对 Cmake 代码进行任何更改。.spv在我的树外构建文件夹或我的源文件夹中都没有生成文件。当我VERBOSE=1 make使用 C++ 源代码在我的真实项目上运行时,我会看到 C++ 编译器的命令,但看不到任何glslc命令。

我认为罪魁祸首可能是 Cmake 函数的某种作用域,我通过复制和粘贴函数的源代码然后手动替换其参数的值,将其中一个着色器调用移到任何函数调用之外。两种样式都显示在下面的 MCVE 中。

除了add_custom_commandCmake 有一个add_custom_target功能,但Cmake 的文档说如下:

[add_custom_target] 添加具有给定名称的目标以执行给定命令。目标没有输出文件,即使命令尝试使用目标的名称创建文件,它也始终被认为是过时的。使用 add_custom_command() 命令生成具有依赖关系的文件。默认情况下,没有任何东西取决于自定义目标。这不是我想要的,因为我不希望每次运行 Cmake 时都构建我的着色器,而是仅当自上次构建以来已更改 glsl 文件时,作为链接的 C++ 应用程序的依赖项,因为这就是他们是,我希望克莱恩认识到这一点。

这是一个 MCVE:

目录结构:

在 Linux 上重现该问题的命令:

CMakeLists.txt:

碎片着色器.glsl:

顶点着色器.glsl:

0 投票
2 回答
2677 浏览

opengl - 将 spirv 与 OpenGL 一起使用,gl_VertexIndex 始终为 0

我正在尝试将 spirv 与OpenGL一起使用一起使用。之前在我的着色器中我必须gl_VertexID计算一个矩形的 uv,现在我用gl_VertexIndex.

如果我使用代码gl_VertexID工作,如果我使用gl_VertexIndex代码工作,但如果我使用OpenGLspirvvulkangl_VertexIndex工作,gl_VertexIndex总是0.

这是我正在使用的测试绘制命令:

不应该gl_VertexIndex0to5吗?

0 投票
1 回答
2468 浏览

batch-file - Compiling GLSL to corresponding Spir V for use in a Vulkan Application

I'm using Jonno Robson's Vulkan code base from github found here: Vulkan-Terrain-Generator as a guide and or learning reference to better understand Vulkan. I don't have any issues with the source code itself, but my question or concern pertains to compiling GLSL shader codes into Spir V code. I am new to SpirV its compilers and tool kits. I've tried using both: glslangValidator.exe and glslc.exe to convert the shader files into Spir V files.

In Jonno's code base, he converted each GLSL shader file into a corresponding spirv file. I tried using the flag options that he used in his batch file the only difference is I replaced the directory that points to his glslangValidator.exe with my own directory.

I'm trying to achieve the same effect where it will take all of the shader files that are in the directory of the batch file to be compiled from GLSL to Spir V where it will append .spv to the end of each of the new SpirV files that it will generate in that directory after converting it from GLSL to the respected Spir V byte code.

Here is what my batch file looks like:

compile.bat

However it is not working for me after I double click on the batch file. It opens and runs, but it is not generating the expected shader_filename.vert.spv ... shader_filename.frag.spv files.

I don't know what platform they did theirs on, but I'm running Windows 7 and I don't know if that makes a difference with the command arguments or flags to be fed within the batch commands. I don't know if they used any other tool kit within the Vulkan SDK or some outside library or tool or what not.

What I would like to be able to do with this batch file is to convert all of the shader files into the appropriate Spir V files with the simplest batch command there is. I don't want to have to write the same command over and over again for each shader file as there are over 20 shaders in this directory.

How can I achieve this or what are the proper command arguments for either glslangValidator or glslc to generate the needed SpirV files?

I have read the documents found here: SPIR-V Toolchain but I'm still not sure how to properly generate the needed batch file.

0 投票
0 回答
390 浏览

clang - 如何在 spir-v 二进制内核中正确使用 clCreateProgramWithIL()?

我需要创建一个 OpenCL 应用程序来检测它作为输入接收的 OpenCL 内核的代码,以用于一些奇异的分析目的(还没有找到我需要的东西,所以我需要/想自己做)。

我想将内核编译为中间表示(现在是 LLVM-IR),对其进行检测(使用 LLVM C++ 绑定),将检测代码转换为 SPIR-V,然后在主机代码中使用clCreateProgramWithIL().

现在,我只是在编译一个简单的 OpenCL 内核,它添加了 2 个向量,没有检测:

要将上述内容编译为 LLVM IR,我使用以下命令:

之后,我使用工具(此处)进行vadd.bc转换。vadd.spvllvm-spirv

最后,我尝试从 C 主机代码构建内核,如下所示:

clBuildProgram运行主机代码后,我从命令中收到上述错误:

vadd.spv文件似乎没有与 OpenCL 内核库链接。知道如何实现这一目标吗?

0 投票
1 回答
457 浏览

opencl - 将 OpenCL SPIR-V 转换为 Vulkan SPIR-V

是否可以将 OpenCL 风格的 SPIR-V 转换为 Vulkan 风格的 SPIR-V?
我知道可以使用 clspv 将 OpenCL C 编译为 Vulkan 风格的 SPIR-V,但我没有看到任何迹象表明它也支持摄取 OpenCL 风格的 SPIR-V。

如果您知道如何实现这一点,谢谢您的任何建议:)

0 投票
1 回答
1378 浏览

opengl - 为 Vulkan 自动编译 OpenGL 着色器

有没有办法为 Vulkan 自动编译 OpenGL 着色器?问题出在制服上。

我尝试过为 OpenGL 编译,然后用 spirv-cross 反编译--vulkan-semantics,但它仍然有非透明的制服。

spirv-cross 似乎只有为 OpenGL 编译 Vulkan 着色器的工具。

0 投票
0 回答
1030 浏览

glsl - 为什么 Vulkan 无法识别我的 SPIR-V 着色器?

我正在编写一个简单的 Vulkan 应用程序来熟悉 API。当我调用 vkCreateGraphicsPipelines 时,我的程序将“LLVM 错误:无效的 SPIR-V 幻数”打印到标准错误并退出。

SPIR-V 规范(https://www.khronos.org/registry/spir-v/specs/1.2/SPIRV.pdf,我认为第 3 章与此相关)声明着色器模块被假定为单词流,而不是字节,我的 SPIR-V 文件是字节流。

所以我对我的 SPIR-V 文件的前两个字进行了字节交换,它确实识别出了幻数,但是 vkCreateGraphicsPipelines 退出并出现错误代码 -1000012000(VK_ERROR_INVALID_SHADER_NV 的定义),这意味着着色器阶段无法编译(参见https://www .khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkCreateShaderModule.html)。当我对整个 SPIR-V 文件(使用“dd conv=swab”)进行字节交换时,也会发生完全相同的事情。

我不确定首先是什么问题,因为https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VkShaderModuleCreateInfo.html指出 SPIR 的格式- V码是自动确定的。如果有人可以推荐一个修复程序,即使它是一个 hack,我将不胜感激。

如果这很重要,我正在使用 glslangValidator 生成 SPIR-V。

加载着色器模块的代码:

0 投票
2 回答
1988 浏览

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

我目前正在学习 Vulkan API,是时候创建管道了,我选择了 HLSL,因为将来我想在 DirectX 中重用着色器,当我获得 RTX GPU 时,我打算带来光线追踪,我是 HLSL 的新手,我写了一个简单的顶点着色器:

按照本教程,我尝试编译:glslc.exe VertexShader.hlsl -o vertex.spv

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

那么,如何在 Vulkan 中编译 HLSL?

0 投票
0 回答
65 浏览

parallel-processing - 计算内核上的意外索引排序问题

当我尝试按降序进行索引排序时,我遇到了一个奇怪的问题。我很确定我错过了关于 GPU 如何工作的一些基本概念,因为我希望这个程序能够正常执行:

这个程序适用于小的输入——让我们假设一个从 1 到 500 的自然数的有序列表。如果我们用 50 或 75 替换 150u,结果如预期:前 75 个数字从 75 下降到 1,之后他们从 76 到 500 开始。

问题是输入超过 100 时,一些索引会被打乱。结果完全是结构的乱码,但索引当然保持在范围内。奇怪的是,如果 while 不变量递增到 5000 表示 500 个元素的循环,则排序再次开始工作。

知道问题可能是什么吗?我很确定我无法理解一些基本的同步。据我了解,除了在函数末尾交换索引之前,我的代码中不需要任何其他障碍。

值得一提的是,这是对以下 SPIR-V 函数的翻译:

例如,如果我们将 150u 更改为 250u 并可视化结果,我们会得到以下结果:

以 250u 为例

在这里,我们可以看到排序表明,在某些情况下,while 循环似乎没有运行足够的次数——结果中存在重复值,并且一些值消失了。

任何输入表示赞赏!

0 投票
0 回答
240 浏览

layout - 尽管有标量限定符,但 Vec3 存储缓冲区不是有效的布局

据我了解,scalarvulkan GLSL 中的布局限定符应该允许一个简单的 vec3 值数组起作用,显然不需要指定任何物理设备功能。我已经尝试过指定标量布局功能,例如:

但无济于事。我收到奇怪的规范失效错误。

这是示例代码:

我收到以下 SPIR-V 验证错误:

首先,我不明白为什么它试图将我的缓冲区称为制服?显然我仍然对这完全违反规范感到困惑。