Skip to content

Commit

Permalink
extension: GL_QCOM_image_processing support
Browse files Browse the repository at this point in the history
  • Loading branch information
wooyoungqcom authored Aug 22, 2023
1 parent 4e7ccd4 commit db8719a
Show file tree
Hide file tree
Showing 24 changed files with 939 additions and 5 deletions.
1 change: 1 addition & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ template("glslang_sources_common") {
"SPIRV/GLSL.ext.KHR.h",
"SPIRV/GLSL.ext.NV.h",
"SPIRV/GLSL.ext.ARM.h",
"SPIRV/GLSL.ext.QCOM.h",
"SPIRV/GLSL.std.450.h",
"SPIRV/GlslangToSpv.cpp",
"SPIRV/GlslangToSpv.h",
Expand Down
41 changes: 41 additions & 0 deletions SPIRV/GLSL.ext.QCOM.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
** Copyright (c) 2021 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and/or associated documentation files (the "Materials"),
** to deal in the Materials without restriction, including without limitation
** the rights to use, copy, modify, merge, publish, distribute, sublicense,
** and/or sell copies of the Materials, and to permit persons to whom the
** Materials are furnished to do so, subject to the following conditions:
**
** The above copyright notice and this permission notice shall be included in
** all copies or substantial portions of the Materials.
**
** MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS KHRONOS
** STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND
** HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
** OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
** THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
** FROM,OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS
** IN THE MATERIALS.
*/

#ifndef GLSLextQCOM_H
#define GLSLextQCOM_H

enum BuiltIn;
enum Decoration;
enum Op;
enum Capability;

static const int GLSLextQCOMVersion = 100;
static const int GLSLextQCOMRevision = 1;

//SPV_QCOM_image_processing
const char* const E_SPV_QCOM_image_processing = "SPV_QCOM_image_processing";

#endif // #ifndef GLSLextQCOM_H
51 changes: 51 additions & 0 deletions SPIRV/GlslangToSpv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ namespace spv {
#include "GLSL.ext.AMD.h"
#include "GLSL.ext.NV.h"
#include "GLSL.ext.ARM.h"
#include "GLSL.ext.QCOM.h"
#include "NonSemanticDebugPrintf.h"
}

Expand Down Expand Up @@ -220,6 +221,7 @@ class TGlslangToSpvTraverser : public glslang::TIntermTraverser {
spv::Id createNoArgOperation(glslang::TOperator op, spv::Decoration precision, spv::Id typeId);
spv::Id getSymbolId(const glslang::TIntermSymbol* node);
void addMeshNVDecoration(spv::Id id, int member, const glslang::TQualifier & qualifier);
void addImageProcessingQCOMDecoration(spv::Id id, spv::Decoration decor);
spv::Id createSpvConstant(const glslang::TIntermTyped&);
spv::Id createSpvConstantFromConstUnionArray(const glslang::TType& type, const glslang::TConstUnionArray&,
int& nextConst, bool specConstant);
Expand Down Expand Up @@ -3276,6 +3278,20 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt
noReturnValue = true;
break;

case glslang::EOpImageSampleWeightedQCOM:
builder.addCapability(spv::CapabilityTextureSampleWeightedQCOM);
builder.addExtension(spv::E_SPV_QCOM_image_processing);
break;
case glslang::EOpImageBoxFilterQCOM:
builder.addCapability(spv::CapabilityTextureBoxFilterQCOM);
builder.addExtension(spv::E_SPV_QCOM_image_processing);
break;
case glslang::EOpImageBlockMatchSADQCOM:
case glslang::EOpImageBlockMatchSSDQCOM:
builder.addCapability(spv::CapabilityTextureBlockMatchQCOM);
builder.addExtension(spv::E_SPV_QCOM_image_processing);
break;

case glslang::EOpDebugPrintf:
noReturnValue = true;
break;
Expand Down Expand Up @@ -9023,6 +9039,27 @@ spv::Id TGlslangToSpvTraverser::createMiscOperation(glslang::TOperator op, spv::
return 0;

}

case glslang::EOpImageSampleWeightedQCOM:
typeId = builder.makeVectorType(builder.makeFloatType(32), 4);
opCode = spv::OpImageSampleWeightedQCOM;
addImageProcessingQCOMDecoration(operands[2], spv::DecorationWeightTextureQCOM);
break;
case glslang::EOpImageBoxFilterQCOM:
typeId = builder.makeVectorType(builder.makeFloatType(32), 4);
opCode = spv::OpImageBoxFilterQCOM;
break;
case glslang::EOpImageBlockMatchSADQCOM:
typeId = builder.makeVectorType(builder.makeFloatType(32), 4);
opCode = spv::OpImageBlockMatchSADQCOM;
addImageProcessingQCOMDecoration(operands[0], spv::DecorationBlockMatchTextureQCOM);
addImageProcessingQCOMDecoration(operands[2], spv::DecorationBlockMatchTextureQCOM);
break;
case glslang::EOpImageBlockMatchSSDQCOM:
typeId = builder.makeVectorType(builder.makeFloatType(32), 4);
opCode = spv::OpImageBlockMatchSSDQCOM;
addImageProcessingQCOMDecoration(operands[0], spv::DecorationBlockMatchTextureQCOM);
addImageProcessingQCOMDecoration(operands[2], spv::DecorationBlockMatchTextureQCOM);
break;
default:
return 0;
Expand Down Expand Up @@ -9568,6 +9605,20 @@ void TGlslangToSpvTraverser::addMeshNVDecoration(spv::Id id, int member, const g
}
}

void TGlslangToSpvTraverser::addImageProcessingQCOMDecoration(spv::Id id, spv::Decoration decor)
{
spv::Op opc = builder.getOpCode(id);
if (opc == spv::OpSampledImage) {
id = builder.getIdOperand(id, 0);
opc = builder.getOpCode(id);
}

if (opc == spv::OpLoad) {
spv::Id texid = builder.getIdOperand(id, 0);
builder.addDecoration(texid, decor);
}
}

// Make a full tree of instructions to build a SPIR-V specialization constant,
// or regular constant if possible.
//
Expand Down
1 change: 1 addition & 0 deletions SPIRV/SpvBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ class Builder {
ImageFormat getImageTypeFormat(Id typeId) const
{ return (ImageFormat)module.getInstruction(typeId)->getImmediateOperand(6); }
Id getResultingAccessChainType() const;
Id getIdOperand(Id resultId, int idx) { return module.getInstruction(resultId)->getIdOperand(idx); }

bool isPointer(Id resultId) const { return isPointerType(getTypeId(resultId)); }
bool isScalar(Id resultId) const { return isScalarType(getTypeId(resultId)); }
Expand Down
1 change: 1 addition & 0 deletions SPIRV/SpvPostProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace spv {
#include "GLSL.ext.AMD.h"
#include "GLSL.ext.NV.h"
#include "GLSL.ext.ARM.h"
#include "GLSL.ext.QCOM.h"
}

namespace spv {
Expand Down
1 change: 1 addition & 0 deletions SPIRV/disassemble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ namespace spv {
#include "GLSL.ext.NV.h"
#include "GLSL.ext.ARM.h"
#include "NonSemanticShaderDebugInfo100.h"
#include "GLSL.ext.QCOM.h"
}
}
const char* GlslStd450DebugNames[spv::GLSLstd450Count];
Expand Down
43 changes: 42 additions & 1 deletion SPIRV/doc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ namespace spv {
#include "GLSL.ext.AMD.h"
#include "GLSL.ext.NV.h"
#include "GLSL.ext.ARM.h"
#include "GLSL.ext.QCOM.h"
}
}

Expand Down Expand Up @@ -311,7 +312,9 @@ const char* DecorationString(int decoration)
case DecorationCeiling:
default: return "Bad";

case DecorationExplicitInterpAMD: return "ExplicitInterpAMD";
case DecorationWeightTextureQCOM: return "DecorationWeightTextureQCOM";
case DecorationBlockMatchTextureQCOM: return "DecorationBlockMatchTextureQCOM";
case DecorationExplicitInterpAMD: return "ExplicitInterpAMD";
case DecorationOverrideCoverageNV: return "OverrideCoverageNV";
case DecorationPassthroughNV: return "PassthroughNV";
case DecorationViewportRelativeNV: return "ViewportRelativeNV";
Expand Down Expand Up @@ -1040,6 +1043,11 @@ const char* CapabilityString(int info)
case CapabilityCoreBuiltinsARM: return "CoreBuiltinsARM";

case CapabilityShaderInvocationReorderNV: return "ShaderInvocationReorderNV";

case CapabilityTextureSampleWeightedQCOM: return "TextureSampleWeightedQCOM";
case CapabilityTextureBoxFilterQCOM: return "TextureBoxFilterQCOM";
case CapabilityTextureBlockMatchQCOM: return "TextureBlockMatchQCOM";

default: return "Bad";
}
}
Expand Down Expand Up @@ -1538,6 +1546,11 @@ const char* OpcodeString(int op)
case OpDepthAttachmentReadEXT: return "OpDepthAttachmentReadEXT";
case OpStencilAttachmentReadEXT: return "OpStencilAttachmentReadEXT";

