summaryrefslogtreecommitdiff
path: root/graphics/shaderc/fix-glslang-build.patch
blob: bbea79b9a6d5b02b2d99bd5a5f3f3f89317f4ebf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
From ccf948e975e0ddd08f07c5244f23f3158d65ed7b Mon Sep 17 00:00:00 2001
From: David Neto <dneto@google.com>
Date: Wed, 21 Aug 2019 15:56:13 -0400
Subject: [PATCH] Force Glslang to support HLSL in its interface

Fixes a compilation problem introduced by recent
Glslang changes to optionally build into a very small
GLSL-only binary.

Also fix test cases to have set and binding layout qualifiers on
buffers when compiling for Vulkan.  This rule is now enforced by
Glslang.
---
 README.md                                | 8 ++++++++
 glslc/test/option_dash_fhlsl_offsets.py  | 1 +
 libshaderc/src/common_shaders_for_test.h | 1 +
 libshaderc_util/CMakeLists.txt           | 3 +++
 libshaderc_util/src/compiler_test.cc     | 1 +
 5 files changed, 14 insertions(+)

diff --git a/README.md b/README.md
index e2c33555..172c8e04 100644
--- a/README.md
+++ b/README.md
@@ -93,6 +93,14 @@ Shaderc into.
 
 The rest of this section describes how to build Shaderc from sources.
 
+Note: Shaderc assumes Glslang supports HLSL compilation.  The instructions
+below assume you're building Glslang from sources, and in a subtree
+of `shaderc/third_party`.  In that scenario, Glslang's HLSL support
+is automatically enabled.  Shaderc also can be built using a Glslang
+from outside the `shaderc/third_party` tree.  In that case you must
+ensure that that external Glslang is built with HLSL functionality.
+See Glslang's `ENABLE_HLSL` CMake setting.)
+
 1) Check out the source code:
 
 ```sh
diff --git a/glslc/test/option_dash_fhlsl_offsets.py b/glslc/test/option_dash_fhlsl_offsets.py
index 631a2754..4682d310 100644
--- a/glslc/test/option_dash_fhlsl_offsets.py
+++ b/glslc/test/option_dash_fhlsl_offsets.py
@@ -19,6 +19,7 @@
 
 # A GLSL shader with uniforms without explicit bindings.
 GLSL_SHADER = """#version 450
+  layout(set=0, binding=0)
   buffer B { float x; vec3 y; } my_ssbo;
   void main() {
     my_ssbo.x = 1.0;
diff --git a/libshaderc/src/common_shaders_for_test.h b/libshaderc/src/common_shaders_for_test.h
index 512742a3..c87ed76f 100644
--- a/libshaderc/src/common_shaders_for_test.h
+++ b/libshaderc/src/common_shaders_for_test.h
@@ -293,6 +293,7 @@ const char kShaderWithUniformsWithoutBindings[] =
 // A GLSL vertex shader with a weirdly packed block.
 const char kGlslShaderWeirdPacking[] =
     R"(#version 450
+       layout(set=0, binding=0)
        buffer B { float x; vec3 foo; } my_ssbo;
        void main() { my_ssbo.x = 1.0; })";
 
diff --git a/libshaderc_util/CMakeLists.txt b/libshaderc_util/CMakeLists.txt
index 85e100c0..f8ae95d0 100644
--- a/libshaderc_util/CMakeLists.txt
+++ b/libshaderc_util/CMakeLists.txt
@@ -26,6 +26,9 @@ add_library(shaderc_util STATIC
 shaderc_default_compile_options(shaderc_util)
 target_include_directories(shaderc_util
   PUBLIC include PRIVATE ${glslang_SOURCE_DIR})
+# We use parts of Glslang's HLSL compilation interface, which
+# now requires this preprocessor definition.
+add_definitions(-DENABLE_HLSL)
 
 find_package(Threads)
 target_link_libraries(shaderc_util PRIVATE
diff --git a/libshaderc_util/src/compiler_test.cc b/libshaderc_util/src/compiler_test.cc
index 1a0b21c4..f6207e69 100644
--- a/libshaderc_util/src/compiler_test.cc
+++ b/libshaderc_util/src/compiler_test.cc
@@ -119,6 +119,7 @@ const char kGlslVertShaderNoExplicitLocation[] =
 // A GLSL vertex shader with a weirdly packed block.
 const char kGlslShaderWeirdPacking[] =
     R"(#version 450
+       layout(set = 0, binding = 0)
        buffer B { float x; vec3 foo; } my_ssbo;
        void main() { my_ssbo.x = 1.0; })";