New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-17 19:57:08 -04:00
|
|
|
using Ryujinx.Graphics.Shader.IntermediateRepresentation;
|
|
|
|
using Ryujinx.Graphics.Shader.StructuredIr;
|
2019-10-13 02:02:07 -04:00
|
|
|
using System;
|
New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-17 19:57:08 -04:00
|
|
|
|
|
|
|
using static Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions.InstGenHelper;
|
|
|
|
using static Ryujinx.Graphics.Shader.StructuredIr.InstructionInfo;
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
|
|
|
|
{
|
|
|
|
static class InstGenMemory
|
|
|
|
{
|
2020-04-21 19:35:28 -04:00
|
|
|
public static string ImageLoadOrStore(CodeGenContext context, AstOperation operation)
|
2019-10-17 22:41:18 -04:00
|
|
|
{
|
|
|
|
AstTextureOperation texOp = (AstTextureOperation)operation;
|
|
|
|
|
|
|
|
bool isBindless = (texOp.Flags & TextureFlags.Bindless) != 0;
|
|
|
|
|
2020-11-09 17:35:04 -05:00
|
|
|
// TODO: Bindless texture support. For now we just return 0/do nothing.
|
|
|
|
if (isBindless)
|
|
|
|
{
|
|
|
|
return texOp.Inst == Instruction.ImageLoad ? NumberFormatter.FormatFloat(0) : "// imageStore(bindless)";
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isArray = (texOp.Type & SamplerType.Array) != 0;
|
2019-11-02 22:07:21 -04:00
|
|
|
bool isIndexed = (texOp.Type & SamplerType.Indexed) != 0;
|
2019-10-17 22:41:18 -04:00
|
|
|
|
2020-04-21 19:35:28 -04:00
|
|
|
string texCall = texOp.Inst == Instruction.ImageLoad ? "imageLoad" : "imageStore";
|
2019-10-17 22:41:18 -04:00
|
|
|
|
2019-11-02 22:07:21 -04:00
|
|
|
int srcIndex = isBindless ? 1 : 0;
|
|
|
|
|
|
|
|
string Src(VariableType type)
|
|
|
|
{
|
|
|
|
return GetSoureExpr(context, texOp.GetSource(srcIndex++), type);
|
|
|
|
}
|
|
|
|
|
|
|
|
string indexExpr = null;
|
|
|
|
|
|
|
|
if (isIndexed)
|
|
|
|
{
|
|
|
|
indexExpr = Src(VariableType.S32);
|
|
|
|
}
|
|
|
|
|
|
|
|
string imageName = OperandManager.GetImageName(context.Config.Stage, texOp, indexExpr);
|
2019-10-17 22:41:18 -04:00
|
|
|
|
|
|
|
texCall += "(" + imageName;
|
|
|
|
|
|
|
|
int coordsCount = texOp.Type.GetDimensions();
|
|
|
|
|
2020-04-21 19:35:28 -04:00
|
|
|
int pCount = coordsCount + (isArray ? 1 : 0);
|
2019-10-17 22:41:18 -04:00
|
|
|
|
|
|
|
void Append(string str)
|
|
|
|
{
|
|
|
|
texCall += ", " + str;
|
|
|
|
}
|
|
|
|
|
2020-11-02 14:53:23 -05:00
|
|
|
string ApplyScaling(string vector)
|
|
|
|
{
|
|
|
|
int index = context.FindImageDescriptorIndex(texOp);
|
|
|
|
TextureUsageFlags flags = TextureUsageFlags.NeedsScaleValue;
|
|
|
|
|
|
|
|
if ((context.Config.Stage == ShaderStage.Fragment || context.Config.Stage == ShaderStage.Compute) &&
|
|
|
|
texOp.Inst == Instruction.ImageLoad &&
|
|
|
|
!isBindless &&
|
|
|
|
!isIndexed)
|
|
|
|
{
|
|
|
|
// Image scales start after texture ones.
|
|
|
|
int scaleIndex = context.TextureDescriptors.Count + index;
|
|
|
|
|
|
|
|
if (pCount == 3 && isArray)
|
|
|
|
{
|
|
|
|
// The array index is not scaled, just x and y.
|
|
|
|
vector = "ivec3(Helper_TexelFetchScale((" + vector + ").xy, " + scaleIndex + "), (" + vector + ").z)";
|
|
|
|
}
|
|
|
|
else if (pCount == 2 && !isArray)
|
|
|
|
{
|
|
|
|
vector = "Helper_TexelFetchScale(" + vector + ", " + scaleIndex + ")";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
flags |= TextureUsageFlags.ResScaleUnsupported;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
flags |= TextureUsageFlags.ResScaleUnsupported;
|
|
|
|
}
|
|
|
|
|
2020-11-09 17:35:04 -05:00
|
|
|
if (!isBindless)
|
|
|
|
{
|
|
|
|
context.ImageDescriptors[index] = context.ImageDescriptors[index].SetFlag(flags);
|
|
|
|
}
|
2020-11-02 14:53:23 -05:00
|
|
|
|
|
|
|
return vector;
|
|
|
|
}
|
|
|
|
|
2019-10-17 22:41:18 -04:00
|
|
|
if (pCount > 1)
|
|
|
|
{
|
|
|
|
string[] elems = new string[pCount];
|
|
|
|
|
|
|
|
for (int index = 0; index < pCount; index++)
|
|
|
|
{
|
|
|
|
elems[index] = Src(VariableType.S32);
|
|
|
|
}
|
|
|
|
|
2020-11-02 14:53:23 -05:00
|
|
|
Append(ApplyScaling("ivec" + pCount + "(" + string.Join(", ", elems) + ")"));
|
2019-10-17 22:41:18 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Append(Src(VariableType.S32));
|
|
|
|
}
|
|
|
|
|
2020-04-21 19:35:28 -04:00
|
|
|
if (texOp.Inst == Instruction.ImageStore)
|
2019-10-17 22:41:18 -04:00
|
|
|
{
|
2020-04-21 19:35:28 -04:00
|
|
|
VariableType type = texOp.Format.GetComponentType();
|
|
|
|
|
|
|
|
string[] cElems = new string[4];
|
|
|
|
|
|
|
|
for (int index = 0; index < 4; index++)
|
2019-10-17 22:41:18 -04:00
|
|
|
{
|
2020-04-21 19:35:28 -04:00
|
|
|
if (srcIndex < texOp.SourcesCount)
|
|
|
|
{
|
|
|
|
cElems[index] = Src(type);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cElems[index] = type switch
|
|
|
|
{
|
|
|
|
VariableType.S32 => NumberFormatter.FormatInt(0),
|
|
|
|
VariableType.U32 => NumberFormatter.FormatUint(0),
|
|
|
|
_ => NumberFormatter.FormatFloat(0)
|
|
|
|
};
|
|
|
|
}
|
2019-10-17 22:41:18 -04:00
|
|
|
}
|
2020-04-21 19:35:28 -04:00
|
|
|
|
|
|
|
string prefix = type switch
|
2019-10-17 22:41:18 -04:00
|
|
|
{
|
2020-04-21 19:35:28 -04:00
|
|
|
VariableType.S32 => "i",
|
|
|
|
VariableType.U32 => "u",
|
|
|
|
_ => string.Empty
|
|
|
|
};
|
2019-10-17 22:41:18 -04:00
|
|
|
|
2020-04-21 19:35:28 -04:00
|
|
|
Append(prefix + "vec4(" + string.Join(", ", cElems) + ")");
|
|
|
|
}
|
2019-10-17 22:41:18 -04:00
|
|
|
|
2020-04-21 19:35:28 -04:00
|
|
|
texCall += ")" + (texOp.Inst == Instruction.ImageLoad ? GetMask(texOp.Index) : "");
|
2019-10-17 22:41:18 -04:00
|
|
|
|
|
|
|
return texCall;
|
|
|
|
}
|
|
|
|
|
2019-10-13 02:02:07 -04:00
|
|
|
public static string LoadAttribute(CodeGenContext context, AstOperation operation)
|
|
|
|
{
|
|
|
|
IAstNode src1 = operation.GetSource(0);
|
|
|
|
IAstNode src2 = operation.GetSource(1);
|
|
|
|
|
|
|
|
if (!(src1 is AstOperand attr) || attr.Type != OperandType.Attribute)
|
|
|
|
{
|
|
|
|
throw new InvalidOperationException("First source of LoadAttribute must be a attribute.");
|
|
|
|
}
|
|
|
|
|
|
|
|
string indexExpr = GetSoureExpr(context, src2, GetSrcVarType(operation.Inst, 1));
|
|
|
|
|
2020-07-28 18:01:11 -04:00
|
|
|
return OperandManager.GetAttributeName(attr, context.Config, isOutAttr: false, indexExpr);
|
2019-10-13 02:02:07 -04:00
|
|
|
}
|
|
|
|
|
New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-17 19:57:08 -04:00
|
|
|
public static string LoadConstant(CodeGenContext context, AstOperation operation)
|
|
|
|
{
|
2019-10-13 02:02:07 -04:00
|
|
|
IAstNode src1 = operation.GetSource(0);
|
|
|
|
IAstNode src2 = operation.GetSource(1);
|
|
|
|
|
|
|
|
string offsetExpr = GetSoureExpr(context, src2, GetSrcVarType(operation.Inst, 1));
|
|
|
|
|
|
|
|
offsetExpr = Enclose(offsetExpr, src2, Instruction.ShiftRightS32, isLhs: true);
|
|
|
|
|
2020-10-12 20:40:50 -04:00
|
|
|
if (src1 is AstOperand oper && oper.Type == OperandType.Constant)
|
|
|
|
{
|
|
|
|
return OperandManager.GetConstantBufferName(oper.Value, offsetExpr, context.Config.Stage, context.CbIndexable);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
string slotExpr = GetSoureExpr(context, src1, GetSrcVarType(operation.Inst, 0));
|
|
|
|
|
|
|
|
return OperandManager.GetConstantBufferName(slotExpr, offsetExpr, context.Config.Stage);
|
|
|
|
}
|
2019-10-13 02:02:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static string LoadLocal(CodeGenContext context, AstOperation operation)
|
2019-11-08 15:29:41 -05:00
|
|
|
{
|
|
|
|
return LoadLocalOrShared(context, operation, DefaultNames.LocalMemoryName);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static string LoadShared(CodeGenContext context, AstOperation operation)
|
|
|
|
{
|
|
|
|
return LoadLocalOrShared(context, operation, DefaultNames.SharedMemoryName);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static string LoadLocalOrShared(CodeGenContext context, AstOperation operation, string arrayName)
|
2019-10-13 02:02:07 -04:00
|
|
|
{
|
|
|
|
IAstNode src1 = operation.GetSource(0);
|
New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-17 19:57:08 -04:00
|
|
|
|
2019-10-13 02:02:07 -04:00
|
|
|
string offsetExpr = GetSoureExpr(context, src1, GetSrcVarType(operation.Inst, 0));
|
|
|
|
|
2019-11-08 15:29:41 -05:00
|
|
|
return $"{arrayName}[{offsetExpr}]";
|
2019-10-13 02:02:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static string LoadStorage(CodeGenContext context, AstOperation operation)
|
|
|
|
{
|
|
|
|
IAstNode src1 = operation.GetSource(0);
|
|
|
|
IAstNode src2 = operation.GetSource(1);
|
2019-11-08 15:29:41 -05:00
|
|
|
|
2019-11-30 21:53:09 -05:00
|
|
|
string indexExpr = GetSoureExpr(context, src1, GetSrcVarType(operation.Inst, 0));
|
|
|
|
string offsetExpr = GetSoureExpr(context, src2, GetSrcVarType(operation.Inst, 1));
|
2019-11-08 15:29:41 -05:00
|
|
|
|
2019-11-30 21:53:09 -05:00
|
|
|
return GetStorageBufferAccessor(indexExpr, offsetExpr, context.Config.Stage);
|
2019-10-13 02:02:07 -04:00
|
|
|
}
|
|
|
|
|
2019-12-11 01:54:18 -05:00
|
|
|
public static string Lod(CodeGenContext context, AstOperation operation)
|
|
|
|
{
|
|
|
|
AstTextureOperation texOp = (AstTextureOperation)operation;
|
|
|
|
|
|
|
|
int coordsCount = texOp.Type.GetDimensions();
|
|
|
|
|
|
|
|
bool isBindless = (texOp.Flags & TextureFlags.Bindless) != 0;
|
|
|
|
|
2020-11-09 17:35:04 -05:00
|
|
|
// TODO: Bindless texture support. For now we just return 0.
|
|
|
|
if (isBindless)
|
|
|
|
{
|
|
|
|
return NumberFormatter.FormatFloat(0);
|
|
|
|
}
|
|
|
|
|
2019-12-11 01:54:18 -05:00
|
|
|
bool isIndexed = (texOp.Type & SamplerType.Indexed) != 0;
|
|
|
|
|
|
|
|
string indexExpr = null;
|
|
|
|
|
|
|
|
if (isIndexed)
|
|
|
|
{
|
|
|
|
indexExpr = GetSoureExpr(context, texOp.GetSource(0), VariableType.S32);
|
|
|
|
}
|
|
|
|
|
|
|
|
string samplerName = OperandManager.GetSamplerName(context.Config.Stage, texOp, indexExpr);
|
|
|
|
|
|
|
|
int coordsIndex = isBindless || isIndexed ? 1 : 0;
|
|
|
|
|
|
|
|
string coordsExpr;
|
|
|
|
|
|
|
|
if (coordsCount > 1)
|
|
|
|
{
|
|
|
|
string[] elems = new string[coordsCount];
|
|
|
|
|
|
|
|
for (int index = 0; index < coordsCount; index++)
|
|
|
|
{
|
|
|
|
elems[index] = GetSoureExpr(context, texOp.GetSource(coordsIndex + index), VariableType.F32);
|
|
|
|
}
|
|
|
|
|
|
|
|
coordsExpr = "vec" + coordsCount + "(" + string.Join(", ", elems) + ")";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
coordsExpr = GetSoureExpr(context, texOp.GetSource(coordsIndex), VariableType.F32);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $"textureQueryLod({samplerName}, {coordsExpr}){GetMask(texOp.Index)}";
|
|
|
|
}
|
|
|
|
|
2019-10-13 02:02:07 -04:00
|
|
|
public static string StoreLocal(CodeGenContext context, AstOperation operation)
|
2019-11-08 15:29:41 -05:00
|
|
|
{
|
|
|
|
return StoreLocalOrShared(context, operation, DefaultNames.LocalMemoryName);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static string StoreShared(CodeGenContext context, AstOperation operation)
|
|
|
|
{
|
|
|
|
return StoreLocalOrShared(context, operation, DefaultNames.SharedMemoryName);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static string StoreLocalOrShared(CodeGenContext context, AstOperation operation, string arrayName)
|
2019-10-13 02:02:07 -04:00
|
|
|
{
|
|
|
|
IAstNode src1 = operation.GetSource(0);
|
|
|
|
IAstNode src2 = operation.GetSource(1);
|
|
|
|
|
|
|
|
string offsetExpr = GetSoureExpr(context, src1, GetSrcVarType(operation.Inst, 0));
|
|
|
|
|
2020-10-25 16:00:44 -04:00
|
|
|
VariableType srcType = OperandManager.GetNodeDestType(context, src2);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
2019-11-08 15:29:41 -05:00
|
|
|
string src = TypeConversion.ReinterpretCast(context, src2, srcType, VariableType.U32);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
2019-11-08 15:29:41 -05:00
|
|
|
return $"{arrayName}[{offsetExpr}] = {src}";
|
2019-10-13 02:02:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static string StoreStorage(CodeGenContext context, AstOperation operation)
|
|
|
|
{
|
|
|
|
IAstNode src1 = operation.GetSource(0);
|
|
|
|
IAstNode src2 = operation.GetSource(1);
|
2019-11-30 21:53:09 -05:00
|
|
|
IAstNode src3 = operation.GetSource(2);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
2019-11-30 21:53:09 -05:00
|
|
|
string indexExpr = GetSoureExpr(context, src1, GetSrcVarType(operation.Inst, 0));
|
|
|
|
string offsetExpr = GetSoureExpr(context, src2, GetSrcVarType(operation.Inst, 1));
|
2019-10-13 02:02:07 -04:00
|
|
|
|
2020-10-25 16:00:44 -04:00
|
|
|
VariableType srcType = OperandManager.GetNodeDestType(context, src3);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
2019-11-30 21:53:09 -05:00
|
|
|
string src = TypeConversion.ReinterpretCast(context, src3, srcType, VariableType.U32);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
2019-11-30 21:53:09 -05:00
|
|
|
string sb = GetStorageBufferAccessor(indexExpr, offsetExpr, context.Config.Stage);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
2019-11-08 15:29:41 -05:00
|
|
|
return $"{sb} = {src}";
|
New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-17 19:57:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static string TextureSample(CodeGenContext context, AstOperation operation)
|
|
|
|
{
|
|
|
|
AstTextureOperation texOp = (AstTextureOperation)operation;
|
|
|
|
|
2019-10-30 23:29:22 -04:00
|
|
|
bool isBindless = (texOp.Flags & TextureFlags.Bindless) != 0;
|
|
|
|
bool isGather = (texOp.Flags & TextureFlags.Gather) != 0;
|
|
|
|
bool hasDerivatives = (texOp.Flags & TextureFlags.Derivatives) != 0;
|
|
|
|
bool intCoords = (texOp.Flags & TextureFlags.IntCoords) != 0;
|
|
|
|
bool hasLodBias = (texOp.Flags & TextureFlags.LodBias) != 0;
|
|
|
|
bool hasLodLevel = (texOp.Flags & TextureFlags.LodLevel) != 0;
|
|
|
|
bool hasOffset = (texOp.Flags & TextureFlags.Offset) != 0;
|
|
|
|
bool hasOffsets = (texOp.Flags & TextureFlags.Offsets) != 0;
|
2019-10-13 02:02:07 -04:00
|
|
|
|
2019-10-17 22:41:18 -04:00
|
|
|
bool isArray = (texOp.Type & SamplerType.Array) != 0;
|
2019-11-02 22:07:21 -04:00
|
|
|
bool isIndexed = (texOp.Type & SamplerType.Indexed) != 0;
|
2019-10-17 22:41:18 -04:00
|
|
|
bool isMultisample = (texOp.Type & SamplerType.Multisample) != 0;
|
|
|
|
bool isShadow = (texOp.Type & SamplerType.Shadow) != 0;
|
2019-10-13 02:02:07 -04:00
|
|
|
|
2020-11-09 17:35:04 -05:00
|
|
|
// TODO: Bindless texture support. For now we just return 0.
|
|
|
|
if (isBindless)
|
|
|
|
{
|
|
|
|
return NumberFormatter.FormatFloat(0);
|
|
|
|
}
|
|
|
|
|
2019-10-13 02:02:07 -04:00
|
|
|
// This combination is valid, but not available on GLSL.
|
|
|
|
// For now, ignore the LOD level and do a normal sample.
|
|
|
|
// TODO: How to implement it properly?
|
|
|
|
if (hasLodLevel && isArray && isShadow)
|
|
|
|
{
|
|
|
|
hasLodLevel = false;
|
|
|
|
}
|
New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-17 19:57:08 -04:00
|
|
|
|
|
|
|
string texCall = intCoords ? "texelFetch" : "texture";
|
|
|
|
|
|
|
|
if (isGather)
|
|
|
|
{
|
|
|
|
texCall += "Gather";
|
|
|
|
}
|
2019-10-30 23:29:22 -04:00
|
|
|
else if (hasDerivatives)
|
|
|
|
{
|
|
|
|
texCall += "Grad";
|
|
|
|
}
|
New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-17 19:57:08 -04:00
|
|
|
else if (hasLodLevel && !intCoords)
|
|
|
|
{
|
|
|
|
texCall += "Lod";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasOffset)
|
|
|
|
{
|
|
|
|
texCall += "Offset";
|
|
|
|
}
|
|
|
|
else if (hasOffsets)
|
|
|
|
{
|
|
|
|
texCall += "Offsets";
|
|
|
|
}
|
|
|
|
|
2019-11-02 22:07:21 -04:00
|
|
|
int srcIndex = isBindless ? 1 : 0;
|
|
|
|
|
|
|
|
string Src(VariableType type)
|
|
|
|
{
|
|
|
|
return GetSoureExpr(context, texOp.GetSource(srcIndex++), type);
|
|
|
|
}
|
|
|
|
|
|
|
|
string indexExpr = null;
|
|
|
|
|
|
|
|
if (isIndexed)
|
|
|
|
{
|
|
|
|
indexExpr = Src(VariableType.S32);
|
|
|
|
}
|
|
|
|
|
|
|
|
string samplerName = OperandManager.GetSamplerName(context.Config.Stage, texOp, indexExpr);
|
New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-17 19:57:08 -04:00
|
|
|
|
|
|
|
texCall += "(" + samplerName;
|
|
|
|
|
2019-10-17 22:41:18 -04:00
|
|
|
int coordsCount = texOp.Type.GetDimensions();
|
New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-17 19:57:08 -04:00
|
|
|
|
|
|
|
int pCount = coordsCount;
|
|
|
|
|
|
|
|
int arrayIndexElem = -1;
|
|
|
|
|
|
|
|
if (isArray)
|
|
|
|
{
|
|
|
|
arrayIndexElem = pCount++;
|
|
|
|
}
|
|
|
|
|
2019-07-01 22:39:22 -04:00
|
|
|
// The sampler 1D shadow overload expects a
|
|
|
|
// dummy value on the middle of the vector, who knows why...
|
2019-10-17 22:41:18 -04:00
|
|
|
bool hasDummy1DShadowElem = texOp.Type == (SamplerType.Texture1D | SamplerType.Shadow);
|
New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-17 19:57:08 -04:00
|
|
|
|
|
|
|
if (hasDummy1DShadowElem)
|
|
|
|
{
|
|
|
|
pCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isShadow && !isGather)
|
|
|
|
{
|
|
|
|
pCount++;
|
|
|
|
}
|
|
|
|
|
2019-07-01 22:39:22 -04:00
|
|
|
// On textureGather*, the comparison value is
|
|
|
|
// always specified as an extra argument.
|
New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-17 19:57:08 -04:00
|
|
|
bool hasExtraCompareArg = isShadow && isGather;
|
|
|
|
|
|
|
|
if (pCount == 5)
|
|
|
|
{
|
|
|
|
pCount = 4;
|
|
|
|
|
|
|
|
hasExtraCompareArg = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Append(string str)
|
|
|
|
{
|
|
|
|
texCall += ", " + str;
|
|
|
|
}
|
|
|
|
|
|
|
|
VariableType coordType = intCoords ? VariableType.S32 : VariableType.F32;
|
|
|
|
|
|
|
|
string AssemblePVector(int count)
|
|
|
|
{
|
|
|
|
if (count > 1)
|
|
|
|
{
|
|
|
|
string[] elems = new string[count];
|
|
|
|
|
|
|
|
for (int index = 0; index < count; index++)
|
|
|
|
{
|
|
|
|
if (arrayIndexElem == index)
|
|
|
|
{
|
|
|
|
elems[index] = Src(VariableType.S32);
|
|
|
|
|
|
|
|
if (!intCoords)
|
|
|
|
{
|
|
|
|
elems[index] = "float(" + elems[index] + ")";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (index == 1 && hasDummy1DShadowElem)
|
|
|
|
{
|
|
|
|
elems[index] = NumberFormatter.FormatFloat(0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
elems[index] = Src(coordType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
string prefix = intCoords ? "i" : string.Empty;
|
|
|
|
|
|
|
|
return prefix + "vec" + count + "(" + string.Join(", ", elems) + ")";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return Src(coordType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-06 22:41:07 -04:00
|
|
|
string ApplyScaling(string vector)
|
|
|
|
{
|
|
|
|
if (intCoords)
|
|
|
|
{
|
|
|
|
int index = context.FindTextureDescriptorIndex(texOp);
|
2020-11-02 14:53:23 -05:00
|
|
|
TextureUsageFlags flags = TextureUsageFlags.NeedsScaleValue;
|
2020-07-06 22:41:07 -04:00
|
|
|
|
|
|
|
if ((context.Config.Stage == ShaderStage.Fragment || context.Config.Stage == ShaderStage.Compute) &&
|
2020-11-02 14:53:23 -05:00
|
|
|
!isBindless &&
|
|
|
|
!isIndexed)
|
2020-07-06 22:41:07 -04:00
|
|
|
{
|
2020-10-28 16:27:46 -04:00
|
|
|
if (pCount == 3 && isArray)
|
|
|
|
{
|
|
|
|
// The array index is not scaled, just x and y.
|
2020-11-02 14:53:23 -05:00
|
|
|
vector = "ivec3(Helper_TexelFetchScale((" + vector + ").xy, " + index + "), (" + vector + ").z)";
|
2020-10-28 16:27:46 -04:00
|
|
|
}
|
|
|
|
else if (pCount == 2 && !isArray)
|
|
|
|
{
|
2020-11-02 14:53:23 -05:00
|
|
|
vector = "Helper_TexelFetchScale(" + vector + ", " + index + ")";
|
2020-10-28 16:27:46 -04:00
|
|
|
}
|
2020-11-02 14:53:23 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
flags |= TextureUsageFlags.ResScaleUnsupported;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Resolution scaling cannot be applied to this texture right now.
|
|
|
|
// Flag so that we know to blacklist scaling on related textures when binding them.
|
2020-07-06 22:41:07 -04:00
|
|
|
|
2020-11-02 14:53:23 -05:00
|
|
|
flags |= TextureUsageFlags.ResScaleUnsupported;
|
|
|
|
}
|
2020-10-28 16:27:46 -04:00
|
|
|
|
2020-11-09 17:35:04 -05:00
|
|
|
if (!isBindless)
|
|
|
|
{
|
|
|
|
context.TextureDescriptors[index] = context.TextureDescriptors[index].SetFlag(flags);
|
|
|
|
}
|
2020-07-06 22:41:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return vector;
|
|
|
|
}
|
|
|
|
|
|
|
|
Append(ApplyScaling(AssemblePVector(pCount)));
|
New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-17 19:57:08 -04:00
|
|
|
|
2019-10-30 23:29:22 -04:00
|
|
|
string AssembleDerivativesVector(int count)
|
|
|
|
{
|
|
|
|
if (count > 1)
|
|
|
|
{
|
|
|
|
string[] elems = new string[count];
|
|
|
|
|
|
|
|
for (int index = 0; index < count; index++)
|
|
|
|
{
|
|
|
|
elems[index] = Src(VariableType.F32);
|
|
|
|
}
|
|
|
|
|
|
|
|
return "vec" + count + "(" + string.Join(", ", elems) + ")";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return Src(VariableType.F32);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-11 01:54:18 -05:00
|
|
|
if (hasExtraCompareArg)
|
2019-10-30 23:29:22 -04:00
|
|
|
{
|
2019-12-11 01:54:18 -05:00
|
|
|
Append(Src(VariableType.F32));
|
2019-10-30 23:29:22 -04:00
|
|
|
}
|
|
|
|
|
2019-12-11 01:54:18 -05:00
|
|
|
if (hasDerivatives)
|
New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-17 19:57:08 -04:00
|
|
|
{
|
2019-12-11 01:54:18 -05:00
|
|
|
Append(AssembleDerivativesVector(coordsCount)); // dPdx
|
|
|
|
Append(AssembleDerivativesVector(coordsCount)); // dPdy
|
New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-17 19:57:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isMultisample)
|
|
|
|
{
|
|
|
|
Append(Src(VariableType.S32));
|
|
|
|
}
|
|
|
|
else if (hasLodLevel)
|
|
|
|
{
|
|
|
|
Append(Src(coordType));
|
|
|
|
}
|
|
|
|
|
|
|
|
string AssembleOffsetVector(int count)
|
|
|
|
{
|
|
|
|
if (count > 1)
|
|
|
|
{
|
|
|
|
string[] elems = new string[count];
|
|
|
|
|
|
|
|
for (int index = 0; index < count; index++)
|
|
|
|
{
|
|
|
|
elems[index] = Src(VariableType.S32);
|
|
|
|
}
|
|
|
|
|
|
|
|
return "ivec" + count + "(" + string.Join(", ", elems) + ")";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return Src(VariableType.S32);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasOffset)
|
|
|
|
{
|
|
|
|
Append(AssembleOffsetVector(coordsCount));
|
|
|
|
}
|
|
|
|
else if (hasOffsets)
|
|
|
|
{
|
|
|
|
texCall += $", ivec{coordsCount}[4](";
|
|
|
|
|
|
|
|
texCall += AssembleOffsetVector(coordsCount) + ", ";
|
|
|
|
texCall += AssembleOffsetVector(coordsCount) + ", ";
|
|
|
|
texCall += AssembleOffsetVector(coordsCount) + ", ";
|
|
|
|
texCall += AssembleOffsetVector(coordsCount) + ")";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasLodBias)
|
|
|
|
{
|
|
|
|
Append(Src(VariableType.F32));
|
|
|
|
}
|
|
|
|
|
2019-07-01 22:39:22 -04:00
|
|
|
// textureGather* optional extra component index,
|
|
|
|
// not needed for shadow samplers.
|
New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-17 19:57:08 -04:00
|
|
|
if (isGather && !isShadow)
|
|
|
|
{
|
|
|
|
Append(Src(VariableType.S32));
|
|
|
|
}
|
|
|
|
|
2019-11-08 15:29:41 -05:00
|
|
|
texCall += ")" + (isGather || !isShadow ? GetMask(texOp.Index) : "");
|
New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-17 19:57:08 -04:00
|
|
|
|
|
|
|
return texCall;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static string TextureSize(CodeGenContext context, AstOperation operation)
|
|
|
|
{
|
|
|
|
AstTextureOperation texOp = (AstTextureOperation)operation;
|
|
|
|
|
2019-11-02 22:07:21 -04:00
|
|
|
bool isBindless = (texOp.Flags & TextureFlags.Bindless) != 0;
|
|
|
|
|
2020-11-09 17:35:04 -05:00
|
|
|
// TODO: Bindless texture support. For now we just return 0.
|
|
|
|
if (isBindless)
|
|
|
|
{
|
|
|
|
return NumberFormatter.FormatInt(0);
|
|
|
|
}
|
|
|
|
|
2019-11-02 22:07:21 -04:00
|
|
|
bool isIndexed = (texOp.Type & SamplerType.Indexed) != 0;
|
|
|
|
|
|
|
|
string indexExpr = null;
|
|
|
|
|
|
|
|
if (isIndexed)
|
|
|
|
{
|
|
|
|
indexExpr = GetSoureExpr(context, texOp.GetSource(0), VariableType.S32);
|
|
|
|
}
|
New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-17 19:57:08 -04:00
|
|
|
|
2019-11-02 22:07:21 -04:00
|
|
|
string samplerName = OperandManager.GetSamplerName(context.Config.Stage, texOp, indexExpr);
|
New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-17 19:57:08 -04:00
|
|
|
|
2019-12-11 01:54:18 -05:00
|
|
|
int lodSrcIndex = isBindless || isIndexed ? 1 : 0;
|
|
|
|
|
|
|
|
IAstNode lod = operation.GetSource(lodSrcIndex);
|
New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-17 19:57:08 -04:00
|
|
|
|
2019-12-11 01:54:18 -05:00
|
|
|
string lodExpr = GetSoureExpr(context, lod, GetSrcVarType(operation.Inst, lodSrcIndex));
|
New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-17 19:57:08 -04:00
|
|
|
|
2020-03-22 17:31:31 -04:00
|
|
|
if (texOp.Index == 3)
|
|
|
|
{
|
|
|
|
return $"textureQueryLevels({samplerName})";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return $"textureSize({samplerName}, {lodExpr}){GetMask(texOp.Index)}";
|
|
|
|
}
|
New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-17 19:57:08 -04:00
|
|
|
}
|
|
|
|
|
2019-11-08 15:29:41 -05:00
|
|
|
private static string GetStorageBufferAccessor(string slotExpr, string offsetExpr, ShaderStage stage)
|
New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-17 19:57:08 -04:00
|
|
|
{
|
2019-11-08 15:29:41 -05:00
|
|
|
string sbName = OperandManager.GetShaderStagePrefix(stage);
|
New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-17 19:57:08 -04:00
|
|
|
|
2019-11-08 15:29:41 -05:00
|
|
|
sbName += "_" + DefaultNames.StorageNamePrefix;
|
|
|
|
|
|
|
|
return $"{sbName}[{slotExpr}].{DefaultNames.DataName}[{offsetExpr}]";
|
|
|
|
}
|
|
|
|
|
|
|
|
private static string GetMask(int index)
|
|
|
|
{
|
|
|
|
return '.' + "rgba".Substring(index, 1);
|
New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-17 19:57:08 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|