case OpImageSampleWeightedQCOM: return "OpImageSampleWeightedQCOM";
case OpImageBoxFilterQCOM: return "OpImageBoxFilterQCOM";
case OpImageBlockMatchSADQCOM: return "OpImageBlockMatchSADQCOM";
case OpImageBlockMatchSSDQCOM: return "OpImageBlockMatchSSDQCOM";

default:
return "Bad";
}
Expand Down Expand Up @@ -3339,6 +3352,34 @@ void Parameterize()
InstructionDesc[OpColorAttachmentReadEXT].operands.push(OperandId, "'Sample'", true);
InstructionDesc[OpStencilAttachmentReadEXT].operands.push(OperandId, "'Sample'", true);
InstructionDesc[OpDepthAttachmentReadEXT].operands.push(OperandId, "'Sample'", true);

InstructionDesc[OpImageSampleWeightedQCOM].operands.push(OperandId, "'source texture'");
InstructionDesc[OpImageSampleWeightedQCOM].operands.push(OperandId, "'texture coordinates'");
InstructionDesc[OpImageSampleWeightedQCOM].operands.push(OperandId, "'weights texture'");
InstructionDesc[OpImageSampleWeightedQCOM].operands.push(OperandImageOperands, "", true);
InstructionDesc[OpImageSampleWeightedQCOM].setResultAndType(true, true);

