Commit 6689a54d by Shahbaz Youssefi Committed by Commit Bot

Vulkan: autogen for SPIR-V instruction build and parse

Handwritten SPIR-V instruction parse and build code is replaced with autogenerated functions based on the SPIR-V grammar. Bug: angleproject:4889 Change-Id: I09d724fd944e79c03fe4eadca3ee3e3ef0b49872 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2644721 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarTim Van Patten <timvp@google.com>
parent cc5083e0
...@@ -685,6 +685,8 @@ if (angle_enable_vulkan || angle_enable_metal) { ...@@ -685,6 +685,8 @@ if (angle_enable_vulkan || angle_enable_metal) {
] ]
deps = [ deps = [
":libANGLE_headers", ":libANGLE_headers",
"$angle_root/src/common/spirv:angle_spirv_builder",
"$angle_root/src/common/spirv:angle_spirv_parser",
"${angle_glslang_dir}:glslang_default_resource_limits_sources", "${angle_glslang_dir}:glslang_default_resource_limits_sources",
"${angle_glslang_dir}:glslang_lib_sources", "${angle_glslang_dir}:glslang_lib_sources",
"${angle_spirv_headers_dir}:spv_headers", "${angle_spirv_headers_dir}:spv_headers",
......
{
"src/common/spirv/gen_spirv_builder_and_parser.py":
"02381e3a7cf898265de3ba438b3b6e5e",
"src/common/spirv/spirv_instruction_builder_autogen.cpp":
"b9c0c27ab2de86955528d4d8ba9be817",
"src/common/spirv/spirv_instruction_builder_autogen.h":
"9629f02ff30720ec38a9aad0fc5c1503",
"src/common/spirv/spirv_instruction_parser_autogen.cpp":
"55d28bb4b003dbecf31e162ff996fc4f",
"src/common/spirv/spirv_instruction_parser_autogen.h":
"68c5746bc94e6b9f891ff2a11869ccd1",
"third_party/vulkan-deps/spirv-headers/src/include/spirv/1.0/spirv.core.grammar.json":
"a8c4239344b2fc10bfc4ace7ddee1867"
}
\ No newline at end of file
...@@ -115,6 +115,8 @@ generators = { ...@@ -115,6 +115,8 @@ generators = {
'scripts/gen_proc_table.py', 'scripts/gen_proc_table.py',
'restricted traces': 'restricted traces':
'src/tests/restricted_traces/gen_restricted_traces.py', 'src/tests/restricted_traces/gen_restricted_traces.py',
'SPIR-V helpers':
'src/common/spirv/gen_spirv_builder_and_parser.py',
'Static builtins': 'Static builtins':
'src/compiler/translator/gen_builtin_symbols.py', 'src/compiler/translator/gen_builtin_symbols.py',
'uniform type': 'uniform type':
......
...@@ -70,6 +70,9 @@ class FastVector final ...@@ -70,6 +70,9 @@ class FastVector final
void push_back(const value_type &value); void push_back(const value_type &value);
void push_back(value_type &&value); void push_back(value_type &&value);
template <typename... Args>
void emplace_back(Args &&... args);
void pop_back(); void pop_back();
reference front(); reference front();
...@@ -288,9 +291,16 @@ ANGLE_INLINE void FastVector<T, N, Storage>::push_back(const value_type &value) ...@@ -288,9 +291,16 @@ ANGLE_INLINE void FastVector<T, N, Storage>::push_back(const value_type &value)
template <class T, size_t N, class Storage> template <class T, size_t N, class Storage>
ANGLE_INLINE void FastVector<T, N, Storage>::push_back(value_type &&value) ANGLE_INLINE void FastVector<T, N, Storage>::push_back(value_type &&value)
{ {
emplace_back(std::move(value));
}
template <class T, size_t N, class Storage>
template <typename... Args>
ANGLE_INLINE void FastVector<T, N, Storage>::emplace_back(Args &&... args)
{
if (mSize == mReservedSize) if (mSize == mReservedSize)
ensure_capacity(mSize + 1); ensure_capacity(mSize + 1);
mData[mSize++] = std::move(value); mData[mSize++] = std::move(T(std::forward<Args>(args)...));
} }
template <class T, size_t N, class Storage> template <class T, size_t N, class Storage>
......
# Copyright 2021 The ANGLE Project Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("../../../gni/angle.gni")
angle_source_set("angle_spirv_builder") {
sources = [
"spirv_instruction_builder_autogen.cpp",
"spirv_instruction_builder_autogen.h",
"spirv_types.h",
]
deps = [
"$angle_root:angle_common",
"${angle_spirv_headers_dir}:spv_headers",
]
}
angle_source_set("angle_spirv_parser") {
sources = [
"spirv_instruction_parser_autogen.cpp",
"spirv_instruction_parser_autogen.h",
"spirv_types.h",
]
deps = [
"$angle_root:angle_common",
"${angle_spirv_headers_dir}:spv_headers",
]
}
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
//
// Copyright 2021 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// spirv_types.h:
// Strong types for SPIR-V Ids to prevent mistakes when using the builder and parser APIs.
//
#ifndef COMMON_SPIRV_TYPES_H_
#define COMMON_SPIRV_TYPES_H_
#include <spirv/unified1/spirv.hpp>
#include "common/FastVector.h"
namespace angle
{
namespace spirv
{
template <typename Helper>
class BoxedUint32
{
public:
BoxedUint32() : mValue{0} {}
explicit BoxedUint32(uint32_t value) : mValue{value} {}
template <typename T>
T as() const
{
return T{mValue};
}
BoxedUint32(const BoxedUint32 &other) = default;
BoxedUint32 &operator=(const BoxedUint32 &other) = default;
operator uint32_t() const { return mValue.value; }
bool operator==(const BoxedUint32 &other) const { return mValue.value == other.mValue.value; }
// Applicable to ids, which cannot be 0.
bool valid() const { return static_cast<bool>(mValue.value); }
private:
Helper mValue;
};
struct IdRefHelper
{
spv::Id value;
};
struct LiteralIntegerHelper
{
uint32_t value;
};
using IdRef = BoxedUint32<IdRefHelper>;
// IdResult, IdResultType, IdMemorySemantics and IdScope are all translated as IdRef. This makes
// the type verification weaker, but stops the API from becoming tediously verbose.
using IdResult = IdRef;
using IdResultType = IdRef;
using IdMemorySemantics = IdRef;
using IdScope = IdRef;
using LiteralInteger = BoxedUint32<LiteralIntegerHelper>;
using LiteralString = const char *;
// Note: In ANGLE's use cases, all literals fit in 32 bits.
using LiteralContextDependentNumber = LiteralInteger;
// TODO(syoussefi): To be made stronger when generating SPIR-V from the translator.
// http://anglebug.com/4889
using LiteralExtInstInteger = LiteralInteger;
struct PairLiteralIntegerIdRef
{
LiteralInteger literal;
IdRef id;
};
struct PairIdRefLiteralInteger
{
IdRef id;
LiteralInteger literal;
};
struct PairIdRefIdRef
{
IdRef id1;
IdRef id2;
};
// Some instructions need 4 components. The drivers uniform struct in ANGLE has 8 fields. A value
// of 8 means almost no instruction would end up making dynamic allocations. Notable exceptions are
// user-defined structs/blocks and OpEntryPoint.
constexpr size_t kFastVectorSize = 8;
template <typename T>
using FastVectorHelper = angle::FastVector<T, kFastVectorSize>;
using IdRefList = FastVectorHelper<IdRef>;
using LiteralIntegerList = FastVectorHelper<LiteralInteger>;
using PairLiteralIntegerIdRefList = FastVectorHelper<PairLiteralIntegerIdRef>;
using PairIdRefLiteralIntegerList = FastVectorHelper<PairIdRefLiteralInteger>;
using PairIdRefIdRefList = FastVectorHelper<PairIdRefIdRef>;
} // namespace spirv
} // namespace angle
#endif // COMMON_SPIRV_TYPES_H_
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment