MCPcopy Create free account
hub / github.com/KhronosGroup/SPIRV-Tools / UpdateImageOperands

Function UpdateImageOperands

source/opt/folding_rules.cpp:4377–4441  ·  view source on GitHub ↗

If an image instruction's operand is a constant, updates the image operand flag from Offset to ConstOffset.

Source from the content-addressed store, hash-verified

4375// If an image instruction's operand is a constant, updates the image operand
4376// flag from Offset to ConstOffset.
4377FoldingRule UpdateImageOperands() {
4378 return [](IRContext*, Instruction* inst,
4379 const std::vector<const analysis::Constant*>& constants) {
4380 const auto opcode = inst->opcode();
4381 (void)opcode;
4382 assert((opcode == spv::Op::OpImageSampleImplicitLod ||
4383 opcode == spv::Op::OpImageSampleExplicitLod ||
4384 opcode == spv::Op::OpImageSampleDrefImplicitLod ||
4385 opcode == spv::Op::OpImageSampleDrefExplicitLod ||
4386 opcode == spv::Op::OpImageSampleProjImplicitLod ||
4387 opcode == spv::Op::OpImageSampleProjExplicitLod ||
4388 opcode == spv::Op::OpImageSampleProjDrefImplicitLod ||
4389 opcode == spv::Op::OpImageSampleProjDrefExplicitLod ||
4390 opcode == spv::Op::OpImageFetch ||
4391 opcode == spv::Op::OpImageGather ||
4392 opcode == spv::Op::OpImageDrefGather ||
4393 opcode == spv::Op::OpImageRead || opcode == spv::Op::OpImageWrite ||
4394 opcode == spv::Op::OpImageSparseSampleImplicitLod ||
4395 opcode == spv::Op::OpImageSparseSampleExplicitLod ||
4396 opcode == spv::Op::OpImageSparseSampleDrefImplicitLod ||
4397 opcode == spv::Op::OpImageSparseSampleDrefExplicitLod ||
4398 opcode == spv::Op::OpImageSparseSampleProjImplicitLod ||
4399 opcode == spv::Op::OpImageSparseSampleProjExplicitLod ||
4400 opcode == spv::Op::OpImageSparseSampleProjDrefImplicitLod ||
4401 opcode == spv::Op::OpImageSparseSampleProjDrefExplicitLod ||
4402 opcode == spv::Op::OpImageSparseFetch ||
4403 opcode == spv::Op::OpImageSparseGather ||
4404 opcode == spv::Op::OpImageSparseDrefGather ||
4405 opcode == spv::Op::OpImageSparseRead) &&
4406 "Wrong opcode. Should be an image instruction.");
4407
4408 int32_t operand_index = ImageOperandsMaskInOperandIndex(inst);
4409 if (operand_index >= 0) {
4410 auto image_operands = inst->GetSingleWordInOperand(operand_index);
4411 if (image_operands & uint32_t(spv::ImageOperandsMask::Offset)) {
4412 uint32_t offset_operand_index = operand_index + 1;
4413 if (image_operands & uint32_t(spv::ImageOperandsMask::Bias))
4414 offset_operand_index++;
4415 if (image_operands & uint32_t(spv::ImageOperandsMask::Lod))
4416 offset_operand_index++;
4417 if (image_operands & uint32_t(spv::ImageOperandsMask::Grad))
4418 offset_operand_index += 2;
4419 assert(((image_operands &
4420 uint32_t(spv::ImageOperandsMask::ConstOffset)) == 0) &&
4421 "Offset and ConstOffset may not be used together");
4422 if (offset_operand_index < inst->NumOperands()) {
4423 if (constants[offset_operand_index]) {
4424 if (constants[offset_operand_index]->IsZero()) {
4425 inst->RemoveInOperand(offset_operand_index);
4426 } else {
4427 image_operands = image_operands |
4428 uint32_t(spv::ImageOperandsMask::ConstOffset);
4429 }
4430 image_operands =
4431 image_operands & ~uint32_t(spv::ImageOperandsMask::Offset);
4432 inst->SetInOperand(operand_index, {image_operands});
4433 return true;
4434 }

Callers 1

AddFoldingRulesMethod · 0.85

Calls 7

NumOperandsMethod · 0.80
RemoveInOperandMethod · 0.80
SetInOperandMethod · 0.80
opcodeMethod · 0.45
IsZeroMethod · 0.45

Tested by

no test coverage detected