Merge pull request #2621 from Rob2309/auto-sampled-textures-tests
Added usage hint for --auto-sampled-textures and added test cases
diff --git a/StandAlone/StandAlone.cpp b/StandAlone/StandAlone.cpp
index d38f4ad..c6dc597 100644
--- a/StandAlone/StandAlone.cpp
+++ b/StandAlone/StandAlone.cpp
@@ -1819,6 +1819,8 @@
" without explicit bindings\n"
" --auto-map-locations | --aml automatically locate input/output lacking\n"
" 'location' (fragile, not cross stage)\n"
+ " --auto-sampled-textures Removes sampler variables and converts\n"
+ " existing textures to sampled textures\n"
" --client {vulkan<ver>|opengl<ver>} see -V and -G\n"
" --depfile <file> writes depfile for build systems\n"
" --dump-builtin-symbols prints builtin symbol table prior each compile\n"
diff --git a/Test/baseResults/glsl.autosampledtextures.frag.out b/Test/baseResults/glsl.autosampledtextures.frag.out
new file mode 100644
index 0000000..2183898
--- /dev/null
+++ b/Test/baseResults/glsl.autosampledtextures.frag.out
@@ -0,0 +1,45 @@
+glsl.autosampledtextures.frag
+// Module Version 10000
+// Generated by (magic number): 8000a
+// Id's are bound by 23
+
+ Capability Shader
+ 1: ExtInstImport "GLSL.std.450"
+ MemoryModel Logical GLSL450
+ EntryPoint Fragment 4 "main" 17 21
+ ExecutionMode 4 OriginUpperLeft
+ Source GLSL 460
+ Name 4 "main"
+ Name 9 "color"
+ Name 13 "u_Tex"
+ Name 17 "in_UV"
+ Name 21 "out_Color"
+ Decorate 13(u_Tex) DescriptorSet 0
+ Decorate 13(u_Tex) Binding 0
+ Decorate 17(in_UV) Location 0
+ Decorate 21(out_Color) Location 0
+ 2: TypeVoid
+ 3: TypeFunction 2
+ 6: TypeFloat 32
+ 7: TypeVector 6(float) 4
+ 8: TypePointer Function 7(fvec4)
+ 10: TypeImage 6(float) 2D sampled format:Unknown
+ 11: TypeSampledImage 10
+ 12: TypePointer UniformConstant 11
+ 13(u_Tex): 12(ptr) Variable UniformConstant
+ 15: TypeVector 6(float) 2
+ 16: TypePointer Input 15(fvec2)
+ 17(in_UV): 16(ptr) Variable Input
+ 20: TypePointer Output 7(fvec4)
+ 21(out_Color): 20(ptr) Variable Output
+ 4(main): 2 Function None 3
+ 5: Label
+ 9(color): 8(ptr) Variable Function
+ 14: 11 Load 13(u_Tex)
+ 18: 15(fvec2) Load 17(in_UV)
+ 19: 7(fvec4) ImageSampleImplicitLod 14 18
+ Store 9(color) 19
+ 22: 7(fvec4) Load 9(color)
+ Store 21(out_Color) 22
+ Return
+ FunctionEnd
diff --git a/Test/baseResults/hlsl.autosampledtextures.frag.out b/Test/baseResults/hlsl.autosampledtextures.frag.out
new file mode 100644
index 0000000..559c130
--- /dev/null
+++ b/Test/baseResults/hlsl.autosampledtextures.frag.out
@@ -0,0 +1,77 @@
+hlsl.autosampledtextures.frag
+// Module Version 10000
+// Generated by (magic number): 8000a
+// Id's are bound by 45
+
+ Capability Shader
+ 1: ExtInstImport "GLSL.std.450"
+ MemoryModel Logical GLSL450
+ EntryPoint Fragment 4 "MainPs" 36 40
+ ExecutionMode 4 OriginUpperLeft
+ Source HLSL 500
+ Name 4 "MainPs"
+ Name 8 "PS_INPUT"
+ MemberName 8(PS_INPUT) 0 "vTextureCoords"
+ Name 11 "PS_OUTPUT"
+ MemberName 11(PS_OUTPUT) 0 "vColor"
+ Name 14 "@MainPs(struct-PS_INPUT-vf21;"
+ Name 13 "i"
+ Name 17 "ps_output"
+ Name 23 "g_tColor"
+ Name 34 "i"
+ Name 36 "i.vTextureCoords"
+ Name 40 "@entryPointOutput.vColor"
+ Name 41 "param"
+ Decorate 23(g_tColor) DescriptorSet 0
+ Decorate 23(g_tColor) Binding 0
+ Decorate 36(i.vTextureCoords) Location 0
+ Decorate 40(@entryPointOutput.vColor) Location 0
+ 2: TypeVoid
+ 3: TypeFunction 2
+ 6: TypeFloat 32
+ 7: TypeVector 6(float) 2
+ 8(PS_INPUT): TypeStruct 7(fvec2)
+ 9: TypePointer Function 8(PS_INPUT)
+ 10: TypeVector 6(float) 4
+ 11(PS_OUTPUT): TypeStruct 10(fvec4)
+ 12: TypeFunction 11(PS_OUTPUT) 9(ptr)
+ 16: TypePointer Function 11(PS_OUTPUT)
+ 18: TypeInt 32 1
+ 19: 18(int) Constant 0
+ 20: TypeImage 6(float) 2D sampled format:Unknown
+ 21: TypeSampledImage 20
+ 22: TypePointer UniformConstant 21
+ 23(g_tColor): 22(ptr) Variable UniformConstant
+ 25: TypePointer Function 7(fvec2)
+ 29: TypePointer Function 10(fvec4)
+ 35: TypePointer Input 7(fvec2)
+36(i.vTextureCoords): 35(ptr) Variable Input
+ 39: TypePointer Output 10(fvec4)
+40(@entryPointOutput.vColor): 39(ptr) Variable Output
+ 4(MainPs): 2 Function None 3
+ 5: Label
+ 34(i): 9(ptr) Variable Function
+ 41(param): 9(ptr) Variable Function
+ 37: 7(fvec2) Load 36(i.vTextureCoords)
+ 38: 25(ptr) AccessChain 34(i) 19
+ Store 38 37
+ 42: 8(PS_INPUT) Load 34(i)
+ Store 41(param) 42
+ 43:11(PS_OUTPUT) FunctionCall 14(@MainPs(struct-PS_INPUT-vf21;) 41(param)
+ 44: 10(fvec4) CompositeExtract 43 0
+ Store 40(@entryPointOutput.vColor) 44
+ Return
+ FunctionEnd
+14(@MainPs(struct-PS_INPUT-vf21;):11(PS_OUTPUT) Function None 12
+ 13(i): 9(ptr) FunctionParameter
+ 15: Label
+ 17(ps_output): 16(ptr) Variable Function
+ 24: 21 Load 23(g_tColor)
+ 26: 25(ptr) AccessChain 13(i) 19
+ 27: 7(fvec2) Load 26
+ 28: 10(fvec4) ImageSampleImplicitLod 24 27
+ 30: 29(ptr) AccessChain 17(ps_output) 19
+ Store 30 28
+ 31:11(PS_OUTPUT) Load 17(ps_output)
+ ReturnValue 31
+ FunctionEnd
diff --git a/Test/glsl.autosampledtextures.frag b/Test/glsl.autosampledtextures.frag
new file mode 100644
index 0000000..db4e68e
--- /dev/null
+++ b/Test/glsl.autosampledtextures.frag
@@ -0,0 +1,13 @@
+#version 460
+
+layout (location = 0) in vec2 in_UV;
+
+layout (set=0, binding=0) uniform texture2D u_Tex;
+layout (set=0, binding=0) uniform sampler u_Sampler;
+
+layout (location = 0) out vec4 out_Color;
+
+void main() {
+ vec4 color = texture(sampler2D(u_Tex, u_Sampler), in_UV);
+ out_Color = color;
+}
diff --git a/Test/hlsl.autosampledtextures.frag b/Test/hlsl.autosampledtextures.frag
new file mode 100644
index 0000000..7c72bec
--- /dev/null
+++ b/Test/hlsl.autosampledtextures.frag
@@ -0,0 +1,21 @@
+Texture2D g_tColor;
+
+SamplerState g_sAniso;
+
+struct PS_INPUT
+{
+ float2 vTextureCoords : TEXCOORD2 ;
+} ;
+
+struct PS_OUTPUT
+{
+ float4 vColor : SV_Target0 ;
+} ;
+
+PS_OUTPUT MainPs ( PS_INPUT i )
+{
+ PS_OUTPUT ps_output ;
+
+ ps_output . vColor = g_tColor . Sample ( g_sAniso , i . vTextureCoords . xy ) ;
+ return ps_output ;
+}
\ No newline at end of file
diff --git a/Test/runtests b/Test/runtests
index 69312e1..a7bdda7 100755
--- a/Test/runtests
+++ b/Test/runtests
@@ -281,6 +281,15 @@
diff -b $BASEDIR/spv.400.frag.nanclamp.out $TARGETDIR/spv.400.frag.nanclamp.out || HASERROR=1
#
+# Test --auto-sampled-textures
+#
+echo "Testing auto-sampled-textures"
+run --auto-sampled-textures -H -Od -e MainPs -D -S frag hlsl.autosampledtextures.frag > $TARGETDIR/hlsl.autosampledtextures.frag.out
+diff -b $BASEDIR/hlsl.autosampledtextures.frag.out $TARGETDIR/hlsl.autosampledtextures.frag.out || HASERROR=1
+run --auto-sampled-textures -H -Od -S frag glsl.autosampledtextures.frag > $TARGETDIR/glsl.autosampledtextures.frag.out
+diff -b $BASEDIR/glsl.autosampledtextures.frag.out $TARGETDIR/glsl.autosampledtextures.frag.out || HASERROR=1
+
+#
# Final checking
#
if [ $HASERROR -eq 0 ]