InstructionDesc[OpImageBoxFilterQCOM].operands.push(OperandId, "'source texture'");
InstructionDesc[OpImageBoxFilterQCOM].operands.push(OperandId, "'texture coordinates'");
InstructionDesc[OpImageBoxFilterQCOM].operands.push(OperandId, "'box size'");
InstructionDesc[OpImageBoxFilterQCOM].operands.push(OperandImageOperands, "", true);
InstructionDesc[OpImageBoxFilterQCOM].setResultAndType(true, true);

InstructionDesc[OpImageBlockMatchSADQCOM].operands.push(OperandId, "'target texture'");
InstructionDesc[OpImageBlockMatchSADQCOM].operands.push(OperandId, "'target coordinates'");
InstructionDesc[OpImageBlockMatchSADQCOM].operands.push(OperandId, "'reference texture'");
InstructionDesc[OpImageBlockMatchSADQCOM].operands.push(OperandId, "'reference coordinates'");
InstructionDesc[OpImageBlockMatchSADQCOM].operands.push(OperandId, "'block size'");
InstructionDesc[OpImageBlockMatchSADQCOM].operands.push(OperandImageOperands, "", true);
InstructionDesc[OpImageBlockMatchSADQCOM].setResultAndType(true, true);

InstructionDesc[OpImageBlockMatchSSDQCOM].operands.push(OperandId, "'target texture'");
InstructionDesc[OpImageBlockMatchSSDQCOM].operands.push(OperandId, "'target coordinates'");
InstructionDesc[OpImageBlockMatchSSDQCOM].operands.push(OperandId, "'reference texture'");
InstructionDesc[OpImageBlockMatchSSDQCOM].operands.push(OperandId, "'reference coordinates'");
InstructionDesc[OpImageBlockMatchSSDQCOM].operands.push(OperandId, "'block size'");
InstructionDesc[OpImageBlockMatchSSDQCOM].operands.push(OperandImageOperands, "", true);
InstructionDesc[OpImageBlockMatchSSDQCOM].setResultAndType(true, true);
});
}

