Skip to content

Commit

Permalink
add TextureCubeArray type and functions
Browse files Browse the repository at this point in the history
  • Loading branch information
csyonghe committed Sep 5, 2017
1 parent 5e936e7 commit 727250e
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 10 deletions.
24 changes: 20 additions & 4 deletions Source/SpireCore/GLSLCodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Spire
{
class GLSLCodeGen : public CLikeCodeGen
{
private:
public:
bool useVulkanBinding = false;
bool useSingleDescSet = false;
protected:
Expand Down Expand Up @@ -241,6 +241,12 @@ namespace Spire
case ILBaseType::Texture3D:
textureName = "texture3D";
break;
case ILBaseType::TextureCubeArray:
textureName = "textureCubeArray";
break;
case ILBaseType::TextureCubeShadowArray:
textureName = "textureCubeArray";
break;
default:
throw NotImplementedException();
}
Expand Down Expand Up @@ -271,6 +277,12 @@ namespace Spire
case ILBaseType::Texture3D:
samplerName = "sampler3D";
break;
case ILBaseType::TextureCubeArray:
samplerName = "samplerCubeArray";
break;
case ILBaseType::TextureCubeShadowArray:
samplerName = "samplerCubeArrayShadow";
break;
default:
throw NotImplementedException();
}
Expand Down Expand Up @@ -436,7 +448,8 @@ namespace Spire
{
if (!useVulkanBinding && field.Value.Type->IsSamplerState())
continue;
if (input.Attributes.ContainsKey("VertexInput"))
//if (input.Attributes.ContainsKey("VertexInput"))
if (useVulkanBinding || input.Attributes.ContainsKey("VertexInput"))
sb.GlobalHeader << "layout(location = " << index << ") ";
if (!isVertexShader && (input.Attributes.ContainsKey("Flat") || field.Value.Type->IsIntegral()))
sb.GlobalHeader << "flat ";
Expand Down Expand Up @@ -899,18 +912,21 @@ namespace Spire
{
private:
String declPrefix;
bool isVulkan;
public:
StandardOutputStrategy(GLSLCodeGen * pCodeGen, ILWorld * world, String prefix)
: OutputStrategy(pCodeGen, world), declPrefix(prefix)
{}
{
isVulkan = pCodeGen->useVulkanBinding;
}
virtual void DeclareOutput(CodeGenContext & ctx, ILStage * stage) override
{
int location = 0;
for (auto & field : world->OutputType->Members)
{
if (field.Value.Attributes.ContainsKey("FragDepth"))
continue;
if (stage->StageType == "FragmentShader")
if (isVulkan || stage->StageType == "FragmentShader")
ctx.GlobalHeader << "layout(location = " << location << ") ";
if (declPrefix.Length())
ctx.GlobalHeader << declPrefix << " ";
Expand Down
2 changes: 2 additions & 0 deletions Source/SpireCore/HLSLCodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ namespace Spire
{ "sampler2DShadow", "Texture2D" },
{ "sampler2DArrayShadow", "Texture2DArray" },
{ "samplerCubeShadow", "TextureCube" },
{ "samplerCubeArray", "TextureCubeArray" },
{ "samplerCubeArrayShadow", "TextureCubeArray" },
{ "sampler3D", "Texture3D" }
};

Expand Down
12 changes: 10 additions & 2 deletions Source/SpireCore/IL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ namespace Spire
return new ILBasicType(ILBaseType::Texture2DArrayShadow);
if (parser.LookAhead("sampler3D") || parser.LookAhead("Texture3D"))
return new ILBasicType(ILBaseType::Texture3D);
if (parser.LookAhead("samplerCubeArray") || parser.LookAhead("TextureCubeArray"))
return new ILBasicType(ILBaseType::TextureCubeArray);
if (parser.LookAhead("samplerCubeArrayShadow") || parser.LookAhead("TextureCubeShadowArray") || parser.LookAhead("TextureCubeArrayShadow"))
return new ILBasicType(ILBaseType::TextureCubeShadowArray);
if (parser.LookAhead("bool"))
return new ILBasicType(ILBaseType::Bool);
return nullptr;
Expand Down Expand Up @@ -126,6 +130,10 @@ namespace Spire
return 8;
else if (type == ILBaseType::Texture2DArrayShadow)
return 8;
else if (type == ILBaseType::TextureCubeArray)
return 8;
else if (type == ILBaseType::TextureCubeShadowArray)
return 8;
else if (type == ILBaseType::Bool)
return 4;
else
Expand Down Expand Up @@ -239,7 +247,7 @@ namespace Spire
auto basicType = dynamic_cast<ILBasicType*>(this);
if (basicType)
return basicType->Type == ILBaseType::Texture2D || basicType->Type == ILBaseType::TextureCube || basicType->Type == ILBaseType::Texture2DArray ||
basicType->Type == ILBaseType::Texture3D;
basicType->Type == ILBaseType::Texture3D || basicType->Type == ILBaseType::TextureCubeArray;
else
return false;
}
Expand All @@ -250,7 +258,7 @@ namespace Spire
if (basicType)
return basicType->Type == ILBaseType::Texture2D || basicType->Type == ILBaseType::TextureCube || basicType->Type == ILBaseType::Texture2DArray ||
basicType->Type == ILBaseType::Texture2DShadow || basicType->Type == ILBaseType::TextureCubeShadow || basicType->Type == ILBaseType::Texture2DArrayShadow ||
basicType->Type == ILBaseType::Texture3D;
basicType->Type == ILBaseType::Texture3D || basicType->Type == ILBaseType::TextureCubeShadowArray || basicType->Type == ILBaseType::TextureCubeArray;
else
return false;
}
Expand Down
8 changes: 8 additions & 0 deletions Source/SpireCore/IL.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ namespace Spire
TextureCubeShadow = 52,
Texture2DArrayShadow = 53,
Texture3D = 54,
TextureCubeArray = 55,
TextureCubeShadowArray = 56,
Bool = 128, Bool2 = 129, Bool3 = 130, Bool4 = 131,
UInt = 512, UInt2 = 513, UInt3 = 514, UInt4 = 515,
SamplerState = 4096, SamplerComparisonState = 4097
Expand Down Expand Up @@ -130,6 +132,8 @@ namespace Spire
case ILBaseType::Texture2DShadow:
case ILBaseType::TextureCubeShadow:
case ILBaseType::Texture2DArrayShadow:
case ILBaseType::TextureCubeArray:
case ILBaseType::TextureCubeShadowArray:
case ILBaseType::Texture3D:
return BindableResourceType::Texture;
case ILBaseType::SamplerState:
Expand Down Expand Up @@ -194,6 +198,10 @@ namespace Spire
return "sampler2DArrayShadow";
else if (Type == ILBaseType::Texture3D)
return "sampler3D";
else if (Type == ILBaseType::TextureCubeArray)
return "samplerCubeArray";
else if (Type == ILBaseType::TextureCubeShadowArray)
return "samplerCubeArrayShadow";
else if (Type == ILBaseType::Bool)
return "bool";
else if (Type == ILBaseType::Bool2)
Expand Down
3 changes: 3 additions & 0 deletions Source/SpireCore/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ namespace Spire
typeNames.Add("Texture2DArrayShadow");
typeNames.Add("TextureCube");
typeNames.Add("TextureCubeShadow");
typeNames.Add("TextureCubeArray");
typeNames.Add("TextureCubeShadowArray");
typeNames.Add("TextureCubeArrayShadow");
typeNames.Add("Texture3D");
typeNames.Add("texture");
typeNames.Add("Texture");
Expand Down
4 changes: 4 additions & 0 deletions Source/SpireCore/SemanticsVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ namespace Spire
expType->BaseType = BaseType::Texture2D;
else if (typeNode->TypeName == "TextureCUBE" || typeNode->TypeName == "TextureCube")
expType->BaseType = BaseType::TextureCube;
else if (typeNode->TypeName == "TextureCubeArray")
expType->BaseType = BaseType::TextureCubeArray;
else if (typeNode->TypeName == "TextureCubeShadowArray" || typeNode->TypeName == "TextureCubeArrayShadow")
expType->BaseType = BaseType::TextureCubeShadowArray;
else if (typeNode->TypeName == "Texture2DArray")
expType->BaseType = BaseType::Texture2DArray;
else if (typeNode->TypeName == "Texture2DArrayShadow")
Expand Down
5 changes: 5 additions & 0 deletions Source/SpireCore/StdInclude.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,24 @@ __intrinsic vec4 Sample(Texture2DArray tex, SamplerState sampler, vec3 uv, ivec3
__intrinsic vec4 Sample(TextureCube tex, SamplerState sampler, vec3 uv);
__intrinsic vec4 Sample(Texture3D tex, SamplerState sampler, vec3 uv);
__intrinsic vec4 Sample(Texture2DArray tex, SamplerState sampler, vec3 uv);
__intrinsic vec4 Sample(TextureCubeArray tex, SamplerState sampler, vec4 uv);
__intrinsic vec4 SampleLevel(Texture2D tex, SamplerState sampler, vec2 uv, float lod);
__intrinsic vec4 SampleLevel(TextureCube tex, SamplerState sampler, vec3 uv, float lod);
__intrinsic vec4 SampleLevel(Texture3D tex, SamplerState sampler, vec3 uv, float lod);
__intrinsic vec4 SampleLevel(TextureCubeArray tex, SamplerState sampler, vec4 uv, float lod);
__intrinsic float SampleCmp(Texture2DShadow tex, SamplerComparisonState s, vec2 location, float compareValue, ivec2 offset);
__intrinsic float SampleCmp(Texture2DShadow tex, SamplerComparisonState s, vec2 location, float compareValue);
__intrinsic float SampleCmp(Texture2DArrayShadow tex, SamplerComparisonState s, vec3 location, float compareValue, ivec2 offset);
__intrinsic float SampleCmp(Texture2DArrayShadow tex, SamplerComparisonState s, vec3 location, float compareValue);
__intrinsic float SampleCmp(TextureCubeShadowArray tex, SamplerComparisonState s, vec4 location, float compareValue);
__intrinsic vec4 SampleGrad(Texture2D tex, SamplerState sampler, vec2 uv, vec2 ddx, vec2 ddy);
__intrinsic vec4 SampleGrad(Texture2D tex, SamplerState sampler, vec2 uv, vec2 ddx, vec2 ddy, ivec2 offset);
__intrinsic vec4 SampleGrad(TextureCube tex, SamplerState sampler, vec3 uv, vec3 ddx, vec3 ddy);
__intrinsic vec4 SampleGrad(TextureCubeArray tex, SamplerState sampler, vec4 uv, vec3 ddx, vec3 ddy);
__intrinsic vec4 SampleBias(Texture2D tex, SamplerState sampler, vec2 uv, float bias);
__intrinsic vec4 SampleBias(Texture2D tex, SamplerState sampler, vec2 uv, float bias, ivec2 offset);
__intrinsic vec4 SampleBias(TextureCube tex, SamplerState sampler, vec3 uv, float bias);
__intrinsic vec4 SampleBias(TextureCubeArray tex, SamplerState sampler, vec4 uv, float bias);
__intrinsic vec4 SampleBias(Texture2DArray tex, SamplerState sampler, vec3 uv, float bias);
__intrinsic vec4 Load(Texture2D tex, int3 location);
__intrinsic vec4 Load(Texture2D tex, int3 location, ivec2 offset);
Expand Down
6 changes: 6 additions & 0 deletions Source/SpireCore/Syntax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ namespace Spire
case Compiler::BaseType::Texture3D:
case Compiler::BaseType::TextureCube:
case Compiler::BaseType::TextureCubeShadow:
case Compiler::BaseType::TextureCubeArray:
case Compiler::BaseType::TextureCubeShadowArray:
return BindableResourceType::Texture;
case Compiler::BaseType::SamplerState:
case Compiler::BaseType::SamplerComparisonState:
Expand Down Expand Up @@ -728,6 +730,8 @@ namespace Spire
basicType->BaseType == BaseType::Texture2DShadow ||
basicType->BaseType == BaseType::TextureCubeShadow ||
basicType->BaseType == BaseType::Texture2DArrayShadow ||
basicType->BaseType == BaseType::TextureCubeArray ||
basicType->BaseType == BaseType::TextureCubeShadowArray ||
basicType->BaseType == BaseType::Texture3D;
return false;
}
Expand All @@ -742,6 +746,8 @@ namespace Spire
basicType->BaseType == BaseType::TextureCubeShadow ||
basicType->BaseType == BaseType::Texture2DArrayShadow ||
basicType->BaseType == BaseType::Texture3D ||
basicType->BaseType == BaseType::TextureCubeArray ||
basicType->BaseType == BaseType::TextureCubeShadowArray ||
basicType->BaseType == BaseType::SamplerState;
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions Source/SpireCore/Syntax.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ namespace Spire
TextureCubeShadow = 52,
Texture2DArrayShadow = 53,
Texture3D = 54,
TextureCubeArray = 55,
TextureCubeShadowArray = 56,
SamplerState = 4096, SamplerComparisonState = 4097,
Function = 64,
Shader = 256,
Expand Down
20 changes: 16 additions & 4 deletions Source/SpireCore/TypeLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ struct DefaultLayoutRulesImpl : LayoutRulesImpl

case BaseType::Texture2D:
case BaseType::TextureCube:
case BaseType::Texture2DArray:
case BaseType::Texture2DArrayShadow:
case BaseType::Texture2DShadow:
case BaseType::Texture3D:
case BaseType::TextureCubeShadow:
case BaseType::TextureCubeArray:
case BaseType::TextureCubeShadowArray:
return{ 8, 8 };

default:
Expand Down Expand Up @@ -89,10 +96,15 @@ struct DefaultLayoutRulesImpl : LayoutRulesImpl
case ILBaseType::Float3x3: return GetMatrixLayout(GetScalarLayout(ILBaseType::Float), 3, 3);
case ILBaseType::Float4x4: return GetMatrixLayout(GetScalarLayout(ILBaseType::Float), 4, 4);

case ILBaseType::Texture2D:
case ILBaseType::Texture2DShadow:
case ILBaseType::TextureCube:
case ILBaseType::TextureCubeShadow:
case ILBaseType::Texture2D:
case ILBaseType::TextureCube:
case ILBaseType::Texture2DArray:
case ILBaseType::Texture2DArrayShadow:
case ILBaseType::Texture2DShadow:
case ILBaseType::Texture3D:
case ILBaseType::TextureCubeShadow:
case ILBaseType::TextureCubeArray:
case ILBaseType::TextureCubeShadowArray:
return{ 8, 8 };

default:
Expand Down

0 comments on commit 727250e

Please sign in to comment.