-
Notifications
You must be signed in to change notification settings - Fork 817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: Include Preprocessing reformats include file's source #2233
Comments
Normal operation of glslang is to make one pass, simultaneously tokenizing, preprocessing, and parsing, all within a window of only a few tokens, passing through the file once. A long time ago, Google partially added a feature that was similar to seeing what your code might look like if it was preprocessed but not actually compiled. That is a side-subject to actually correctly using glslang. I'm not quite sure if your operating with the first paragraph above, or the second one. It could be you see the code for the second one, but that is just a distraction? Or, are you actually trying to have glslang output preprocessed code? |
I'm using glslang via shaderc. I make three passes:
The first will actually substitute all instances of After all includes have been collected, I swap any This gives me code that looks like an Finally SPIR-V is compiled. |
An example of what I produce mid-way through pass nr. 1 #ifndef _GENERATED_INCLUDE_GUARD_irr_builtin_glsl_ext_LumaMeter_common_glsl_0
#define _GENERATED_INCLUDE_GUARD_irr_builtin_glsl_ext_LumaMeter_common_glsl_0
#elif !defined(_GENERATED_INCLUDE_GUARD_irr_builtin_glsl_ext_LumaMeter_common_glsl_1)
#define _GENERATED_INCLUDE_GUARD_irr_builtin_glsl_ext_LumaMeter_common_glsl_1
#elif !defined(_GENERATED_INCLUDE_GUARD_irr_builtin_glsl_ext_LumaMeter_common_glsl_2)
#define _GENERATED_INCLUDE_GUARD_irr_builtin_glsl_ext_LumaMeter_common_glsl_2
#elif !defined(_GENERATED_INCLUDE_GUARD_irr_builtin_glsl_ext_LumaMeter_common_glsl_3)
#define _GENERATED_INCLUDE_GUARD_irr_builtin_glsl_ext_LumaMeter_common_glsl_3
#elif !defined(_GENERATED_INCLUDE_GUARD_irr_builtin_glsl_ext_LumaMeter_common_glsl_4)
#define _GENERATED_INCLUDE_GUARD_irr_builtin_glsl_ext_LumaMeter_common_glsl_4
#elif !defined(_GENERATED_INCLUDE_GUARD_irr_builtin_glsl_ext_LumaMeter_common_glsl_5)
#define _GENERATED_INCLUDE_GUARD_irr_builtin_glsl_ext_LumaMeter_common_glsl_5
#endif
#ifndef _GENERATED_INCLUDE_GUARD_irr_builtin_glsl_ext_LumaMeter_common_glsl_5
_this_is_hash_ifndef _IRR_GLSL_EXT_LUMA_METER_COMMON_INCLUDED_
_this_is_hash_define _IRR_GLSL_EXT_LUMA_METER_COMMON_INCLUDED_
_this_is_hash_ifndef _IRR_GLSL_EXT_LUMA_METER_INVOCATION_COUNT
_this_is_hash_define _IRR_GLSL_EXT_LUMA_METER_INVOCATION_COUNT 256 // change this simultaneously with the constexpr in `CGLSLLumaBuiltinIncludeLoader`
_this_is_hash_endif
_this_is_hash_ifndef _IRR_GLSL_EXT_LUMA_METER_UNIFORMS_DEFINED_
_this_is_hash_define _IRR_GLSL_EXT_LUMA_METER_UNIFORMS_DEFINED_
struct irr_glsl_ext_LumaMeter_Uniforms_t
{
vec2 meteringWindowScale;
vec2 meteringWindowOffset;
};
_this_is_hash_endif
_this_is_hash_define _IRR_GLSL_EXT_LUMA_METER_MODE_GEOM_MEAN 0
_this_is_hash_define _IRR_GLSL_EXT_LUMA_METER_MODE_MODE 1
_this_is_hash_if _IRR_GLSL_EXT_LUMA_METER_MODE_DEFINED_==_IRR_GLSL_EXT_LUMA_METER_MODE_MODE
_this_is_hash_define _IRR_GLSL_EXT_LUMA_METER_BIN_COUNT _IRR_GLSL_EXT_LUMA_METER_INVOCATION_COUNT
_this_is_hash_ifdef _IRR_GLSL_EXT_LUMA_METER_FIRST_PASS_DEFINED_
_this_is_hash_define _IRR_GLSL_EXT_LUMA_METER_PADDED_BIN_COUNT (_IRR_GLSL_EXT_LUMA_METER_BIN_COUNT+1)
_this_is_hash_ifndef _IRR_GLSL_EXT_LUMA_METER_LOCAL_REPLICATION_POW_DEFINED_
_this_is_hash_define _IRR_GLSL_EXT_LUMA_METER_LOCAL_REPLICATION_POW_DEFINED_ 3
_this_is_hash_endif
_this_is_hash_define _IRR_GLSL_EXT_LUMA_METER_LOCAL_REPLICATION (1<<_IRR_GLSL_EXT_LUMA_METER_LOCAL_REPLICATION_POW_DEFINED_)
_this_is_hash_define _IRR_GLSL_EXT_LUMA_METER_SHARED_SIZE_NEEDED_ (_IRR_GLSL_EXT_LUMA_METER_PADDED_BIN_COUNT*_IRR_GLSL_EXT_LUMA_METER_LOCAL_REPLICATION)
_this_is_hash_else
_this_is_hash_define _IRR_GLSL_EXT_LUMA_METER_SHARED_SIZE_NEEDED_ (_IRR_GLSL_EXT_LUMA_METER_BIN_COUNT*2)
_this_is_hash_endif
_this_is_hash_if (_IRR_GLSL_EXT_LUMA_METER_MAX_LUMA_DEFINED_-_IRR_GLSL_EXT_LUMA_METER_MIN_LUMA_DEFINED_)%%_IRR_GLSL_EXT_LUMA_METER_BIN_COUNT!=0
_this_is_hash_error "The number of bins must evenly divide the histogram range!"
_this_is_hash_endif
_this_is_hash_define _IRR_GLSL_EXT_LUMA_METER_BIN_GLOBAL_REPLICATION 4 // change this simultaneously with the constexpr in `CGLSLLumaBuiltinIncludeLoader`
_this_is_hash_define _IRR_GLSL_EXT_LUMA_METER_BIN_GLOBAL_COUNT (_IRR_GLSL_EXT_LUMA_METER_BIN_COUNT*_IRR_GLSL_EXT_LUMA_METER_BIN_GLOBAL_REPLICATION)
struct irr_glsl_ext_LumaMeter_output_t
{
uint packedHistogram[_IRR_GLSL_EXT_LUMA_METER_BIN_GLOBAL_COUNT];
};
_this_is_hash_elif _IRR_GLSL_EXT_LUMA_METER_MODE_DEFINED_==_IRR_GLSL_EXT_LUMA_METER_MODE_GEOM_MEAN
_this_is_hash_ifdef _IRR_GLSL_EXT_LUMA_METER_FIRST_PASS_DEFINED_
_this_is_hash_define _IRR_GLSL_EXT_LUMA_METER_SHARED_SIZE_NEEDED_ _IRR_GLSL_EXT_LUMA_METER_INVOCATION_COUNT
_this_is_hash_else
_this_is_hash_define _IRR_GLSL_EXT_LUMA_METER_SHARED_SIZE_NEEDED_ 0
_this_is_hash_endif
struct irr_glsl_ext_LumaMeter_output_t
{
uint unormAverage;
};
_this_is_hash_else
_this_is_hash_error "Unsupported Metering Mode!"
_this_is_hash_endif
_this_is_hash_ifndef _IRR_GLSL_EXT_LUMA_METER_UNIFORMS_SET_DEFINED_
_this_is_hash_define _IRR_GLSL_EXT_LUMA_METER_UNIFORMS_SET_DEFINED_ 0
_this_is_hash_endif
_this_is_hash_ifndef _IRR_GLSL_EXT_LUMA_METER_UNIFORMS_BINDING_DEFINED_
_this_is_hash_define _IRR_GLSL_EXT_LUMA_METER_UNIFORMS_BINDING_DEFINED_ 0
_this_is_hash_endif
_this_is_hash_ifndef _IRR_GLSL_EXT_LUMA_METER_OUTPUT_SET_DEFINED_
_this_is_hash_define _IRR_GLSL_EXT_LUMA_METER_OUTPUT_SET_DEFINED_ 0
_this_is_hash_endif
_this_is_hash_ifndef _IRR_GLSL_EXT_LUMA_METER_OUTPUT_BINDING_DEFINED_
_this_is_hash_define _IRR_GLSL_EXT_LUMA_METER_OUTPUT_BINDING_DEFINED_ 1
_this_is_hash_endif
_this_is_hash_ifndef _IRR_GLSL_EXT_LUMA_METER_INPUT_IMAGE_SET_DEFINED_
_this_is_hash_define _IRR_GLSL_EXT_LUMA_METER_INPUT_IMAGE_SET_DEFINED_ 0
_this_is_hash_endif
_this_is_hash_ifndef _IRR_GLSL_EXT_LUMA_METER_INPUT_IMAGE_BINDING_DEFINED_
_this_is_hash_define _IRR_GLSL_EXT_LUMA_METER_INPUT_IMAGE_BINDING_DEFINED_ 2
_this_is_hash_endif
_this_is_hash_ifdef _IRR_GLSL_EXT_LUMA_METER_FIRST_PASS_DEFINED_
_this_is_hash_ifndef _IRR_GLSL_EXT_LUMA_METER_PUSH_CONSTANTS_DEFINED_
_this_is_hash_define _IRR_GLSL_EXT_LUMA_METER_PUSH_CONSTANTS_DEFINED_
layout(push_constant) uniform PushConstants
{
int currentFirstPassOutput;
} pc;
_this_is_hash_endif
_this_is_hash_ifndef _IRR_GLSL_EXT_LUMA_METER_OUTPUT_DESCRIPTOR_DEFINED_
_this_is_hash_define _IRR_GLSL_EXT_LUMA_METER_OUTPUT_DESCRIPTOR_DEFINED_
layout(set=_IRR_GLSL_EXT_LUMA_METER_OUTPUT_SET_DEFINED_, binding=_IRR_GLSL_EXT_LUMA_METER_OUTPUT_BINDING_DEFINED_) restrict coherent buffer OutputBuffer
{
irr_glsl_ext_LumaMeter_output_t outParams[];
};
_this_is_hash_endif
_this_is_hash_ifndef _IRR_GLSL_EXT_LUMA_METER_INPUT_IMAGE_DESCRIPTOR_DEFINED_
_this_is_hash_define _IRR_GLSL_EXT_LUMA_METER_INPUT_IMAGE_DESCRIPTOR_DEFINED_
layout(set=_IRR_GLSL_EXT_LUMA_METER_INPUT_IMAGE_SET_DEFINED_, binding=_IRR_GLSL_EXT_LUMA_METER_INPUT_IMAGE_BINDING_DEFINED_) uniform sampler2DArray inputImage;
_this_is_hash_endif
_this_is_hash_endif
_this_is_hash_if _IRR_GLSL_EXT_LUMA_METER_SHARED_SIZE_NEEDED_>0 && !defined(_IRR_GLSL_SCRATCH_SHARED_DEFINED_)
_this_is_hash_define _IRR_GLSL_SCRATCH_SHARED_DEFINED_ histogram
shared uint _IRR_GLSL_SCRATCH_SHARED_DEFINED_[_IRR_GLSL_EXT_LUMA_METER_SHARED_SIZE_NEEDED_];
_this_is_hash_elif defined(_IRR_GLSL_SCRATCH_SHARED_SIZE_DEFINED_) && _IRR_GLSL_SCRATCH_SHARED_SIZE_DEFINED_<_IRR_GLSL_EXT_LUMA_METER_SHARED_SIZE_NEEDED_
_this_is_hash_error "Not enough shared memory declared"
_this_is_hash_endif
_this_is_hash_if _IRR_GLSL_EXT_LUMA_METER_MODE_DEFINED_==_IRR_GLSL_EXT_LUMA_METER_MODE_MODE
_this_is_hash_ifdef _IRR_GLSL_EXT_LUMA_METER_FIRST_PASS_DEFINED_
void irr_glsl_ext_LumaMeter_clearFirstPassOutput()
{
uint globalIndex = gl_LocalInvocationIndex+gl_WorkGroupID.x*_IRR_GLSL_EXT_LUMA_METER_BIN_COUNT;
if (globalIndex<_IRR_GLSL_EXT_LUMA_METER_BIN_GLOBAL_COUNT)
{
outParams[(pc.currentFirstPassOutput!=0 ? 0:textureSize(inputImage,0).z)+int(gl_WorkGroupID.z)].packedHistogram[globalIndex] = 0u;
}
}
void irr_glsl_ext_LumaMeter_setFirstPassOutput(in uint writeOutVal)
{
uint globalIndex = gl_LocalInvocationIndex;
globalIndex += (gl_WorkGroupID.x&uint(_IRR_GLSL_EXT_LUMA_METER_BIN_GLOBAL_REPLICATION-1))*_IRR_GLSL_EXT_LUMA_METER_BIN_COUNT;
atomicAdd(outParams[(pc.currentFirstPassOutput!=0 ? textureSize(inputImage,0).z:0)+int(gl_WorkGroupID.z)].packedHistogram[globalIndex],writeOutVal);
}
_this_is_hash_endif
// TODO: move to `CGLSLScanBuiltinIncludeLoader` but clean that include up first and fix shaderc macro handling
uint irr_glsl_workgroupExclusiveAdd(uint val)
{
//! Bad INEFFICIENT Kogge-Stone adder, don't implement this way!
for (int pass=1; pass<_IRR_GLSL_EXT_LUMA_METER_BIN_COUNT; pass<<=1)
{
uint index = gl_LocalInvocationIndex+(pass&0x1)*_IRR_GLSL_EXT_LUMA_METER_BIN_COUNT;
_IRR_GLSL_SCRATCH_SHARED_DEFINED_[index] = val;
barrier();
memoryBarrierShared();
if (gl_LocalInvocationIndex>=pass)
val += _IRR_GLSL_SCRATCH_SHARED_DEFINED_[index-pass];
}
barrier();
memoryBarrierShared();
return val;
}
// TODO: turn `upper_bound__minus_onePoT` into a macro `irr_glsl_parallel_upper_bound__minus_onePoT` and introduce lower_bound, and non-minus one variants
_this_is_hash_if _IRR_GLSL_EXT_LUMA_METER_BIN_COUNT&(_IRR_GLSL_EXT_LUMA_METER_BIN_COUNT-1)
_this_is_hash_error "Parallel Upper Bound requires the Histogram Bin Count to be PoT"
_this_is_hash_endif
int upper_bound__minus_onePoT(in uint val, int arrayLenPoT)
{
arrayLenPoT >>= 1;
int ret = (val<_IRR_GLSL_SCRATCH_SHARED_DEFINED_[arrayLenPoT]) ? 0:arrayLenPoT;
for (; arrayLenPoT>0; arrayLenPoT>>=1)
{
int right = ret+arrayLenPoT;
ret = (val<_IRR_GLSL_SCRATCH_SHARED_DEFINED_[right]) ? 0:right;
}
return ret;
}
struct irr_glsl_ext_LumaMeter_PassInfo_t
{
uvec2 percentileRange; // (lowerPercentile,upperPercentile)
};
float irr_glsl_ext_LumaMeter_getMeasuredLumaLog2(in irr_glsl_ext_LumaMeter_output_t firstPassOutput, in irr_glsl_ext_LumaMeter_PassInfo_t info)
{
uint histogramVal = firstPassOutput.packedHistogram[gl_LocalInvocationIndex];
for (int i=0; i<_IRR_GLSL_EXT_LUMA_METER_BIN_GLOBAL_REPLICATION; i++)
histogramVal += firstPassOutput.packedHistogram[gl_LocalInvocationIndex+i*_IRR_GLSL_EXT_LUMA_METER_BIN_COUNT];
// do the prefix sum stuff
_IRR_GLSL_SCRATCH_SHARED_DEFINED_[gl_LocalInvocationIndex] = irr_glsl_workgroupExclusiveAdd(histogramVal);
barrier();
memoryBarrierShared();
float foundPercentiles[2];
bool lower2Threads = gl_LocalInvocationIndex<2u;
if (lower2Threads)
{
int found = upper_bound__minus_onePoT(percentileRange[gl_LocalInvocationIndex],_IRR_GLSL_EXT_LUMA_METER_BIN_COUNT);
float foundValue = float(found)/float(_IRR_GLSL_EXT_LUMA_METER_BIN_COUNT);
_IRR_GLSL_SCRATCH_SHARED_DEFINED_[gl_LocalInvocationIndex] = floatBitsToUint(foundValue);
}
barrier();
memoryBarrierShared();
return (uintBitsToFloat(_IRR_GLSL_SCRATCH_SHARED_DEFINED_[0])+uintBitsToFloat(_IRR_GLSL_SCRATCH_SHARED_DEFINED_[1]))*0.5;
}
_this_is_hash_undef _IRR_GLSL_EXT_LUMA_METER_BIN_GLOBAL_REPLICATION
_this_is_hash_elif _IRR_GLSL_EXT_LUMA_METER_MODE_DEFINED_==_IRR_GLSL_EXT_LUMA_METER_MODE_GEOM_MEAN
_this_is_hash_define _IRR_GLSL_EXT_LUMA_METER_GEOM_MEAN_MAX_WG_INCREMENT 0x1000u
_this_is_hash_ifdef _IRR_GLSL_EXT_LUMA_METER_FIRST_PASS_DEFINED_
void irr_glsl_ext_LumaMeter_clearFirstPassOutput()
{
if (all(equal(uvec2(0,0),gl_GlobalInvocationID.xy)))
outParams[(pc.currentFirstPassOutput!=0 ? 0:textureSize(inputImage,0).z)+int(gl_WorkGroupID.z)].unormAverage = 0u;
}
void irr_glsl_ext_LumaMeter_setFirstPassOutput(in float writeOutVal)
{
if (gl_LocalInvocationIndex==0u)
{
float normalizedAvg = writeOutVal/float(_IRR_GLSL_EXT_LUMA_METER_INVOCATION_COUNT);
uint incrementor = uint(float(_IRR_GLSL_EXT_LUMA_METER_GEOM_MEAN_MAX_WG_INCREMENT)*normalizedAvg+0.5);
atomicAdd(outParams[(pc.currentFirstPassOutput!=0 ? textureSize(inputImage,0).z:0)+int(gl_WorkGroupID.z)].unormAverage,incrementor);
}
}
_this_is_hash_endif
struct irr_glsl_ext_LumaMeter_PassInfo_t
{
float rcpFirstPassWGCount;
};
float irr_glsl_ext_LumaMeter_impl_getMeasuredLumaLog2(in irr_glsl_ext_LumaMeter_output_t firstPassOutput, in irr_glsl_ext_LumaMeter_PassInfo_t info)
{
return float(firstPassOutput.unormAverage)*info.rcpFirstPassWGCount/float(_IRR_GLSL_EXT_LUMA_METER_GEOM_MEAN_MAX_WG_INCREMENT);
}
_this_is_hash_undef _IRR_GLSL_EXT_LUMA_METER_GEOM_MEAN_MAX_WG_INCREMENT
_this_is_hash_endif
float irr_glsl_ext_LumaMeter_getMeasuredLumaLog2(in irr_glsl_ext_LumaMeter_output_t firstPassOutput, in irr_glsl_ext_LumaMeter_PassInfo_t info)
{
const float MinLuma = intBitsToFloat(_IRR_GLSL_EXT_LUMA_METER_MIN_LUMA_DEFINED_);
const float MaxLuma = intBitsToFloat(_IRR_GLSL_EXT_LUMA_METER_MAX_LUMA_DEFINED_);
return irr_glsl_ext_LumaMeter_impl_getMeasuredLumaLog2(firstPassOutput,info)*log2(MaxLuma/MinLuma)+log2(MinLuma);
}
float irr_glsl_ext_LumaMeter_getOptiXIntensity(in float measuredLumaLog2)
{
return exp2(log(0.18)-measuredLumaLog2);
}
_this_is_hash_endif
#endif
#ifdef _GENERATED_INCLUDE_GUARD_irr_builtin_glsl_ext_LumaMeter_common_glsl_5
#undef _GENERATED_INCLUDE_GUARD_irr_builtin_glsl_ext_LumaMeter_common_glsl_5
#elif defined(_GENERATED_INCLUDE_GUARD_irr_builtin_glsl_ext_LumaMeter_common_glsl_4)
#undef _GENERATED_INCLUDE_GUARD_irr_builtin_glsl_ext_LumaMeter_common_glsl_4
#elif defined(_GENERATED_INCLUDE_GUARD_irr_builtin_glsl_ext_LumaMeter_common_glsl_3)
#undef _GENERATED_INCLUDE_GUARD_irr_builtin_glsl_ext_LumaMeter_common_glsl_3
#elif defined(_GENERATED_INCLUDE_GUARD_irr_builtin_glsl_ext_LumaMeter_common_glsl_2)
#undef _GENERATED_INCLUDE_GUARD_irr_builtin_glsl_ext_LumaMeter_common_glsl_2
#elif defined(_GENERATED_INCLUDE_GUARD_irr_builtin_glsl_ext_LumaMeter_common_glsl_1)
#undef _GENERATED_INCLUDE_GUARD_irr_builtin_glsl_ext_LumaMeter_common_glsl_1
#elif defined(_GENERATED_INCLUDE_GUARD_irr_builtin_glsl_ext_LumaMeter_common_glsl_0)
#undef _GENERATED_INCLUDE_GUARD_irr_builtin_glsl_ext_LumaMeter_common_glsl_0
#endif |
A worked exampleIn the original header I have: #define _IRR_GLSL_EXT_LUMA_METER_PADDED_BIN_COUNT (_IRR_GLSL_EXT_LUMA_METER_BIN_COUNT+1) which I replace with (while I use shaderc/glslang to resolve includes) this_is_hash_define _IRR_GLSL_EXT_LUMA_METER_PADDED_BIN_COUNT (_IRR_GLSL_EXT_LUMA_METER_BIN_COUNT+1) after glslang is done collecting the headers (parsing and retokenizing) this_is_hash_define _IRR_GLSL_EXT_LUMA_METER_PADDED_BIN_COUNT(_IRR_GLSL_EXT_LUMA_METER_BIN_COUNT+1) after my function exits ( I swap the #define _IRR_GLSL_EXT_LUMA_METER_PADDED_BIN_COUNT(_IRR_GLSL_EXT_LUMA_METER_BIN_COUNT+1) and I'm missing the space in front of the |
Glslang does not officially support using the preprocessor without also compiling. The path that tries to recreate the source indeed is not a high-quality proven path, and perhaps should be disabled, but some people found it useful and wanted to retain it. I'm unclear on if there is an issue here with shaderc or with glslang. |
Its extremely useful, that way I don;t need to compile a shader for every single possible combination of extensions/runtime features.
Me too, |
I managed to fix it somewhat (at least for the non-function like defines) What would be great is if I could somehow detect if the current token has had a whitespace before it in the original and then decide whether to emit a space before a |
@johnkslang what's the reason for making the
tokenize is losing the |
This fixes my issues entirely Both use cases of macros that get the beginning
Is this a kind of code-change that could be merged or do I break something greatly? |
I'm responsible for the preprocessing-only path. |
@dneto0 I managed to fix it for myself https://github.com/KhronosGroup/glslang/compare/master...devshgraphicsprogramming:Fix2233?expand=1 question is can you upstream such a fix? |
I've been experimenting with your proposed change. There is a problem with saving and restoring the "save" state in the MacroExpand method. Here is the delta from running the glslang-gtest suite:
Somehow that state change is an invalid thing to do. I'm looking further. |
Focusing just on the change in ShaderLang.cpp, every variation I try does the wrong thing to the following sample:
Here's one variation of the output, which is wrong:
This is wrong because on the Y2 macro definition, the parameter list is no longer connected to the macro definition but is glued to the expansion. Here is another, which is wrong in a different way:
This one is wrong because in the Y2 macro, the parameter list is next to the Y2, but still also glued to the expansion. I think your algorithm for replacing the #define with _this_is_define needs to distinguish the two cases, and produce different outputs, e.g. this_is_define_without_params and this_is_define_with_params. Then you can re-insert the space that the preprocessor expansion removes. Thanks again for your patience in waiting for this reply. |
The spacesActually my change produces none of the variations of the output you've listed. I've ran a simple shader through my engine and a debugger. Input is #define Y (a+b)
#define Y2(a,b) (a/b) My engine swaps to produce _this_is_hash_define Y (a+b)
_this_is_hash_define Y2(a,b) (a/b) The glslang preprocessor with my patch produces _this_is_hash_define Y (a + b)
_this_is_hash_define Y2(a, b)(a / b) My engine swaps back to produce #define Y (a + b)
#define Y2(a, b)(a / b)
It might be wrong "visually" but its still a valid function macro that your compiler compiles properly (or any C compiler). The failed test case
To do my change I needed to know if a whitespace preceeded the current
I kind-of don't understand whats going on in that function fully... but we will of course look into what's going on. |
From examining
glslang/MachineIndependent/ShaderLang.cpp
it seems apparent that the entire include file is parsed (obviously so the preprocessor directives can be honoured), but then the actual source produced from all the headers is de-parsed into a string of formatted tokensThis is a problem for me as I outline in this shaderc issue:
google/shaderc#1069
Long story short :
This is working for me quite well, but the only place where it breaks are:
#defines
that have a () after them, such as_this_is_a_hashdefine ONE_MORE_THAN_A (A+1)
_this_is_a_hashdefine FUNC(X) (X*X)
The cause of all this is because your
PreprocessDeferred
re-glues together the headers from tokens and the(
and)
symbols are on some sort of a list of tokens that are explicitly stated not to need a space before them.Is there any way to fix this behaviour?
could I remove
(
fromnoSpaceBeforeTokens
without affecting somethng else adversely?The text was updated successfully, but these errors were encountered: