Skip to content

Commit

Permalink
Added -fauto-sampled-textures test and renamed functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob2309 authored and dneto0 committed May 10, 2021
1 parent 0166712 commit 3ea1d6e
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 17 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ Qining Lu <[email protected]>
Jakob Vogel <[email protected]>
David Yen <[email protected]>
Adam Chainz <[email protected]>
Robin Quint <[email protected]>
8 changes: 5 additions & 3 deletions glslc/src/main.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Copyright 2015 The Shaderc Authors. All rights reserved.
// MODIFIED BY Robin Quint
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -62,6 +61,9 @@ An input file of - represents standard input.
Automatically assign locations to uniform variables that
don't have an explicit 'location' layout in the shader
source.
-fauto-sampled-textures
Removes sampler variables and converts existing textures
to combined image-samplers
-fentry-point=<name>
Specify the entry point name for HLSL compilation, for
all subsequent source files. Default is "main".
Expand Down Expand Up @@ -308,8 +310,8 @@ int main(int argc, char** argv) {
}
} else if (arg == "-fauto-bind-uniforms") {
compiler.options().SetAutoBindUniforms(true);
} else if (arg == "-fupgrade-textures") {
compiler.options().SetUpgradeTextures(true);
} else if (arg == "-fauto-sampled-textures") {
compiler.options().SetAutoSampledTextures(true);
} else if (arg == "-fauto-map-locations") {
compiler.options().SetAutoMapLocations(true);
} else if (arg == "-fhlsl-iomap") {
Expand Down
56 changes: 56 additions & 0 deletions glslc/test/option_fauto_sampled_textures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright 2018 The Shaderc Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import expect
from glslc_test_framework import inside_glslc_testsuite
from placeholder import FileShader

# A GLSL shader with a separate sampler and texture2D object
GLSL_SHADER_SEPARATE_IMAGE_SAMPLER = """#version 460
in vec2 in_UV;
out vec4 out_Color;
layout (set=0,binding=0) uniform sampler u_Sampler;
layout (set=0,binding=0) uniform texture2D u_Tex;
void main() {
out_Color = texture(sampler2D(u_Tex, u_Sampler), in_UV);
}"""


# An HLSL fragment shader with the usual Texture2D and SamplerState pair
HLSL_SHADER_SEPARATE_IMAGE_SAMPLER = """
Texture2D u_Tex;
SamplerState u_Sampler;
float4 Frag(float2 uv) : COLOR0 {
return u_Tex.Sample(u_Sampler, uv);
}"""


@inside_glslc_testsuite('OptionFAutoSampledTextures')
class FAutoSampledTexturesCheckGLSL(expect.ValidAssemblyFileWithSubstr):
"""Tests that the compiler combines GLSL sampler and texture2D objects."""

exit(17)

shader = FileShader(GLSL_SHADER_SEPARATE_IMAGE_SAMPLER, '.frag')
glslc_args = ['-S', '-fauto-sampled-textures', shader]
expected_assembly_substr = "%11 = OpTypeSampledImage %10\n%_ptr_UniformConstant_11 = OpTypePointer UniformConstant %11\n %u_Tex = OpVariable %_ptr_UniformConstant_11 UniformConstant"

@inside_glslc_testsuite('OptionFAutoSampledTextures')
class FAutoSampledTexturesCheckHLSL(expect.ValidAssemblyFileWithSubstr):
"""Tests that the HLSL compiler combines HLSL Texture2D and SamplerState objects into SPIRV SampledImage."""

shader = FileShader(HLSL_SHADER_SEPARATE_IMAGE_SAMPLER, '.hlsl')
glslc_args = ['-S', '-fshader-stage=frag', '-fentry-point=Frag', '-fauto-sampled-textures', shader]
expected_assembly_substr = "%15 = OpTypeSampledImage %14\n%_ptr_UniformConstant_15 = OpTypePointer UniformConstant %15\n %u_Tex = OpVariable %_ptr_UniformConstant_15 UniformConstant"

5 changes: 3 additions & 2 deletions libshaderc/include/shaderc/shaderc.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Copyright 2015 The Shaderc Authors. All rights reserved.
// MODIFIED BY Robin Quint
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -408,7 +407,9 @@ SHADERC_EXPORT void shaderc_compile_options_set_limit(
SHADERC_EXPORT void shaderc_compile_options_set_auto_bind_uniforms(
shaderc_compile_options_t options, bool auto_bind);

SHADERC_EXPORT void shaderc_compile_options_set_upgrade_textures(
// Sets whether the compiler should automatically remove sampler variables
// and convert image variables to sampled image variables
SHADERC_EXPORT void shaderc_compile_options_set_auto_sampled_textures(
shaderc_compile_options_t options, bool upgrade);

// Sets whether the compiler should use HLSL IO mapping rules for bindings.
Expand Down
7 changes: 4 additions & 3 deletions libshaderc/include/shaderc/shaderc.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Copyright 2015 The Shaderc Authors. All rights reserved.
// MODIFIED BY Robin Quint
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -275,8 +274,10 @@ class CompileOptions {
shaderc_compile_options_set_auto_bind_uniforms(options_, auto_bind);
}

void SetUpgradeTextures(bool upgrade) {
shaderc_compile_options_set_upgrade_textures(options_, upgrade);
// Sets whether the compiler should automatically remove sampler variables
// and convert image variables to sampled image variables
void SetAutoSampledTextures(bool auto_sampled) {
shaderc_compile_options_set_auto_sampled_textures(options_, auto_sampled);
}

// Sets whether the compiler should use HLSL IO mapping rules for bindings.
Expand Down
5 changes: 2 additions & 3 deletions libshaderc/src/shaderc.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Copyright 2015 The Shaderc Authors. All rights reserved.
// MODIFIED BY Robin Quint
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -498,9 +497,9 @@ void shaderc_compile_options_set_auto_bind_uniforms(
options->compiler.SetAutoBindUniforms(auto_bind);
}

void shaderc_compile_options_set_upgrade_textures(
void shaderc_compile_options_set_auto_sampled_textures(
shaderc_compile_options_t options, bool upgrade) {
options->compiler.SetUpgradeTextures(upgrade);
options->compiler.SetAutoSampledTextures(upgrade);
}

void shaderc_compile_options_set_hlsl_io_mapping(
Expand Down
11 changes: 7 additions & 4 deletions libshaderc_util/include/libshaderc_util/compiler.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Copyright 2015 The Shaderc Authors. All rights reserved.
// MODIFIED BY Robin Quint
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -202,7 +201,7 @@ class Compiler {
source_language_(SourceLanguage::GLSL),
limits_(kDefaultTBuiltInResource),
auto_bind_uniforms_(false),
upgrade_textures_(false),
auto_sampled_textures_(false),
auto_binding_base_(),
auto_map_locations_(false),
hlsl_iomap_(false),
Expand Down Expand Up @@ -279,7 +278,9 @@ class Compiler {
// uniform variables that don't have explicit bindings.
void SetAutoBindUniforms(bool auto_bind) { auto_bind_uniforms_ = auto_bind; }

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

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

bool upgrade_textures_;
// True if the compiler should automatically remove sampler variables
// and convert image variables to sampled image variables
bool auto_sampled_textures_;

// The base binding number per uniform type, per stage, used when automatically
// binding uniforms that don't hzve explicit bindings in the shader source.
Expand Down
3 changes: 1 addition & 2 deletions libshaderc_util/src/compiler.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Copyright 2015 The Shaderc Authors. All rights reserved.
// MODIFIED BY Robin Quint
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -265,7 +264,7 @@ std::tuple<bool, std::vector<uint32_t>, size_t> Compiler::Compile(
shader.setPreamble(preamble.c_str());
shader.setEntryPoint(entry_point_name);
shader.setAutoMapBindings(auto_bind_uniforms_);
if (upgrade_textures_) {
if (auto_sampled_textures_) {
shader.setTextureSamplerTransformMode(EShTexSampTransUpgradeTextureRemoveSampler);
}
shader.setAutoMapLocations(auto_map_locations_);
Expand Down

0 comments on commit 3ea1d6e

Please sign in to comment.