Implement HXSL Syntax.code support #1264
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The proverbial footgun. Introduces
Syntax.code
to HXSL.Rationale is that feature being primarily for rare cases where HXSL doesn't offer some very specific language feature (from recent examples - no access to GLSL
GL_FragDepth
), but user needs access to it. Being able to inject raw language code is much less work than having to somehow implement those features. Additionally it gives partial resolution to all those people in discord asking if they can just use raw GLSL/HLSL for their shaders.Personal reasoning: I prefer giving the user options to shoot themselves in the foot if they so wish. If they want to do some weird stuff with shaders that HXSL can't do out of the box and likely will break - let them, it's their feet, not mine.
The implementation is somewhat volatile, but there's not much can be done about it, given how HXSL compilation process goes.
Syntax
Feature reserves the
ECall(EField("Syntax", target))
expression access as attempt to inject raw code. Target can becode
,hlsl
orglsl
respectively. Thecode
target is language-independent variant and applied in both GLSL and HLSL outputs.Additionally, due to how HXSL compilation process operates every argument have to be denoted with a meta of
@r
,@w
or@rw
, to specify how that variable going to be used.Usage is similar to other
Syntax.code
implementations:Syntax.code("{0} = someOp({1})", @w pixelColor, @r textureColor)
Implementation details
TSyntax
typed expression.TVoid
, and thus cannot be used to obtain some data directly. It may be possible to implement, however.TSyntax
is considered to always have side effects.Syntax.
calls intoTSyntax
and verifies that arguments are valid (first arg should be const String, rest is optional arguments with access meta)hasSyntax
flag toShaderInfos
, which is set whenTSyntax
is used. Processes read/write flags. When Syntax is used, shader is treated same as whenisCompute
orhasDiscard
are set.Notes
Syntax.code("{0}", @rw (var1 + var2))
, which would mark both var1/2 as write. I'm not sure if we should allow multipleTVar
references per argument when write flag is set.Syntax.hlsl
would still impact compilation even for GLSL. This is due to compiler not exactly being aware of which language it targets until the very last step.