Add helper for generating GLSL450 extinst operations

This commit is contained in:
baldurk
2020-04-02 15:07:19 +01:00
parent 85dedabcf8
commit 9716b407d3
4 changed files with 58 additions and 17 deletions
@@ -34,6 +34,57 @@ namespace rdcspv
{
class Editor;
struct IdOrWord
{
constexpr inline IdOrWord() : value(0) {}
constexpr inline IdOrWord(uint32_t val) : value(val) {}
inline IdOrWord(Id id) : value(id.value()) {}
inline operator uint32_t() const { return value; }
constexpr inline bool operator==(const IdOrWord o) const { return value == o.value; }
constexpr inline bool operator!=(const IdOrWord o) const { return value != o.value; }
constexpr inline bool operator<(const IdOrWord o) const { return value < o.value; }
private:
uint32_t value;
};
// helper in the style of the auto-generated one for GLSL ext insts
struct OpGLSL450
{
OpGLSL450(IdResultType resultType, IdResult result, Id glsl450, rdcspv::GLSLstd450 inst,
const rdcarray<IdOrWord> &params)
: op(OpCode), wordCount(MinWordSize + (uint16_t)params.size())
{
this->resultType = resultType;
this->result = result;
this->glsl450 = glsl450;
this->inst = inst;
this->params.resize(params.size());
for(size_t i = 0; i < params.size(); i++)
this->params[i] = params[i];
}
operator Operation() const
{
rdcarray<uint32_t> words;
words.push_back(resultType.value());
words.push_back(result.value());
words.push_back(glsl450.value());
words.push_back((uint32_t)inst);
words.append(params);
return Operation(OpCode, words);
}
static constexpr Op OpCode = Op::ExtInst;
static constexpr uint16_t MinWordSize = 4U;
Op op;
uint16_t wordCount;
IdResultType resultType;
IdResult result;
Id glsl450;
rdcspv::GLSLstd450 inst;
rdcarray<uint32_t> params;
};
struct OperationList : public rdcarray<Operation>
{
// add an operation and return its result id
@@ -463,12 +463,8 @@ void AnnotateShader(const SPIRVPatchData &patchData, const char *entryName,
rdcspv::Id clampedtype =
editor.DeclareType(rdcspv::Scalar(rdcspv::Op::TypeInt, targetIndexWidth, false));
index = editor.AddOperation(
it, rdcspv::Operation(
rdcspv::Op::ExtInst,
{
clampedtype.value(), editor.MakeId().value(), glsl450.value(),
(uint32_t)rdcspv::GLSLstd450::UMin, index.value(), maxSlotID.value(),
}));
it, rdcspv::OpGLSL450(clampedtype, editor.MakeId(), glsl450,
rdcspv::GLSLstd450::UMin, {index, maxSlotID}));
it++;
}
+3 -6
View File
@@ -1055,12 +1055,9 @@ static void ConvertToMeshOutputCompute(const ShaderReflection &refl, const SPIRV
editor.SetName(packed, StringFormat::Fmt("packed_%c", swizzle[c]));
// double comp = PackDouble2x32(packed);
comps[c] = ops.add(rdcspv::Operation(
rdcspv::Op::ExtInst,
{
editor.DeclareType(rdcspv::scalar<double>()).value(), editor.MakeId().value(),
glsl450.value(), (uint32_t)rdcspv::GLSLstd450::PackDouble2x32, packed.value(),
}));
comps[c] = ops.add(rdcspv::OpGLSL450(editor.DeclareType(rdcspv::scalar<double>()),
editor.MakeId(), glsl450,
rdcspv::GLSLstd450::PackDouble2x32, {packed}));
}
// if there's only one component it's ready, otherwise construct a vector
+2 -5
View File
@@ -623,11 +623,8 @@ static void CreatePSInputFetcher(rdcarray<uint32_t> &fragspv, uint32_t &structSt
ops.add(rdcspv::OpFSub(float2Type, editor.MakeId(), fragXY, destXY));
// abs()
rdcspv::Id fragXYAbs = ops.add(rdcspv::Operation(
rdcspv::Op::ExtInst, {
float2Type.value(), editor.MakeId().value(), glsl450.value(),
(uint32_t)rdcspv::GLSLstd450::FAbs, fragXYRelative.value(),
}));
rdcspv::Id fragXYAbs = ops.add(rdcspv::OpGLSL450(float2Type, editor.MakeId(), glsl450,
rdcspv::GLSLstd450::FAbs, {fragXYRelative}));
rdcspv::Id half = editor.AddConstantImmediate<float>(0.5f);
rdcspv::Id threshold =