SPIR-V | a simple SPIR-V parser | Parser library
kandi X-RAY | SPIR-V Summary
kandi X-RAY | SPIR-V Summary
SPIR-V
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of SPIR-V
SPIR-V Key Features
SPIR-V Examples and Code Snippets
Community Discussions
Trending Discussions on SPIR-V
QUESTION
I'm writing a Vulkan compute shader in Android studio and launching it on Android phone. The problem I'm experiencing is next - I can not use any subgroup operations like subgroupAdd
and subgroupElect
. When I'm trying to use these functions I have an error like this:
reduce_vec.comp:35: error: 'subgroup op' : requires SPIR-V 1.3
I have checked - my Android phone supports subgroups, and my shader accepts such extensions:
...ANSWER
Answered 2022-Feb-08 at 09:23Android solution
You can pass arguments to the Android shaderc compiler in your Gradle DSL:
https://developer.android.com/ndk/guides/graphics/shader-compilers
You need glslcArgs
to contain --target-env=vulkan1.1
Flexible solution
Build your own compilation pipeline to compile from source into SPIR-V, and then include the SPIR-V binary files directly into your Android project.
There are multiple language front-ends that can generate SPIR-V, for GLSL the Khronos tools are here:
QUESTION
I want to compile the following code into SPIR-V ...
ANSWER
Answered 2022-Feb-02 at 02:17It is 3 am in the morning over here, I should just go to sleep.
Chances anyone end up having the same problem are small, but I'd still rather answer it myself than delete it:
I simply had to add a SpecializationConstant to set the size of the sampler2D array, now it works without requiring any extension.
Good night
QUESTION
I am in the process of writing a binary processing module for SPIR-V shaders to fix alignment issues with float4x3[6] matrices because of driver bugs. Right now i have:
- injected necessary appropriate OpTypes and OpTypePointers.
- processed the binary to change constant buffer members from float4x3[6] to vec4[18]
- injected function properly unpacking vec4[18] into float4x3[6] accepting vec4[18] as a pointer to Uniform array 18.
- created Private storage qualifier matrix unpack targets as OpVariables.(Private in SPIR-V just means invocation-level global...).
- injected preambles about composite extraction and construction to call my new function. (since from what im seeing we need to copy arguments from constant buffers to functions always, so thats what I do).
- called the function from entrypoint, for every float4x3[6] member to have ready unpacked matrices when main() starts.
- changed OpAccessChain operations that referenced given members in constant buffers and swapped them with access chains referencing my new Private targets.
But now i ran into trouble. It looks like a function in SPIR-V can either accept Private or Function storage qualifier pointers. Not both. Is there any way i can tell SPIR-V "Yeah, you can dump both of those storage classes here as arguments"?
Or do i need to rework my solution to utilize Function storage class matrix targets, and inject them and calls to unpack them every single time they are used in a new function? This seems much less elegant since there might be way more unpack operations then. And much less hassle-free, since i would have to scan every OpFunction block separately and inject OpVariables with Function storage into every block that uses the matrices.
My problem is, after all this machinery is done my targets are living as OpTypePointer of Private Storage Duration. Therefore i cannot use them in ANY SPIR-V function generated from HLSL, since they take OpTypePointers of Function duration. My unpack function is sole exception to this since i injected it directly in SPIR-V asm, byte by byte and was able to precisely tune OpFunctionParameters in header.
...ANSWER
Answered 2022-Jan-31 at 16:54This is a matter of calling conventions. Or rather, the lack of calling conventions in SPIR-V.
Higher-level languages like GLSL and HLSL have calling conventions. They explain what it means for a function to take an input parameter and how that relates to the argument being given to it.
SPIR-V doesn't have calling conventions in that sense. Or more to the point, you have to construct the calling conventions you want using SPIR-V.
Parameters in HLSL are conceptually always passed by copy. If the parameter is an input parameter, then the copy is initialized with the given argument. If the parameter is an output parameter, the data from the function is copied into the argument after calling the function.
The HLSL compiler must implement this in SPIR-V. So if a function takes a struct
input parameter, that function's input parameter must be new storage from any existing object. When a caller tries to call this function, it must create storage for that parameter. That storage will use the Function
storage qualifier, so the parameter also uses that qualifier.
SPIR-V requires that pointer types specify the storage qualifier of the objects they point to. This is important, as how the compiler goes about generating the GPU assembly which accesses the object can be different (perhaps drastically). As such, a function cannot accept a pointer that points to different storage classes; the function has to pick one.
So if your SPIR-V adjustment system sees a function call whose source data comes from something you need to adjust, then you have two options:
Create a new function which is a copy of the old one, except that it takes a
Private
pointer.Follow the calling convention by creating
Function
-local storage and copying from yourPrivate
data into it prior to calling the function (and copying back out if it is an output parameter). There's probably code to do that sitting there already, so you probably only need to change where it copies from/to.
QUESTION
So I'm developing a game engine framework for myself in C#/.NET and I have been trying to simplify building shader files (the rendering engine consumes SPIR-V files, which I want to generate from GLSL source). My current approach has been to use a custom .targets file which is imported into a CSPROJ, and that file defines a custom target like this:
...ANSWER
Answered 2022-Jan-14 at 02:16I am not sure I understand your problem correctly, but if you want your .vert.spv copied to another folder use File.Copy()
QUESTION
I'm trying to figure out how to use debugPrintfEXT but with no luck. First I've enabled the extension in my vertex shader
...ANSWER
Answered 2022-Jan-12 at 20:44You also need to enable the VK_KHR_shader_non_semantic_info
device extension in your application code when you create the device.
LunarG has also recently published a white paper about debugPrintfEXT
.
QUESTION
Naga validate this snippet:
...ANSWER
Answered 2021-Dec-17 at 20:42To store in a rgba8uint
, you need to use the type vec4
. See here for the corresponding type for each texture storage. If that's not working, you may have a different problem. (Are you passing in 10.
etc to the vec4
? It should be 10u
. Wgsl is very strict about types.)
QUESTION
I encountered a strange problem with compiling Vulkan compute shader. I have this shader (which is not even all that complex)
...ANSWER
Answered 2021-Sep-30 at 13:16Upon closer inspection I noticed that normally all the generated SPIR-V files for my shaders take about 10-30KB. However, this one shader takes 178KB.
With help of spirv-dis
I looked inside the generated assembly and noticed that vast majority of the op-codes was OpConstant
. It was because I had structs that looked like
QUESTION
I am trying to write a compute shader that raytraces an image, pixels on the right of the yz plane sample from image A, those on the left from image B.
I don't want to have to sample both images so I am trying to use non uniform access by doing:
texture(textures[nonuniformEXT(sampler_id)], vec2(0.5));
and enabling the relevant extension in the shader. This triggers the following validaiton layer error:
...ANSWER
Answered 2021-Aug-24 at 15:35You have to enable the feature at device creation.
You can check for support of the feature by calling vkGetPhysicalDeviceFeatures2 and following the pNext
chain through to a VkPhysicalDeviceVulkan12Features, and checking that shaderSampledImageArrayNonUniformIndexing
member is to VK_TRUE
.
After that when creating the device with vkCreateDevice, inside the pCreateInfo
structure, in the pNext
chain you have to have a VkPhysicalDeviceVulkan12Features with shaderSampledImageArrayNonUniformIndexing
set to VK_TRUE
.
QUESTION
Recently the extension VK_EXT_shader_atomic_float
has been added. I'm trying to figure out how to use it.
I've added the appropriate flag to my shader
...ANSWER
Answered 2021-Aug-06 at 06:52If you go here
https://vulkan.lunarg.com/doc/view/1.2.182.0/linux/1.2-extensions/vkspec.html#spirvenv-capabilities
you can scroll down to the desired extension. In this case it's
QUESTION
Is is possible to have an array of specialization constants such that the glsl code looks similar to the following:
...ANSWER
Answered 2021-Mar-02 at 06:08While Vulkan-flavored GLSL requires that specialization constants are scalars, SPIR-V itself is not so restrictive. You can declare a specialization constant array, just as you can declare a non-specialized constant array. The latter effectively becomes the former upon specialization constants being provided. The interface for specializing constants in Vulkan acknowledges the possibility that different constants being specialized have different sizes, so an array of them would be valid from an API perspective.
But so long as you are stuck with GLSL, you have to live within its limitations. At least, as far as SPIR-V generation is concerned.
However, if you're willing to do some surgery on the SPIR-V after generating it, you can construct what you need. Given the name of the array in question, you can track down the OpName
that matches that array name. Once you find it, you can find the ResultID (every SPIR-V opcode has one) that the OpName
opcode specifies. That opcode should be an OpConstantComposite
.
All you need to do is turn this OpConstantComposite
opcode into OpSpecConstantComposite
. The two codes use the same parameters and so forth, so you're just swapping the opcode out for the other one.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install SPIR-V
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page