2023-04-25 22:51:07 +00:00
|
|
|
using Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions;
|
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 23:57:08 +00:00
|
|
|
using Ryujinx.Graphics.Shader.IntermediateRepresentation;
|
|
|
|
using Ryujinx.Graphics.Shader.StructuredIr;
|
2019-10-13 06:02:07 +00:00
|
|
|
using Ryujinx.Graphics.Shader.Translation;
|
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 23:57:08 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2020-10-25 20:00:44 +00:00
|
|
|
using System.Diagnostics;
|
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 23:57:08 +00:00
|
|
|
using static Ryujinx.Graphics.Shader.StructuredIr.InstructionInfo;
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
|
|
|
|
{
|
|
|
|
class OperandManager
|
|
|
|
{
|
2023-07-24 16:35:04 +00:00
|
|
|
private readonly Dictionary<AstOperand, string> _locals;
|
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 23:57:08 +00:00
|
|
|
|
|
|
|
public OperandManager()
|
|
|
|
{
|
|
|
|
_locals = new Dictionary<AstOperand, string>();
|
|
|
|
}
|
|
|
|
|
|
|
|
public string DeclareLocal(AstOperand operand)
|
|
|
|
{
|
|
|
|
string name = $"{DefaultNames.LocalNamePrefix}_{_locals.Count}";
|
|
|
|
|
|
|
|
_locals.Add(operand, name);
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2022-11-12 23:20:40 +00:00
|
|
|
public string GetExpression(CodeGenContext context, AstOperand operand)
|
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 23:57:08 +00:00
|
|
|
{
|
2021-05-19 21:15:26 +00:00
|
|
|
return operand.Type switch
|
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 23:57:08 +00:00
|
|
|
{
|
2021-05-19 21:15:26 +00:00
|
|
|
OperandType.Argument => GetArgumentName(operand.Value),
|
|
|
|
OperandType.Constant => NumberFormatter.FormatInt(operand.Value),
|
|
|
|
OperandType.LocalVariable => _locals[operand],
|
|
|
|
OperandType.Undefined => DefaultNames.UndefinedName,
|
2023-06-28 06:59:13 +00:00
|
|
|
_ => throw new ArgumentException($"Invalid operand type \"{operand.Type}\"."),
|
2021-05-19 21:15:26 +00: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 23:57:08 +00:00
|
|
|
}
|
|
|
|
|
2020-10-25 20:00:44 +00:00
|
|
|
public static string GetArgumentName(int argIndex)
|
|
|
|
{
|
|
|
|
return $"{DefaultNames.ArgumentNamePrefix}{argIndex}";
|
|
|
|
}
|
|
|
|
|
2023-04-25 22:51:07 +00:00
|
|
|
public static AggregateType GetNodeDestType(CodeGenContext context, IAstNode node)
|
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 23:57:08 +00:00
|
|
|
{
|
2023-04-25 22:51:07 +00:00
|
|
|
// TODO: Get rid of that function entirely and return the type from the operation generation
|
|
|
|
// functions directly, like SPIR-V does.
|
|
|
|
|
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 23:57:08 +00:00
|
|
|
if (node is AstOperation operation)
|
|
|
|
{
|
2023-06-15 20:31:53 +00:00
|
|
|
if (operation.Inst == Instruction.Load || operation.Inst.IsAtomic())
|
2019-10-13 06:02:07 +00:00
|
|
|
{
|
2023-04-25 22:51:07 +00:00
|
|
|
switch (operation.StorageKind)
|
2021-08-26 23:44:47 +00:00
|
|
|
{
|
2023-05-20 19:19:26 +00:00
|
|
|
case StorageKind.ConstantBuffer:
|
2023-06-03 23:12:18 +00:00
|
|
|
case StorageKind.StorageBuffer:
|
2023-06-28 06:59:13 +00:00
|
|
|
if (operation.GetSource(0) is not AstOperand bindingIndex || bindingIndex.Type != OperandType.Constant)
|
2023-05-20 19:19:26 +00:00
|
|
|
{
|
|
|
|
throw new InvalidOperationException($"First input of {operation.Inst} with {operation.StorageKind} storage must be a constant operand.");
|
|
|
|
}
|
|
|
|
|
2023-06-28 06:59:13 +00:00
|
|
|
if (operation.GetSource(1) is not AstOperand fieldIndex || fieldIndex.Type != OperandType.Constant)
|
2023-05-20 19:19:26 +00:00
|
|
|
{
|
|
|
|
throw new InvalidOperationException($"Second input of {operation.Inst} with {operation.StorageKind} storage must be a constant operand.");
|
|
|
|
}
|
|
|
|
|
2023-06-03 23:12:18 +00:00
|
|
|
BufferDefinition buffer = operation.StorageKind == StorageKind.ConstantBuffer
|
2023-08-14 01:26:42 +00:00
|
|
|
? context.Properties.ConstantBuffers[bindingIndex.Value]
|
|
|
|
: context.Properties.StorageBuffers[bindingIndex.Value];
|
2023-05-20 19:19:26 +00:00
|
|
|
StructureField field = buffer.Type.Fields[fieldIndex.Value];
|
|
|
|
|
|
|
|
return field.Type & AggregateType.ElementTypeMask;
|
|
|
|
|
2023-06-15 20:31:53 +00:00
|
|
|
case StorageKind.LocalMemory:
|
|
|
|
case StorageKind.SharedMemory:
|
2023-06-28 06:59:13 +00:00
|
|
|
if (operation.GetSource(0) is not AstOperand { Type: OperandType.Constant } bindingId)
|
2023-06-15 20:31:53 +00:00
|
|
|
{
|
|
|
|
throw new InvalidOperationException($"First input of {operation.Inst} with {operation.StorageKind} storage must be a constant operand.");
|
|
|
|
}
|
|
|
|
|
|
|
|
MemoryDefinition memory = operation.StorageKind == StorageKind.LocalMemory
|
2023-08-14 01:26:42 +00:00
|
|
|
? context.Properties.LocalMemories[bindingId.Value]
|
|
|
|
: context.Properties.SharedMemories[bindingId.Value];
|
2023-06-15 20:31:53 +00:00
|
|
|
|
|
|
|
return memory.Type & AggregateType.ElementTypeMask;
|
|
|
|
|
2023-04-25 22:51:07 +00:00
|
|
|
case StorageKind.Input:
|
|
|
|
case StorageKind.InputPerPatch:
|
|
|
|
case StorageKind.Output:
|
|
|
|
case StorageKind.OutputPerPatch:
|
2023-06-28 06:59:13 +00:00
|
|
|
if (operation.GetSource(0) is not AstOperand varId || varId.Type != OperandType.Constant)
|
2023-04-25 22:51:07 +00:00
|
|
|
{
|
|
|
|
throw new InvalidOperationException($"First input of {operation.Inst} with {operation.StorageKind} storage must be a constant operand.");
|
|
|
|
}
|
|
|
|
|
|
|
|
IoVariable ioVariable = (IoVariable)varId.Value;
|
|
|
|
bool isOutput = operation.StorageKind == StorageKind.Output || operation.StorageKind == StorageKind.OutputPerPatch;
|
|
|
|
bool isPerPatch = operation.StorageKind == StorageKind.InputPerPatch || operation.StorageKind == StorageKind.OutputPerPatch;
|
|
|
|
int location = 0;
|
|
|
|
int component = 0;
|
|
|
|
|
2023-08-14 01:26:42 +00:00
|
|
|
if (context.Definitions.HasPerLocationInputOrOutput(ioVariable, isOutput))
|
2023-04-25 22:51:07 +00:00
|
|
|
{
|
2023-06-28 06:59:13 +00:00
|
|
|
if (operation.GetSource(1) is not AstOperand vecIndex || vecIndex.Type != OperandType.Constant)
|
2023-04-25 22:51:07 +00:00
|
|
|
{
|
|
|
|
throw new InvalidOperationException($"Second input of {operation.Inst} with {operation.StorageKind} storage must be a constant operand.");
|
|
|
|
}
|
|
|
|
|
|
|
|
location = vecIndex.Value;
|
|
|
|
|
|
|
|
if (operation.SourcesCount > 2 &&
|
|
|
|
operation.GetSource(2) is AstOperand elemIndex &&
|
|
|
|
elemIndex.Type == OperandType.Constant &&
|
2023-08-14 01:26:42 +00:00
|
|
|
context.Definitions.HasPerLocationInputOrOutputComponent(ioVariable, location, elemIndex.Value, isOutput))
|
2023-04-25 22:51:07 +00:00
|
|
|
{
|
|
|
|
component = elemIndex.Value;
|
|
|
|
}
|
|
|
|
}
|
2021-08-26 23:44:47 +00:00
|
|
|
|
2023-08-14 01:26:42 +00:00
|
|
|
(_, AggregateType varType) = IoMap.GetGlslVariable(
|
|
|
|
context.Definitions,
|
|
|
|
context.HostCapabilities,
|
|
|
|
ioVariable,
|
|
|
|
location,
|
|
|
|
component,
|
|
|
|
isOutput,
|
|
|
|
isPerPatch);
|
2023-04-25 22:51:07 +00:00
|
|
|
|
|
|
|
return varType & AggregateType.ElementTypeMask;
|
|
|
|
}
|
2019-10-13 06:02:07 +00:00
|
|
|
}
|
2020-10-25 20:00:44 +00:00
|
|
|
else if (operation.Inst == Instruction.Call)
|
|
|
|
{
|
|
|
|
AstOperand funcId = (AstOperand)operation.GetSource(0);
|
|
|
|
|
|
|
|
Debug.Assert(funcId.Type == OperandType.Constant);
|
|
|
|
|
|
|
|
return context.GetFunction(funcId.Value).ReturnType;
|
|
|
|
}
|
2022-12-29 15:09:34 +00:00
|
|
|
else if (operation.Inst == Instruction.VectorExtract)
|
2020-04-21 23:35:28 +00:00
|
|
|
{
|
2022-12-29 15:09:34 +00:00
|
|
|
return GetNodeDestType(context, operation.GetSource(0)) & ~AggregateType.ElementCountMask;
|
|
|
|
}
|
|
|
|
else if (operation is AstTextureOperation texOp)
|
|
|
|
{
|
2024-04-07 21:25:55 +00:00
|
|
|
if (texOp.Inst.IsImage())
|
2022-12-29 15:09:34 +00:00
|
|
|
{
|
|
|
|
return texOp.GetVectorType(texOp.Format.GetComponentType());
|
|
|
|
}
|
|
|
|
else if (texOp.Inst == Instruction.TextureSample)
|
|
|
|
{
|
|
|
|
return texOp.GetVectorType(GetDestVarType(operation.Inst));
|
|
|
|
}
|
2020-04-21 23:35:28 +00:00
|
|
|
}
|
2019-10-13 06:02:07 +00: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 23:57:08 +00:00
|
|
|
return GetDestVarType(operation.Inst);
|
|
|
|
}
|
|
|
|
else if (node is AstOperand operand)
|
|
|
|
{
|
2020-10-25 20:00:44 +00:00
|
|
|
if (operand.Type == OperandType.Argument)
|
|
|
|
{
|
|
|
|
int argIndex = operand.Value;
|
|
|
|
|
|
|
|
return context.CurrentFunction.GetArgumentType(argIndex);
|
|
|
|
}
|
|
|
|
|
2023-04-25 22:51:07 +00:00
|
|
|
return OperandInfo.GetVarType(operand);
|
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 23:57:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new ArgumentException($"Invalid node type \"{node?.GetType().Name ?? "null"}\".");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-06-28 06:59:13 +00:00
|
|
|
}
|