From e0d528d7bfc638684afebd9b4b0272be8ca80c89 Mon Sep 17 00:00:00 2001 From: GPUCode Date: Sun, 6 Nov 2022 21:02:05 +0200 Subject: [PATCH 1/3] Add missing GLSL instructions --- include/sirit/sirit.h | 29 +++++++++++++++++++++++++++++ src/instructions/arithmetic.cpp | 2 ++ src/instructions/extension.cpp | 4 ++++ src/instructions/memory.cpp | 6 ++++++ 4 files changed, 41 insertions(+) diff --git a/include/sirit/sirit.h b/include/sirit/sirit.h index aea4468..0a9fce9 100644 --- a/include/sirit/sirit.h +++ b/include/sirit/sirit.h @@ -365,6 +365,17 @@ public: /// Make a copy of a vector, with a single, variably selected, component modified. Id OpVectorInsertDynamic(Id result_type, Id vector, Id component, Id index); + /// Select arbitrary components from two vectors to make a new vector. + Id OpVectorShuffle(Id result_type, Id vector_1, Id vector_2, std::span components); + + /// Select arbitrary components from two vectors to make a new vector. + template + requires(...&& std::is_convertible_v) Id + OpVectorShuffle(Id result_type, Id vector_1, Id vector_2, Ts&&... components) { + const Literal stack_literals[] = {std::forward(components)...}; + return OpVectorShuffle(result_type, vector_1, vector_2, std::span{stack_literals}); + } + /// Make a copy of a composite object, while modifying one part of it. Id OpCompositeInsert(Id result_type, Id object, Id composite, std::span indexes = {}); @@ -686,6 +697,12 @@ public: /// Result is the unsigned integer addition of Operand 1 and Operand 2, including its carry. Id OpIAddCarry(Id result_type, Id operand_1, Id operand_2); + /// Multiplication of floating-point vector Operand 1 with scalar Operand 2. + Id OpVectorTimesScalar(Id result_type, Id operand_1, Id operand_2); + + /// Dot product of floating-point vector Operand 1 and vector Operand 2. + Id OpDot(Id result_type, Id operand_1, Id operand_2); + // Extensions /// Execute an instruction in an imported set of extended instructions. @@ -837,6 +854,18 @@ public: /// of the pixel specified by offset. Id OpInterpolateAtOffset(Id result_type, Id interpolant, Id offset); + /// Result is the vector in the same direction as x but with a length of 1. + Id OpNormalize(Id result_type, Id x); + + /// Result is the cross product of x and y. + Id OpCross(Id result_type, Id x, Id y); + + /// Result is the length of vector x. + Id OpLength(Id result_type, Id x); + + /// Result is the linear blend of x and y i.e x * (1 - a) + y * a + Id OpFMix(Id result_type, Id x, Id y, Id a); + // Derivatives /// Same result as either OpDPdxFine or OpDPdxCoarse on the input. diff --git a/src/instructions/arithmetic.cpp b/src/instructions/arithmetic.cpp index 4fa8057..ab62177 100644 --- a/src/instructions/arithmetic.cpp +++ b/src/instructions/arithmetic.cpp @@ -40,5 +40,7 @@ DEFINE_BINARY(OpFMod, spv::Op::OpFMod) DEFINE_BINARY(OpSRem, spv::Op::OpSRem) DEFINE_BINARY(OpFRem, spv::Op::OpFRem) DEFINE_BINARY(OpIAddCarry, spv::Op::OpIAddCarry) +DEFINE_BINARY(OpVectorTimesScalar, spv::Op::OpVectorTimesScalar) +DEFINE_BINARY(OpDot, spv::Op::OpDot) } // namespace Sirit diff --git a/src/instructions/extension.cpp b/src/instructions/extension.cpp index 9f7aa43..005c189 100644 --- a/src/instructions/extension.cpp +++ b/src/instructions/extension.cpp @@ -72,5 +72,9 @@ DEFINE_UNARY(OpFindUMsb, GLSLstd450FindUMsb) DEFINE_UNARY(OpInterpolateAtCentroid, GLSLstd450InterpolateAtCentroid) DEFINE_BINARY(OpInterpolateAtSample, GLSLstd450InterpolateAtSample) DEFINE_BINARY(OpInterpolateAtOffset, GLSLstd450InterpolateAtOffset) +DEFINE_UNARY(OpNormalize, GLSLstd450Normalize) +DEFINE_BINARY(OpCross, GLSLstd450Cross) +DEFINE_UNARY(OpLength, GLSLstd450Length) +DEFINE_TRINARY(OpFMix, GLSLstd450FMix) } // namespace Sirit diff --git a/src/instructions/memory.cpp b/src/instructions/memory.cpp index a542e9f..68f0154 100644 --- a/src/instructions/memory.cpp +++ b/src/instructions/memory.cpp @@ -46,6 +46,12 @@ Id Module::OpVectorInsertDynamic(Id result_type, Id vector, Id component, Id ind << index << EndOp{}; } +Id Module::OpVectorShuffle(Id result_type, Id vector_1, Id vector_2, std::span components) { + code->Reserve(5 + components.size()); + return *code << OpId{spv::Op::OpVectorShuffle, result_type} << vector_1 << vector_2 + << components << EndOp{}; +} + Id Module::OpCompositeInsert(Id result_type, Id object, Id composite, std::span indexes) { code->Reserve(5 + indexes.size()); From d75e3198d0c6a17c3d798ad5daf3133a52579f93 Mon Sep 17 00:00:00 2001 From: GPUCode Date: Sun, 6 Nov 2022 21:46:14 +0200 Subject: [PATCH 2/3] stream: Add missing span include --- src/stream.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/stream.h b/src/stream.h index 7029b6c..42e2041 100644 --- a/src/stream.h +++ b/src/stream.h @@ -7,6 +7,7 @@ #pragma once #include +#include #include #include #include From 18c37509fa44b8c6e4543b5d429fbae5d8fe4e5d Mon Sep 17 00:00:00 2001 From: GPUCode <47210458+GPUCode@users.noreply.github.com> Date: Sun, 20 Nov 2022 13:01:05 +0200 Subject: [PATCH 3/3] Support variadic arguments for OpPhi --- include/sirit/sirit.h | 6 ++++++ src/stream.h | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/sirit/sirit.h b/include/sirit/sirit.h index 0a9fce9..dc3c567 100644 --- a/include/sirit/sirit.h +++ b/include/sirit/sirit.h @@ -256,6 +256,12 @@ public: */ Id OpPhi(Id result_type, std::span operands); + template + requires(...&& std::is_convertible_v) Id + OpPhi(Id result_type, Ts&&... operands) { + return OpPhi(result_type, std::span({operands...})); + } + /** * The SSA phi function. This instruction will be revisited when patching phi nodes. * diff --git a/src/stream.h b/src/stream.h index 42e2041..bf9e48a 100644 --- a/src/stream.h +++ b/src/stream.h @@ -7,11 +7,11 @@ #pragma once #include -#include #include #include #include #include +#include #include #include #include