Skip to content

Commit 3ea1d6e

Browse files
Rob2309dneto0
authored andcommittedMay 10, 2021
Added -fauto-sampled-textures test and renamed functions
1 parent 0166712 commit 3ea1d6e

File tree

8 files changed

+79
-17
lines changed

8 files changed

+79
-17
lines changed
 

‎CONTRIBUTORS

+1
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ Qining Lu <qining@google.com>
2121
Jakob Vogel <JakobpunktVogel@gmail.com>
2222
David Yen <dyen@google.com>
2323
Adam Chainz <adam@adamj.eu>
24+
Robin Quint <robin.quint@outlook.com>

‎glslc/src/main.cc

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// Copyright 2015 The Shaderc Authors. All rights reserved.
2-
// MODIFIED BY Robin Quint
32
//
43
// Licensed under the Apache License, Version 2.0 (the "License");
54
// you may not use this file except in compliance with the License.
@@ -62,6 +61,9 @@ An input file of - represents standard input.
6261
Automatically assign locations to uniform variables that
6362
don't have an explicit 'location' layout in the shader
6463
source.
64+
-fauto-sampled-textures
65+
Removes sampler variables and converts existing textures
66+
to combined image-samplers
6567
-fentry-point=<name>
6668
Specify the entry point name for HLSL compilation, for
6769
all subsequent source files. Default is "main".
@@ -308,8 +310,8 @@ int main(int argc, char** argv) {
308310
}
309311
} else if (arg == "-fauto-bind-uniforms") {
310312
compiler.options().SetAutoBindUniforms(true);
311-
} else if (arg == "-fupgrade-textures") {
312-
compiler.options().SetUpgradeTextures(true);
313+
} else if (arg == "-fauto-sampled-textures") {
314+
compiler.options().SetAutoSampledTextures(true);
313315
} else if (arg == "-fauto-map-locations") {
314316
compiler.options().SetAutoMapLocations(true);
315317
} else if (arg == "-fhlsl-iomap") {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Copyright 2018 The Shaderc Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import expect
16+
from glslc_test_framework import inside_glslc_testsuite
17+
from placeholder import FileShader
18+
19+
# A GLSL shader with a separate sampler and texture2D object
20+
GLSL_SHADER_SEPARATE_IMAGE_SAMPLER = """#version 460
21+
in vec2 in_UV;
22+
out vec4 out_Color;
23+
layout (set=0,binding=0) uniform sampler u_Sampler;
24+
layout (set=0,binding=0) uniform texture2D u_Tex;
25+
void main() {
26+
out_Color = texture(sampler2D(u_Tex, u_Sampler), in_UV);
27+
}"""
28+
29+
30+
# An HLSL fragment shader with the usual Texture2D and SamplerState pair
31+
HLSL_SHADER_SEPARATE_IMAGE_SAMPLER = """
32+
Texture2D u_Tex;
33+
SamplerState u_Sampler;
34+
float4 Frag(float2 uv) : COLOR0 {
35+
return u_Tex.Sample(u_Sampler, uv);
36+
}"""
37+
38+
39+
@inside_glslc_testsuite('OptionFAutoSampledTextures')
40+
class FAutoSampledTexturesCheckGLSL(expect.ValidAssemblyFileWithSubstr):
41+
"""Tests that the compiler combines GLSL sampler and texture2D objects."""
42+
43+
exit(17)
44+
45+
shader = FileShader(GLSL_SHADER_SEPARATE_IMAGE_SAMPLER, '.frag')
46+
glslc_args = ['-S', '-fauto-sampled-textures', shader]
47+
expected_assembly_substr = "%11 = OpTypeSampledImage %10\n%_ptr_UniformConstant_11 = OpTypePointer UniformConstant %11\n %u_Tex = OpVariable %_ptr_UniformConstant_11 UniformConstant"
48+
49+
@inside_glslc_testsuite('OptionFAutoSampledTextures')
50+
class FAutoSampledTexturesCheckHLSL(expect.ValidAssemblyFileWithSubstr):
51+
"""Tests that the HLSL compiler combines HLSL Texture2D and SamplerState objects into SPIRV SampledImage."""
52+
53+
shader = FileShader(HLSL_SHADER_SEPARATE_IMAGE_SAMPLER, '.hlsl')
54+
glslc_args = ['-S', '-fshader-stage=frag', '-fentry-point=Frag', '-fauto-sampled-textures', shader]
55+
expected_assembly_substr = "%15 = OpTypeSampledImage %14\n%_ptr_UniformConstant_15 = OpTypePointer UniformConstant %15\n %u_Tex = OpVariable %_ptr_UniformConstant_15 UniformConstant"
56+

‎libshaderc/include/shaderc/shaderc.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// Copyright 2015 The Shaderc Authors. All rights reserved.
2-
// MODIFIED BY Robin Quint
32
//
43
// Licensed under the Apache License, Version 2.0 (the "License");
54
// you may not use this file except in compliance with the License.
@@ -408,7 +407,9 @@ SHADERC_EXPORT void shaderc_compile_options_set_limit(
408407
SHADERC_EXPORT void shaderc_compile_options_set_auto_bind_uniforms(
409408
shaderc_compile_options_t options, bool auto_bind);
410409

411-
SHADERC_EXPORT void shaderc_compile_options_set_upgrade_textures(
410+
// Sets whether the compiler should automatically remove sampler variables
411+
// and convert image variables to sampled image variables
412+
SHADERC_EXPORT void shaderc_compile_options_set_auto_sampled_textures(
412413
shaderc_compile_options_t options, bool upgrade);
413414

414415
// Sets whether the compiler should use HLSL IO mapping rules for bindings.

‎libshaderc/include/shaderc/shaderc.hpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// Copyright 2015 The Shaderc Authors. All rights reserved.
2-
// MODIFIED BY Robin Quint
32
//
43
// Licensed under the Apache License, Version 2.0 (the "License");
54
// you may not use this file except in compliance with the License.
@@ -275,8 +274,10 @@ class CompileOptions {
275274
shaderc_compile_options_set_auto_bind_uniforms(options_, auto_bind);
276275
}
277276

278-
void SetUpgradeTextures(bool upgrade) {
279-
shaderc_compile_options_set_upgrade_textures(options_, upgrade);
277+
// Sets whether the compiler should automatically remove sampler variables
278+
// and convert image variables to sampled image variables
279+
void SetAutoSampledTextures(bool auto_sampled) {
280+
shaderc_compile_options_set_auto_sampled_textures(options_, auto_sampled);
280281
}
281282

282283
// Sets whether the compiler should use HLSL IO mapping rules for bindings.

‎libshaderc/src/shaderc.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// Copyright 2015 The Shaderc Authors. All rights reserved.
2-
// MODIFIED BY Robin Quint
32
//
43
// Licensed under the Apache License, Version 2.0 (the "License");
54
// you may not use this file except in compliance with the License.
@@ -498,9 +497,9 @@ void shaderc_compile_options_set_auto_bind_uniforms(
498497
options->compiler.SetAutoBindUniforms(auto_bind);
499498
}
500499

501-
void shaderc_compile_options_set_upgrade_textures(
500+
void shaderc_compile_options_set_auto_sampled_textures(
502501
shaderc_compile_options_t options, bool upgrade) {
503-
options->compiler.SetUpgradeTextures(upgrade);
502+
options->compiler.SetAutoSampledTextures(upgrade);
504503
}
505504

506505
void shaderc_compile_options_set_hlsl_io_mapping(

‎libshaderc_util/include/libshaderc_util/compiler.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// Copyright 2015 The Shaderc Authors. All rights reserved.
2-
// MODIFIED BY Robin Quint
32
//
43
// Licensed under the Apache License, Version 2.0 (the "License");
54
// you may not use this file except in compliance with the License.
@@ -202,7 +201,7 @@ class Compiler {
202201
source_language_(SourceLanguage::GLSL),
203202
limits_(kDefaultTBuiltInResource),
204203
auto_bind_uniforms_(false),
205-
upgrade_textures_(false),
204+
auto_sampled_textures_(false),
206205
auto_binding_base_(),
207206
auto_map_locations_(false),
208207
hlsl_iomap_(false),
@@ -279,7 +278,9 @@ class Compiler {
279278
// uniform variables that don't have explicit bindings.
280279
void SetAutoBindUniforms(bool auto_bind) { auto_bind_uniforms_ = auto_bind; }
281280

282-
void SetUpgradeTextures(bool upgrade) { upgrade_textures_ = upgrade; }
281+
// Sets whether the compiler should automatically remove sampler variables
282+
// and convert image variables to sampled image variables
283+
void SetAutoSampledTextures(bool auto_sampled) { auto_sampled_textures_ = auto_sampled; }
283284

284285
// Sets the lowest binding number used when automatically assigning bindings
285286
// for uniform resources of the given type, for all shader stages. The default
@@ -496,7 +497,9 @@ class Compiler {
496497
// have explicit bindings.
497498
bool auto_bind_uniforms_;
498499

499-
bool upgrade_textures_;
500+
// True if the compiler should automatically remove sampler variables
501+
// and convert image variables to sampled image variables
502+
bool auto_sampled_textures_;
500503

501504
// The base binding number per uniform type, per stage, used when automatically
502505
// binding uniforms that don't hzve explicit bindings in the shader source.

‎libshaderc_util/src/compiler.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// Copyright 2015 The Shaderc Authors. All rights reserved.
2-
// MODIFIED BY Robin Quint
32
//
43
// Licensed under the Apache License, Version 2.0 (the "License");
54
// you may not use this file except in compliance with the License.
@@ -265,7 +264,7 @@ std::tuple<bool, std::vector<uint32_t>, size_t> Compiler::Compile(
265264
shader.setPreamble(preamble.c_str());
266265
shader.setEntryPoint(entry_point_name);
267266
shader.setAutoMapBindings(auto_bind_uniforms_);
268-
if (upgrade_textures_) {
267+
if (auto_sampled_textures_) {
269268
shader.setTextureSamplerTransformMode(EShTexSampTransUpgradeTextureRemoveSampler);
270269
}
271270
shader.setAutoMapLocations(auto_map_locations_);

0 commit comments

Comments
 (0)
Please sign in to comment.