2019-06-06 22:31:14 +00:00
|
|
|
// Copyright 2019 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <cstddef>
|
|
|
|
#include <memory>
|
2019-07-18 00:03:53 +00:00
|
|
|
#include <optional>
|
2019-06-06 22:31:14 +00:00
|
|
|
#include <string>
|
|
|
|
#include <tuple>
|
|
|
|
#include <utility>
|
|
|
|
#include <variant>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "video_core/engines/shader_bytecode.h"
|
|
|
|
|
|
|
|
namespace VideoCommon::Shader {
|
|
|
|
|
|
|
|
enum class OperationCode {
|
|
|
|
Assign, /// (float& dest, float src) -> void
|
|
|
|
|
|
|
|
Select, /// (MetaArithmetic, bool pred, float a, float b) -> float
|
|
|
|
|
|
|
|
FAdd, /// (MetaArithmetic, float a, float b) -> float
|
|
|
|
FMul, /// (MetaArithmetic, float a, float b) -> float
|
|
|
|
FDiv, /// (MetaArithmetic, float a, float b) -> float
|
|
|
|
FFma, /// (MetaArithmetic, float a, float b, float c) -> float
|
|
|
|
FNegate, /// (MetaArithmetic, float a) -> float
|
|
|
|
FAbsolute, /// (MetaArithmetic, float a) -> float
|
|
|
|
FClamp, /// (MetaArithmetic, float value, float min, float max) -> float
|
2019-07-20 21:38:25 +00:00
|
|
|
FCastHalf0, /// (MetaArithmetic, f16vec2 a) -> float
|
|
|
|
FCastHalf1, /// (MetaArithmetic, f16vec2 a) -> float
|
2019-06-06 22:31:14 +00:00
|
|
|
FMin, /// (MetaArithmetic, float a, float b) -> float
|
|
|
|
FMax, /// (MetaArithmetic, float a, float b) -> float
|
|
|
|
FCos, /// (MetaArithmetic, float a) -> float
|
|
|
|
FSin, /// (MetaArithmetic, float a) -> float
|
|
|
|
FExp2, /// (MetaArithmetic, float a) -> float
|
|
|
|
FLog2, /// (MetaArithmetic, float a) -> float
|
|
|
|
FInverseSqrt, /// (MetaArithmetic, float a) -> float
|
|
|
|
FSqrt, /// (MetaArithmetic, float a) -> float
|
|
|
|
FRoundEven, /// (MetaArithmetic, float a) -> float
|
|
|
|
FFloor, /// (MetaArithmetic, float a) -> float
|
|
|
|
FCeil, /// (MetaArithmetic, float a) -> float
|
|
|
|
FTrunc, /// (MetaArithmetic, float a) -> float
|
|
|
|
FCastInteger, /// (MetaArithmetic, int a) -> float
|
|
|
|
FCastUInteger, /// (MetaArithmetic, uint a) -> float
|
2019-11-03 02:44:46 +00:00
|
|
|
FSwizzleAdd, /// (float a, float b, uint mask) -> float
|
2019-06-06 22:31:14 +00:00
|
|
|
|
|
|
|
IAdd, /// (MetaArithmetic, int a, int b) -> int
|
|
|
|
IMul, /// (MetaArithmetic, int a, int b) -> int
|
|
|
|
IDiv, /// (MetaArithmetic, int a, int b) -> int
|
|
|
|
INegate, /// (MetaArithmetic, int a) -> int
|
|
|
|
IAbsolute, /// (MetaArithmetic, int a) -> int
|
|
|
|
IMin, /// (MetaArithmetic, int a, int b) -> int
|
|
|
|
IMax, /// (MetaArithmetic, int a, int b) -> int
|
|
|
|
ICastFloat, /// (MetaArithmetic, float a) -> int
|
|
|
|
ICastUnsigned, /// (MetaArithmetic, uint a) -> int
|
|
|
|
ILogicalShiftLeft, /// (MetaArithmetic, int a, uint b) -> int
|
|
|
|
ILogicalShiftRight, /// (MetaArithmetic, int a, uint b) -> int
|
|
|
|
IArithmeticShiftRight, /// (MetaArithmetic, int a, uint b) -> int
|
|
|
|
IBitwiseAnd, /// (MetaArithmetic, int a, int b) -> int
|
|
|
|
IBitwiseOr, /// (MetaArithmetic, int a, int b) -> int
|
|
|
|
IBitwiseXor, /// (MetaArithmetic, int a, int b) -> int
|
|
|
|
IBitwiseNot, /// (MetaArithmetic, int a) -> int
|
|
|
|
IBitfieldInsert, /// (MetaArithmetic, int base, int insert, int offset, int bits) -> int
|
|
|
|
IBitfieldExtract, /// (MetaArithmetic, int value, int offset, int offset) -> int
|
|
|
|
IBitCount, /// (MetaArithmetic, int) -> int
|
2019-11-12 14:07:22 +00:00
|
|
|
IBitMSB, /// (MetaArithmetic, int) -> int
|
2019-06-06 22:31:14 +00:00
|
|
|
|
|
|
|
UAdd, /// (MetaArithmetic, uint a, uint b) -> uint
|
|
|
|
UMul, /// (MetaArithmetic, uint a, uint b) -> uint
|
|
|
|
UDiv, /// (MetaArithmetic, uint a, uint b) -> uint
|
|
|
|
UMin, /// (MetaArithmetic, uint a, uint b) -> uint
|
|
|
|
UMax, /// (MetaArithmetic, uint a, uint b) -> uint
|
|
|
|
UCastFloat, /// (MetaArithmetic, float a) -> uint
|
|
|
|
UCastSigned, /// (MetaArithmetic, int a) -> uint
|
|
|
|
ULogicalShiftLeft, /// (MetaArithmetic, uint a, uint b) -> uint
|
|
|
|
ULogicalShiftRight, /// (MetaArithmetic, uint a, uint b) -> uint
|
|
|
|
UArithmeticShiftRight, /// (MetaArithmetic, uint a, uint b) -> uint
|
|
|
|
UBitwiseAnd, /// (MetaArithmetic, uint a, uint b) -> uint
|
|
|
|
UBitwiseOr, /// (MetaArithmetic, uint a, uint b) -> uint
|
|
|
|
UBitwiseXor, /// (MetaArithmetic, uint a, uint b) -> uint
|
|
|
|
UBitwiseNot, /// (MetaArithmetic, uint a) -> uint
|
|
|
|
UBitfieldInsert, /// (MetaArithmetic, uint base, uint insert, int offset, int bits) -> uint
|
|
|
|
UBitfieldExtract, /// (MetaArithmetic, uint value, int offset, int offset) -> uint
|
|
|
|
UBitCount, /// (MetaArithmetic, uint) -> uint
|
2019-11-12 14:07:22 +00:00
|
|
|
UBitMSB, /// (MetaArithmetic, uint) -> uint
|
2019-06-06 22:31:14 +00:00
|
|
|
|
2019-07-20 21:38:25 +00:00
|
|
|
HAdd, /// (MetaArithmetic, f16vec2 a, f16vec2 b) -> f16vec2
|
|
|
|
HMul, /// (MetaArithmetic, f16vec2 a, f16vec2 b) -> f16vec2
|
|
|
|
HFma, /// (MetaArithmetic, f16vec2 a, f16vec2 b, f16vec2 c) -> f16vec2
|
|
|
|
HAbsolute, /// (f16vec2 a) -> f16vec2
|
|
|
|
HNegate, /// (f16vec2 a, bool first, bool second) -> f16vec2
|
|
|
|
HClamp, /// (f16vec2 src, float min, float max) -> f16vec2
|
|
|
|
HCastFloat, /// (MetaArithmetic, float a) -> f16vec2
|
|
|
|
HUnpack, /// (Tegra::Shader::HalfType, T value) -> f16vec2
|
|
|
|
HMergeF32, /// (f16vec2 src) -> float
|
|
|
|
HMergeH0, /// (f16vec2 dest, f16vec2 src) -> f16vec2
|
|
|
|
HMergeH1, /// (f16vec2 dest, f16vec2 src) -> f16vec2
|
|
|
|
HPack2, /// (float a, float b) -> f16vec2
|
2019-06-06 22:31:14 +00:00
|
|
|
|
|
|
|
LogicalAssign, /// (bool& dst, bool src) -> void
|
|
|
|
LogicalAnd, /// (bool a, bool b) -> bool
|
|
|
|
LogicalOr, /// (bool a, bool b) -> bool
|
|
|
|
LogicalXor, /// (bool a, bool b) -> bool
|
|
|
|
LogicalNegate, /// (bool a) -> bool
|
|
|
|
LogicalPick2, /// (bool2 pair, uint index) -> bool
|
2019-07-20 01:20:34 +00:00
|
|
|
LogicalAnd2, /// (bool2 a) -> bool
|
2019-06-06 22:31:14 +00:00
|
|
|
|
|
|
|
LogicalFLessThan, /// (float a, float b) -> bool
|
|
|
|
LogicalFEqual, /// (float a, float b) -> bool
|
|
|
|
LogicalFLessEqual, /// (float a, float b) -> bool
|
|
|
|
LogicalFGreaterThan, /// (float a, float b) -> bool
|
|
|
|
LogicalFNotEqual, /// (float a, float b) -> bool
|
|
|
|
LogicalFGreaterEqual, /// (float a, float b) -> bool
|
|
|
|
LogicalFIsNan, /// (float a) -> bool
|
|
|
|
|
|
|
|
LogicalILessThan, /// (int a, int b) -> bool
|
|
|
|
LogicalIEqual, /// (int a, int b) -> bool
|
|
|
|
LogicalILessEqual, /// (int a, int b) -> bool
|
|
|
|
LogicalIGreaterThan, /// (int a, int b) -> bool
|
|
|
|
LogicalINotEqual, /// (int a, int b) -> bool
|
|
|
|
LogicalIGreaterEqual, /// (int a, int b) -> bool
|
|
|
|
|
|
|
|
LogicalULessThan, /// (uint a, uint b) -> bool
|
|
|
|
LogicalUEqual, /// (uint a, uint b) -> bool
|
|
|
|
LogicalULessEqual, /// (uint a, uint b) -> bool
|
|
|
|
LogicalUGreaterThan, /// (uint a, uint b) -> bool
|
|
|
|
LogicalUNotEqual, /// (uint a, uint b) -> bool
|
|
|
|
LogicalUGreaterEqual, /// (uint a, uint b) -> bool
|
|
|
|
|
|
|
|
Logical2HLessThan, /// (MetaHalfArithmetic, f16vec2 a, f16vec2) -> bool2
|
|
|
|
Logical2HEqual, /// (MetaHalfArithmetic, f16vec2 a, f16vec2) -> bool2
|
|
|
|
Logical2HLessEqual, /// (MetaHalfArithmetic, f16vec2 a, f16vec2) -> bool2
|
|
|
|
Logical2HGreaterThan, /// (MetaHalfArithmetic, f16vec2 a, f16vec2) -> bool2
|
|
|
|
Logical2HNotEqual, /// (MetaHalfArithmetic, f16vec2 a, f16vec2) -> bool2
|
|
|
|
Logical2HGreaterEqual, /// (MetaHalfArithmetic, f16vec2 a, f16vec2) -> bool2
|
|
|
|
Logical2HLessThanWithNan, /// (MetaHalfArithmetic, f16vec2 a, f16vec2) -> bool2
|
|
|
|
Logical2HEqualWithNan, /// (MetaHalfArithmetic, f16vec2 a, f16vec2) -> bool2
|
|
|
|
Logical2HLessEqualWithNan, /// (MetaHalfArithmetic, f16vec2 a, f16vec2) -> bool2
|
|
|
|
Logical2HGreaterThanWithNan, /// (MetaHalfArithmetic, f16vec2 a, f16vec2) -> bool2
|
|
|
|
Logical2HNotEqualWithNan, /// (MetaHalfArithmetic, f16vec2 a, f16vec2) -> bool2
|
|
|
|
Logical2HGreaterEqualWithNan, /// (MetaHalfArithmetic, f16vec2 a, f16vec2) -> bool2
|
|
|
|
|
|
|
|
Texture, /// (MetaTexture, float[N] coords) -> float4
|
|
|
|
TextureLod, /// (MetaTexture, float[N] coords) -> float4
|
|
|
|
TextureGather, /// (MetaTexture, float[N] coords) -> float4
|
|
|
|
TextureQueryDimensions, /// (MetaTexture, float a) -> float4
|
|
|
|
TextureQueryLod, /// (MetaTexture, float[N] coords) -> float4
|
|
|
|
TexelFetch, /// (MetaTexture, int[N], int) -> float4
|
2019-11-12 17:43:08 +00:00
|
|
|
TextureGradient, /// (MetaTexture, float[N] coords, float[N*2] derivates) -> float4
|
2019-06-06 22:31:14 +00:00
|
|
|
|
2019-09-18 04:50:40 +00:00
|
|
|
ImageLoad, /// (MetaImage, int[N] coords) -> void
|
|
|
|
ImageStore, /// (MetaImage, int[N] coords) -> void
|
|
|
|
|
2019-07-18 00:03:53 +00:00
|
|
|
AtomicImageAdd, /// (MetaImage, int[N] coords) -> void
|
|
|
|
AtomicImageAnd, /// (MetaImage, int[N] coords) -> void
|
|
|
|
AtomicImageOr, /// (MetaImage, int[N] coords) -> void
|
|
|
|
AtomicImageXor, /// (MetaImage, int[N] coords) -> void
|
|
|
|
AtomicImageExchange, /// (MetaImage, int[N] coords) -> void
|
2019-04-27 05:07:18 +00:00
|
|
|
|
2020-03-13 16:06:26 +00:00
|
|
|
AtomicUExchange, /// (memory, uint) -> uint
|
|
|
|
AtomicUAdd, /// (memory, uint) -> uint
|
|
|
|
AtomicUMin, /// (memory, uint) -> uint
|
|
|
|
AtomicUMax, /// (memory, uint) -> uint
|
|
|
|
AtomicUAnd, /// (memory, uint) -> uint
|
|
|
|
AtomicUOr, /// (memory, uint) -> uint
|
|
|
|
AtomicUXor, /// (memory, uint) -> uint
|
|
|
|
|
|
|
|
AtomicIExchange, /// (memory, int) -> int
|
|
|
|
AtomicIAdd, /// (memory, int) -> int
|
|
|
|
AtomicIMin, /// (memory, int) -> int
|
|
|
|
AtomicIMax, /// (memory, int) -> int
|
|
|
|
AtomicIAnd, /// (memory, int) -> int
|
|
|
|
AtomicIOr, /// (memory, int) -> int
|
|
|
|
AtomicIXor, /// (memory, int) -> int
|
2020-01-16 07:00:52 +00:00
|
|
|
|
2020-04-06 05:24:47 +00:00
|
|
|
ReduceUAdd, /// (memory, uint) -> void
|
|
|
|
ReduceUMin, /// (memory, uint) -> void
|
|
|
|
ReduceUMax, /// (memory, uint) -> void
|
|
|
|
ReduceUAnd, /// (memory, uint) -> void
|
|
|
|
ReduceUOr, /// (memory, uint) -> void
|
|
|
|
ReduceUXor, /// (memory, uint) -> void
|
|
|
|
|
|
|
|
ReduceIAdd, /// (memory, int) -> void
|
|
|
|
ReduceIMin, /// (memory, int) -> void
|
|
|
|
ReduceIMax, /// (memory, int) -> void
|
|
|
|
ReduceIAnd, /// (memory, int) -> void
|
|
|
|
ReduceIOr, /// (memory, int) -> void
|
|
|
|
ReduceIXor, /// (memory, int) -> void
|
|
|
|
|
2019-06-25 17:03:51 +00:00
|
|
|
Branch, /// (uint branch_target) -> void
|
|
|
|
BranchIndirect, /// (uint branch_target) -> void
|
|
|
|
PushFlowStack, /// (uint branch_target) -> void
|
|
|
|
PopFlowStack, /// () -> void
|
|
|
|
Exit, /// () -> void
|
|
|
|
Discard, /// () -> void
|
2019-06-06 22:31:14 +00:00
|
|
|
|
|
|
|
EmitVertex, /// () -> void
|
|
|
|
EndPrimitive, /// () -> void
|
|
|
|
|
2019-10-30 21:17:27 +00:00
|
|
|
InvocationId, /// () -> int
|
2019-06-06 22:31:14 +00:00
|
|
|
YNegate, /// () -> float
|
|
|
|
LocalInvocationIdX, /// () -> uint
|
|
|
|
LocalInvocationIdY, /// () -> uint
|
|
|
|
LocalInvocationIdZ, /// () -> uint
|
|
|
|
WorkGroupIdX, /// () -> uint
|
|
|
|
WorkGroupIdY, /// () -> uint
|
|
|
|
WorkGroupIdZ, /// () -> uint
|
|
|
|
|
2019-08-10 02:50:21 +00:00
|
|
|
BallotThread, /// (bool) -> uint
|
|
|
|
VoteAll, /// (bool) -> bool
|
|
|
|
VoteAny, /// (bool) -> bool
|
|
|
|
VoteEqual, /// (bool) -> bool
|
|
|
|
|
2019-11-03 02:44:13 +00:00
|
|
|
ThreadId, /// () -> uint
|
|
|
|
ShuffleIndexed, /// (uint value, uint index) -> uint
|
2019-08-27 01:09:12 +00:00
|
|
|
|
2019-12-10 00:46:12 +00:00
|
|
|
MemoryBarrierGL, /// () -> void
|
|
|
|
|
2019-06-06 22:31:14 +00:00
|
|
|
Amount,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class InternalFlag {
|
|
|
|
Zero = 0,
|
|
|
|
Sign = 1,
|
|
|
|
Carry = 2,
|
|
|
|
Overflow = 3,
|
|
|
|
Amount = 4,
|
|
|
|
};
|
|
|
|
|
2019-06-02 21:52:07 +00:00
|
|
|
enum class MetaStackClass {
|
|
|
|
Ssy,
|
|
|
|
Pbk,
|
|
|
|
};
|
|
|
|
|
2019-06-06 23:01:28 +00:00
|
|
|
class OperationNode;
|
|
|
|
class ConditionalNode;
|
|
|
|
class GprNode;
|
2020-01-07 18:53:46 +00:00
|
|
|
class CustomVarNode;
|
2019-06-06 23:01:28 +00:00
|
|
|
class ImmediateNode;
|
|
|
|
class InternalFlagNode;
|
|
|
|
class PredicateNode;
|
|
|
|
class AbufNode;
|
|
|
|
class CbufNode;
|
|
|
|
class LmemNode;
|
2019-11-01 03:34:38 +00:00
|
|
|
class PatchNode;
|
2019-07-30 03:21:46 +00:00
|
|
|
class SmemNode;
|
2019-06-06 23:01:28 +00:00
|
|
|
class GmemNode;
|
|
|
|
class CommentNode;
|
|
|
|
|
2020-01-07 18:53:46 +00:00
|
|
|
using NodeData = std::variant<OperationNode, ConditionalNode, GprNode, CustomVarNode, ImmediateNode,
|
2019-11-01 03:34:38 +00:00
|
|
|
InternalFlagNode, PredicateNode, AbufNode, PatchNode, CbufNode,
|
|
|
|
LmemNode, SmemNode, GmemNode, CommentNode>;
|
2019-06-06 23:01:28 +00:00
|
|
|
using Node = std::shared_ptr<NodeData>;
|
|
|
|
using Node4 = std::array<Node, 4>;
|
|
|
|
using NodeBlock = std::vector<Node>;
|
|
|
|
|
2020-01-05 19:23:24 +00:00
|
|
|
class BindlessSamplerNode;
|
|
|
|
class ArraySamplerNode;
|
|
|
|
|
|
|
|
using TrackSamplerData = std::variant<BindlessSamplerNode, ArraySamplerNode>;
|
|
|
|
using TrackSampler = std::shared_ptr<TrackSamplerData>;
|
|
|
|
|
2019-06-06 22:31:14 +00:00
|
|
|
class Sampler {
|
|
|
|
public:
|
2019-06-06 23:01:28 +00:00
|
|
|
/// This constructor is for bound samplers
|
2019-10-28 05:31:05 +00:00
|
|
|
constexpr explicit Sampler(u32 index, u32 offset, Tegra::Shader::TextureType type,
|
2020-01-05 22:36:21 +00:00
|
|
|
bool is_array, bool is_shadow, bool is_buffer, bool is_indexed)
|
2019-11-06 07:32:43 +00:00
|
|
|
: index{index}, offset{offset}, type{type}, is_array{is_array}, is_shadow{is_shadow},
|
2020-01-05 22:36:21 +00:00
|
|
|
is_buffer{is_buffer}, is_indexed{is_indexed} {}
|
2019-06-06 22:31:14 +00:00
|
|
|
|
2019-06-06 23:01:28 +00:00
|
|
|
/// This constructor is for bindless samplers
|
2019-10-28 05:31:05 +00:00
|
|
|
constexpr explicit Sampler(u32 index, u32 offset, u32 buffer, Tegra::Shader::TextureType type,
|
2020-01-05 22:36:21 +00:00
|
|
|
bool is_array, bool is_shadow, bool is_buffer, bool is_indexed)
|
2019-10-28 05:31:05 +00:00
|
|
|
: index{index}, offset{offset}, buffer{buffer}, type{type}, is_array{is_array},
|
2020-01-05 22:36:21 +00:00
|
|
|
is_shadow{is_shadow}, is_buffer{is_buffer}, is_bindless{true}, is_indexed{is_indexed} {}
|
2019-10-28 05:31:05 +00:00
|
|
|
|
|
|
|
constexpr u32 GetIndex() const {
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
constexpr u32 GetOffset() const {
|
2019-06-06 22:31:14 +00:00
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
2019-10-28 05:31:05 +00:00
|
|
|
constexpr u32 GetBuffer() const {
|
|
|
|
return buffer;
|
2019-06-06 22:31:14 +00:00
|
|
|
}
|
|
|
|
|
2019-10-28 05:31:05 +00:00
|
|
|
constexpr Tegra::Shader::TextureType GetType() const {
|
2019-06-06 22:31:14 +00:00
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2019-10-28 05:31:05 +00:00
|
|
|
constexpr bool IsArray() const {
|
2019-06-06 22:31:14 +00:00
|
|
|
return is_array;
|
|
|
|
}
|
|
|
|
|
2019-10-28 05:31:05 +00:00
|
|
|
constexpr bool IsShadow() const {
|
2019-06-06 22:31:14 +00:00
|
|
|
return is_shadow;
|
|
|
|
}
|
|
|
|
|
2019-11-06 07:32:43 +00:00
|
|
|
constexpr bool IsBuffer() const {
|
|
|
|
return is_buffer;
|
|
|
|
}
|
|
|
|
|
2019-10-28 05:31:05 +00:00
|
|
|
constexpr bool IsBindless() const {
|
2019-06-06 22:31:14 +00:00
|
|
|
return is_bindless;
|
|
|
|
}
|
|
|
|
|
2020-01-05 22:36:21 +00:00
|
|
|
constexpr bool IsIndexed() const {
|
|
|
|
return is_indexed;
|
|
|
|
}
|
|
|
|
|
|
|
|
constexpr u32 Size() const {
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2020-01-24 14:44:34 +00:00
|
|
|
constexpr void SetSize(u32 new_size) {
|
2020-01-05 22:36:21 +00:00
|
|
|
size = new_size;
|
|
|
|
}
|
|
|
|
|
2019-06-06 22:31:14 +00:00
|
|
|
private:
|
2019-10-28 05:31:05 +00:00
|
|
|
u32 index{}; ///< Emulated index given for the this sampler.
|
|
|
|
u32 offset{}; ///< Offset in the const buffer from where the sampler is being read.
|
|
|
|
u32 buffer{}; ///< Buffer where the bindless sampler is being read (unused on bound samplers).
|
2020-02-22 22:40:26 +00:00
|
|
|
u32 size{1}; ///< Size of the sampler.
|
2019-10-28 05:31:05 +00:00
|
|
|
|
2019-06-06 22:31:14 +00:00
|
|
|
Tegra::Shader::TextureType type{}; ///< The type used to sample this texture (Texture2D, etc)
|
|
|
|
bool is_array{}; ///< Whether the texture is being sampled as an array texture or not.
|
|
|
|
bool is_shadow{}; ///< Whether the texture is being sampled as a depth texture or not.
|
2019-11-06 07:32:43 +00:00
|
|
|
bool is_buffer{}; ///< Whether the texture is a texture buffer without sampler.
|
2019-06-06 22:31:14 +00:00
|
|
|
bool is_bindless{}; ///< Whether this sampler belongs to a bindless texture or not.
|
2020-01-05 22:36:21 +00:00
|
|
|
bool is_indexed{}; ///< Whether this sampler is an indexed array of textures.
|
2019-06-06 22:31:14 +00:00
|
|
|
};
|
|
|
|
|
2020-01-05 19:23:24 +00:00
|
|
|
/// Represents a tracked bindless sampler into a direct const buffer
|
|
|
|
class ArraySamplerNode final {
|
|
|
|
public:
|
|
|
|
explicit ArraySamplerNode(u32 index, u32 base_offset, u32 bindless_var)
|
|
|
|
: index{index}, base_offset{base_offset}, bindless_var{bindless_var} {}
|
|
|
|
|
2020-01-24 14:44:34 +00:00
|
|
|
constexpr u32 GetIndex() const {
|
2020-01-05 19:23:24 +00:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2020-01-24 14:44:34 +00:00
|
|
|
constexpr u32 GetBaseOffset() const {
|
2020-01-05 19:23:24 +00:00
|
|
|
return base_offset;
|
|
|
|
}
|
|
|
|
|
2020-01-24 14:44:34 +00:00
|
|
|
constexpr u32 GetIndexVar() const {
|
2020-01-05 19:23:24 +00:00
|
|
|
return bindless_var;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
u32 index;
|
|
|
|
u32 base_offset;
|
|
|
|
u32 bindless_var;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Represents a tracked bindless sampler into a direct const buffer
|
|
|
|
class BindlessSamplerNode final {
|
|
|
|
public:
|
|
|
|
explicit BindlessSamplerNode(u32 index, u32 offset) : index{index}, offset{offset} {}
|
|
|
|
|
2020-01-24 14:44:34 +00:00
|
|
|
constexpr u32 GetIndex() const {
|
2020-01-05 19:23:24 +00:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2020-01-24 14:44:34 +00:00
|
|
|
constexpr u32 GetOffset() const {
|
2020-01-05 19:23:24 +00:00
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
u32 index;
|
|
|
|
u32 offset;
|
2019-06-06 22:31:14 +00:00
|
|
|
};
|
|
|
|
|
2019-09-06 02:26:05 +00:00
|
|
|
class Image final {
|
2019-04-27 05:07:18 +00:00
|
|
|
public:
|
2019-10-28 05:31:05 +00:00
|
|
|
/// This constructor is for bound images
|
|
|
|
constexpr explicit Image(u32 index, u32 offset, Tegra::Shader::ImageType type)
|
|
|
|
: index{index}, offset{offset}, type{type} {}
|
2019-04-27 05:07:18 +00:00
|
|
|
|
2019-10-28 05:31:05 +00:00
|
|
|
/// This constructor is for bindless samplers
|
|
|
|
constexpr explicit Image(u32 index, u32 offset, u32 buffer, Tegra::Shader::ImageType type)
|
|
|
|
: index{index}, offset{offset}, buffer{buffer}, type{type}, is_bindless{true} {}
|
2019-07-18 00:03:53 +00:00
|
|
|
|
|
|
|
void MarkWrite() {
|
|
|
|
is_written = true;
|
|
|
|
}
|
2019-04-27 06:04:13 +00:00
|
|
|
|
2019-09-06 02:26:05 +00:00
|
|
|
void MarkRead() {
|
|
|
|
is_read = true;
|
|
|
|
}
|
|
|
|
|
2019-09-18 04:50:40 +00:00
|
|
|
void MarkAtomic() {
|
|
|
|
MarkWrite();
|
|
|
|
MarkRead();
|
|
|
|
is_atomic = true;
|
2019-09-06 02:26:05 +00:00
|
|
|
}
|
|
|
|
|
2019-10-28 05:31:05 +00:00
|
|
|
constexpr u32 GetIndex() const {
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
constexpr u32 GetOffset() const {
|
2019-04-27 05:07:18 +00:00
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
2019-10-28 05:31:05 +00:00
|
|
|
constexpr u32 GetBuffer() const {
|
|
|
|
return buffer;
|
2019-04-27 05:07:18 +00:00
|
|
|
}
|
|
|
|
|
2019-09-06 02:26:05 +00:00
|
|
|
constexpr Tegra::Shader::ImageType GetType() const {
|
2019-04-27 05:07:18 +00:00
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2019-09-06 02:26:05 +00:00
|
|
|
constexpr bool IsBindless() const {
|
2019-04-27 05:07:18 +00:00
|
|
|
return is_bindless;
|
|
|
|
}
|
|
|
|
|
2019-09-06 02:26:05 +00:00
|
|
|
constexpr bool IsWritten() const {
|
|
|
|
return is_written;
|
2019-07-12 00:54:07 +00:00
|
|
|
}
|
|
|
|
|
2019-07-18 00:03:53 +00:00
|
|
|
constexpr bool IsRead() const {
|
|
|
|
return is_read;
|
|
|
|
}
|
|
|
|
|
2019-09-18 04:50:40 +00:00
|
|
|
constexpr bool IsAtomic() const {
|
|
|
|
return is_atomic;
|
2019-07-18 00:03:53 +00:00
|
|
|
}
|
|
|
|
|
2019-04-27 05:07:18 +00:00
|
|
|
private:
|
2019-10-28 05:31:05 +00:00
|
|
|
u32 index{};
|
|
|
|
u32 offset{};
|
|
|
|
u32 buffer{};
|
|
|
|
|
2019-04-27 05:07:18 +00:00
|
|
|
Tegra::Shader::ImageType type{};
|
|
|
|
bool is_bindless{};
|
2019-09-06 02:26:05 +00:00
|
|
|
bool is_written{};
|
2019-07-18 00:03:53 +00:00
|
|
|
bool is_read{};
|
2019-09-18 04:50:40 +00:00
|
|
|
bool is_atomic{};
|
2019-04-27 05:07:18 +00:00
|
|
|
};
|
|
|
|
|
2019-06-06 22:31:14 +00:00
|
|
|
struct GlobalMemoryBase {
|
|
|
|
u32 cbuf_index{};
|
|
|
|
u32 cbuf_offset{};
|
|
|
|
|
|
|
|
bool operator<(const GlobalMemoryBase& rhs) const {
|
|
|
|
return std::tie(cbuf_index, cbuf_offset) < std::tie(rhs.cbuf_index, rhs.cbuf_offset);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-06-06 23:01:28 +00:00
|
|
|
/// Parameters describing an arithmetic operation
|
2019-06-06 22:31:14 +00:00
|
|
|
struct MetaArithmetic {
|
2019-06-06 23:01:28 +00:00
|
|
|
bool precise{}; ///< Whether the operation can be constraint or not
|
2019-06-06 22:31:14 +00:00
|
|
|
};
|
|
|
|
|
2019-06-06 23:01:28 +00:00
|
|
|
/// Parameters describing a texture sampler
|
2019-06-06 22:31:14 +00:00
|
|
|
struct MetaTexture {
|
|
|
|
const Sampler& sampler;
|
2019-06-06 23:01:28 +00:00
|
|
|
Node array;
|
|
|
|
Node depth_compare;
|
2019-06-06 22:31:14 +00:00
|
|
|
std::vector<Node> aoffi;
|
2019-12-16 07:09:24 +00:00
|
|
|
std::vector<Node> ptp;
|
2019-11-12 17:43:08 +00:00
|
|
|
std::vector<Node> derivates;
|
2019-06-06 23:01:28 +00:00
|
|
|
Node bias;
|
|
|
|
Node lod;
|
2020-02-02 01:49:25 +00:00
|
|
|
Node component;
|
2019-06-06 22:31:14 +00:00
|
|
|
u32 element{};
|
2020-02-02 01:49:25 +00:00
|
|
|
Node index;
|
2019-06-06 22:31:14 +00:00
|
|
|
};
|
|
|
|
|
2019-04-27 05:07:18 +00:00
|
|
|
struct MetaImage {
|
|
|
|
const Image& image;
|
|
|
|
std::vector<Node> values;
|
2019-09-18 04:07:01 +00:00
|
|
|
u32 element{};
|
2019-04-27 05:07:18 +00:00
|
|
|
};
|
|
|
|
|
2019-06-06 23:01:28 +00:00
|
|
|
/// Parameters that modify an operation but are not part of any particular operand
|
2019-06-21 01:22:20 +00:00
|
|
|
using Meta =
|
|
|
|
std::variant<MetaArithmetic, MetaTexture, MetaImage, MetaStackClass, Tegra::Shader::HalfType>;
|
2019-06-06 22:31:14 +00:00
|
|
|
|
2019-12-30 17:54:53 +00:00
|
|
|
class AmendNode {
|
|
|
|
public:
|
2020-01-04 18:40:57 +00:00
|
|
|
std::optional<std::size_t> GetAmendIndex() const {
|
2019-12-30 17:54:53 +00:00
|
|
|
if (amend_index == amend_null_index) {
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
return {amend_index};
|
|
|
|
}
|
|
|
|
|
2020-01-04 18:40:57 +00:00
|
|
|
void SetAmendIndex(std::size_t index) {
|
2019-12-30 17:54:53 +00:00
|
|
|
amend_index = index;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearAmend() {
|
|
|
|
amend_index = amend_null_index;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-01-04 18:40:57 +00:00
|
|
|
static constexpr std::size_t amend_null_index = 0xFFFFFFFFFFFFFFFFULL;
|
|
|
|
std::size_t amend_index{amend_null_index};
|
2019-12-30 17:54:53 +00:00
|
|
|
};
|
|
|
|
|
2019-06-06 22:31:14 +00:00
|
|
|
/// Holds any kind of operation that can be done in the IR
|
2019-12-30 17:54:53 +00:00
|
|
|
class OperationNode final : public AmendNode {
|
2019-06-06 22:31:14 +00:00
|
|
|
public:
|
|
|
|
explicit OperationNode(OperationCode code) : OperationNode(code, Meta{}) {}
|
|
|
|
|
|
|
|
explicit OperationNode(OperationCode code, Meta meta)
|
2019-10-15 22:21:56 +00:00
|
|
|
: OperationNode(code, std::move(meta), std::vector<Node>{}) {}
|
2019-06-06 22:31:14 +00:00
|
|
|
|
|
|
|
explicit OperationNode(OperationCode code, std::vector<Node> operands)
|
|
|
|
: OperationNode(code, Meta{}, std::move(operands)) {}
|
|
|
|
|
|
|
|
explicit OperationNode(OperationCode code, Meta meta, std::vector<Node> operands)
|
|
|
|
: code{code}, meta{std::move(meta)}, operands{std::move(operands)} {}
|
|
|
|
|
|
|
|
template <typename... Args>
|
|
|
|
explicit OperationNode(OperationCode code, Meta meta, Args&&... operands)
|
|
|
|
: code{code}, meta{std::move(meta)}, operands{operands...} {}
|
|
|
|
|
|
|
|
OperationCode GetCode() const {
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Meta& GetMeta() const {
|
|
|
|
return meta;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::size_t GetOperandsCount() const {
|
|
|
|
return operands.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
const Node& operator[](std::size_t operand_index) const {
|
|
|
|
return operands.at(operand_index);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
OperationCode code{};
|
|
|
|
Meta meta{};
|
|
|
|
std::vector<Node> operands;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Encloses inside any kind of node that returns a boolean conditionally-executed code
|
2019-12-30 17:54:53 +00:00
|
|
|
class ConditionalNode final : public AmendNode {
|
2019-06-06 22:31:14 +00:00
|
|
|
public:
|
|
|
|
explicit ConditionalNode(Node condition, std::vector<Node>&& code)
|
2019-06-06 23:01:28 +00:00
|
|
|
: condition{std::move(condition)}, code{std::move(code)} {}
|
2019-06-06 22:31:14 +00:00
|
|
|
|
2019-06-06 23:01:28 +00:00
|
|
|
const Node& GetCondition() const {
|
2019-06-06 22:31:14 +00:00
|
|
|
return condition;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<Node>& GetCode() const {
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-06-06 23:01:28 +00:00
|
|
|
Node condition; ///< Condition to be satisfied
|
2019-06-06 22:31:14 +00:00
|
|
|
std::vector<Node> code; ///< Code to execute
|
|
|
|
};
|
|
|
|
|
|
|
|
/// A general purpose register
|
|
|
|
class GprNode final {
|
|
|
|
public:
|
|
|
|
explicit constexpr GprNode(Tegra::Shader::Register index) : index{index} {}
|
|
|
|
|
|
|
|
u32 GetIndex() const {
|
|
|
|
return static_cast<u32>(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-06-06 23:01:28 +00:00
|
|
|
Tegra::Shader::Register index{};
|
2019-06-06 22:31:14 +00:00
|
|
|
};
|
|
|
|
|
2020-01-07 18:53:46 +00:00
|
|
|
/// A custom variable
|
|
|
|
class CustomVarNode final {
|
|
|
|
public:
|
|
|
|
explicit constexpr CustomVarNode(u32 index) : index{index} {}
|
|
|
|
|
2020-01-24 14:44:34 +00:00
|
|
|
constexpr u32 GetIndex() const {
|
2020-01-07 18:53:46 +00:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
u32 index{};
|
|
|
|
};
|
|
|
|
|
2019-06-06 22:31:14 +00:00
|
|
|
/// A 32-bits value that represents an immediate value
|
|
|
|
class ImmediateNode final {
|
|
|
|
public:
|
|
|
|
explicit constexpr ImmediateNode(u32 value) : value{value} {}
|
|
|
|
|
|
|
|
u32 GetValue() const {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-06-06 23:01:28 +00:00
|
|
|
u32 value{};
|
2019-06-06 22:31:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// One of Maxwell's internal flags
|
|
|
|
class InternalFlagNode final {
|
|
|
|
public:
|
|
|
|
explicit constexpr InternalFlagNode(InternalFlag flag) : flag{flag} {}
|
|
|
|
|
|
|
|
InternalFlag GetFlag() const {
|
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-06-06 23:01:28 +00:00
|
|
|
InternalFlag flag{};
|
2019-06-06 22:31:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// A predicate register, it can be negated without additional nodes
|
|
|
|
class PredicateNode final {
|
|
|
|
public:
|
|
|
|
explicit constexpr PredicateNode(Tegra::Shader::Pred index, bool negated)
|
|
|
|
: index{index}, negated{negated} {}
|
|
|
|
|
|
|
|
Tegra::Shader::Pred GetIndex() const {
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsNegated() const {
|
|
|
|
return negated;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-06-06 23:01:28 +00:00
|
|
|
Tegra::Shader::Pred index{};
|
|
|
|
bool negated{};
|
2019-06-06 22:31:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Attribute buffer memory (known as attributes or varyings in GLSL terms)
|
|
|
|
class AbufNode final {
|
|
|
|
public:
|
|
|
|
// Initialize for standard attributes (index is explicit).
|
|
|
|
explicit AbufNode(Tegra::Shader::Attribute::Index index, u32 element, Node buffer = {})
|
|
|
|
: buffer{std::move(buffer)}, index{index}, element{element} {}
|
|
|
|
|
|
|
|
// Initialize for physical attributes (index is a variable value).
|
|
|
|
explicit AbufNode(Node physical_address, Node buffer = {})
|
2019-06-06 23:01:28 +00:00
|
|
|
: physical_address{std::move(physical_address)}, buffer{std::move(buffer)} {}
|
2019-06-06 22:31:14 +00:00
|
|
|
|
|
|
|
Tegra::Shader::Attribute::Index GetIndex() const {
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 GetElement() const {
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
2019-06-06 23:01:28 +00:00
|
|
|
const Node& GetBuffer() const {
|
2019-06-06 22:31:14 +00:00
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsPhysicalBuffer() const {
|
|
|
|
return static_cast<bool>(physical_address);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Node& GetPhysicalAddress() const {
|
|
|
|
return physical_address;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Node physical_address;
|
|
|
|
Node buffer;
|
|
|
|
Tegra::Shader::Attribute::Index index{};
|
|
|
|
u32 element{};
|
|
|
|
};
|
|
|
|
|
2019-11-01 03:34:38 +00:00
|
|
|
/// Patch memory (used to communicate tessellation stages).
|
|
|
|
class PatchNode final {
|
|
|
|
public:
|
|
|
|
explicit PatchNode(u32 offset) : offset{offset} {}
|
|
|
|
|
|
|
|
u32 GetOffset() const {
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
u32 offset{};
|
|
|
|
};
|
|
|
|
|
2019-06-06 22:31:14 +00:00
|
|
|
/// Constant buffer node, usually mapped to uniform buffers in GLSL
|
|
|
|
class CbufNode final {
|
|
|
|
public:
|
2019-06-06 23:01:28 +00:00
|
|
|
explicit CbufNode(u32 index, Node offset) : index{index}, offset{std::move(offset)} {}
|
2019-06-06 22:31:14 +00:00
|
|
|
|
|
|
|
u32 GetIndex() const {
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2019-06-06 23:01:28 +00:00
|
|
|
const Node& GetOffset() const {
|
2019-06-06 22:31:14 +00:00
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-06-06 23:01:28 +00:00
|
|
|
u32 index{};
|
|
|
|
Node offset;
|
2019-06-06 22:31:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Local memory node
|
|
|
|
class LmemNode final {
|
|
|
|
public:
|
2019-06-06 23:01:28 +00:00
|
|
|
explicit LmemNode(Node address) : address{std::move(address)} {}
|
2019-07-30 03:21:46 +00:00
|
|
|
|
|
|
|
const Node& GetAddress() const {
|
|
|
|
return address;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Node address;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Shared memory node
|
|
|
|
class SmemNode final {
|
|
|
|
public:
|
|
|
|
explicit SmemNode(Node address) : address{std::move(address)} {}
|
2019-06-06 22:31:14 +00:00
|
|
|
|
2019-06-06 23:01:28 +00:00
|
|
|
const Node& GetAddress() const {
|
2019-06-06 22:31:14 +00:00
|
|
|
return address;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-06-06 23:01:28 +00:00
|
|
|
Node address;
|
2019-06-06 22:31:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Global memory node
|
|
|
|
class GmemNode final {
|
|
|
|
public:
|
|
|
|
explicit GmemNode(Node real_address, Node base_address, const GlobalMemoryBase& descriptor)
|
2019-06-06 23:01:28 +00:00
|
|
|
: real_address{std::move(real_address)}, base_address{std::move(base_address)},
|
|
|
|
descriptor{descriptor} {}
|
2019-06-06 22:31:14 +00:00
|
|
|
|
2019-06-06 23:01:28 +00:00
|
|
|
const Node& GetRealAddress() const {
|
2019-06-06 22:31:14 +00:00
|
|
|
return real_address;
|
|
|
|
}
|
|
|
|
|
2019-06-06 23:01:28 +00:00
|
|
|
const Node& GetBaseAddress() const {
|
2019-06-06 22:31:14 +00:00
|
|
|
return base_address;
|
|
|
|
}
|
|
|
|
|
|
|
|
const GlobalMemoryBase& GetDescriptor() const {
|
|
|
|
return descriptor;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-06-06 23:01:28 +00:00
|
|
|
Node real_address;
|
|
|
|
Node base_address;
|
|
|
|
GlobalMemoryBase descriptor;
|
2019-06-06 22:31:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Commentary, can be dropped
|
2020-01-04 18:40:57 +00:00
|
|
|
class CommentNode final {
|
2019-06-06 22:31:14 +00:00
|
|
|
public:
|
|
|
|
explicit CommentNode(std::string text) : text{std::move(text)} {}
|
|
|
|
|
|
|
|
const std::string& GetText() const {
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string text;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace VideoCommon::Shader
|