LukasBanana / XShaderCompiler

Shader cross compiler to translate HLSL (Shader Model 4 and 5) to GLSL
BSD 3-Clause "New" or "Revised" License
352 stars 48 forks source link

Added support for the 'layout' attribute #49

Closed BearishSun closed 7 years ago

BearishSun commented 7 years ago

I've added support for the 'layout' attribute that allows the user to specify image layout format such as rgba8 using a non-standard [layout(rgba8)] attribute, as we discussed yesterday.

This functionality is only enabled when XSC_ENABLE_LANGUAGE_EXT is enabled through CMake AND when the necessary extension is enabled through input options/CLI/GUI.

I've added the -E<TYPE> CLI option which works similar to -W<TYPE>, and allows specific (or all) extensions to be enabled. Since I know you are working on an extension of your own I assume this is preferred than having separate options for each extension.

The core additions are:

I'll probably do a secondary PR in which I track which buffers are actually being written to. In that case we can always avoid writing out the layout format, and since most RW buffers are only used for writes, this should allow the user to avoid attributes in majority of situations.

BearishSun commented 7 years ago

Added another commit in order to avoid writing image layout format qualifiers if images aren't used for any reads (i.e. what I wrote in the last paragraph above).

LukasBanana commented 7 years ago

I just looked at it for a moment, but it looks good so far. The idea of using -E<TYPE> for language extensions is great 👍 , but I think I should then change the -E ENTRY command to -e ENTRY, let's see. Also making the enum ImageLayoutFormat always available is sensible.

BearishSun commented 7 years ago

Ah indeed, I missed the fact that "-E" was already in use, something should get renamed.

LukasBanana commented 7 years ago

Yes, but I appreciate the upper case letters for commands with integrated types like -W, -S, etc. I'll take care of it. Maybe I find another suitable name for the extensions.

BearishSun commented 7 years ago

Thought you might find it useful :)

I amended the last commit, it was incorrectly applying writeonly to non RW buffers.

LukasBanana commented 7 years ago

I renamed your -E language extension command to -X for eXtension.

I also made the extensions member and its enum in ShaderInput always enabled, but it is ignored if XSC_ENABLE_LANGUAGE_EXT is not defined. In this way, the client programmer doesn't need to define XSC_ENABLE_LANGUAGE_EXT for it's own projects (only to bulid the compiler). In the XscDebugger the respective PropertyGrid entry is then disbaled, but visible so that you always see what is build into the ccompiler and what is not.