Questions tagged [spir-v]

SPIR-V is an intermediate representation language designed by the Khronos Group for use by OpenCL (2.0+), OpenGL (4.6+), and Vulkan (all versions). Do not use this tag for questions about SPIR, the earlier standard used with OpenCL before 2.0.

SPIR-V (Standard, Portable, Intermediate Representation-V) is an intermediate representation language for parallel compute and graphics programs. It is intended to be a target for higher-level languages to be compiled into, and is consumed by compute/graphics APIs like OpenCL, OpenGL, and Vulkan.

For Vulkan, SPIR-V is the only option for providing shaders (though there is an extension to directly send a version of GLSL to the Vulkan compiler, it is not widely implemented). OpenGL supports SPIR-V only in version 4.6 (and as an extension). OpenCL 2.0 and above support versions of SPIR-V.

The current version of SPIR-V is 1.3.

Note that SPIR-V is quite distinct from the older SPIR. SPIR was just a way of translating OpenCL C into LLVM's IR language.

102 questions
38
votes
2 answers

OpenCL, Vulkan, Sycl

I am trying to understand the OpenCL ecosystem and how Vulkan comes into play. I understand that OpenCL is a framework to execute code on GPUs as well as CPUs, using kernels that may be compiled to SPIR. Vulkan can also be used as a compute-API…
cor3ntin
  • 876
  • 1
  • 7
  • 9
12
votes
1 answer

Why do we need SPIR-V?

I have been reading about heterogeneous computing and came across SPIR-V. There I found the following: SPIR-V is the first open standard, cross-API intermediate language for natively representing parallel compute and graphics.. From this image I…
Dimitar Hristov
  • 123
  • 1
  • 7
10
votes
2 answers

Instanced GLSL shaders in Vulkan?

This is the (simplest) instancing shader I can come up with, which basically just transforms a bunch of 2D primitives: #version 400 #extension GL_ARB_draw_instanced : enable #extension GL_ARB_shading_language_420pack : enable layout(std140, binding…
MuertoExcobito
  • 9,741
  • 2
  • 37
  • 78
7
votes
5 answers

How to use glslang

I am trying to use glslang to compile glsl shader code to SPIR-V binaries. The glslang project can be found here: https://github.com/KhronosGroup/glslang It works well via the glslangValidator.exe manually in the command line. But i would like to…
Aedoro
  • 609
  • 1
  • 6
  • 21
5
votes
1 answer

Vulkan Array of Specialization Constants

Is is possible to have an array of specialization constants such that the glsl code looks similar to the following: layout(constant_id = 0) const vec2 arr[2] = vec2[] ( vec2(2.0f, 2.0f), vec2(4.0f, 4.0f) ); or,…
Ryoku
  • 397
  • 2
  • 16
5
votes
1 answer

Automatically compile OpenGL Shaders for Vulkan

Is there any way to automatically compile OpenGL shaders for Vulkan? The problem is with the uniforms. 'non-opaque uniforms outside a block' : not allowed when using GLSL for Vulkan I have tried compiling for OpenGL, then decompiling with…
me'
  • 494
  • 3
  • 14
5
votes
2 answers

Using spirv with OpenGL, gl_VertexIndex is always 0

I am trying to use spirv with OpenGL. Before in my shaders I had gl_VertexID to calculate the uv of a rectangle and now I replaced it with gl_VertexIndex. If I use gl_VertexID the code works, if I use gl_VertexIndex in spirv with vulkan the code…
Rhu Mage
  • 667
  • 1
  • 8
  • 21
5
votes
1 answer

Does every variable have to be set for every vertex emitted in a geometry shader?

In my geometry shader that I was using in OpenGL setting a variable once at the beginning and then emitting vertices without resetting it works, but in vulkan if I don't write to that variable between every EmitVertex() my code will not work…
Rhu Mage
  • 667
  • 1
  • 8
  • 21
5
votes
3 answers

How to compile OpenCL Kernels to SPIR-V using Clang

I need compile OpenCL kernels in SPIR-V to use with Vulkan, I tried with Google CLSPV https://github.com/google/clspv, but the problem occur with vectorization, functions like vload8 doesn't work. So I need compile OpenCL kernels in SPIR-V using…
Alex
  • 3,301
  • 4
  • 29
  • 43
5
votes
1 answer

How to get 16bit floats in modern GLSL with Vulkan?

It appears at one point in time Nvidia had an extension that permitted half floating point values for OpenGL 1.1, but apparently since that time *the world half has been reclaimed by the modern GLSL spec at some point. Today I can use 16bit…
Krupip
  • 4,404
  • 2
  • 32
  • 54
5
votes
1 answer

Is there a way to use clz() in a Vulkan compute shader?

I'm interested in implementing a particular algorithm in a set of Vulkan compute shaders. The algorithm uses a clz() function at one point. I expect that my NVIDIA GPU probably offers hardware support for this function; CUDA uses a clz instruction…
mjwach
  • 1,174
  • 2
  • 9
  • 25
4
votes
1 answer

Specialization constant used for array size

I'm trying to use a SPIR-V specialization constant to define the size of an array in a uniform block. #version 460 core layout(constant_id = 0) const uint count = 0; layout(binding = 0) uniform Uniform { vec4 foo[count]; uint…
diapir
  • 2,872
  • 1
  • 19
  • 26
4
votes
1 answer

Control decorations when compiling GLSL to SPIR-V with glslang

The SPIR-V specification allows a module to request that a branch will be flattened or a loop unrolled using control decorations for the appropriate instructions. This has a significant impact on the final performance profile of the shader. However,…
Quinchilion
  • 912
  • 6
  • 16
3
votes
1 answer

Should I use dxc or glslangValidator?

In the Vulkan SDK there are two different tools that allow to compile HLSL to SPIR-V: dxc and glslangValidator. Why do we need two? What are the differences? How do I decide which one to use?
tuket
  • 3,232
  • 1
  • 26
  • 41
3
votes
1 answer

How would I set sampler2D uniforms in OpenGL in a SPIR-V Shader?

I am compiling this shader with glslangValidator, and am using OpenGL 4.3 Core Profile with the extension GL_ARB_gl_spirv, and using the GLAD webservice to generate function pointers to access the Core OpenGL API, and SDL2 to create the context, if…
KapowCabbage
  • 65
  • 1
  • 8
1
2 3 4 5 6 7