From 7615d9468cfe3cca42d8c12fd59c77d2134bdf4a Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Thu, 4 Jun 2020 17:29:54 +0000 Subject: [PATCH] [spirv-writer] Cleanup capabilities code. This CL simplifies the capabilities code in the SPIR-V builder. Bug: tint:5 Change-Id: Iff99350b2d6a2534c82ea3d47a0a9186d0dcb6ac Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22661 Reviewed-by: Ryan Harrison --- src/writer/spirv/builder.cc | 13 ++++++++----- src/writer/spirv/builder.h | 7 ++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc index 382681b1ed..cf3ee87ef5 100644 --- a/src/writer/spirv/builder.cc +++ b/src/writer/spirv/builder.cc @@ -138,11 +138,10 @@ Builder::Builder(ast::Module* mod) : mod_(mod), scope_stack_({}) {} Builder::~Builder() = default; bool Builder::Build() { - push_capability(spv::Op::OpCapability, {Operand::Int(SpvCapabilityShader)}); + push_capability(SpvCapabilityShader); // TODO(dneto): Stop using the Vulkan memory model. crbug.com/tint/63 - push_capability(spv::Op::OpCapability, - {Operand::Int(SpvCapabilityVulkanMemoryModel)}); + push_capability(SpvCapabilityVulkanMemoryModel); push_preamble(spv::Op::OpExtension, {Operand::String("SPV_KHR_vulkan_memory_model")}); @@ -221,6 +220,11 @@ void Builder::iterate(std::function cb) const { } } +void Builder::push_capability(uint32_t cap) { + capabilities_.push_back( + Instruction{spv::Op::OpCapability, {Operand::Int(cap)}}); +} + uint32_t Builder::GenerateU32Literal(uint32_t val) { ast::type::U32Type u32; ast::SintLiteral lit(&u32, val); @@ -1251,8 +1255,7 @@ uint32_t Builder::GenerateIntrinsic(const std::string& name, if (ast::intrinsic::IsFineDerivative(name) || ast::intrinsic::IsCoarseDerivative(name)) { - push_capability(spv::Op::OpCapability, - {Operand::Int(SpvCapabilityDerivativeControl)}); + push_capability(SpvCapabilityDerivativeControl); } spv::Op op = spv::Op::OpNop; diff --git a/src/writer/spirv/builder.h b/src/writer/spirv/builder.h index b8ac524679..61a2e36d1f 100644 --- a/src/writer/spirv/builder.h +++ b/src/writer/spirv/builder.h @@ -120,11 +120,8 @@ class Builder { void iterate(std::function cb) const; /// Adds an instruction to the list of capabilities - /// @param op the op to set - /// @param operands the operands for the instruction - void push_capability(spv::Op op, const std::vector& operands) { - capabilities_.push_back(Instruction{op, operands}); - } + /// @param cap the capability to set + void push_capability(uint32_t cap); /// @returns the capabilities const std::vector& capabilities() const { return capabilities_; } /// Adds an instruction to the preamble