shader-slang / slang

Making it easier to work with shaders
MIT License
1.79k stars 160 forks source link

Vertex entrypoints missing from capability system? #4317

Closed natevm closed 3 weeks ago

natevm commented 4 weeks ago

Updating to the most recent version of slang, I seem to now get odd compatibility errors for exclusively "vertex" entrypoint types.

Here's some example code, meant to help rasterize an ImGui window to a framebuffer:

#include "sharedCode.h"

[[vk::push_constant]] PushConstants pc;

struct BGVertexStageOutput {
  float4 position : SV_POSITION;
};

layout(binding = 0) ConstantBuffer<BackgroundData> bgRecord;

[shader("vertex")]
BGVertexStageOutput backgroundVertex(uint vertexID : SV_VertexID) {
  BGVertexStageOutput output;
  float3 position = gprt::load<float3>(bgRecord.vertex, vertexID);
  output.position = float4(position, 1.f);
  return output;
}

[shader("fragment")]
float4 backgroundPixel(float4 position : SV_POSITION) {
  int2 pixelID = int2(position.xy);
  int pattern = (pixelID.x / 32) ^ (pixelID.y / 32);
  float3 color = bool(pattern & 1) ? bgRecord.color1 : bgRecord.color0;
  return float4(color, 1.0f);
}

All entrypoints with [shader("vertex")] now throw an error similar to the following:

error 36107: entrypoint 'backgroundVertex' requires capability 'textualTarget + hlsl + sm_4_0 + callable | textualTarget + hlsl + sm_4_0 + fragment | textualTarget + hlsl + sm_4_0 + compute | textualTarget + hlsl + sm_4_0 + anyhit | textualTarget + hlsl + sm_4_0 + closesthit | textualTarget + hlsl + sm_4_0 + miss | textualTarget + hlsl + sm_4_0 + raygen | textualTarget + hlsl + sm_4_0 + intersection | textualTarget + glsl + glsl_spirv_1_0 + callable + GL_ARB_sparse_texture_clamp + GL_EXT_samplerless_texture_functions | textualTarget + glsl + glsl_spirv_1_0 + fragment + GL_ARB_sparse_texture_clamp + GL_EXT_samplerless_texture_functions | textualTarget + glsl + glsl_spirv_1_0 + compute + GL_ARB_sparse_texture_clamp + GL_EXT_samplerless_texture_functions | textualTarget + glsl + glsl_spirv_1_0 + anyhit + GL_ARB_sparse_texture_clamp + GL_EXT_samplerless_texture_functions | textualTarget + glsl + glsl_spirv_1_0 + closesthit + GL_ARB_sparse_texture_clamp + GL_EXT_samplerless_texture_functions | textualTarget + glsl + glsl_spirv_1_0 + miss + GL_ARB_sparse_texture_clamp + GL_EXT_samplerless_texture_functions | textualTarget + glsl + glsl_spirv_1_0 + raygen + GL_ARB_sparse_texture_clamp + GL_EXT_samplerless_texture_functions | textualTarget + glsl + glsl_spirv_1_0 + intersection + GL_ARB_sparse_texture_clamp + GL_EXT_samplerless_texture_functions | textualTarget + cpp + callable | textualTarget + cpp + fragment | textualTarget + cpp + compute | textualTarget + cpp + anyhit | textualTarget + cpp + closesthit | textualTarget + cpp + miss | textualTarget + cpp + raygen | textualTarget + cpp + intersection | textualTarget + cuda + cuda_sm_1_0 + cuda_sm_2_0 + callable | textualTarget + cuda + cuda_sm_1_0 + cuda_sm_2_0 + fragment | textualTarget + cuda + cuda_sm_1_0 + cuda_sm_2_0 + compute | textualTarget + cuda + cuda_sm_1_0 + cuda_sm_2_0 + anyhit | textualTarget + cuda + cuda_sm_1_0 + cuda_sm_2_0 + closesthit | textualTarget + cuda + cuda_sm_1_0 + cuda_sm_2_0 + miss | textualTarget + cuda + cuda_sm_1_0 + cuda_sm_2_0 + raygen | textualTarget + cuda + cuda_sm_1_0 + cuda_sm_2_0 + intersection | textualTarget + metal + callable | textualTarget + metal + fragment | textualTarget + metal + compute | textualTarget + metal + anyhit | textualTarget + metal + closesthit | textualTarget + metal + miss | textualTarget + metal + raygen | textualTarget + metal + intersection | spirv_1_0 + callable + SPV_GOOGLE_user_type + spvImageQuery + spvImageGatherExtended + spvMinLod | spirv_1_0 + fragment + SPV_GOOGLE_user_type + spvImageQuery + spvImageGatherExtended + spvMinLod | spirv_1_0 + compute + SPV_GOOGLE_user_type + spvImageQuery + spvImageGatherExtended + spvMinLod | spirv_1_0 + anyhit + SPV_GOOGLE_user_type + spvImageQuery + spvImageGatherExtended + spvMinLod | spirv_1_0 + closesthit + SPV_GOOGLE_user_type + spvImageQuery + spvImageGatherExtended + spvMinLod | spirv_1_0 + miss + SPV_GOOGLE_user_type + spvImageQuery + spvImageGatherExtended + spvMinLod | spirv_1_0 + raygen + SPV_GOOGLE_user_type + spvImageQuery + spvImageGatherExtended + spvMinLod | spirv_1_0 + intersection + SPV_GOOGLE_user_type + spvImageQuery + spvImageGatherExtended + spvMinLod', which is incompatible with the current compilation target 'spirv_1_0 + spirv_1_1 + spirv_1_2 + spirv_1_3 + spirv_1_4 + spirv_1_5 + vertex + SPV_KHR_fragment_shader_barycentric + SPV_EXT_fragment_fully_covered + SPV_EXT_descriptor_indexing + SPV_EXT_shader_atomic_float_add + SPV_EXT_shader_atomic_float16_add + SPV_EXT_shader_atomic_float_min_max + SPV_EXT_mesh_shader + SPV_KHR_ray_tracing + SPV_KHR_ray_query + SPV_GOOGLE_user_type'

