[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 <rharrison@chromium.org>
This commit is contained in:
parent
65cd5a8e0d
commit
7615d9468c
|
@ -138,11 +138,10 @@ Builder::Builder(ast::Module* mod) : mod_(mod), scope_stack_({}) {}
|
||||||
Builder::~Builder() = default;
|
Builder::~Builder() = default;
|
||||||
|
|
||||||
bool Builder::Build() {
|
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
|
// TODO(dneto): Stop using the Vulkan memory model. crbug.com/tint/63
|
||||||
push_capability(spv::Op::OpCapability,
|
push_capability(SpvCapabilityVulkanMemoryModel);
|
||||||
{Operand::Int(SpvCapabilityVulkanMemoryModel)});
|
|
||||||
push_preamble(spv::Op::OpExtension,
|
push_preamble(spv::Op::OpExtension,
|
||||||
{Operand::String("SPV_KHR_vulkan_memory_model")});
|
{Operand::String("SPV_KHR_vulkan_memory_model")});
|
||||||
|
|
||||||
|
@ -221,6 +220,11 @@ void Builder::iterate(std::function<void(const Instruction&)> 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) {
|
uint32_t Builder::GenerateU32Literal(uint32_t val) {
|
||||||
ast::type::U32Type u32;
|
ast::type::U32Type u32;
|
||||||
ast::SintLiteral lit(&u32, val);
|
ast::SintLiteral lit(&u32, val);
|
||||||
|
@ -1251,8 +1255,7 @@ uint32_t Builder::GenerateIntrinsic(const std::string& name,
|
||||||
|
|
||||||
if (ast::intrinsic::IsFineDerivative(name) ||
|
if (ast::intrinsic::IsFineDerivative(name) ||
|
||||||
ast::intrinsic::IsCoarseDerivative(name)) {
|
ast::intrinsic::IsCoarseDerivative(name)) {
|
||||||
push_capability(spv::Op::OpCapability,
|
push_capability(SpvCapabilityDerivativeControl);
|
||||||
{Operand::Int(SpvCapabilityDerivativeControl)});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
spv::Op op = spv::Op::OpNop;
|
spv::Op op = spv::Op::OpNop;
|
||||||
|
|
|
@ -120,11 +120,8 @@ class Builder {
|
||||||
void iterate(std::function<void(const Instruction&)> cb) const;
|
void iterate(std::function<void(const Instruction&)> cb) const;
|
||||||
|
|
||||||
/// Adds an instruction to the list of capabilities
|
/// Adds an instruction to the list of capabilities
|
||||||
/// @param op the op to set
|
/// @param cap the capability to set
|
||||||
/// @param operands the operands for the instruction
|
void push_capability(uint32_t cap);
|
||||||
void push_capability(spv::Op op, const std::vector<Operand>& operands) {
|
|
||||||
capabilities_.push_back(Instruction{op, operands});
|
|
||||||
}
|
|
||||||
/// @returns the capabilities
|
/// @returns the capabilities
|
||||||
const std::vector<Instruction>& capabilities() const { return capabilities_; }
|
const std::vector<Instruction>& capabilities() const { return capabilities_; }
|
||||||
/// Adds an instruction to the preamble
|
/// Adds an instruction to the preamble
|
||||||
|
|
Loading…
Reference in New Issue