-
Notifications
You must be signed in to change notification settings - Fork 654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Redesign functionality of GLSLcompiler class #655
WIP: Redesign functionality of GLSLcompiler class #655
Conversation
Not sure if this should be a separate sample. Imo it would be better if this was an addition to the existing basic raytracing sample, e.g. maybe a compile time define so people can toggle between GLSL and HLSL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to run hlsl_shaders, but get the following error:
[error] [framework\common\vk_common.cpp:386] Failed to compile shader, Error: ERROR: #version: ES shaders for SPIR-V require version 310 or higher
ERROR: :20: '' : syntax error, unexpected LEFT_BRACKET
ERROR: 2 compilation errors. No code generated.
Would I need to update anything on my end?
Besides that: is there any means to switch between HSLS and GLSL now?
0dfc743
to
e9ba043
Compare
358c127
to
f8d8ba0
Compare
framework/shader_compiler.h
Outdated
@@ -33,7 +33,7 @@ namespace vkb | |||
{ | |||
/// Helper class to generate SPIRV code from GLSL source |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the compiler now being able to support other languages, the comments need to be changed too. They still refer to GLSL only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That comment still needs to be updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
@@ -54,19 +54,21 @@ class GLSLCompiler | |||
static void reset_target_environment(); | |||
|
|||
/** | |||
* @brief Compiles GLSL to SPIRV code | |||
* @brief Compiles GLSL/HLSL to SPIRV code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this correct? If so, what tool is used to compile HLSL tp SPIR-V (dxc)? Or does it simply load offline compiled SPV? If it's the latter, the comment needs to be changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Glslang is used for compilation at runtime and for offline compilation DirectX Shader Compiler is being used.
@@ -410,7 +410,7 @@ void HlslShaders::prepare_pipelines() | |||
|
|||
// Load shaders | |||
std::array<VkPipelineShaderStageCreateInfo, 2> shader_stages{}; | |||
shader_stages[0] = load_hlsl_shader("hlsl_shaders/hlsl_shader.vert", VK_SHADER_STAGE_VERTEX_BIT); | |||
shader_stages[0] = load_shader("hlsl_shaders/hlsl_shader.vert", VK_SHADER_STAGE_VERTEX_BIT, vkb::ShaderSourceLanguage::VK_HLSL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change doesn't seem correct. This is a standalone sample that is supposed to use it's own hlsl loading function, but this line would use the one from the framework instead. The change should be reverted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still needs to be reverted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted
@@ -1,4 +1,4 @@ | |||
/* Copyright (c) 2021-2023, NVIDIA CORPORATION. All rights reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's okay to replace the existing copyright. If you add to a file, please append your copyright instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still open. This sample was done by Andreas (Nvidia).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to revert fix, it caused CI checks for copyrights to fail
I did a first quick review and added a few comments. One thing I'm not sure about is the direction of this PR. On one hand it seems to add HLSL support to the framework's compiler, but only through glslang, which is very very limited. And on the other hand it also adds direct loading of SPIR-V for e.g. the basic ray tracing sample. Tbh. I think we should discuss a different approach that better fits our framework strategy. We've been talking about HLSL support for quite some time and one option would be adding direct SPIR-V loading to the shader compiler (as a derived class maybe) so we can add HLSL to all samples with offline compiled SPIR-V files via DXC. The goal is also to not have to change every sample but to support shader language selection at framework level instead. And imo we should move into that direction. I appreciate the work put in this PR, but it feels a bit like a stop gap towards our actual goal and we might revert a large part of that PR in the future. I'll wait for other opinions, and I'd happily discuss this in the next samples call :) |
Hi @SaschaWillems, |
Tbh I'm not sure if that's the right approach. HLSL in glslang is very limited and the actual reference compiler is DXC. So if we want to add HLSL support we should either integrate DXC or offline compile HLSL to SPIR-V and just use that. |
Update README fix validation layers errors
…e the same as in setup_render_pass
Remove hlsl_raytracing_basic
to shader_compiler - Add ShaderSourceLanguage enum - Add src_language parameter to load_shader for support different shader languages - Change headers and few names in existing samples
to keep the order of arguments more meaningful - Add switch in UI to changing shaders language in raytracing_basic sample
fix typo bring HPP load_shader() and update_render_pass_flags() in line with non-hpp version use a single compile_to_spirv() with default source language rather than have 2 flavours
Signed-off-by: pawel-jastrzebski-mobica <pawel.jastrzebski@mobica.com>
docs/build.adoc
Outdated
@@ -208,13 +212,20 @@ build\windows\app\bin\Release\AMD64\vulkan_samples.exe | |||
* C{pp}14 Compiler | |||
* <<cmake-options,CMake Options>> | |||
* <<3d-models,3D models>> | |||
* Vulkan SDK |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be reverted? We don't require the SDK to build our samples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted
docs/build.adoc
Outdated
@@ -243,11 +254,18 @@ cmake --build build/linux --config Release --target vulkan_samples -j$(nproc) | |||
* https://vulkan.lunarg.com/doc/sdk/latest/mac/getting_started.html[Vulkan SDK] `./install_vulkan.py` | |||
* <<cmake-options,CMake Options>> | |||
* <<3d-models,3D models>> | |||
* Vulkan SDK |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted
@SaschaWillems : do you want to remove the whole off-line shader compilation functionality from the PR? |
Signed-off-by: pawel-jastrzebski-mobica <pawel.jastrzebski@mobica.com>
Nope, having a way to compile the HLSL shaders vie the build system is fine. Problem is where those projects are put in the project structure. They appear at the top level, but should instead be part of the sample itself. |
unnecessary spv files.
from add_custom_command to execute_process.
for hpp_hello_triangle.cpp
I changed way of using dxc for offline compilation. I had problem with add_custom_target/add_custom_command that created targets in top level view of Visual Studio solution, I was only found way how to move it into other folders, but couldn't move it under other targets like specific samples. From what I red and understood, this is most probably not possible. The difference in how it works now is rather not significant, before HLSL shaders were compiled at the start of executing build command, e.g. "cmake --build build/linux --config Release --target vulkan_samples -j$(nproc)" I also updated cmake to only compile shaders if dxc executable is found, by searching for it under VULKAN_SDK path. There is still glslang used for compilation HLSL shaders at sample runtime, and rather big modification of hpp_hello_triangle.cpp which I'm not sure if is needed. There is still some work left to do, mostly stylistic like naming scheme and directories/folders paths, but core functionality of this PR that is compiling HLSL shaders seems to be done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you undo the addition of HLSL shaders for the ray tracing basic sample. I'm already working on adding actual HLSL shaders, and to clearly divide work this PR should only add the offline compilation part.
@SaschaWillems As we discussed that we should only add offline compilation for HLSL, I've created created new PR that only do this, as it seemed easier and less misguiding when looking at this PR title. |
Closing this as we're going a different direction |
Description
Redesign functionality of GLSLcompiler class. Change name of this class to ShaderCompiler. Add support for HLSL, GLSL and SPV files.
General Checklist:
Please ensure the following points are checked:
Sample Checklist
If your PR contains a new or modified sample, these further checks must be carried out in addition to the General Checklist: