Skip to content

Commit

Permalink
Merge pull request #1918 from KhronosGroup/format-attributes
Browse files Browse the repository at this point in the history
HLSL: Add attributes for image formats and nonreadable/nonwritable
  • Loading branch information
johnkslang authored Oct 3, 2019
2 parents 7bc0473 + 8a97d38 commit 135e3e3
Show file tree
Hide file tree
Showing 14 changed files with 697 additions and 1 deletion.
501 changes: 501 additions & 0 deletions Test/baseResults/hlsl.format.rwtexture.frag.out

Large diffs are not rendered by default.

63 changes: 63 additions & 0 deletions Test/hlsl.format.rwtexture.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
SamplerState g_sSamp : register(s0);

[[spv::format_rgba32f]] RWTexture1D <float4> g_tTex1df4 : register(t0);
[[spv::format_rg32f]] RWTexture1D <int4> g_tTex1di4;
[[spv::format_rgba8snorm]] RWTexture1D <uint4> g_tTex1du4;

[[spv::format_rgba8i]] RWTexture2D <float4> g_tTex2df4;
[[spv::format_r11fg11fb10f]] RWTexture2D <int4> g_tTex2di4;
[[spv::format_r8snorm]] RWTexture2D <uint4> g_tTex2du4;

[[spv::format_rg8]] [[spv::nonwritable]] RWTexture3D <float4> g_tTex3df4;
[[spv::format_rgba16i]] [[spv::nonreadable]] RWTexture3D <int4> g_tTex3di4;
[[spv::format_r8i]] [[spv::nonwritable]] [[spv::nonreadable]] RWTexture3D <uint4> g_tTex3du4;

[[spv::format_rgba8ui]] RWTexture1DArray <float4> g_tTex1df4a;
[[spv::format_rg32ui]] RWTexture1DArray <int4> g_tTex1di4a;
[[spv::format_r16ui]] RWTexture1DArray <uint4> g_tTex1du4a;

[[spv::format_rgb10a2ui]] RWTexture2DArray <float4> g_tTex2df4a;
[[spv::format_r8ui]] RWTexture2DArray <int4> g_tTex2di4a;
[[spv::format_rgba16f]] RWTexture2DArray <uint4> g_tTex2du4a;

[[spv::format_rgba8 ]] RWTexture2DArray<int4> g_tTex01;
[[spv::format_rg16f ]] RWTexture2DArray<int4> g_tTex02;
[[spv::format_r16f ]] RWTexture2DArray<int4> g_tTex03;
[[spv::format_rgb10a2 ]] RWTexture2DArray<int4> g_tTex04;
[[spv::format_rg16 ]] RWTexture2DArray<int4> g_tTex05;
[[spv::format_r32f ]] RWTexture2DArray<int4> g_tTex06;
[[spv::format_rgba16 ]] RWTexture2DArray<int4> g_tTex07;
[[spv::format_r16 ]] RWTexture2DArray<int4> g_tTex08;
[[spv::format_r8 ]] RWTexture2DArray<int4> g_tTex09;
[[spv::format_rgba16snorm ]] RWTexture2DArray<int4> g_tTex10;
[[spv::format_rg16snorm ]] RWTexture2DArray<int4> g_tTex11;
[[spv::format_r16snorm ]] RWTexture2DArray<int4> g_tTex12;
[[spv::format_r8snorm ]] RWTexture2DArray<int4> g_tTex13;
[[spv::format_rgba32i ]] RWTexture2DArray<int4> g_tTex14;
[[spv::format_r32i ]] RWTexture2DArray<int4> g_tTex15;
[[spv::format_r32ui ]] RWTexture2DArray<int4> g_tTex16;
[[spv::format_rg16i ]] RWTexture2DArray<int4> g_tTex17;
[[spv::format_r16i ]] RWTexture2DArray<int4> g_tTex18;
[[spv::format_rg32i ]] RWTexture2DArray<int4> g_tTex19;
[[spv::format_rg8i ]] RWTexture2DArray<int4> g_tTex20;
[[spv::format_rg8ui ]] RWTexture2DArray<int4> g_tTex21;
[[spv::format_rgba32ui ]] RWTexture2DArray<int4> g_tTex22;
[[spv::format_rgba16ui ]] RWTexture2DArray<int4> g_tTex23;
[[spv::format_rg32ui ]] RWTexture2DArray<int4> g_tTex24;
[[spv::format_rg16ui ]] RWTexture2DArray<int4> g_tTex25;

struct PS_OUTPUT
{
float4 Color : SV_Target0;
float Depth : SV_Depth;
};

PS_OUTPUT main()
{
PS_OUTPUT psout;

psout.Color = 1.0;
psout.Depth = 1.0;

return psout;
}
Empty file modified glslang/MachineIndependent/Constant.cpp
100755 → 100644
Empty file.
Empty file modified glslang/MachineIndependent/ShaderLang.cpp
100755 → 100644
Empty file.
Empty file modified glslang/MachineIndependent/SymbolTable.cpp
100755 → 100644
Empty file.
Empty file modified glslang/MachineIndependent/SymbolTable.h
100755 → 100644
Empty file.
44 changes: 43 additions & 1 deletion glslang/MachineIndependent/attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,49 @@ namespace glslang {
EatMaxIterations,
EatIterationMultiple,
EatPeelCount,
EatPartialCount
EatPartialCount,
EatFormatRgba32f,
EatFormatRgba16f,
EatFormatR32f,
EatFormatRgba8,
EatFormatRgba8Snorm,
EatFormatRg32f,
EatFormatRg16f,
EatFormatR11fG11fB10f,
EatFormatR16f,
EatFormatRgba16,
EatFormatRgb10A2,
EatFormatRg16,
EatFormatRg8,
EatFormatR16,
EatFormatR8,
EatFormatRgba16Snorm,
EatFormatRg16Snorm,
EatFormatRg8Snorm,
EatFormatR16Snorm,
EatFormatR8Snorm,
EatFormatRgba32i,
EatFormatRgba16i,
EatFormatRgba8i,
EatFormatR32i,
EatFormatRg32i,
EatFormatRg16i,
EatFormatRg8i,
EatFormatR16i,
EatFormatR8i,
EatFormatRgba32ui,
EatFormatRgba16ui,
EatFormatRgba8ui,
EatFormatR32ui,
EatFormatRgb10a2ui,
EatFormatRg32ui,
EatFormatRg16ui,
EatFormatRg8ui,
EatFormatR16ui,
EatFormatR8ui,
EatFormatUnknown,
EatNonWritable,
EatNonReadable
};

