Skip to content
Snippets Groups Projects
Commit eb71cdd5 authored by xavier's avatar xavier
Browse files

HLSL: fix preprocessor concatenation behaviour.

Fix #772.
parent 82e95a3a
No related branches found
No related tags found
No related merge requests found
hlsl.preprocessor.frag
Shader version: 500
gl_FragCoord origin is upper left
0:? Sequence
0:9 Function Definition: @main(vf4; ( temp 4-component vector of float)
0:9 Function Parameters:
0:9 'input' ( in 4-component vector of float)
0:? Sequence
0:10 Sequence
0:10 move second child to first child ( temp 4-component vector of float)
0:10 'tex' ( temp 4-component vector of float)
0:10 texture ( temp 4-component vector of float)
0:10 Construct combined texture-sampler ( temp sampler2D)
0:10 'test_texture' ( uniform texture2D)
0:10 'test_texture_ss' ( uniform sampler)
0:10 vector swizzle ( temp 2-component vector of float)
0:10 vector swizzle ( temp 2-component vector of float)
0:10 'input' ( in 4-component vector of float)
0:10 Sequence
0:10 Constant:
0:10 0 (const int)
0:10 Constant:
0:10 1 (const int)
0:10 Sequence
0:10 Constant:
0:10 0 (const int)
0:10 Constant:
0:10 1 (const int)
0:11 Branch: Return with expression
0:11 'tex' ( temp 4-component vector of float)
0:9 Function Definition: main( ( temp void)
0:9 Function Parameters:
0:? Sequence
0:9 move second child to first child ( temp 4-component vector of float)
0:? 'input' ( temp 4-component vector of float)
0:? 'input' (layout( location=0) in 4-component vector of float)
0:9 move second child to first child ( temp 4-component vector of float)
0:? '@entryPointOutput' (layout( location=0) out 4-component vector of float)
0:9 Function Call: @main(vf4; ( temp 4-component vector of float)
0:? 'input' ( temp 4-component vector of float)
0:? Linker Objects
0:? 'test_texture' ( uniform texture2D)
0:? 'test_texture_ss' ( uniform sampler)
0:? '@entryPointOutput' (layout( location=0) out 4-component vector of float)
0:? 'input' (layout( location=0) in 4-component vector of float)
Linked fragment stage:
Shader version: 500
gl_FragCoord origin is upper left
0:? Sequence
0:9 Function Definition: @main(vf4; ( temp 4-component vector of float)
0:9 Function Parameters:
0:9 'input' ( in 4-component vector of float)
0:? Sequence
0:10 Sequence
0:10 move second child to first child ( temp 4-component vector of float)
0:10 'tex' ( temp 4-component vector of float)
0:10 texture ( temp 4-component vector of float)
0:10 Construct combined texture-sampler ( temp sampler2D)
0:10 'test_texture' ( uniform texture2D)
0:10 'test_texture_ss' ( uniform sampler)
0:10 vector swizzle ( temp 2-component vector of float)
0:10 vector swizzle ( temp 2-component vector of float)
0:10 'input' ( in 4-component vector of float)
0:10 Sequence
0:10 Constant:
0:10 0 (const int)
0:10 Constant:
0:10 1 (const int)
0:10 Sequence
0:10 Constant:
0:10 0 (const int)
0:10 Constant:
0:10 1 (const int)
0:11 Branch: Return with expression
0:11 'tex' ( temp 4-component vector of float)
0:9 Function Definition: main( ( temp void)
0:9 Function Parameters:
0:? Sequence
0:9 move second child to first child ( temp 4-component vector of float)
0:? 'input' ( temp 4-component vector of float)
0:? 'input' (layout( location=0) in 4-component vector of float)
0:9 move second child to first child ( temp 4-component vector of float)
0:? '@entryPointOutput' (layout( location=0) out 4-component vector of float)
0:9 Function Call: @main(vf4; ( temp 4-component vector of float)
0:? 'input' ( temp 4-component vector of float)
0:? Linker Objects
0:? 'test_texture' ( uniform texture2D)
0:? 'test_texture_ss' ( uniform sampler)
0:? '@entryPointOutput' (layout( location=0) out 4-component vector of float)
0:? 'input' (layout( location=0) in 4-component vector of float)
// Module Version 10000
// Generated by (magic number): 80001
// Id's are bound by 40
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 33 36
ExecutionMode 4 OriginUpperLeft
Source HLSL 500
Name 4 "main"
Name 11 "@main(vf4;"
Name 10 "input"
Name 13 "tex"
Name 16 "test_texture"
Name 20 "test_texture_ss"
Name 31 "input"
Name 33 "input"
Name 36 "@entryPointOutput"
Name 37 "param"
Decorate 16(test_texture) DescriptorSet 0
Decorate 20(test_texture_ss) DescriptorSet 0
Decorate 33(input) Location 0
Decorate 36(@entryPointOutput) Location 0
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypeVector 6(float) 4
8: TypePointer Function 7(fvec4)
9: TypeFunction 7(fvec4) 8(ptr)
14: TypeImage 6(float) 2D sampled format:Unknown
15: TypePointer UniformConstant 14
16(test_texture): 15(ptr) Variable UniformConstant
18: TypeSampler
19: TypePointer UniformConstant 18
20(test_texture_ss): 19(ptr) Variable UniformConstant
22: TypeSampledImage 14
24: TypeVector 6(float) 2
32: TypePointer Input 7(fvec4)
33(input): 32(ptr) Variable Input
35: TypePointer Output 7(fvec4)
36(@entryPointOutput): 35(ptr) Variable Output
4(main): 2 Function None 3
5: Label
31(input): 8(ptr) Variable Function
37(param): 8(ptr) Variable Function
34: 7(fvec4) Load 33(input)
Store 31(input) 34
38: 7(fvec4) Load 31(input)
Store 37(param) 38
39: 7(fvec4) FunctionCall 11(@main(vf4;) 37(param)
Store 36(@entryPointOutput) 39
Return
FunctionEnd
11(@main(vf4;): 7(fvec4) Function None 9
10(input): 8(ptr) FunctionParameter
12: Label
13(tex): 8(ptr) Variable Function
17: 14 Load 16(test_texture)
21: 18 Load 20(test_texture_ss)
23: 22 SampledImage 17 21
25: 7(fvec4) Load 10(input)
26: 24(fvec2) VectorShuffle 25 25 0 1
27: 7(fvec4) ImageSampleImplicitLod 23 26
Store 13(tex) 27
28: 7(fvec4) Load 13(tex)
ReturnValue 28
FunctionEnd
This diff is collapsed.
#define DEFINE_TEXTURE(name) Texture2D name; SamplerState name##_ss;
#define SAMPLE_TEXTURE(name, uv) name.Sample(name##_ss, (uv).xy)
#define test_texture2 test_texture
DEFINE_TEXTURE(test_texture)
float4 main(float4 input : TEXCOORD0) : SV_TARGET
{
float4 tex = SAMPLE_TEXTURE(test_texture2, input.xy);
return tex;
}
#define DLAYER 3
#define DMACRO1 TEXCOORD1
#define DMACRO(num) TEXCOORD##num
struct S {
float4 pos : POSITION;
float2 UV0 : TEXCOORD0;
float2 UV1 : DMACRO1;
float2 UV2 : DMACRO(2);
float2 UV3 : DMACRO(DLAYER);
};
S main(float4 v : POSITION)
{
S s;
s.pos = v;
s.UV0 = float2(v.x,v.x);
s.UV1 = float2(v.y,v.y);
s.UV2 = float2(v.z,v.z);
s.UV3 = float2(v.w,v.w);
return s;
}
...@@ -1068,6 +1068,10 @@ int TPpContext::tMacroInput::scan(TPpToken* ppToken) ...@@ -1068,6 +1068,10 @@ int TPpContext::tMacroInput::scan(TPpToken* ppToken)
pasting = true; pasting = true;
} }
// HLSL does expand macros before concatenation
if (pasting && pp->parseContext.isReadingHLSL())
pasting = false;
// TODO: preprocessor: properly handle whitespace (or lack of it) between tokens when expanding // TODO: preprocessor: properly handle whitespace (or lack of it) between tokens when expanding
if (token == PpAtomIdentifier) { if (token == PpAtomIdentifier) {
int i; int i;
......
...@@ -311,11 +311,13 @@ INSTANTIATE_TEST_CASE_P( ...@@ -311,11 +311,13 @@ INSTANTIATE_TEST_CASE_P(
{"hlsl.matType.bool.frag", "main"}, {"hlsl.matType.bool.frag", "main"},
{"hlsl.matType.int.frag", "main"}, {"hlsl.matType.int.frag", "main"},
{"hlsl.max.frag", "PixelShaderFunction"}, {"hlsl.max.frag", "PixelShaderFunction"},
{"hlsl.preprocessor.frag", "main"},
{"hlsl.precedence.frag", "PixelShaderFunction"}, {"hlsl.precedence.frag", "PixelShaderFunction"},
{"hlsl.precedence2.frag", "PixelShaderFunction"}, {"hlsl.precedence2.frag", "PixelShaderFunction"},
{"hlsl.scalar2matrix.frag", "main"}, {"hlsl.scalar2matrix.frag", "main"},
{"hlsl.semantic.geom", "main"}, {"hlsl.semantic.geom", "main"},
{"hlsl.semantic.vert", "main"}, {"hlsl.semantic.vert", "main"},
{"hlsl.semantic-1.vert", "main"},
{"hlsl.scope.frag", "PixelShaderFunction"}, {"hlsl.scope.frag", "PixelShaderFunction"},
{"hlsl.sin.frag", "PixelShaderFunction"}, {"hlsl.sin.frag", "PixelShaderFunction"},
{"hlsl.struct.frag", "PixelShaderFunction"}, {"hlsl.struct.frag", "PixelShaderFunction"},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment