|
|
@@ -37,6 +37,7 @@ namespace ShaderGen.Glsl
|
|
|
{ "SampleGrad", SampleGrad },
|
|
|
{ "SampleComparisonLevelZero", SampleComparisonLevelZero },
|
|
|
{ "Load", Load },
|
|
|
+ { "Store", Store },
|
|
|
{ "Discard", Discard },
|
|
|
{ "Saturate", Saturate },
|
|
|
{ nameof(ShaderBuiltins.ClipToTextureCoordinates), ClipToTextureCoordinates },
|
|
|
@@ -145,6 +146,13 @@ namespace ShaderGen.Glsl
|
|
|
};
|
|
|
ret.Add("System.Numerics.Vector4", new DictionaryTypeInvocationTranslator(v4Mappings));
|
|
|
|
|
|
+ Dictionary<string, InvocationTranslator> u2Mappings = new Dictionary<string, InvocationTranslator>()
|
|
|
+ {
|
|
|
+ { "ctor", VectorCtor },
|
|
|
+ };
|
|
|
+ ret.Add("ShaderGen.UInt2", new DictionaryTypeInvocationTranslator(u2Mappings));
|
|
|
+ ret.Add("ShaderGen.Int2", new DictionaryTypeInvocationTranslator(u2Mappings));
|
|
|
+
|
|
|
Dictionary<string, InvocationTranslator> m4x4Mappings = new Dictionary<string, InvocationTranslator>()
|
|
|
{
|
|
|
{ "ctor", MatrixCtor }
|
|
|
@@ -302,7 +310,33 @@ namespace ShaderGen.Glsl
|
|
|
|
|
|
private static string Load(string typeName, string methodName, InvocationParameterInfo[] parameters)
|
|
|
{
|
|
|
- return $"texelFetch({parameters[0].Identifier}, ivec2({parameters[2].Identifier}), {parameters[3].Identifier})";
|
|
|
+ if (parameters[0].FullTypeName.Contains("RWTexture2D"))
|
|
|
+ {
|
|
|
+ if (parameters[0].FullTypeName.Contains("<float>"))
|
|
|
+ {
|
|
|
+ return $"imageLoad({parameters[0].Identifier}, ivec2({parameters[1].Identifier})).r";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return $"imageLoad({parameters[0].Identifier}, ivec2({parameters[1].Identifier}))";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return $"texelFetch({parameters[0].Identifier}, ivec2({parameters[2].Identifier}), {parameters[3].Identifier})";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static string Store(string typeName, string methodName, InvocationParameterInfo[] parameters)
|
|
|
+ {
|
|
|
+ if (parameters[0].FullTypeName.Contains("<float>"))
|
|
|
+ {
|
|
|
+ return $"imageStore({parameters[0].Identifier}, ivec2({parameters[1].Identifier}), vec4({parameters[2].Identifier}))";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return $"imageStore({parameters[0].Identifier}, ivec2({parameters[1].Identifier}), {parameters[2].Identifier})";
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private static string Discard(string typeName, string methodName, InvocationParameterInfo[] parameters)
|
|
|
@@ -465,6 +499,8 @@ namespace ShaderGen.Glsl
|
|
|
if (name == "System.Numerics.Vector2") { shaderType = "vec2"; elementCount = 2; }
|
|
|
else if (name == "System.Numerics.Vector3") { shaderType = "vec3"; elementCount = 3; }
|
|
|
else if (name == "System.Numerics.Vector4") { shaderType = "vec4"; elementCount = 4; }
|
|
|
+ else if (name == "ShaderGen.Int2") { shaderType = "ivec2"; elementCount = 2; }
|
|
|
+ else if (name == "ShaderGen.UInt2") { shaderType = "uvec2"; elementCount = 2; }
|
|
|
else { throw new ShaderGenerationException("VectorCtor translator was called on an invalid type: " + name); }
|
|
|
}
|
|
|
}
|