class TIntermAggregate;
Expand Down
Empty file modified glslang/MachineIndependent/parseVersions.h
100755 → 100644
Empty file.
1 change: 1 addition & 0 deletions gtests/Hlsl.FromFile.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ INSTANTIATE_TEST_CASE_P(
{"hlsl.hull.void.tesc", "main"},
{"hlsl.hull.ctrlpt-1.tesc", "main"},
{"hlsl.hull.ctrlpt-2.tesc", "main"},
{"hlsl.format.rwtexture.frag", "main"},
{"hlsl.groupid.comp", "main"},
{"hlsl.identifier.sample.frag", "main"},
{"hlsl.if.frag", "PixelShaderFunction"},
Expand Down
43 changes: 43 additions & 0 deletions hlsl/hlslAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,49 @@ namespace glslang {
return EatConstantId;
else if (name == "push_constant")
return EatPushConstant;
} else if (nameSpace == "spv") {
if (name == "format_rgba32f") return EatFormatRgba32f;
if (name == "format_rgba16f") return EatFormatRgba16f;
if (name == "format_r32f") return EatFormatR32f;
if (name == "format_rgba8") return EatFormatRgba8;
if (name == "format_rgba8snorm") return EatFormatRgba8Snorm;
if (name == "format_rg32f") return EatFormatRg32f;
if (name == "format_rg16f") return EatFormatRg16f;
if (name == "format_r11fg11fb10f") return EatFormatR11fG11fB10f;
if (name == "format_r16f") return EatFormatR16f;
if (name == "format_rgba16") return EatFormatRgba16;
if (name == "format_rgb10a2") return EatFormatRgb10A2;
if (name == "format_rg16") return EatFormatRg16;
if (name == "format_rg8") return EatFormatRg8;
if (name == "format_r16") return EatFormatR16;
if (name == "format_r8") return EatFormatR8;
if (name == "format_rgba16snorm") return EatFormatRgba16Snorm;
if (name == "format_rg16snorm") return EatFormatRg16Snorm;
if (name == "format_rg8snorm") return EatFormatRg8Snorm;
if (name == "format_r16snorm") return EatFormatR16Snorm;
if (name == "format_r8snorm") return EatFormatR8Snorm;
if (name == "format_rgba32i") return EatFormatRgba32i;
if (name == "format_rgba16i") return EatFormatRgba16i;
if (name == "format_rgba8i") return EatFormatRgba8i;
if (name == "format_r32i") return EatFormatR32i;
if (name == "format_rg32i") return EatFormatRg32i;
if (name == "format_rg16i") return EatFormatRg16i;
if (name == "format_rg8i") return EatFormatRg8i;
if (name == "format_r16i") return EatFormatR16i;
if (name == "format_r8i") return EatFormatR8i;
if (name == "format_rgba32ui") return EatFormatRgba32ui;
if (name == "format_rgba16ui") return EatFormatRgba16ui;
if (name == "format_rgba8ui") return EatFormatRgba8ui;
if (name == "format_r32ui") return EatFormatR32ui;
if (name == "format_rgb10a2ui") return EatFormatRgb10a2ui;
if (name == "format_rg32ui") return EatFormatRg32ui;
if (name == "format_rg16ui") return EatFormatRg16ui;
if (name == "format_rg8ui") return EatFormatRg8ui;
if (name == "format_r16ui") return EatFormatR16ui;
if (name == "format_r8ui") return EatFormatR8ui;

if (name == "nonwritable") return EatNonWritable;
if (name == "nonreadable") return EatNonReadable;
} else if (nameSpace.size() > 0)
return EatNone;

Expand Down
Empty file modified hlsl/hlslGrammar.cpp
100755 → 100644
Empty file.
Empty file modified hlsl/hlslGrammar.h
100755 → 100644
Empty file.
46 changes: 46 additions & 0 deletions hlsl/hlslParseHelper.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -1950,6 +1950,52 @@ void HlslParseContext::transferTypeAttributes(const TSourceLoc& loc, const TAttr
setSpecConstantId(loc, type.getQualifier(), value);
}
break;

// image formats
case EatFormatRgba32f: type.getQualifier().layoutFormat = ElfRgba32f; break;
case EatFormatRgba16f: type.getQualifier().layoutFormat = ElfRgba16f; break;
case EatFormatR32f: type.getQualifier().layoutFormat = ElfR32f; break;
case EatFormatRgba8: type.getQualifier().layoutFormat = ElfRgba8; break;
case EatFormatRgba8Snorm: type.getQualifier().layoutFormat = ElfRgba8Snorm; break;
case EatFormatRg32f: type.getQualifier().layoutFormat = ElfRg32f; break;
case EatFormatRg16f: type.getQualifier().layoutFormat = ElfRg16f; break;
case EatFormatR11fG11fB10f: type.getQualifier().layoutFormat = ElfR11fG11fB10f; break;
case EatFormatR16f: type.getQualifier().layoutFormat = ElfR16f; break;
case EatFormatRgba16: type.getQualifier().layoutFormat = ElfRgba16; break;
case EatFormatRgb10A2: type.getQualifier().layoutFormat = ElfRgb10A2; break;
case EatFormatRg16: type.getQualifier().layoutFormat = ElfRg16; break;
case EatFormatRg8: type.getQualifier().layoutFormat = ElfRg8; break;
case EatFormatR16: type.getQualifier().layoutFormat = ElfR16; break;
case EatFormatR8: type.getQualifier().layoutFormat = ElfR8; break;
case EatFormatRgba16Snorm: type.getQualifier().layoutFormat = ElfRgba16Snorm; break;
case EatFormatRg16Snorm: type.getQualifier().layoutFormat = ElfRg16Snorm; break;
case EatFormatRg8Snorm: type.getQualifier().layoutFormat = ElfRg8Snorm; break;
case EatFormatR16Snorm: type.getQualifier().layoutFormat = ElfR16Snorm; break;
case EatFormatR8Snorm: type.getQualifier().layoutFormat = ElfR8Snorm; break;
case EatFormatRgba32i: type.getQualifier().layoutFormat = ElfRgba32i; break;
case EatFormatRgba16i: type.getQualifier().layoutFormat = ElfRgba16i; break;
case EatFormatRgba8i: type.getQualifier().layoutFormat = ElfRgba8i; break;
case EatFormatR32i: type.getQualifier().layoutFormat = ElfR32i; break;
case EatFormatRg32i: type.getQualifier().layoutFormat = ElfRg32i; break;
case EatFormatRg16i: type.getQualifier().layoutFormat = ElfRg16i; break;
case EatFormatRg8i: type.getQualifier().layoutFormat = ElfRg8i; break;
case EatFormatR16i: type.getQualifier().layoutFormat = ElfR16i; break;
case EatFormatR8i: type.getQualifier().layoutFormat = ElfR8i; break;
case EatFormatRgba32ui: type.getQualifier().layoutFormat = ElfRgba32ui; break;
case EatFormatRgba16ui: type.getQualifier().layoutFormat = ElfRgba16ui; break;
case EatFormatRgba8ui: type.getQualifier().layoutFormat = ElfRgba8ui; break;
case EatFormatR32ui: type.getQualifier().layoutFormat = ElfR32ui; break;
case EatFormatRgb10a2ui: type.getQualifier().layoutFormat = ElfRgb10a2ui; break;
case EatFormatRg32ui: type.getQualifier().layoutFormat = ElfRg32ui; break;
case EatFormatRg16ui: type.getQualifier().layoutFormat = ElfRg16ui; break;
case EatFormatRg8ui: type.getQualifier().layoutFormat = ElfRg8ui; break;
case EatFormatR16ui: type.getQualifier().layoutFormat = ElfR16ui; break;
case EatFormatR8ui: type.getQualifier().layoutFormat = ElfR8ui; break;
case EatFormatUnknown: type.getQualifier().layoutFormat = ElfNone; break;

case EatNonWritable: type.getQualifier().readonly = true; break;
case EatNonReadable: type.getQualifier().writeonly = true; break;

default:
if (! allowEntry)
warn(loc, "attribute does not apply to a type", "", "");
Expand Down
Empty file modified hlsl/hlslParseHelper.h
100755 → 100644
Empty file.

0 comments on commit 135e3e3

Please sign in to comment.