| 588 | } |
| 589 | |
| 590 | spv_result_t ValidateSpecConstantOp(ValidationState_t& _, |
| 591 | const Instruction* inst) { |
| 592 | const auto op = inst->GetOperandAs<spv::Op>(2); |
| 593 | |
| 594 | // The binary parser already ensures that the op is valid for *some* |
| 595 | // environment. Here we check restrictions. |
| 596 | switch (op) { |
| 597 | case spv::Op::OpQuantizeToF16: |
| 598 | if (!_.HasCapability(spv::Capability::Shader)) { |
| 599 | return _.diag(SPV_ERROR_INVALID_ID, inst) |
| 600 | << "Specialization constant operation " << spvOpcodeString(op) |
| 601 | << " requires Shader capability"; |
| 602 | } |
| 603 | break; |
| 604 | |
| 605 | case spv::Op::OpUConvert: |
| 606 | if (!_.features().uconvert_spec_constant_op && |
| 607 | !_.HasCapability(spv::Capability::Kernel)) { |
| 608 | return _.diag(SPV_ERROR_INVALID_ID, inst) |
| 609 | << "Prior to SPIR-V 1.4, specialization constant operation " |
| 610 | "UConvert requires Kernel capability or extension " |
| 611 | "SPV_AMD_gpu_shader_int16"; |
| 612 | } |
| 613 | break; |
| 614 | |
| 615 | case spv::Op::OpConvertFToS: |
| 616 | case spv::Op::OpConvertSToF: |
| 617 | case spv::Op::OpConvertFToU: |
| 618 | case spv::Op::OpConvertUToF: |
| 619 | case spv::Op::OpConvertPtrToU: |
| 620 | case spv::Op::OpConvertUToPtr: |
| 621 | case spv::Op::OpGenericCastToPtr: |
| 622 | case spv::Op::OpPtrCastToGeneric: |
| 623 | case spv::Op::OpBitcast: |
| 624 | case spv::Op::OpFNegate: |
| 625 | case spv::Op::OpFAdd: |
| 626 | case spv::Op::OpFSub: |
| 627 | case spv::Op::OpFMul: |
| 628 | case spv::Op::OpFDiv: |
| 629 | case spv::Op::OpFRem: |
| 630 | case spv::Op::OpFMod: |
| 631 | case spv::Op::OpAccessChain: |
| 632 | case spv::Op::OpInBoundsAccessChain: |
| 633 | case spv::Op::OpPtrAccessChain: |
| 634 | case spv::Op::OpInBoundsPtrAccessChain: |
| 635 | if (!_.HasCapability(spv::Capability::Kernel)) { |
| 636 | return _.diag(SPV_ERROR_INVALID_ID, inst) |
| 637 | << "Specialization constant operation " << spvOpcodeString(op) |
| 638 | << " requires Kernel capability"; |
| 639 | } |
| 640 | break; |
| 641 | |
| 642 | default: |
| 643 | break; |
| 644 | } |
| 645 | |
| 646 | // TODO(dneto): Validate result type and arguments to the various operations. |
| 647 | return SPV_SUCCESS; |
no test coverage detected