Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
a7fe342
Enabled SPIR-V 1.4 extension and use VK 1.1 if required
SaschaWillems Aug 30, 2025
daed1e4
Add slang shaders for
SaschaWillems Aug 30, 2025
f489823
Add slang shaders for
SaschaWillems Aug 30, 2025
6c93e2a
Add slang shaders for
SaschaWillems Aug 30, 2025
01f58f3
Fix copyright
SaschaWillems Aug 30, 2025
a2257b2
Add slang shaders for
SaschaWillems Aug 30, 2025
b02d478
Fix copyright
SaschaWillems Aug 30, 2025
ff46ff1
Add slang shaders for
SaschaWillems Aug 31, 2025
a18bddd
Add slang shaders for
SaschaWillems Aug 31, 2025
81989aa
Add slang shaders for
SaschaWillems Aug 31, 2025
a890f98
Add slang shaders for
SaschaWillems Aug 31, 2025
9f15aa2
Add slang shaders for
SaschaWillems Aug 31, 2025
3c1e5f4
Update reeadme for shaders
SaschaWillems Aug 31, 2025
eaf4100
Add slang shaders for
SaschaWillems Aug 31, 2025
5e81c99
Add slang shaders to hpp variant
SaschaWillems Aug 31, 2025
27acadf
Add slang shaders for
SaschaWillems Sep 1, 2025
432bc6d
Add slang shaders for
SaschaWillems Sep 2, 2025
07d6838
Add slang shaders for
SaschaWillems Sep 2, 2025
003f1e6
Add slang shaders for
SaschaWillems Sep 2, 2025
ef4a176
Add slang shaders for
SaschaWillems Sep 3, 2025
4e15a75
Add slang shaders for
SaschaWillems Sep 3, 2025
d16a26f
Add slang shaders for
SaschaWillems Sep 3, 2025
4909393
Fix copyright
SaschaWillems Sep 3, 2025
6eba1f6
Skip Slang offline compilation on MacOS/iOS when run through CI
SaschaWillems Sep 3, 2025
0bb37bc
Fix copyright
SaschaWillems Sep 3, 2025
e318e24
Add slang shaders for
SaschaWillems Sep 5, 2025
448cee6
Fix lighting for gshader_to_mshader
SaschaWillems Sep 6, 2025
1dc4d1a
Add slang shaders for
SaschaWillems Sep 6, 2025
ef15575
Fix descriptor indexing not properly displaying right side of screen …
SaschaWillems Sep 6, 2025
0f8d412
Add offline compiled SPIR-V files for slang shaders
SaschaWillems Sep 6, 2025
b26031d
Enalbe VK_KHR_Shader_Draw_Parameters when using Slang
SaschaWillems Sep 6, 2025
51a19ac
Add slang shaders for
SaschaWillems Sep 6, 2025
c12102d
Add slang shaders for
SaschaWillems Sep 7, 2025
830e264
Merge branch 'main' into shaders_09_2025
SaschaWillems Sep 8, 2025
7e88e7e
Recompile Slang shader with updated compiler version
SaschaWillems Sep 20, 2025
d22353b
Fix ambient factor
SaschaWillems Sep 20, 2025
c4bc0d6
Clamp specular contribution
SaschaWillems Sep 20, 2025
20a1c7d
Fix copyright
SaschaWillems Sep 20, 2025
0381a5e
Enable device extensions required for proper Slang support
SaschaWillems Sep 20, 2025
43b0091
Enable feature required when using Slang
SaschaWillems Sep 20, 2025
0750f19
Add CMake option to disable Slang shader compilation
SaschaWillems Sep 20, 2025
df272dd
Add note on Slang compiler requirements
SaschaWillems Sep 20, 2025
3e8347e
Fix normal calculation
SaschaWillems Sep 22, 2025
018f1b1
Check if required feature is supported and if not exit gracefully
SaschaWillems Oct 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bldsys/cmake/global_options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ set(VKB_WSI_SELECTION "XCB" CACHE STRING "Select WSI target (XCB, XLIB, WAYLAND,
set(VKB_CLANG_TIDY OFF CACHE STRING "Use CMake Clang Tidy integration")
set(VKB_CLANG_TIDY_EXTRAS "-header-filter=framework,samples,app;-checks=-*,google-*,-google-runtime-references;--fix;--fix-errors" CACHE STRING "Clang Tidy Parameters")
set(VKB_PROFILING OFF CACHE BOOL "Enable Tracy profiling")
set(VKB_SKIP_SLANG_SHADER_COMPILATION OFF CACHE BOOL "Skips compilation for Slang shader")

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "bin/${CMAKE_BUILD_TYPE}/${TARGET_ARCH}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "lib/${CMAKE_BUILD_TYPE}/${TARGET_ARCH}")
Expand Down
3 changes: 3 additions & 0 deletions bldsys/cmake/sample_helper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ endif()
if (($ENV{CI} MATCHES true) AND ((CMAKE_SYSTEM_NAME MATCHES "Darwin") OR (CMAKE_SYSTEM_NAME MATCHES "iOS")))
set(SLANG_SKIP_COMPILE true)
endif()
if(VKB_SKIP_SLANG_SHADER_COMPILATION)
set(SLANG_SKIP_COMPILE true)
endif()
if(NOT SLANG_SKIP_COMPILE AND Vulkan_slang_EXECUTABLE AND DEFINED SHADERS_SLANG)
set(OUTPUT_FILES "")
set(SLANG_TARGET_NAME ${PROJECT_NAME}-SLANG)
Expand Down
8 changes: 8 additions & 0 deletions docs/build.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ Tracy is not currently enabled for Android builds. In the future, we may add sup

*Default:* `OFF`

=== VKB_SKIP_SLANG_SHADER_COMPILATION

By default, Slang shaders are compiled if a Slang compiler is found on the system. In cases where this is undesirable, set this to `OFF` to disable Slang shader compilation.

You can still select Slang as a shading language target for the samples since Slang shaders are included as precompiled SPIR-V files.

*Default:* `OFF`

== Quality Assurance

We use a small set of tools to provide a level of quality to the project.
Expand Down
8 changes: 8 additions & 0 deletions samples/api/hello_triangle/hello_triangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,14 @@ void HelloTriangle::init_device()

// Since this sample has visual output, the device needs to support the swapchain extension
std::vector<const char *> required_device_extensions{VK_KHR_SWAPCHAIN_EXTENSION_NAME};
// Shaders generated by Slang require a certain SPIR-V environment that can't be satisfied by Vulkan 1.0, so we need to expliclity up that to at least 1.1 and enable some required extensions
if (get_shading_language() == vkb::ShadingLanguage::SLANG)
{
required_device_extensions.push_back(VK_KHR_SPIRV_1_4_EXTENSION_NAME);
required_device_extensions.push_back(VK_KHR_SHADER_FLOAT_CONTROLS_EXTENSION_NAME);
required_device_extensions.push_back(VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME);
}

if (!validate_extensions(required_device_extensions, device_extensions))
{
throw std::runtime_error("Required device extensions are missing.");
Expand Down
5 changes: 5 additions & 0 deletions samples/extensions/color_write_enable/color_write_enable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ void ColorWriteEnable::request_gpu_features(vkb::core::PhysicalDeviceC &gpu)
{
gpu.get_mutable_requested_features().independentBlend = true;
}

if (get_shading_language() == vkb::ShadingLanguage::SLANG)
{
gpu.get_mutable_requested_features().shaderStorageImageReadWithoutFormat = true;
}
}

void ColorWriteEnable::setup_descriptor_pool()
Expand Down
2 changes: 2 additions & 0 deletions shaders/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ This folder contains the textual shaders for the samples. All samples come with

The samples load offline compiled SPIR-V variants of the GLSL/Slang/HLSL shaders. If you have the appropriate compiler installed, e.g. via the LunarG VUlkan SDK, shaders will be automatically compiled when building the samples project.

**Note for compiling Slang shaders**: The minimum required version of the Slang compiler is `2025.16.1`. Older versions might have issues compiling shaders or may result in invalid SPIR-V. It's advised to use the latest version from link:https://github.com/shader-slang/slang/releases[here].

== Selecting shading language

To select a shading language, use the `--shading-language` argument followed by the shading language `glsl`, `slang` or `hlsl`. Samples default to `glsl`.
Expand Down
Binary file not shown.
Binary file modified shaders/compute_nbody/slang/particle.vert.spv
Binary file not shown.
Binary file modified shaders/compute_nbody/slang/particle_calculate.comp.spv
Binary file not shown.
Binary file modified shaders/compute_nbody/slang/particle_integrate.comp.spv
Binary file not shown.
5 changes: 3 additions & 2 deletions shaders/conditional_rendering/hlsl/model.vert.hlsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2024, Sascha Willems
/* Copyright (c) 2024-2025, Sascha Willems
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -49,7 +49,8 @@ VSOutput main(VSInput input)
{
VSOutput output = (VSOutput) 0;
float4 localPos = mul(ubo.view, mul(push_constants.model, float4(input.Pos, 1.0)));
output.Normal = input.Normal;
float3x3 nMat = (float3x3) mul(ubo.view, push_constants.model);
output.Normal = mul(nMat, input.Normal);
output.Color = push_constants.color.rgb;
output.Pos = mul(ubo.projection, localPos);
const float3 lightPos = float3(10.0, -10.0, 10.0);
Expand Down
Binary file modified shaders/conditional_rendering/hlsl/model.vert.spv
Binary file not shown.
2 changes: 1 addition & 1 deletion shaders/conditional_rendering/slang/model.frag.slang
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ float4 main(VSOutput input)
float3 L = normalize(input.LightVec);
float3 V = normalize(input.ViewVec);
float3 R = reflect(-L, N);
float3 ambient = float3(0.1);
float3 ambient = float3(0.25);
float3 diffuse = max(dot(N, L), 0.0) * float3(1.0);
float3 specular = pow(max(dot(R, V), 0.0), 16.0) * float3(0.75);
return float4((ambient + diffuse) * input.Color.rgb + specular, 1.0);
Expand Down
Binary file modified shaders/conditional_rendering/slang/model.frag.spv
Binary file not shown.
3 changes: 2 additions & 1 deletion shaders/conditional_rendering/slang/model.vert.slang
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ VSOutput main(VSInput input, uniform float4x4 modelMatrix, uniform float4 modelC
{
VSOutput output;
float4 localPos = mul(ubo.view, mul(modelMatrix, float4(input.Pos, 1.0)));
output.Normal = input.Normal;
float3x3 nMat = (float3x3)mul(ubo.view, modelMatrix);
output.Normal = mul(nMat, input.Normal);
output.Color = modelColor.rgb;
output.Pos = mul(ubo.projection, localPos);
const float3 lightPos = float3(10.0, -10.0, 10.0);
Expand Down
Binary file modified shaders/conditional_rendering/slang/model.vert.spv
Binary file not shown.
Binary file modified shaders/conservative_rasterization/slang/triangle.vert.spv
Binary file not shown.
Binary file modified shaders/descriptor_buffer_basic/slang/cube.vert.spv
Binary file not shown.
Binary file modified shaders/dynamic_line_rasterization/slang/base.frag.spv
Binary file not shown.
Binary file modified shaders/dynamic_line_rasterization/slang/base.vert.spv
Binary file not shown.
Binary file modified shaders/dynamic_line_rasterization/slang/grid.vert.spv
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified shaders/dynamic_rendering/slang/gbuffer.frag.spv
Binary file not shown.
Binary file modified shaders/dynamic_rendering/slang/gbuffer.vert.spv
Binary file not shown.
Binary file modified shaders/dynamic_rendering_local_read/slang/composition.frag.spv
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified shaders/dynamic_uniform_buffers/slang/base.vert.spv
Binary file not shown.
Binary file modified shaders/fragment_shading_rate/slang/scene.frag.spv
Binary file not shown.
Binary file modified shaders/fragment_shading_rate/slang/scene.vert.spv
Binary file not shown.
Binary file modified shaders/graphics_pipeline_library/slang/shared.vert.spv
Binary file not shown.
Binary file modified shaders/gshader_to_mshader/slang/gshader_to_mshader.mesh.spv
Binary file not shown.
5 changes: 3 additions & 2 deletions shaders/hdr/hlsl/gbuffer.frag.hlsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2024, Sascha Willems
/* Copyright (c) 2024-2025, Sascha Willems
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -97,7 +97,8 @@ FSOutput main(VSOutput input)
fresnel *= (1.0 - F0);
fresnel += F0;

float spec = (fresnel * geoAtt) / (NdotV * NdotL * 3.14);
// Note: clamp to zero to mitigate any divide by zero
float spec = max((fresnel * geoAtt) / (NdotV * NdotL * 3.14), 0.0);

color = textureEnvMap.Sample(samplerEnvMap, reflect(-wViewVec, wNormal));

Expand Down
Binary file modified shaders/hdr/hlsl/gbuffer.frag.spv
Binary file not shown.
3 changes: 2 additions & 1 deletion shaders/hdr/slang/gbuffer.frag.slang
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ FSOutput main(VSOutput input)
fresnel *= (1.0 - F0);
fresnel += F0;

float spec = (fresnel * geoAtt) / (NdotV * NdotL * 3.14);
// Note: clamp to zero to mitigate any divide by zero
float spec = max((fresnel * geoAtt) / (NdotV * NdotL * 3.14), 0.0);

color = samplerEnvMap.Sample(reflect(-wViewVec, wNormal));

Expand Down
Binary file modified shaders/hdr/slang/gbuffer.frag.spv
Binary file not shown.
Binary file modified shaders/logic_op_dynamic_state/slang/background.vert.spv
Binary file not shown.
Binary file modified shaders/logic_op_dynamic_state/slang/baseline.frag.spv
Binary file not shown.
Binary file modified shaders/logic_op_dynamic_state/slang/baseline.vert.spv
Binary file not shown.
Binary file modified shaders/mesh_shading/slang/ms.mesh.spv
Binary file not shown.
Binary file modified shaders/open_cl_interop/slang/texture_display.vert.spv
Binary file not shown.
Binary file modified shaders/patch_control_points/slang/tess.tesc.spv
Binary file not shown.
Binary file modified shaders/patch_control_points/slang/tess.tese.spv
Binary file not shown.
Binary file modified shaders/patch_control_points/slang/tess.vert.spv
Binary file not shown.
Binary file modified shaders/profiles/slang/profiles.frag.spv
Binary file not shown.
Binary file modified shaders/profiles/slang/profiles.vert.spv
Binary file not shown.
Binary file modified shaders/push_descriptors/slang/cube.vert.spv
Binary file not shown.
Binary file modified shaders/ray_queries/slang/ray_shadow.frag.spv
Binary file not shown.
Binary file modified shaders/ray_queries/slang/ray_shadow.vert.spv
Binary file not shown.
Binary file modified shaders/ray_tracing_basic/slang/closesthit.rchit.spv
Binary file not shown.
Binary file modified shaders/ray_tracing_basic/slang/miss.rmiss.spv
Binary file not shown.
Binary file modified shaders/ray_tracing_basic/slang/raygen.rgen.spv
Binary file not shown.
Binary file modified shaders/ray_tracing_extended/slang/closesthit.rchit.spv
Binary file not shown.
Binary file modified shaders/ray_tracing_extended/slang/miss.rmiss.spv
Binary file not shown.
Binary file modified shaders/ray_tracing_extended/slang/raygen.rgen.spv
Binary file not shown.
Binary file modified shaders/ray_tracing_position_fetch/slang/closesthit.rchit.spv
Binary file not shown.
Binary file modified shaders/ray_tracing_position_fetch/slang/miss.rmiss.spv
Binary file not shown.
Binary file modified shaders/ray_tracing_position_fetch/slang/raygen.rgen.spv
Binary file not shown.
Binary file not shown.
Binary file modified shaders/shader_debugprintf/slang/scene.frag.spv
Binary file not shown.
Binary file modified shaders/shader_debugprintf/slang/scene.vert.spv
Binary file not shown.
Binary file modified shaders/sparse_image/slang/sparse.frag.spv
Binary file not shown.
Binary file modified shaders/sparse_image/slang/sparse.vert.spv
Binary file not shown.
Binary file modified shaders/synchronization_2/slang/particle.vert.spv
Binary file not shown.
Binary file modified shaders/synchronization_2/slang/particle_calculate.comp.spv
Binary file not shown.
Binary file modified shaders/synchronization_2/slang/particle_integrate.comp.spv
Binary file not shown.
Binary file modified shaders/terrain_tessellation/slang/skysphere.vert.spv
Binary file not shown.
Binary file modified shaders/terrain_tessellation/slang/terrain.frag.spv
Binary file not shown.
Binary file modified shaders/terrain_tessellation/slang/terrain.tesc.spv
Binary file not shown.
Binary file modified shaders/terrain_tessellation/slang/terrain.tese.spv
Binary file not shown.
Binary file modified shaders/texture_compression_basisu/slang/texture.vert.spv
Binary file not shown.
Binary file modified shaders/texture_mipmap_generation/slang/texture.frag.spv
Binary file not shown.
Binary file modified shaders/texture_mipmap_generation/slang/texture.vert.spv
Binary file not shown.
Binary file modified shaders/vertex_dynamic_state/slang/gbuffer.frag.spv
Binary file not shown.
Binary file modified shaders/vertex_dynamic_state/slang/gbuffer.vert.spv
Binary file not shown.
Loading