It seems a bit like "vertex" is missing from the list of entrypoint names. I see "fragment" in the above error message, but not vertex.

csyonghe commented 4 weeks ago

@ArielG-NV Looking at our capdef file, it seems that we have

alias raytracingstages_fragment = raytracing_stages | fragment;
alias raytracingstages_compute = raytracing_stages | compute;
alias raytracingstages_compute_amplification_mesh = raytracingstages_compute | amplification_mesh;
alias raytracingstages_compute_fragment = raytracing_stages | compute_fragment;
alias raytracingstages_compute_fragment_geometry_vertex = raytracing_stages | compute_fragment_geometry_vertex;

And many UAV functions are defined for these stages only. This is wrong. I don't think there are any reasons vertex/mesh/amplification and tessellation shaders should be excluded from things like RWStructuredBuffer or Texture sampling intrinsics. Let's remove all of these stage capability aliases and make sure those intrinsics are supported for ALL stages.

For example,

alias appendstructuredbuffer = sm_5_0 + raytracingstages_compute_fragment;
...
alias byteaddressbuffer = sm_4_0;
alias byteaddressbuffer_rw = sm_4_0 + raytracingstages_compute_fragment;
alias consumestructuredbuffer = sm_5_0 + raytracingstages_compute_fragment;

I don't think this is true. Vertex/Mesh/Amplification/Domain/Hull shader can use rw/append/consume structured buffer.

ArielG-NV commented 4 weeks ago

I will remove these

most language concepts are not clear on what works, I believe there may have to be some trial and error here at some point

example of docs being not updated

ArielG-NV commented 4 weeks ago

@natevm to temporarily work around this issue, please use the following compile option: -ignore-capabilities