GithubHelp home page GithubHelp logo

Comments (9)

csyonghe avatar csyonghe commented on July 27, 2024

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.

mklefrancois avatar mklefrancois commented on July 27, 2024

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.

csyonghe avatar csyonghe commented on July 27, 2024

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.

csyonghe avatar csyonghe commented on July 27, 2024

Can you attach the full spirv here?

from slang.

mklefrancois avatar mklefrancois commented on July 27, 2024

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.

csyonghe avatar csyonghe commented on July 27, 2024

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.

csyonghe avatar csyonghe commented on July 27, 2024

On my test machine, I can't reproduce the validation error you mentioned. Probably because we use different sdk version?

from slang.

mklefrancois avatar mklefrancois commented on July 27, 2024

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.

csyonghe avatar csyonghe commented on July 27, 2024

Will take a look. Thanks!

from slang.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.