slang
slang copied to clipboard
glslang compiler error
$ slangc -v
v0.19.21⏎
Compiling the following file with slangc -profile glsl_450 shaders.slang -entry compute_main -stage compute -o compute.spv
causes the error:
glslang: shaders.slang(33): error : 'uint8_t' : undeclared identifier
glslang: shaders.slang(33): error : '' : compilation terminated
glslang: note : ERROR: 2 compilation errors. No code generated.
Where shaders.slang
is this file:
// (Descriptor Binding, Descriptor Set)
[vk::binding(0, 0)]
RWTexture2D<float4> uav;
[vk::binding(1, 0)]
RWStructuredBuffer<Cell> pixel_buffer_cells;
struct Pixel {
uint32_t palette_index;
uint32_t depth;
// uint16_t empty_data; // Padding.
uint32_t screen_x;
uint32_t screen_y;
// float3 normals;
}
struct Cell {
Pixel pixels[8 * 8 * 8];
}
struct GpuPixelBuffer {
Cell cells[38 * 60];
}
[shader("compute")]
[numthreads(8,8,1)]
void compute_main(
uint3 group_id : SV_GroupID,
uint3 group_thread_id : SV_GroupThreadID,
uint3 dispatch_thread_id : SV_DispatchThreadID,
uint group_index : SV_GroupIndex) {
if (dispatch_thread_id.x > 480 || dispatch_thread_id.y > 300) {
// return;
}
uint8_t min_depth = 255;
uint current_cell = group_id.x + group_id.y * 60;
uint nearest_pixel_index;
// Iterate through all pixels in the cell.
for (uint i = 0; i < 8 * 8 * 8; i++) {
Pixel current_pixel = pixel_buffer_cells[current_cell].pixels[i];
// 255 is a value that cannot be used safely anyways, so it is a sentinel.
if (current_pixel.depth == 255) {
// break;
}
// if (current_pixel.screen_x
// == dispatch_thread_id.x
// && current_pixel.screen_y
// == dispatch_thread_id.y) {
if (current_pixel.depth < min_depth) {
min_depth = current_pixel.depth;
nearest_pixel_index = i;
}
// }
}
Pixel nearest_pixel = pixel_buffer_cells[current_cell]
.pixels[nearest_pixel_index];
if (nearest_pixel.palette_index == 0) {
uav[dispatch_thread_id.xy] = float4(0.9,1,0,1);
} else if (nearest_pixel.palette_index == 1) {
uav[dispatch_thread_id.xy] = float4(0.65f,0,0,1);
} else if (nearest_pixel.palette_index == 2) {
uav[dispatch_thread_id.xy] = float4(0.3f,0,1,1);
} else {
uav[dispatch_thread_id.xy] = float4(0,0,0,1);
}
}
// Output from vertex shader.
struct VertexStageOutput {
float4 sv_position : SV_Position;
__init(float4 position) {
sv_position = position;
}
};
[shader("vertex")]
VertexStageOutput vertex_main(uint vertex_id : SV_VertexID) {
// Transfom the first three verts into a triangle.
uint2 out_uv = float2((vertex_id << 1) & 2, vertex_id & 2);
float4 sv_position = float4(out_uv * 2.0 - 1.0, 0.0, 1.0) ;
return VertexStageOutput(sv_position);
}
[shader("fragment")]
float4 fragment_main(VertexStageOutput vertex, float4 pixel_coord : SV_Position) : SV_Target {
float4 color;
// float4 color = float4(1,1,1,1);
color = uav.Load(pixel_coord.xy);
return color;
}
I reproduced this error twice.
Thanks for providing a repro for the issue. I haven't had a chance to debug this yet, but from the error messages it seems that the GLSL output that Slang is producing in translation and then feeding to glslang is using uint8_t
without enabling the appropriate GL/VK extension(s) that the type needs.
If it would be appropriate, you might consider changing the min_depth
variable to use a different type and see if that is an effective workaround.
I will try to get to actually debugging and fixing the issue when I get a chance (probably not until next week, unless you can highlight the priority/importance of getting a fix ASAP), or I'd be happy to accept a PR with a fix if anybody in the community wants to help.
This doesn't block my project, so please don't feel rushed on my account.