Expand Down
13 changes: 13 additions & 0 deletions SPIRV/spirv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,8 @@ enum Decoration {
DecorationMaxByteOffsetId = 47,
DecorationNoSignedWrap = 4469,
DecorationNoUnsignedWrap = 4470,
DecorationWeightTextureQCOM = 4487,
DecorationBlockMatchTextureQCOM = 4488,
DecorationExplicitInterpAMD = 4999,
DecorationOverrideCoverageNV = 5248,
DecorationPassthroughNV = 5250,
Expand Down Expand Up @@ -1023,6 +1025,9 @@ enum Capability {
CapabilityRayQueryKHR = 4472,
CapabilityRayTraversalPrimitiveCullingKHR = 4478,
CapabilityRayTracingKHR = 4479,
CapabilityTextureSampleWeightedQCOM = 4484,
CapabilityTextureBoxFilterQCOM = 4485,
CapabilityTextureBlockMatchQCOM = 4486,
CapabilityFloat16ImageAMD = 5008,
CapabilityImageGatherBiasLodAMD = 5009,
CapabilityFragmentMaskAMD = 5010,
Expand Down Expand Up @@ -1678,6 +1683,10 @@ enum Op {
OpRayQueryConfirmIntersectionKHR = 4476,
OpRayQueryProceedKHR = 4477,
OpRayQueryGetIntersectionTypeKHR = 4479,
OpImageSampleWeightedQCOM = 4480,
OpImageBoxFilterQCOM = 4481,
OpImageBlockMatchSSDQCOM = 4482,
OpImageBlockMatchSADQCOM = 4483,
OpGroupIAddNonUniformAMD = 5000,
OpGroupFAddNonUniformAMD = 5001,
OpGroupFMinNonUniformAMD = 5002,
Expand Down Expand Up @@ -2395,6 +2404,10 @@ inline void HasResultAndType(Op opcode, bool *hasResult, bool *hasResultType) {
case OpRayQueryConfirmIntersectionKHR: *hasResult = false; *hasResultType = false; break;
case OpRayQueryProceedKHR: *hasResult = true; *hasResultType = true; break;
case OpRayQueryGetIntersectionTypeKHR: *hasResult = true; *hasResultType = true; break;
case OpImageSampleWeightedQCOM: *hasResult = true; *hasResultType = true; break;
case OpImageBoxFilterQCOM: *hasResult = true; *hasResultType = true; break;
case OpImageBlockMatchSSDQCOM: *hasResult = true; *hasResultType = true; break;
case OpImageBlockMatchSADQCOM: *hasResult = true; *hasResultType = true; break;
case OpGroupIAddNonUniformAMD: *hasResult = true; *hasResultType = true; break;
case OpGroupFAddNonUniformAMD: *hasResult = true; *hasResultType = true; break;
case OpGroupFMinNonUniformAMD: *hasResult = true; *hasResultType = true; break;
Expand Down
Loading

0 comments on commit db8719a

Please sign in to comment.