Comments (9)
InstanceIndex
is for ray tracing stages only.
To get vertex instance id, you need to use SV_InstanceId semantic:
VertexOut vertexMain(int instanceId : SV_InstanceId)
{
}
from slang.
This make no difference with the current issue.
The problem might be that the compilation uses: -emit-spirv-directly -fvk-use-entrypoint-name
and both vertex and fragment are in the same file.
The validation error appears when the value of instanceID is transmitted to the fragment,
Here is how this looks like, the particleID
need to be made available to the fragment shader. But if particleID
== instanceId
or InstanceIndex()
, there will be an error.
// Per-vertex attributes to be assembled from bound vertex buffers.
struct VSin
{
[[vk::location(0)]] float3 position : POSITION;
[[vk::location(1)]] float2 uv : TEXCOORD;
};
// Output of the vertex shader, and input to the fragment shader.
struct PSin
{
nointerpolation uint id : DRAW_ID;
float2 uv : TEXCOORD;
};
// Output of the vertex shader
struct VSout
{
PSin stage;
float4 sv_position : SV_Position;
};
// Output of the fragment shader
struct PSout
{
float4 color : SV_Target;
};
VSout vertexMain(VSin input, int instanceId: SV_InstanceId)
{
uint particleID = instanceId;
float2 particle = input.position.xy * frameInfo.radius + (particles[particleID].position * frameInfo.scale * 2);
VSout output;
output.sv_position = mul(frameInfo.proj, float4(particle, 0.0, 1.0));
output.stage.uv = input.uv;
output.stage.id = particleID;
return output;
}
// Fragment Shader
[shader("pixel")]
PSout fragmentMain(PSin stage, float4 fragCoord : SV_Position)
{
uint particleID = stage.id;
...
}
In GLSL, to transfer the information, we use the layout, like this:
raster.vert
-----------
layout(location = 0) out vec2 outUv;
layout(location = 1) out flat int outParticleID;
main()
{
...
outParticleID = gl_InstanceIndex;
...
}
raster.frag
-----------
layout(location = 0) in vec2 inUv;
layout(location = 1) in flat int inParticleID;
layout(location = 0) out vec4 outColor;
// inParticleID can be used anywhere
So, the Slang code still current emit the error
[VUID-StandaloneSpirv-Flat-04744] Fragment OpEntryPoint operand 35 with Input interfaces with integer or float type must have a Flat decoration for Entry Point id 165.
%gl_InstanceIndex = OpVariable %_ptr_Input_int Input
Tested with SLANGC version: 1707300689
from slang.
The error is confusing since instanceId is never defined as a fragment shader parameter, but somehow the validation layer complains that it is a fragment shader input.
from slang.
Can you attach the full spirv here?
from slang.
I reverted my changes and back using uint particleID = InstanceIndex();
and the error is gone with SLANGC version: 1707300689
The error is present in 2024.0.3
from slang.
It is incorrect to use InstanceIndex by spirv and Vulkan spec. InstanceIndex map to the built in gl_InstanceID or the InstanceId spirv built in, which is removed from the glsl spec / Vulkan. If you update to latest Vulkan sdk you should see the validation error.
from slang.
On my test machine, I can't reproduce the validation error you mentioned. Probably because we use different sdk version?
from slang.
The sample can be found under https://github.com/nvpro-samples/vk_mini_samples/tree/main/samples/realtime_analysis
The shader is raster.slang.
The Vulkan SDK is 1.3.275
Here is the SPIRV output
raster_slang.spv.zip
from slang.
Will take a look. Thanks!
from slang.
Related Issues (20)
- Prepare code integration plan for hybrid DXIL/IR module support
- Implement remaining part for the replayer consumer
- Missing public headers in our release package.
- Write up proposal for improved AST/IR (de)serialization HOT 1
- Slang build/release
- Slang Brownbag for Autodiff IR Passes
- Handle uninitialization warnings for target switches and intrinsic asm
- Flag for enforcing validation warnings HOT 1
- Slang fails to output a `static` variable in form that is optimized by downstream compiler
- read ms workgraphs spec - come up w/presentation and walk the team through it in brownbag session
- CI Strategy
- Deploy OV unit tests in CI
- Incorporate compile-time benchmarks into CI HOT 1
- Missing cuda prelude for `make_bool2(bool)`
- Enums should be allowed to cast to bool implicitly.
- Stop using SpvStorageClass enums as `AddressSpace` values during spirv legalization.
- Check if an Apple machine can be borrowed HOT 2
- [NumThreads(x,y,z)] should be case-insensitive
- Support "State Objects"
- SPIRV validation error with `Texture<uint8_t>` and other small int types HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slang.