Consistent formatting for Dawn/Tint.

This CL updates the clang format files to have a single shared format
between Dawn and Tint. The major changes are tabs are 4 spaces, lines
are 100 columns and namespaces are not indented.

Bug: dawn:1339
Change-Id: I4208742c95643998d9fd14e77a9cc558071ded39
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/87603
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
dan sinclair
2022-05-01 14:40:55 +00:00
committed by Dawn LUCI CQ
parent 73b1d1dafa
commit 41e4d9a34c
1827 changed files with 218382 additions and 227741 deletions

View File

@@ -35,34 +35,32 @@ EntryPoint::EntryPoint(EntryPoint&) = default;
EntryPoint::EntryPoint(EntryPoint&&) = default;
EntryPoint::~EntryPoint() = default;
InterpolationType ASTToInspectorInterpolationType(
ast::InterpolationType ast_type) {
switch (ast_type) {
case ast::InterpolationType::kPerspective:
return InterpolationType::kPerspective;
case ast::InterpolationType::kLinear:
return InterpolationType::kLinear;
case ast::InterpolationType::kFlat:
return InterpolationType::kFlat;
}
InterpolationType ASTToInspectorInterpolationType(ast::InterpolationType ast_type) {
switch (ast_type) {
case ast::InterpolationType::kPerspective:
return InterpolationType::kPerspective;
case ast::InterpolationType::kLinear:
return InterpolationType::kLinear;
case ast::InterpolationType::kFlat:
return InterpolationType::kFlat;
}
return InterpolationType::kUnknown;
return InterpolationType::kUnknown;
}
InterpolationSampling ASTToInspectorInterpolationSampling(
ast::InterpolationSampling sampling) {
switch (sampling) {
case ast::InterpolationSampling::kNone:
return InterpolationSampling::kNone;
case ast::InterpolationSampling::kCenter:
return InterpolationSampling::kCenter;
case ast::InterpolationSampling::kCentroid:
return InterpolationSampling::kCentroid;
case ast::InterpolationSampling::kSample:
return InterpolationSampling::kSample;
}
InterpolationSampling ASTToInspectorInterpolationSampling(ast::InterpolationSampling sampling) {
switch (sampling) {
case ast::InterpolationSampling::kNone:
return InterpolationSampling::kNone;
case ast::InterpolationSampling::kCenter:
return InterpolationSampling::kCenter;
case ast::InterpolationSampling::kCentroid:
return InterpolationSampling::kCentroid;
case ast::InterpolationSampling::kSample:
return InterpolationSampling::kSample;
}
return InterpolationSampling::kUnknown;
return InterpolationSampling::kUnknown;
}
} // namespace tint::inspector

View File

@@ -26,158 +26,149 @@ namespace tint::inspector {
/// Base component type of a stage variable.
enum class ComponentType {
kUnknown = -1,
kFloat,
kUInt,
kSInt,
kUnknown = -1,
kFloat,
kUInt,
kSInt,
};
/// Composition of components of a stage variable.
enum class CompositionType {
kUnknown = -1,
kScalar,
kVec2,
kVec3,
kVec4,
kUnknown = -1,
kScalar,
kVec2,
kVec3,
kVec4,
};
/// Type of interpolation of a stage variable.
enum class InterpolationType { kUnknown = -1, kPerspective, kLinear, kFlat };
/// Type of interpolation sampling of a stage variable.
enum class InterpolationSampling {
kUnknown = -1,
kNone,
kCenter,
kCentroid,
kSample
};
enum class InterpolationSampling { kUnknown = -1, kNone, kCenter, kCentroid, kSample };
/// Reflection data about an entry point input or output.
struct StageVariable {
/// Constructor
StageVariable();
/// Copy constructor
/// @param other the StageVariable to copy
StageVariable(const StageVariable& other);
/// Destructor
~StageVariable();
/// Constructor
StageVariable();
/// Copy constructor
/// @param other the StageVariable to copy
StageVariable(const StageVariable& other);
/// Destructor
~StageVariable();
/// Name of the variable in the shader.
std::string name;
/// Is location attribute present
bool has_location_attribute = false;
/// Value of the location attribute, only valid if #has_location_attribute is
/// true.
uint32_t location_attribute;
/// Is Location attribute present
/// [DEPRECATED]: Use #has_location_attribute
bool& has_location_decoration = has_location_attribute;
/// Value of Location Decoration, only valid if #has_location_decoration is
/// true.
/// [DEPRECATED]: Use #location_attribute
uint32_t& location_decoration = location_attribute;
/// Scalar type that the variable is composed of.
ComponentType component_type = ComponentType::kUnknown;
/// How the scalars are composed for the variable.
CompositionType composition_type = CompositionType::kUnknown;
/// Interpolation type of the variable.
InterpolationType interpolation_type = InterpolationType::kUnknown;
/// Interpolation sampling of the variable.
InterpolationSampling interpolation_sampling =
InterpolationSampling::kUnknown;
/// Name of the variable in the shader.
std::string name;
/// Is location attribute present
bool has_location_attribute = false;
/// Value of the location attribute, only valid if #has_location_attribute is
/// true.
uint32_t location_attribute;
/// Is Location attribute present
/// [DEPRECATED]: Use #has_location_attribute
bool& has_location_decoration = has_location_attribute;
/// Value of Location Decoration, only valid if #has_location_decoration is
/// true.
/// [DEPRECATED]: Use #location_attribute
uint32_t& location_decoration = location_attribute;
/// Scalar type that the variable is composed of.
ComponentType component_type = ComponentType::kUnknown;
/// How the scalars are composed for the variable.
CompositionType composition_type = CompositionType::kUnknown;
/// Interpolation type of the variable.
InterpolationType interpolation_type = InterpolationType::kUnknown;
/// Interpolation sampling of the variable.
InterpolationSampling interpolation_sampling = InterpolationSampling::kUnknown;
};
/// Convert from internal ast::InterpolationType to public ::InterpolationType.
/// @param ast_type internal value to convert from
/// @returns the publicly visible equivalent
InterpolationType ASTToInspectorInterpolationType(
ast::InterpolationType ast_type);
InterpolationType ASTToInspectorInterpolationType(ast::InterpolationType ast_type);
/// Convert from internal ast::InterpolationSampling to public
/// ::InterpolationSampling
/// @param sampling internal value to convert from
/// @returns the publicly visible equivalent
InterpolationSampling ASTToInspectorInterpolationSampling(
ast::InterpolationSampling sampling);
InterpolationSampling ASTToInspectorInterpolationSampling(ast::InterpolationSampling sampling);
/// Reflection data about a pipeline overridable constant referenced by an entry
/// point
struct OverridableConstant {
/// Name of the constant
std::string name;
/// Name of the constant
std::string name;
/// ID of the constant
uint16_t numeric_id;
/// ID of the constant
uint16_t numeric_id;
/// Type of the scalar
enum class Type {
kBool,
kFloat32,
kUint32,
kInt32,
};
/// Type of the scalar
enum class Type {
kBool,
kFloat32,
kUint32,
kInt32,
};
/// Type of the scalar
Type type;
/// Type of the scalar
Type type;
/// Does this pipeline overridable constant have an initializer?
bool is_initialized = false;
/// Does this pipeline overridable constant have an initializer?
bool is_initialized = false;
/// Does this pipeline overridable constant have a numeric ID specified
/// explicitly?
bool is_numeric_id_specified = false;
/// Does this pipeline overridable constant have a numeric ID specified
/// explicitly?
bool is_numeric_id_specified = false;
};
/// Reflection data for an entry point in the shader.
struct EntryPoint {
/// Constructors
EntryPoint();
/// Copy Constructor
EntryPoint(EntryPoint&);
/// Move Constructor
EntryPoint(EntryPoint&&);
~EntryPoint();
/// Constructors
EntryPoint();
/// Copy Constructor
EntryPoint(EntryPoint&);
/// Move Constructor
EntryPoint(EntryPoint&&);
~EntryPoint();
/// The entry point name
std::string name;
/// Remapped entry point name in the backend
std::string remapped_name;
/// The entry point stage
ast::PipelineStage stage = ast::PipelineStage::kNone;
/// The workgroup x size
uint32_t workgroup_size_x = 0;
/// The workgroup y size
uint32_t workgroup_size_y = 0;
/// The workgroup z size
uint32_t workgroup_size_z = 0;
/// List of the input variable accessed via this entry point.
std::vector<StageVariable> input_variables;
/// List of the output variable accessed via this entry point.
std::vector<StageVariable> output_variables;
/// List of the pipeline overridable constants accessed via this entry point.
std::vector<OverridableConstant> overridable_constants;
/// Does the entry point use the sample_mask builtin as an input builtin
/// variable.
bool input_sample_mask_used = false;
/// Does the entry point use the sample_mask builtin as an output builtin
/// variable.
bool output_sample_mask_used = false;
/// Does the entry point use the position builtin as an input builtin
/// variable.
bool input_position_used = false;
/// Does the entry point use the front_facing builtin
bool front_facing_used = false;
/// Does the entry point use the sample_index builtin
bool sample_index_used = false;
/// Does the entry point use the num_workgroups builtin
bool num_workgroups_used = false;
/// The entry point name
std::string name;
/// Remapped entry point name in the backend
std::string remapped_name;
/// The entry point stage
ast::PipelineStage stage = ast::PipelineStage::kNone;
/// The workgroup x size
uint32_t workgroup_size_x = 0;
/// The workgroup y size
uint32_t workgroup_size_y = 0;
/// The workgroup z size
uint32_t workgroup_size_z = 0;
/// List of the input variable accessed via this entry point.
std::vector<StageVariable> input_variables;
/// List of the output variable accessed via this entry point.
std::vector<StageVariable> output_variables;
/// List of the pipeline overridable constants accessed via this entry point.
std::vector<OverridableConstant> overridable_constants;
/// Does the entry point use the sample_mask builtin as an input builtin
/// variable.
bool input_sample_mask_used = false;
/// Does the entry point use the sample_mask builtin as an output builtin
/// variable.
bool output_sample_mask_used = false;
/// Does the entry point use the position builtin as an input builtin
/// variable.
bool input_position_used = false;
/// Does the entry point use the front_facing builtin
bool front_facing_used = false;
/// Does the entry point use the sample_index builtin
bool sample_index_used = false;
/// Does the entry point use the num_workgroups builtin
bool num_workgroups_used = false;
/// @returns the size of the workgroup in {x,y,z} format
std::tuple<uint32_t, uint32_t, uint32_t> workgroup_size() {
return std::tuple<uint32_t, uint32_t, uint32_t>(
workgroup_size_x, workgroup_size_y, workgroup_size_z);
}
/// @returns the size of the workgroup in {x,y,z} format
std::tuple<uint32_t, uint32_t, uint32_t> workgroup_size() {
return std::tuple<uint32_t, uint32_t, uint32_t>(workgroup_size_x, workgroup_size_y,
workgroup_size_z);
}
};
} // namespace tint::inspector

File diff suppressed because it is too large Load Diff

View File

@@ -37,207 +37,196 @@ using SamplerTexturePair = sem::SamplerTexturePair;
/// Extracts information from a program
class Inspector {
public:
/// Constructor
/// @param program Shader program to extract information from.
explicit Inspector(const Program* program);
public:
/// Constructor
/// @param program Shader program to extract information from.
explicit Inspector(const Program* program);
/// Destructor
~Inspector();
/// Destructor
~Inspector();
/// @returns error messages from the Inspector
std::string error() { return diagnostics_.str(); }
/// @returns true if an error was encountered
bool has_error() const { return diagnostics_.contains_errors(); }
/// @returns error messages from the Inspector
std::string error() { return diagnostics_.str(); }
/// @returns true if an error was encountered
bool has_error() const { return diagnostics_.contains_errors(); }
/// @returns vector of entry point information
std::vector<EntryPoint> GetEntryPoints();
/// @returns vector of entry point information
std::vector<EntryPoint> GetEntryPoints();
/// @returns map of const_id to initial value
std::map<uint32_t, Scalar> GetConstantIDs();
/// @returns map of const_id to initial value
std::map<uint32_t, Scalar> GetConstantIDs();
/// @returns map of module-constant name to pipeline constant ID
std::map<std::string, uint32_t> GetConstantNameToIdMap();
/// @returns map of module-constant name to pipeline constant ID
std::map<std::string, uint32_t> GetConstantNameToIdMap();
/// @param entry_point name of the entry point to get information about.
/// @returns the total size of shared storage required by an entry point,
/// including all uniform storage buffers.
uint32_t GetStorageSize(const std::string& entry_point);
/// @param entry_point name of the entry point to get information about.
/// @returns the total size of shared storage required by an entry point,
/// including all uniform storage buffers.
uint32_t GetStorageSize(const std::string& entry_point);
/// @param entry_point name of the entry point to get information about.
/// @returns vector of all of the resource bindings.
std::vector<ResourceBinding> GetResourceBindings(
const std::string& entry_point);
/// @param entry_point name of the entry point to get information about.
/// @returns vector of all of the resource bindings.
std::vector<ResourceBinding> GetResourceBindings(const std::string& entry_point);
/// @param entry_point name of the entry point to get information about.
/// @returns vector of all of the bindings for uniform buffers.
std::vector<ResourceBinding> GetUniformBufferResourceBindings(
const std::string& entry_point);
/// @param entry_point name of the entry point to get information about.
/// @returns vector of all of the bindings for uniform buffers.
std::vector<ResourceBinding> GetUniformBufferResourceBindings(const std::string& entry_point);
/// @param entry_point name of the entry point to get information about.
/// @returns vector of all of the bindings for storage buffers.
std::vector<ResourceBinding> GetStorageBufferResourceBindings(
const std::string& entry_point);
/// @param entry_point name of the entry point to get information about.
/// @returns vector of all of the bindings for storage buffers.
std::vector<ResourceBinding> GetStorageBufferResourceBindings(const std::string& entry_point);
/// @param entry_point name of the entry point to get information about.
/// @returns vector of all of the bindings for read-only storage buffers.
std::vector<ResourceBinding> GetReadOnlyStorageBufferResourceBindings(
const std::string& entry_point);
/// @param entry_point name of the entry point to get information about.
/// @returns vector of all of the bindings for read-only storage buffers.
std::vector<ResourceBinding> GetReadOnlyStorageBufferResourceBindings(
const std::string& entry_point);
/// @param entry_point name of the entry point to get information about.
/// @returns vector of all of the bindings for regular samplers.
std::vector<ResourceBinding> GetSamplerResourceBindings(
const std::string& entry_point);
/// @param entry_point name of the entry point to get information about.
/// @returns vector of all of the bindings for regular samplers.
std::vector<ResourceBinding> GetSamplerResourceBindings(const std::string& entry_point);
/// @param entry_point name of the entry point to get information about.
/// @returns vector of all of the bindings for comparison samplers.
std::vector<ResourceBinding> GetComparisonSamplerResourceBindings(
const std::string& entry_point);
/// @param entry_point name of the entry point to get information about.
/// @returns vector of all of the bindings for comparison samplers.
std::vector<ResourceBinding> GetComparisonSamplerResourceBindings(
const std::string& entry_point);
/// @param entry_point name of the entry point to get information about.
/// @returns vector of all of the bindings for sampled textures.
std::vector<ResourceBinding> GetSampledTextureResourceBindings(
const std::string& entry_point);
/// @param entry_point name of the entry point to get information about.
/// @returns vector of all of the bindings for sampled textures.
std::vector<ResourceBinding> GetSampledTextureResourceBindings(const std::string& entry_point);
/// @param entry_point name of the entry point to get information about.
/// @returns vector of all of the bindings for multisampled textures.
std::vector<ResourceBinding> GetMultisampledTextureResourceBindings(
const std::string& entry_point);
/// @param entry_point name of the entry point to get information about.
/// @returns vector of all of the bindings for multisampled textures.
std::vector<ResourceBinding> GetMultisampledTextureResourceBindings(
const std::string& entry_point);
/// @param entry_point name of the entry point to get information about.
/// @returns vector of all of the bindings for write-only storage textures.
std::vector<ResourceBinding> GetWriteOnlyStorageTextureResourceBindings(
const std::string& entry_point);
/// @param entry_point name of the entry point to get information about.
/// @returns vector of all of the bindings for write-only storage textures.
std::vector<ResourceBinding> GetWriteOnlyStorageTextureResourceBindings(
const std::string& entry_point);
/// @param entry_point name of the entry point to get information about.
/// @returns vector of all of the bindings for depth textures.
std::vector<ResourceBinding> GetDepthTextureResourceBindings(
const std::string& entry_point);
/// @param entry_point name of the entry point to get information about.
/// @returns vector of all of the bindings for depth textures.
std::vector<ResourceBinding> GetDepthTextureResourceBindings(const std::string& entry_point);
/// @param entry_point name of the entry point to get information about.
/// @returns vector of all of the bindings for depth textures.
std::vector<ResourceBinding> GetDepthMultisampledTextureResourceBindings(
const std::string& entry_point);
/// @param entry_point name of the entry point to get information about.
/// @returns vector of all of the bindings for depth textures.
std::vector<ResourceBinding> GetDepthMultisampledTextureResourceBindings(
const std::string& entry_point);
/// @param entry_point name of the entry point to get information about.
/// @returns vector of all of the bindings for external textures.
std::vector<ResourceBinding> GetExternalTextureResourceBindings(
const std::string& entry_point);
/// @param entry_point name of the entry point to get information about.
/// @returns vector of all of the bindings for external textures.
std::vector<ResourceBinding> GetExternalTextureResourceBindings(const std::string& entry_point);
/// @param entry_point name of the entry point to get information about.
/// @returns vector of all of the sampler/texture sampling pairs that are used
/// by that entry point.
std::vector<sem::SamplerTexturePair> GetSamplerTextureUses(
const std::string& entry_point);
/// @param entry_point name of the entry point to get information about.
/// @returns vector of all of the sampler/texture sampling pairs that are used
/// by that entry point.
std::vector<sem::SamplerTexturePair> GetSamplerTextureUses(const std::string& entry_point);
/// @param entry_point name of the entry point to get information about.
/// @param placeholder the sampler binding point to use for texture-only
/// access (e.g., textureLoad)
/// @returns vector of all of the sampler/texture sampling pairs that are used
/// by that entry point.
std::vector<sem::SamplerTexturePair> GetSamplerTextureUses(
const std::string& entry_point,
const sem::BindingPoint& placeholder);
/// @param entry_point name of the entry point to get information about.
/// @param placeholder the sampler binding point to use for texture-only
/// access (e.g., textureLoad)
/// @returns vector of all of the sampler/texture sampling pairs that are used
/// by that entry point.
std::vector<sem::SamplerTexturePair> GetSamplerTextureUses(
const std::string& entry_point,
const sem::BindingPoint& placeholder);
/// @param entry_point name of the entry point to get information about.
/// @returns the total size in bytes of all Workgroup storage-class storage
/// referenced transitively by the entry point.
uint32_t GetWorkgroupStorageSize(const std::string& entry_point);
/// @param entry_point name of the entry point to get information about.
/// @returns the total size in bytes of all Workgroup storage-class storage
/// referenced transitively by the entry point.
uint32_t GetWorkgroupStorageSize(const std::string& entry_point);
/// @returns vector of all valid extension names used by the program. There
/// will be no duplicated names in the returned vector even if an extension
/// is enabled multiple times.
std::vector<std::string> GetUsedExtensionNames();
/// @returns vector of all valid extension names used by the program. There
/// will be no duplicated names in the returned vector even if an extension
/// is enabled multiple times.
std::vector<std::string> GetUsedExtensionNames();
/// @returns vector of all enable directives used by the program, each
/// enable directive represented by a std::pair<std::string,
/// tint::Source::Range> for its extension name and its location of the
/// extension name. There may be multiple enable directives for a same
/// extension.
std::vector<std::pair<std::string, Source>> GetEnableDirectives();
/// @returns vector of all enable directives used by the program, each
/// enable directive represented by a std::pair<std::string,
/// tint::Source::Range> for its extension name and its location of the
/// extension name. There may be multiple enable directives for a same
/// extension.
std::vector<std::pair<std::string, Source>> GetEnableDirectives();
private:
const Program* program_;
diag::List diagnostics_;
std::unique_ptr<
std::unordered_map<std::string,
utils::UniqueVector<sem::SamplerTexturePair>>>
sampler_targets_;
private:
const Program* program_;
diag::List diagnostics_;
std::unique_ptr<std::unordered_map<std::string, utils::UniqueVector<sem::SamplerTexturePair>>>
sampler_targets_;
/// @param name name of the entry point to find
/// @returns a pointer to the entry point if it exists, otherwise returns
/// nullptr and sets the error string.
const ast::Function* FindEntryPointByName(const std::string& name);
/// @param name name of the entry point to find
/// @returns a pointer to the entry point if it exists, otherwise returns
/// nullptr and sets the error string.
const ast::Function* FindEntryPointByName(const std::string& name);
/// Recursively add entry point IO variables.
/// If `type` is a struct, recurse into members, appending the member name.
/// Otherwise, add the variable unless it is a builtin.
/// @param name the name of the variable being added
/// @param type the type of the variable
/// @param attributes the variable attributes
/// @param variables the list to add the variables to
void AddEntryPointInOutVariables(std::string name,
const sem::Type* type,
const ast::AttributeList& attributes,
std::vector<StageVariable>& variables) const;
/// Recursively add entry point IO variables.
/// If `type` is a struct, recurse into members, appending the member name.
/// Otherwise, add the variable unless it is a builtin.
/// @param name the name of the variable being added
/// @param type the type of the variable
/// @param attributes the variable attributes
/// @param variables the list to add the variables to
void AddEntryPointInOutVariables(std::string name,
const sem::Type* type,
const ast::AttributeList& attributes,
std::vector<StageVariable>& variables) const;
/// Recursively determine if the type contains builtin.
/// If `type` is a struct, recurse into members to check for the attribute.
/// Otherwise, check `attributes` for the attribute.
bool ContainsBuiltin(ast::Builtin builtin,
const sem::Type* type,
const ast::AttributeList& attributes) const;
/// Recursively determine if the type contains builtin.
/// If `type` is a struct, recurse into members to check for the attribute.
/// Otherwise, check `attributes` for the attribute.
bool ContainsBuiltin(ast::Builtin builtin,
const sem::Type* type,
const ast::AttributeList& attributes) const;
/// Gathers all the texture resource bindings of the given type for the given
/// entry point.
/// @param entry_point name of the entry point to get information about.
/// @param texture_type the type of the textures to gather.
/// @param resource_type the ResourceBinding::ResourceType for the given
/// texture type.
/// @returns vector of all of the bindings for depth textures.
std::vector<ResourceBinding> GetTextureResourceBindings(
const std::string& entry_point,
const tint::TypeInfo* texture_type,
ResourceBinding::ResourceType resource_type);
/// Gathers all the texture resource bindings of the given type for the given
/// entry point.
/// @param entry_point name of the entry point to get information about.
/// @param texture_type the type of the textures to gather.
/// @param resource_type the ResourceBinding::ResourceType for the given
/// texture type.
/// @returns vector of all of the bindings for depth textures.
std::vector<ResourceBinding> GetTextureResourceBindings(
const std::string& entry_point,
const tint::TypeInfo* texture_type,
ResourceBinding::ResourceType resource_type);
/// @param entry_point name of the entry point to get information about.
/// @param read_only if true get only read-only bindings, if false get
/// write-only bindings.
/// @returns vector of all of the bindings for the requested storage buffers.
std::vector<ResourceBinding> GetStorageBufferResourceBindingsImpl(
const std::string& entry_point,
bool read_only);
/// @param entry_point name of the entry point to get information about.
/// @param read_only if true get only read-only bindings, if false get
/// write-only bindings.
/// @returns vector of all of the bindings for the requested storage buffers.
std::vector<ResourceBinding> GetStorageBufferResourceBindingsImpl(
const std::string& entry_point,
bool read_only);
/// @param entry_point name of the entry point to get information about.
/// @param multisampled_only only get multisampled textures if true, otherwise
/// only get sampled textures.
/// @returns vector of all of the bindings for the request storage buffers.
std::vector<ResourceBinding> GetSampledTextureResourceBindingsImpl(
const std::string& entry_point,
bool multisampled_only);
/// @param entry_point name of the entry point to get information about.
/// @param multisampled_only only get multisampled textures if true, otherwise
/// only get sampled textures.
/// @returns vector of all of the bindings for the request storage buffers.
std::vector<ResourceBinding> GetSampledTextureResourceBindingsImpl(
const std::string& entry_point,
bool multisampled_only);
/// @param entry_point name of the entry point to get information about.
/// @returns vector of all of the bindings for the requested storage textures.
std::vector<ResourceBinding> GetStorageTextureResourceBindingsImpl(
const std::string& entry_point);
/// @param entry_point name of the entry point to get information about.
/// @returns vector of all of the bindings for the requested storage textures.
std::vector<ResourceBinding> GetStorageTextureResourceBindingsImpl(
const std::string& entry_point);
/// Constructs |sampler_targets_| if it hasn't already been instantiated.
void GenerateSamplerTargets();
/// Constructs |sampler_targets_| if it hasn't already been instantiated.
void GenerateSamplerTargets();
/// For a N-uple of expressions, resolve to the appropriate global resources
/// and call 'cb'.
/// 'cb' may be called multiple times.
/// Assumes that not being able to resolve the resources is an error, so will
/// invoke TINT_ICE when that occurs.
/// @tparam N number of expressions in the n-uple
/// @tparam F type of the callback provided.
/// @param exprs N-uple of expressions to resolve.
/// @param cb is a callback function with the signature:
/// `void(std::array<const sem::GlobalVariable*, N>)`, which is invoked
/// whenever a set of expressions are resolved to globals.
template <size_t N, typename F>
void GetOriginatingResources(std::array<const ast::Expression*, N> exprs,
F&& cb);
/// For a N-uple of expressions, resolve to the appropriate global resources
/// and call 'cb'.
/// 'cb' may be called multiple times.
/// Assumes that not being able to resolve the resources is an error, so will
/// invoke TINT_ICE when that occurs.
/// @tparam N number of expressions in the n-uple
/// @tparam F type of the callback provided.
/// @param exprs N-uple of expressions to resolve.
/// @param cb is a callback function with the signature:
/// `void(std::array<const sem::GlobalVariable*, N>)`, which is invoked
/// whenever a set of expressions are resolved to globals.
template <size_t N, typename F>
void GetOriginatingResources(std::array<const ast::Expression*, N> exprs, F&& cb);
};
} // namespace tint::inspector

File diff suppressed because it is too large Load Diff

View File

@@ -24,91 +24,90 @@
namespace tint::inspector {
ResourceBinding::TextureDimension
TypeTextureDimensionToResourceBindingTextureDimension(
ResourceBinding::TextureDimension TypeTextureDimensionToResourceBindingTextureDimension(
const ast::TextureDimension& type_dim) {
switch (type_dim) {
case ast::TextureDimension::k1d:
return ResourceBinding::TextureDimension::k1d;
case ast::TextureDimension::k2d:
return ResourceBinding::TextureDimension::k2d;
case ast::TextureDimension::k2dArray:
return ResourceBinding::TextureDimension::k2dArray;
case ast::TextureDimension::k3d:
return ResourceBinding::TextureDimension::k3d;
case ast::TextureDimension::kCube:
return ResourceBinding::TextureDimension::kCube;
case ast::TextureDimension::kCubeArray:
return ResourceBinding::TextureDimension::kCubeArray;
case ast::TextureDimension::kNone:
return ResourceBinding::TextureDimension::kNone;
}
return ResourceBinding::TextureDimension::kNone;
switch (type_dim) {
case ast::TextureDimension::k1d:
return ResourceBinding::TextureDimension::k1d;
case ast::TextureDimension::k2d:
return ResourceBinding::TextureDimension::k2d;
case ast::TextureDimension::k2dArray:
return ResourceBinding::TextureDimension::k2dArray;
case ast::TextureDimension::k3d:
return ResourceBinding::TextureDimension::k3d;
case ast::TextureDimension::kCube:
return ResourceBinding::TextureDimension::kCube;
case ast::TextureDimension::kCubeArray:
return ResourceBinding::TextureDimension::kCubeArray;
case ast::TextureDimension::kNone:
return ResourceBinding::TextureDimension::kNone;
}
return ResourceBinding::TextureDimension::kNone;
}
ResourceBinding::SampledKind BaseTypeToSampledKind(const sem::Type* base_type) {
if (!base_type) {
return ResourceBinding::SampledKind::kUnknown;
}
if (!base_type) {
return ResourceBinding::SampledKind::kUnknown;
}
if (auto* at = base_type->As<sem::Array>()) {
base_type = at->ElemType();
} else if (auto* mt = base_type->As<sem::Matrix>()) {
base_type = mt->type();
} else if (auto* vt = base_type->As<sem::Vector>()) {
base_type = vt->type();
}
if (auto* at = base_type->As<sem::Array>()) {
base_type = at->ElemType();
} else if (auto* mt = base_type->As<sem::Matrix>()) {
base_type = mt->type();
} else if (auto* vt = base_type->As<sem::Vector>()) {
base_type = vt->type();
}
if (base_type->Is<sem::F32>()) {
return ResourceBinding::SampledKind::kFloat;
} else if (base_type->Is<sem::U32>()) {
return ResourceBinding::SampledKind::kUInt;
} else if (base_type->Is<sem::I32>()) {
return ResourceBinding::SampledKind::kSInt;
} else {
return ResourceBinding::SampledKind::kUnknown;
}
if (base_type->Is<sem::F32>()) {
return ResourceBinding::SampledKind::kFloat;
} else if (base_type->Is<sem::U32>()) {
return ResourceBinding::SampledKind::kUInt;
} else if (base_type->Is<sem::I32>()) {
return ResourceBinding::SampledKind::kSInt;
} else {
return ResourceBinding::SampledKind::kUnknown;
}
}
ResourceBinding::TexelFormat TypeTexelFormatToResourceBindingTexelFormat(
const ast::TexelFormat& image_format) {
switch (image_format) {
case ast::TexelFormat::kR32Uint:
return ResourceBinding::TexelFormat::kR32Uint;
case ast::TexelFormat::kR32Sint:
return ResourceBinding::TexelFormat::kR32Sint;
case ast::TexelFormat::kR32Float:
return ResourceBinding::TexelFormat::kR32Float;
case ast::TexelFormat::kRgba8Unorm:
return ResourceBinding::TexelFormat::kRgba8Unorm;
case ast::TexelFormat::kRgba8Snorm:
return ResourceBinding::TexelFormat::kRgba8Snorm;
case ast::TexelFormat::kRgba8Uint:
return ResourceBinding::TexelFormat::kRgba8Uint;
case ast::TexelFormat::kRgba8Sint:
return ResourceBinding::TexelFormat::kRgba8Sint;
case ast::TexelFormat::kRg32Uint:
return ResourceBinding::TexelFormat::kRg32Uint;
case ast::TexelFormat::kRg32Sint:
return ResourceBinding::TexelFormat::kRg32Sint;
case ast::TexelFormat::kRg32Float:
return ResourceBinding::TexelFormat::kRg32Float;
case ast::TexelFormat::kRgba16Uint:
return ResourceBinding::TexelFormat::kRgba16Uint;
case ast::TexelFormat::kRgba16Sint:
return ResourceBinding::TexelFormat::kRgba16Sint;
case ast::TexelFormat::kRgba16Float:
return ResourceBinding::TexelFormat::kRgba16Float;
case ast::TexelFormat::kRgba32Uint:
return ResourceBinding::TexelFormat::kRgba32Uint;
case ast::TexelFormat::kRgba32Sint:
return ResourceBinding::TexelFormat::kRgba32Sint;
case ast::TexelFormat::kRgba32Float:
return ResourceBinding::TexelFormat::kRgba32Float;
case ast::TexelFormat::kNone:
return ResourceBinding::TexelFormat::kNone;
}
return ResourceBinding::TexelFormat::kNone;
switch (image_format) {
case ast::TexelFormat::kR32Uint:
return ResourceBinding::TexelFormat::kR32Uint;
case ast::TexelFormat::kR32Sint:
return ResourceBinding::TexelFormat::kR32Sint;
case ast::TexelFormat::kR32Float:
return ResourceBinding::TexelFormat::kR32Float;
case ast::TexelFormat::kRgba8Unorm:
return ResourceBinding::TexelFormat::kRgba8Unorm;
case ast::TexelFormat::kRgba8Snorm:
return ResourceBinding::TexelFormat::kRgba8Snorm;
case ast::TexelFormat::kRgba8Uint:
return ResourceBinding::TexelFormat::kRgba8Uint;
case ast::TexelFormat::kRgba8Sint:
return ResourceBinding::TexelFormat::kRgba8Sint;
case ast::TexelFormat::kRg32Uint:
return ResourceBinding::TexelFormat::kRg32Uint;
case ast::TexelFormat::kRg32Sint:
return ResourceBinding::TexelFormat::kRg32Sint;
case ast::TexelFormat::kRg32Float:
return ResourceBinding::TexelFormat::kRg32Float;
case ast::TexelFormat::kRgba16Uint:
return ResourceBinding::TexelFormat::kRgba16Uint;
case ast::TexelFormat::kRgba16Sint:
return ResourceBinding::TexelFormat::kRgba16Sint;
case ast::TexelFormat::kRgba16Float:
return ResourceBinding::TexelFormat::kRgba16Float;
case ast::TexelFormat::kRgba32Uint:
return ResourceBinding::TexelFormat::kRgba32Uint;
case ast::TexelFormat::kRgba32Sint:
return ResourceBinding::TexelFormat::kRgba32Sint;
case ast::TexelFormat::kRgba32Float:
return ResourceBinding::TexelFormat::kRgba32Float;
case ast::TexelFormat::kNone:
return ResourceBinding::TexelFormat::kNone;
}
return ResourceBinding::TexelFormat::kNone;
}
} // namespace tint::inspector

View File

@@ -24,90 +24,89 @@ namespace tint::inspector {
/// Container for information about how a resource is bound
struct ResourceBinding {
/// The dimensionality of a texture
enum class TextureDimension {
/// Invalid texture
kNone = -1,
/// 1 dimensional texture
k1d,
/// 2 dimensional texture
k2d,
/// 2 dimensional array texture
k2dArray,
/// 3 dimensional texture
k3d,
/// cube texture
kCube,
/// cube array texture
kCubeArray,
};
/// The dimensionality of a texture
enum class TextureDimension {
/// Invalid texture
kNone = -1,
/// 1 dimensional texture
k1d,
/// 2 dimensional texture
k2d,
/// 2 dimensional array texture
k2dArray,
/// 3 dimensional texture
k3d,
/// cube texture
kCube,
/// cube array texture
kCubeArray,
};
/// Component type of the texture's data. Same as the Sampled Type parameter
/// in SPIR-V OpTypeImage.
enum class SampledKind { kUnknown = -1, kFloat, kUInt, kSInt };
/// Component type of the texture's data. Same as the Sampled Type parameter
/// in SPIR-V OpTypeImage.
enum class SampledKind { kUnknown = -1, kFloat, kUInt, kSInt };
/// Enumerator of texel image formats
enum class TexelFormat {
kNone = -1,
/// Enumerator of texel image formats
enum class TexelFormat {
kNone = -1,
kRgba8Unorm,
kRgba8Snorm,
kRgba8Uint,
kRgba8Sint,
kRgba16Uint,
kRgba16Sint,
kRgba16Float,
kR32Uint,
kR32Sint,
kR32Float,
kRg32Uint,
kRg32Sint,
kRg32Float,
kRgba32Uint,
kRgba32Sint,
kRgba32Float,
};
kRgba8Unorm,
kRgba8Snorm,
kRgba8Uint,
kRgba8Sint,
kRgba16Uint,
kRgba16Sint,
kRgba16Float,
kR32Uint,
kR32Sint,
kR32Float,
kRg32Uint,
kRg32Sint,
kRg32Float,
kRgba32Uint,
kRgba32Sint,
kRgba32Float,
};
/// kXXX maps to entries returned by GetXXXResourceBindings call.
enum class ResourceType {
kUniformBuffer,
kStorageBuffer,
kReadOnlyStorageBuffer,
kSampler,
kComparisonSampler,
kSampledTexture,
kMultisampledTexture,
kWriteOnlyStorageTexture,
kDepthTexture,
kDepthMultisampledTexture,
kExternalTexture
};
/// kXXX maps to entries returned by GetXXXResourceBindings call.
enum class ResourceType {
kUniformBuffer,
kStorageBuffer,
kReadOnlyStorageBuffer,
kSampler,
kComparisonSampler,
kSampledTexture,
kMultisampledTexture,
kWriteOnlyStorageTexture,
kDepthTexture,
kDepthMultisampledTexture,
kExternalTexture
};
/// Type of resource that is bound.
ResourceType resource_type;
/// Bind group the binding belongs
uint32_t bind_group;
/// Identifier to identify this binding within the bind group
uint32_t binding;
/// Size for this binding, in bytes, if defined.
uint64_t size;
/// Size for this binding without trailing structure padding, in bytes, if
/// defined.
uint64_t size_no_padding;
/// Dimensionality of this binding, if defined.
TextureDimension dim;
/// Kind of data being sampled, if defined.
SampledKind sampled_kind;
/// Format of data, if defined.
TexelFormat image_format;
/// Type of resource that is bound.
ResourceType resource_type;
/// Bind group the binding belongs
uint32_t bind_group;
/// Identifier to identify this binding within the bind group
uint32_t binding;
/// Size for this binding, in bytes, if defined.
uint64_t size;
/// Size for this binding without trailing structure padding, in bytes, if
/// defined.
uint64_t size_no_padding;
/// Dimensionality of this binding, if defined.
TextureDimension dim;
/// Kind of data being sampled, if defined.
SampledKind sampled_kind;
/// Format of data, if defined.
TexelFormat image_format;
};
/// Convert from internal ast::TextureDimension to public
/// ResourceBinding::TextureDimension
/// @param type_dim internal value to convert from
/// @returns the publicly visible equivalent
ResourceBinding::TextureDimension
TypeTextureDimensionToResourceBindingTextureDimension(
ResourceBinding::TextureDimension TypeTextureDimensionToResourceBindingTextureDimension(
const ast::TextureDimension& type_dim);
/// Infer ResourceBinding::SampledKind for a given sem::Type

View File

@@ -19,55 +19,55 @@ namespace tint::inspector {
Scalar::Scalar() : type_(kNull) {}
Scalar::Scalar(bool val) : type_(kBool) {
value_.b = val;
value_.b = val;
}
Scalar::Scalar(uint32_t val) : type_(kU32) {
value_.u = val;
value_.u = val;
}
Scalar::Scalar(int32_t val) : type_(kI32) {
value_.i = val;
value_.i = val;
}
Scalar::Scalar(float val) : type_(kFloat) {
value_.f = val;
value_.f = val;
}
bool Scalar::IsNull() const {
return type_ == kNull;
return type_ == kNull;
}
bool Scalar::IsBool() const {
return type_ == kBool;
return type_ == kBool;
}
bool Scalar::IsU32() const {
return type_ == kU32;
return type_ == kU32;
}
bool Scalar::IsI32() const {
return type_ == kI32;
return type_ == kI32;
}
bool Scalar::IsFloat() const {
return type_ == kFloat;
return type_ == kFloat;
}
bool Scalar::AsBool() const {
return value_.b;
return value_.b;
}
uint32_t Scalar::AsU32() const {
return value_.u;
return value_.u;
}
int32_t Scalar::AsI32() const {
return value_.i;
return value_.i;
}
float Scalar::AsFloat() const {
return value_.f;
return value_.f;
}
} // namespace tint::inspector

View File

@@ -21,56 +21,56 @@ namespace tint::inspector {
/// Contains a literal scalar value
class Scalar {
public:
/// Null Constructor
Scalar();
/// @param val literal scalar value to contain
explicit Scalar(bool val);
/// @param val literal scalar value to contain
explicit Scalar(uint32_t val);
/// @param val literal scalar value to contain
explicit Scalar(int32_t val);
/// @param val literal scalar value to contain
explicit Scalar(float val);
public:
/// Null Constructor
Scalar();
/// @param val literal scalar value to contain
explicit Scalar(bool val);
/// @param val literal scalar value to contain
explicit Scalar(uint32_t val);
/// @param val literal scalar value to contain
explicit Scalar(int32_t val);
/// @param val literal scalar value to contain
explicit Scalar(float val);
/// @returns true if this is a null
bool IsNull() const;
/// @returns true if this is a bool
bool IsBool() const;
/// @returns true if this is a unsigned integer.
bool IsU32() const;
/// @returns true if this is a signed integer.
bool IsI32() const;
/// @returns true if this is a float.
bool IsFloat() const;
/// @returns true if this is a null
bool IsNull() const;
/// @returns true if this is a bool
bool IsBool() const;
/// @returns true if this is a unsigned integer.
bool IsU32() const;
/// @returns true if this is a signed integer.
bool IsI32() const;
/// @returns true if this is a float.
bool IsFloat() const;
/// @returns scalar value if bool, otherwise undefined behaviour.
bool AsBool() const;
/// @returns scalar value if unsigned integer, otherwise undefined behaviour.
uint32_t AsU32() const;
/// @returns scalar value if signed integer, otherwise undefined behaviour.
int32_t AsI32() const;
/// @returns scalar value if float, otherwise undefined behaviour.
float AsFloat() const;
/// @returns scalar value if bool, otherwise undefined behaviour.
bool AsBool() const;
/// @returns scalar value if unsigned integer, otherwise undefined behaviour.
uint32_t AsU32() const;
/// @returns scalar value if signed integer, otherwise undefined behaviour.
int32_t AsI32() const;
/// @returns scalar value if float, otherwise undefined behaviour.
float AsFloat() const;
private:
typedef enum {
kNull,
kBool,
kU32,
kI32,
kFloat,
} Type;
private:
typedef enum {
kNull,
kBool,
kU32,
kI32,
kFloat,
} Type;
typedef union {
bool b;
uint32_t u;
int32_t i;
float f;
} Value;
typedef union {
bool b;
uint32_t u;
int32_t i;
float f;
} Value;
Type type_;
Value value_;
Type type_;
Value value_;
};
} // namespace tint::inspector

View File

@@ -27,37 +27,34 @@ namespace tint::inspector {
InspectorBuilder::InspectorBuilder() = default;
InspectorBuilder::~InspectorBuilder() = default;
void InspectorBuilder::MakeEmptyBodyFunction(std::string name,
ast::AttributeList attributes) {
Func(name, ast::VariableList(), ty.void_(), ast::StatementList{Return()},
attributes);
void InspectorBuilder::MakeEmptyBodyFunction(std::string name, ast::AttributeList attributes) {
Func(name, ast::VariableList(), ty.void_(), ast::StatementList{Return()}, attributes);
}
void InspectorBuilder::MakeCallerBodyFunction(std::string caller,
std::vector<std::string> callees,
ast::AttributeList attributes) {
ast::StatementList body;
body.reserve(callees.size() + 1);
for (auto callee : callees) {
body.push_back(CallStmt(Call(callee)));
}
body.push_back(Return());
ast::StatementList body;
body.reserve(callees.size() + 1);
for (auto callee : callees) {
body.push_back(CallStmt(Call(callee)));
}
body.push_back(Return());
Func(caller, ast::VariableList(), ty.void_(), body, attributes);
Func(caller, ast::VariableList(), ty.void_(), body, attributes);
}
const ast::Struct* InspectorBuilder::MakeInOutStruct(
std::string name,
std::vector<std::tuple<std::string, uint32_t>> inout_vars) {
ast::StructMemberList members;
for (auto var : inout_vars) {
std::string member_name;
uint32_t location;
std::tie(member_name, location) = var;
members.push_back(
Member(member_name, ty.u32(), {Location(location), Flat()}));
}
return Structure(name, members);
ast::StructMemberList members;
for (auto var : inout_vars) {
std::string member_name;
uint32_t location;
std::tie(member_name, location) = var;
members.push_back(Member(member_name, ty.u32(), {Location(location), Flat()}));
}
return Structure(name, members);
}
const ast::Function* InspectorBuilder::MakePlainGlobalReferenceBodyFunction(
@@ -65,79 +62,74 @@ const ast::Function* InspectorBuilder::MakePlainGlobalReferenceBodyFunction(
std::string var,
const ast::Type* type,
ast::AttributeList attributes) {
ast::StatementList stmts;
stmts.emplace_back(Decl(Var("local_" + var, type)));
stmts.emplace_back(Assign("local_" + var, var));
stmts.emplace_back(Return());
ast::StatementList stmts;
stmts.emplace_back(Decl(Var("local_" + var, type)));
stmts.emplace_back(Assign("local_" + var, var));
stmts.emplace_back(Return());
return Func(func, ast::VariableList(), ty.void_(), stmts, attributes);
return Func(func, ast::VariableList(), ty.void_(), stmts, attributes);
}
bool InspectorBuilder::ContainsName(const std::vector<StageVariable>& vec,
const std::string& name) {
for (auto& s : vec) {
if (s.name == name) {
return true;
for (auto& s : vec) {
if (s.name == name) {
return true;
}
}
}
return false;
return false;
}
std::string InspectorBuilder::StructMemberName(size_t idx,
const ast::Type* type) {
return std::to_string(idx) + type->FriendlyName(Symbols());
std::string InspectorBuilder::StructMemberName(size_t idx, const ast::Type* type) {
return std::to_string(idx) + type->FriendlyName(Symbols());
}
const ast::Struct* InspectorBuilder::MakeStructType(
const std::string& name,
std::vector<const ast::Type*> member_types) {
ast::StructMemberList members;
for (auto* type : member_types) {
members.push_back(MakeStructMember(members.size(), type, {}));
}
return MakeStructTypeFromMembers(name, std::move(members));
const ast::Struct* InspectorBuilder::MakeStructType(const std::string& name,
std::vector<const ast::Type*> member_types) {
ast::StructMemberList members;
for (auto* type : member_types) {
members.push_back(MakeStructMember(members.size(), type, {}));
}
return MakeStructTypeFromMembers(name, std::move(members));
}
const ast::Struct* InspectorBuilder::MakeStructTypeFromMembers(
const std::string& name,
ast::StructMemberList members) {
return Structure(name, std::move(members));
const ast::Struct* InspectorBuilder::MakeStructTypeFromMembers(const std::string& name,
ast::StructMemberList members) {
return Structure(name, std::move(members));
}
const ast::StructMember* InspectorBuilder::MakeStructMember(
size_t index,
const ast::Type* type,
ast::AttributeList attributes) {
return Member(StructMemberName(index, type), type, std::move(attributes));
const ast::StructMember* InspectorBuilder::MakeStructMember(size_t index,
const ast::Type* type,
ast::AttributeList attributes) {
return Member(StructMemberName(index, type), type, std::move(attributes));
}
const ast::Struct* InspectorBuilder::MakeUniformBufferType(
const std::string& name,
std::vector<const ast::Type*> member_types) {
return MakeStructType(name, member_types);
return MakeStructType(name, member_types);
}
std::function<const ast::TypeName*()> InspectorBuilder::MakeStorageBufferTypes(
const std::string& name,
std::vector<const ast::Type*> member_types) {
MakeStructType(name, member_types);
return [this, name] { return ty.type_name(name); };
MakeStructType(name, member_types);
return [this, name] { return ty.type_name(name); };
}
void InspectorBuilder::AddUniformBuffer(const std::string& name,
const ast::Type* type,
uint32_t group,
uint32_t binding) {
Global(name, type, ast::StorageClass::kUniform,
ast::AttributeList{
create<ast::BindingAttribute>(binding),
create<ast::GroupAttribute>(group),
});
Global(name, type, ast::StorageClass::kUniform,
ast::AttributeList{
create<ast::BindingAttribute>(binding),
create<ast::GroupAttribute>(group),
});
}
void InspectorBuilder::AddWorkgroupStorage(const std::string& name,
const ast::Type* type) {
Global(name, type, ast::StorageClass::kWorkgroup);
void InspectorBuilder::AddWorkgroupStorage(const std::string& name, const ast::Type* type) {
Global(name, type, ast::StorageClass::kWorkgroup);
}
void InspectorBuilder::AddStorageBuffer(const std::string& name,
@@ -145,76 +137,72 @@ void InspectorBuilder::AddStorageBuffer(const std::string& name,
ast::Access access,
uint32_t group,
uint32_t binding) {
Global(name, type, ast::StorageClass::kStorage, access,
ast::AttributeList{
create<ast::BindingAttribute>(binding),
create<ast::GroupAttribute>(group),
});
Global(name, type, ast::StorageClass::kStorage, access,
ast::AttributeList{
create<ast::BindingAttribute>(binding),
create<ast::GroupAttribute>(group),
});
}
void InspectorBuilder::MakeStructVariableReferenceBodyFunction(
std::string func_name,
std::string struct_name,
std::vector<std::tuple<size_t, const ast::Type*>> members) {
ast::StatementList stmts;
for (auto member : members) {
size_t member_idx;
const ast::Type* member_type;
std::tie(member_idx, member_type) = member;
std::string member_name = StructMemberName(member_idx, member_type);
ast::StatementList stmts;
for (auto member : members) {
size_t member_idx;
const ast::Type* member_type;
std::tie(member_idx, member_type) = member;
std::string member_name = StructMemberName(member_idx, member_type);
stmts.emplace_back(Decl(Var("local" + member_name, member_type)));
}
stmts.emplace_back(Decl(Var("local" + member_name, member_type)));
}
for (auto member : members) {
size_t member_idx;
const ast::Type* member_type;
std::tie(member_idx, member_type) = member;
std::string member_name = StructMemberName(member_idx, member_type);
for (auto member : members) {
size_t member_idx;
const ast::Type* member_type;
std::tie(member_idx, member_type) = member;
std::string member_name = StructMemberName(member_idx, member_type);
stmts.emplace_back(Assign("local" + member_name,
MemberAccessor(struct_name, member_name)));
}
stmts.emplace_back(Assign("local" + member_name, MemberAccessor(struct_name, member_name)));
}
stmts.emplace_back(Return());
stmts.emplace_back(Return());
Func(func_name, ast::VariableList(), ty.void_(), stmts, ast::AttributeList{});
Func(func_name, ast::VariableList(), ty.void_(), stmts, ast::AttributeList{});
}
void InspectorBuilder::AddSampler(const std::string& name,
uint32_t group,
uint32_t binding) {
Global(name, sampler_type(),
ast::AttributeList{
create<ast::BindingAttribute>(binding),
create<ast::GroupAttribute>(group),
});
void InspectorBuilder::AddSampler(const std::string& name, uint32_t group, uint32_t binding) {
Global(name, sampler_type(),
ast::AttributeList{
create<ast::BindingAttribute>(binding),
create<ast::GroupAttribute>(group),
});
}
void InspectorBuilder::AddComparisonSampler(const std::string& name,
uint32_t group,
uint32_t binding) {
Global(name, comparison_sampler_type(),
ast::AttributeList{
create<ast::BindingAttribute>(binding),
create<ast::GroupAttribute>(group),
});
Global(name, comparison_sampler_type(),
ast::AttributeList{
create<ast::BindingAttribute>(binding),
create<ast::GroupAttribute>(group),
});
}
void InspectorBuilder::AddResource(const std::string& name,
const ast::Type* type,
uint32_t group,
uint32_t binding) {
Global(name, type,
ast::AttributeList{
create<ast::BindingAttribute>(binding),
create<ast::GroupAttribute>(group),
});
Global(name, type,
ast::AttributeList{
create<ast::BindingAttribute>(binding),
create<ast::GroupAttribute>(group),
});
}
void InspectorBuilder::AddGlobalVariable(const std::string& name,
const ast::Type* type) {
Global(name, type, ast::StorageClass::kPrivate);
void InspectorBuilder::AddGlobalVariable(const std::string& name, const ast::Type* type) {
Global(name, type, ast::StorageClass::kPrivate);
}
const ast::Function* InspectorBuilder::MakeSamplerReferenceBodyFunction(
@@ -224,16 +212,16 @@ const ast::Function* InspectorBuilder::MakeSamplerReferenceBodyFunction(
const std::string& coords_name,
const ast::Type* base_type,
ast::AttributeList attributes) {
std::string result_name = "sampler_result";
std::string result_name = "sampler_result";
ast::StatementList stmts;
stmts.emplace_back(Decl(Var(result_name, ty.vec(base_type, 4))));
ast::StatementList stmts;
stmts.emplace_back(Decl(Var(result_name, ty.vec(base_type, 4))));
stmts.emplace_back(Assign(result_name, Call("textureSample", texture_name,
sampler_name, coords_name)));
stmts.emplace_back(Return());
stmts.emplace_back(
Assign(result_name, Call("textureSample", texture_name, sampler_name, coords_name)));
stmts.emplace_back(Return());
return Func(func_name, ast::VariableList(), ty.void_(), stmts, attributes);
return Func(func_name, ast::VariableList(), ty.void_(), stmts, attributes);
}
const ast::Function* InspectorBuilder::MakeSamplerReferenceBodyFunction(
@@ -244,22 +232,20 @@ const ast::Function* InspectorBuilder::MakeSamplerReferenceBodyFunction(
const std::string& array_index,
const ast::Type* base_type,
ast::AttributeList attributes) {
std::string result_name = "sampler_result";
std::string result_name = "sampler_result";
ast::StatementList stmts;
ast::StatementList stmts;
stmts.emplace_back(Decl(Var("sampler_result", ty.vec(base_type, 4))));
stmts.emplace_back(Decl(Var("sampler_result", ty.vec(base_type, 4))));
stmts.emplace_back(
Assign("sampler_result", Call("textureSample", texture_name, sampler_name,
coords_name, array_index)));
stmts.emplace_back(Return());
stmts.emplace_back(Assign("sampler_result", Call("textureSample", texture_name, sampler_name,
coords_name, array_index)));
stmts.emplace_back(Return());
return Func(func_name, ast::VariableList(), ty.void_(), stmts, attributes);
return Func(func_name, ast::VariableList(), ty.void_(), stmts, attributes);
}
const ast::Function*
InspectorBuilder::MakeComparisonSamplerReferenceBodyFunction(
const ast::Function* InspectorBuilder::MakeComparisonSamplerReferenceBodyFunction(
const std::string& func_name,
const std::string& texture_name,
const std::string& sampler_name,
@@ -267,66 +253,63 @@ InspectorBuilder::MakeComparisonSamplerReferenceBodyFunction(
const std::string& depth_name,
const ast::Type* base_type,
ast::AttributeList attributes) {
std::string result_name = "sampler_result";
std::string result_name = "sampler_result";
ast::StatementList stmts;
ast::StatementList stmts;
stmts.emplace_back(Decl(Var("sampler_result", base_type)));
stmts.emplace_back(
Assign("sampler_result", Call("textureSampleCompare", texture_name,
sampler_name, coords_name, depth_name)));
stmts.emplace_back(Return());
stmts.emplace_back(Decl(Var("sampler_result", base_type)));
stmts.emplace_back(Assign("sampler_result", Call("textureSampleCompare", texture_name,
sampler_name, coords_name, depth_name)));
stmts.emplace_back(Return());
return Func(func_name, ast::VariableList(), ty.void_(), stmts, attributes);
return Func(func_name, ast::VariableList(), ty.void_(), stmts, attributes);
}
const ast::Type* InspectorBuilder::GetBaseType(
ResourceBinding::SampledKind sampled_kind) {
switch (sampled_kind) {
case ResourceBinding::SampledKind::kFloat:
return ty.f32();
case ResourceBinding::SampledKind::kSInt:
return ty.i32();
case ResourceBinding::SampledKind::kUInt:
return ty.u32();
default:
return nullptr;
}
const ast::Type* InspectorBuilder::GetBaseType(ResourceBinding::SampledKind sampled_kind) {
switch (sampled_kind) {
case ResourceBinding::SampledKind::kFloat:
return ty.f32();
case ResourceBinding::SampledKind::kSInt:
return ty.i32();
case ResourceBinding::SampledKind::kUInt:
return ty.u32();
default:
return nullptr;
}
}
const ast::Type* InspectorBuilder::GetCoordsType(ast::TextureDimension dim,
const ast::Type* scalar) {
switch (dim) {
case ast::TextureDimension::k1d:
return scalar;
case ast::TextureDimension::k2d:
case ast::TextureDimension::k2dArray:
return create<ast::Vector>(scalar, 2);
case ast::TextureDimension::k3d:
case ast::TextureDimension::kCube:
case ast::TextureDimension::kCubeArray:
return create<ast::Vector>(scalar, 3);
default:
[=]() { FAIL() << "Unsupported texture dimension: " << dim; }();
}
return nullptr;
switch (dim) {
case ast::TextureDimension::k1d:
return scalar;
case ast::TextureDimension::k2d:
case ast::TextureDimension::k2dArray:
return create<ast::Vector>(scalar, 2);
case ast::TextureDimension::k3d:
case ast::TextureDimension::kCube:
case ast::TextureDimension::kCubeArray:
return create<ast::Vector>(scalar, 3);
default:
[=]() { FAIL() << "Unsupported texture dimension: " << dim; }();
}
return nullptr;
}
const ast::Type* InspectorBuilder::MakeStorageTextureTypes(
ast::TextureDimension dim,
ast::TexelFormat format) {
return ty.storage_texture(dim, format, ast::Access::kWrite);
const ast::Type* InspectorBuilder::MakeStorageTextureTypes(ast::TextureDimension dim,
ast::TexelFormat format) {
return ty.storage_texture(dim, format, ast::Access::kWrite);
}
void InspectorBuilder::AddStorageTexture(const std::string& name,
const ast::Type* type,
uint32_t group,
uint32_t binding) {
Global(name, type,
ast::AttributeList{
create<ast::BindingAttribute>(binding),
create<ast::GroupAttribute>(group),
});
Global(name, type,
ast::AttributeList{
create<ast::BindingAttribute>(binding),
create<ast::GroupAttribute>(group),
});
}
const ast::Function* InspectorBuilder::MakeStorageTextureBodyFunction(
@@ -334,64 +317,62 @@ const ast::Function* InspectorBuilder::MakeStorageTextureBodyFunction(
const std::string& st_name,
const ast::Type* dim_type,
ast::AttributeList attributes) {
ast::StatementList stmts;
ast::StatementList stmts;
stmts.emplace_back(Decl(Var("dim", dim_type)));
stmts.emplace_back(Assign("dim", Call("textureDimensions", st_name)));
stmts.emplace_back(Return());
stmts.emplace_back(Decl(Var("dim", dim_type)));
stmts.emplace_back(Assign("dim", Call("textureDimensions", st_name)));
stmts.emplace_back(Return());
return Func(func_name, ast::VariableList(), ty.void_(), stmts, attributes);
return Func(func_name, ast::VariableList(), ty.void_(), stmts, attributes);
}
std::function<const ast::Type*()> InspectorBuilder::GetTypeFunction(
ComponentType component,
CompositionType composition) {
std::function<const ast::Type*()> func;
switch (component) {
case ComponentType::kFloat:
func = [this]() -> const ast::Type* { return ty.f32(); };
break;
case ComponentType::kSInt:
func = [this]() -> const ast::Type* { return ty.i32(); };
break;
case ComponentType::kUInt:
func = [this]() -> const ast::Type* { return ty.u32(); };
break;
case ComponentType::kUnknown:
return []() -> const ast::Type* { return nullptr; };
}
std::function<const ast::Type*()> InspectorBuilder::GetTypeFunction(ComponentType component,
CompositionType composition) {
std::function<const ast::Type*()> func;
switch (component) {
case ComponentType::kFloat:
func = [this]() -> const ast::Type* { return ty.f32(); };
break;
case ComponentType::kSInt:
func = [this]() -> const ast::Type* { return ty.i32(); };
break;
case ComponentType::kUInt:
func = [this]() -> const ast::Type* { return ty.u32(); };
break;
case ComponentType::kUnknown:
return []() -> const ast::Type* { return nullptr; };
}
uint32_t n;
switch (composition) {
case CompositionType::kScalar:
return func;
case CompositionType::kVec2:
n = 2;
break;
case CompositionType::kVec3:
n = 3;
break;
case CompositionType::kVec4:
n = 4;
break;
default:
return []() -> ast::Type* { return nullptr; };
}
uint32_t n;
switch (composition) {
case CompositionType::kScalar:
return func;
case CompositionType::kVec2:
n = 2;
break;
case CompositionType::kVec3:
n = 3;
break;
case CompositionType::kVec4:
n = 4;
break;
default:
return []() -> ast::Type* { return nullptr; };
}
return [this, func, n]() -> const ast::Type* { return ty.vec(func(), n); };
return [this, func, n]() -> const ast::Type* { return ty.vec(func(), n); };
}
Inspector& InspectorBuilder::Build() {
if (inspector_) {
if (inspector_) {
return *inspector_;
}
program_ = std::make_unique<Program>(std::move(*this));
[&]() {
ASSERT_TRUE(program_->IsValid()) << diag::Formatter().format(program_->Diagnostics());
}();
inspector_ = std::make_unique<Inspector>(program_.get());
return *inspector_;
}
program_ = std::make_unique<Program>(std::move(*this));
[&]() {
ASSERT_TRUE(program_->IsValid())
<< diag::Formatter().format(program_->Diagnostics());
}();
inspector_ = std::make_unique<Inspector>(program_.get());
return *inspector_;
}
} // namespace tint::inspector

View File

@@ -37,346 +37,327 @@ namespace tint::inspector {
/// Utility class for building programs in inspector tests
class InspectorBuilder : public ProgramBuilder {
public:
InspectorBuilder();
~InspectorBuilder() override;
public:
InspectorBuilder();
~InspectorBuilder() override;
/// Generates an empty function
/// @param name name of the function created
/// @param attributes the function attributes
void MakeEmptyBodyFunction(std::string name, ast::AttributeList attributes);
/// Generates an empty function
/// @param name name of the function created
/// @param attributes the function attributes
void MakeEmptyBodyFunction(std::string name, ast::AttributeList attributes);
/// Generates a function that calls other functions
/// @param caller name of the function created
/// @param callees names of the functions to be called
/// @param attributes the function attributes
void MakeCallerBodyFunction(std::string caller,
std::vector<std::string> callees,
ast::AttributeList attributes);
/// Generates a function that calls other functions
/// @param caller name of the function created
/// @param callees names of the functions to be called
/// @param attributes the function attributes
void MakeCallerBodyFunction(std::string caller,
std::vector<std::string> callees,
ast::AttributeList attributes);
/// Generates a struct that contains user-defined IO members
/// @param name the name of the generated struct
/// @param inout_vars tuples of {name, loc} that will be the struct members
/// @returns a structure object
const ast::Struct* MakeInOutStruct(
std::string name,
std::vector<std::tuple<std::string, uint32_t>> inout_vars);
/// Generates a struct that contains user-defined IO members
/// @param name the name of the generated struct
/// @param inout_vars tuples of {name, loc} that will be the struct members
/// @returns a structure object
const ast::Struct* MakeInOutStruct(std::string name,
std::vector<std::tuple<std::string, uint32_t>> inout_vars);
// TODO(crbug.com/tint/697): Remove this.
/// Add In/Out variables to the global variables
/// @param inout_vars tuples of {in, out} that will be added as entries to the
/// global variables
void AddInOutVariables(
std::vector<std::tuple<std::string, std::string>> inout_vars);
// TODO(crbug.com/tint/697): Remove this.
/// Add In/Out variables to the global variables
/// @param inout_vars tuples of {in, out} that will be added as entries to the
/// global variables
void AddInOutVariables(std::vector<std::tuple<std::string, std::string>> inout_vars);
// TODO(crbug.com/tint/697): Remove this.
/// Generates a function that references in/out variables
/// @param name name of the function created
/// @param inout_vars tuples of {in, out} that will be converted into out = in
/// calls in the function body
/// @param attributes the function attributes
void MakeInOutVariableBodyFunction(
std::string name,
std::vector<std::tuple<std::string, std::string>> inout_vars,
ast::AttributeList attributes);
// TODO(crbug.com/tint/697): Remove this.
/// Generates a function that references in/out variables
/// @param name name of the function created
/// @param inout_vars tuples of {in, out} that will be converted into out = in
/// calls in the function body
/// @param attributes the function attributes
void MakeInOutVariableBodyFunction(std::string name,
std::vector<std::tuple<std::string, std::string>> inout_vars,
ast::AttributeList attributes);
// TODO(crbug.com/tint/697): Remove this.
/// Generates a function that references in/out variables and calls another
/// function.
/// @param caller name of the function created
/// @param callee name of the function to be called
/// @param inout_vars tuples of {in, out} that will be converted into out = in
/// calls in the function body
/// @param attributes the function attributes
/// @returns a function object
const ast::Function* MakeInOutVariableCallerBodyFunction(
std::string caller,
std::string callee,
std::vector<std::tuple<std::string, std::string>> inout_vars,
ast::AttributeList attributes);
// TODO(crbug.com/tint/697): Remove this.
/// Generates a function that references in/out variables and calls another
/// function.
/// @param caller name of the function created
/// @param callee name of the function to be called
/// @param inout_vars tuples of {in, out} that will be converted into out = in
/// calls in the function body
/// @param attributes the function attributes
/// @returns a function object
const ast::Function* MakeInOutVariableCallerBodyFunction(
std::string caller,
std::string callee,
std::vector<std::tuple<std::string, std::string>> inout_vars,
ast::AttributeList attributes);
/// Add a pipeline constant to the global variables, with a specific ID.
/// @param name name of the variable to add
/// @param id id number for the constant id
/// @param type type of the variable
/// @param constructor val to initialize the constant with, if NULL no
/// constructor will be added.
/// @returns the constant that was created
const ast::Variable* AddOverridableConstantWithID(
std::string name,
uint32_t id,
const ast::Type* type,
const ast::Expression* constructor) {
return Override(name, type, constructor, {Id(id)});
}
/// Add a pipeline constant to the global variables, with a specific ID.
/// @param name name of the variable to add
/// @param id id number for the constant id
/// @param type type of the variable
/// @param constructor val to initialize the constant with, if NULL no
/// constructor will be added.
/// @returns the constant that was created
const ast::Variable* AddOverridableConstantWithID(std::string name,
uint32_t id,
const ast::Type* type,
const ast::Expression* constructor) {
return Override(name, type, constructor, {Id(id)});
}
/// Add a pipeline constant to the global variables, without a specific ID.
/// @param name name of the variable to add
/// @param type type of the variable
/// @param constructor val to initialize the constant with, if NULL no
/// constructor will be added.
/// @returns the constant that was created
const ast::Variable* AddOverridableConstantWithoutID(
std::string name,
const ast::Type* type,
const ast::Expression* constructor) {
return Override(name, type, constructor);
}
/// Add a pipeline constant to the global variables, without a specific ID.
/// @param name name of the variable to add
/// @param type type of the variable
/// @param constructor val to initialize the constant with, if NULL no
/// constructor will be added.
/// @returns the constant that was created
const ast::Variable* AddOverridableConstantWithoutID(std::string name,
const ast::Type* type,
const ast::Expression* constructor) {
return Override(name, type, constructor);
}
/// Generates a function that references module-scoped, plain-typed constant
/// or variable.
/// @param func name of the function created
/// @param var name of the constant to be reference
/// @param type type of the const being referenced
/// @param attributes the function attributes
/// @returns a function object
const ast::Function* MakePlainGlobalReferenceBodyFunction(
std::string func,
std::string var,
const ast::Type* type,
ast::AttributeList attributes);
/// Generates a function that references module-scoped, plain-typed constant
/// or variable.
/// @param func name of the function created
/// @param var name of the constant to be reference
/// @param type type of the const being referenced
/// @param attributes the function attributes
/// @returns a function object
const ast::Function* MakePlainGlobalReferenceBodyFunction(std::string func,
std::string var,
const ast::Type* type,
ast::AttributeList attributes);
/// @param vec Vector of StageVariable to be searched
/// @param name Name to be searching for
/// @returns true if name is in vec, otherwise false
bool ContainsName(const std::vector<StageVariable>& vec,
const std::string& name);
/// @param vec Vector of StageVariable to be searched
/// @param name Name to be searching for
/// @returns true if name is in vec, otherwise false
bool ContainsName(const std::vector<StageVariable>& vec, const std::string& name);
/// Builds a string for accessing a member in a generated struct
/// @param idx index of member
/// @param type type of member
/// @returns a string for the member
std::string StructMemberName(size_t idx, const ast::Type* type);
/// Builds a string for accessing a member in a generated struct
/// @param idx index of member
/// @param type type of member
/// @returns a string for the member
std::string StructMemberName(size_t idx, const ast::Type* type);
/// Generates a struct type
/// @param name name for the type
/// @param member_types a vector of member types
/// @returns a struct type
const ast::Struct* MakeStructType(const std::string& name,
std::vector<const ast::Type*> member_types);
/// Generates a struct type
/// @param name name for the type
/// @param member_types a vector of member types
/// @returns a struct type
const ast::Struct* MakeStructType(const std::string& name,
std::vector<const ast::Type*> member_types);
/// Generates a struct type from a list of member nodes.
/// @param name name for the struct type
/// @param members a vector of members
/// @returns a struct type
const ast::Struct* MakeStructTypeFromMembers(const std::string& name,
ast::StructMemberList members);
/// Generates a struct type from a list of member nodes.
/// @param name name for the struct type
/// @param members a vector of members
/// @returns a struct type
const ast::Struct* MakeStructTypeFromMembers(const std::string& name,
ast::StructMemberList members);
/// Generates a struct member with a specified index and type.
/// @param index index of the field within the struct
/// @param type the type of the member field
/// @param attributes a list of attributes to apply to the member field
/// @returns a struct member
const ast::StructMember* MakeStructMember(size_t index,
const ast::Type* type,
ast::AttributeList attributes);
/// Generates a struct member with a specified index and type.
/// @param index index of the field within the struct
/// @param type the type of the member field
/// @param attributes a list of attributes to apply to the member field
/// @returns a struct member
const ast::StructMember* MakeStructMember(size_t index,
const ast::Type* type,
ast::AttributeList attributes);
/// Generates types appropriate for using in an uniform buffer
/// @param name name for the type
/// @param member_types a vector of member types
/// @returns a struct type that has the layout for an uniform buffer.
const ast::Struct* MakeUniformBufferType(
const std::string& name,
std::vector<const ast::Type*> member_types);
/// Generates types appropriate for using in an uniform buffer
/// @param name name for the type
/// @param member_types a vector of member types
/// @returns a struct type that has the layout for an uniform buffer.
const ast::Struct* MakeUniformBufferType(const std::string& name,
std::vector<const ast::Type*> member_types);
/// Generates types appropriate for using in a storage buffer
/// @param name name for the type
/// @param member_types a vector of member types
/// @returns a function that returns the created structure.
std::function<const ast::TypeName*()> MakeStorageBufferTypes(
const std::string& name,
std::vector<const ast::Type*> member_types);
/// Generates types appropriate for using in a storage buffer
/// @param name name for the type
/// @param member_types a vector of member types
/// @returns a function that returns the created structure.
std::function<const ast::TypeName*()> MakeStorageBufferTypes(
const std::string& name,
std::vector<const ast::Type*> member_types);
/// Adds an uniform buffer variable to the program
/// @param name the name of the variable
/// @param type the type to use
/// @param group the binding/group/ to use for the uniform buffer
/// @param binding the binding number to use for the uniform buffer
void AddUniformBuffer(const std::string& name,
const ast::Type* type,
uint32_t group,
uint32_t binding);
/// Adds an uniform buffer variable to the program
/// @param name the name of the variable
/// @param type the type to use
/// @param group the binding/group/ to use for the uniform buffer
/// @param binding the binding number to use for the uniform buffer
void AddUniformBuffer(const std::string& name,
const ast::Type* type,
uint32_t group,
uint32_t binding);
/// Adds a workgroup storage variable to the program
/// @param name the name of the variable
/// @param type the type of the variable
void AddWorkgroupStorage(const std::string& name, const ast::Type* type);
/// Adds a workgroup storage variable to the program
/// @param name the name of the variable
/// @param type the type of the variable
void AddWorkgroupStorage(const std::string& name, const ast::Type* type);
/// Adds a storage buffer variable to the program
/// @param name the name of the variable
/// @param type the type to use
/// @param access the storage buffer access control
/// @param group the binding/group to use for the storage buffer
/// @param binding the binding number to use for the storage buffer
void AddStorageBuffer(const std::string& name,
const ast::Type* type,
ast::Access access,
uint32_t group,
uint32_t binding);
/// Adds a storage buffer variable to the program
/// @param name the name of the variable
/// @param type the type to use
/// @param access the storage buffer access control
/// @param group the binding/group to use for the storage buffer
/// @param binding the binding number to use for the storage buffer
void AddStorageBuffer(const std::string& name,
const ast::Type* type,
ast::Access access,
uint32_t group,
uint32_t binding);
/// Generates a function that references a specific struct variable
/// @param func_name name of the function created
/// @param struct_name name of the struct variabler to be accessed
/// @param members list of members to access, by index and type
void MakeStructVariableReferenceBodyFunction(
std::string func_name,
std::string struct_name,
std::vector<std::tuple<size_t, const ast::Type*>> members);
/// Generates a function that references a specific struct variable
/// @param func_name name of the function created
/// @param struct_name name of the struct variabler to be accessed
/// @param members list of members to access, by index and type
void MakeStructVariableReferenceBodyFunction(
std::string func_name,
std::string struct_name,
std::vector<std::tuple<size_t, const ast::Type*>> members);
/// Adds a regular sampler variable to the program
/// @param name the name of the variable
/// @param group the binding/group to use for the storage buffer
/// @param binding the binding number to use for the storage buffer
void AddSampler(const std::string& name, uint32_t group, uint32_t binding);
/// Adds a regular sampler variable to the program
/// @param name the name of the variable
/// @param group the binding/group to use for the storage buffer
/// @param binding the binding number to use for the storage buffer
void AddSampler(const std::string& name, uint32_t group, uint32_t binding);
/// Adds a comparison sampler variable to the program
/// @param name the name of the variable
/// @param group the binding/group to use for the storage buffer
/// @param binding the binding number to use for the storage buffer
void AddComparisonSampler(const std::string& name,
uint32_t group,
uint32_t binding);
/// Adds a comparison sampler variable to the program
/// @param name the name of the variable
/// @param group the binding/group to use for the storage buffer
/// @param binding the binding number to use for the storage buffer
void AddComparisonSampler(const std::string& name, uint32_t group, uint32_t binding);
/// Adds a sampler or texture variable to the program
/// @param name the name of the variable
/// @param type the type to use
/// @param group the binding/group to use for the resource
/// @param binding the binding number to use for the resource
void AddResource(const std::string& name,
const ast::Type* type,
uint32_t group,
uint32_t binding);
/// Adds a sampler or texture variable to the program
/// @param name the name of the variable
/// @param type the type to use
/// @param group the binding/group to use for the resource
/// @param binding the binding number to use for the resource
void AddResource(const std::string& name,
const ast::Type* type,
uint32_t group,
uint32_t binding);
/// Add a module scope private variable to the progames
/// @param name the name of the variable
/// @param type the type to use
void AddGlobalVariable(const std::string& name, const ast::Type* type);
/// Add a module scope private variable to the progames
/// @param name the name of the variable
/// @param type the type to use
void AddGlobalVariable(const std::string& name, const ast::Type* type);
/// Generates a function that references a specific sampler variable
/// @param func_name name of the function created
/// @param texture_name name of the texture to be sampled
/// @param sampler_name name of the sampler to use
/// @param coords_name name of the coords variable to use
/// @param base_type sampler base type
/// @param attributes the function attributes
/// @returns a function that references all of the values specified
const ast::Function* MakeSamplerReferenceBodyFunction(
const std::string& func_name,
const std::string& texture_name,
const std::string& sampler_name,
const std::string& coords_name,
const ast::Type* base_type,
ast::AttributeList attributes);
/// Generates a function that references a specific sampler variable
/// @param func_name name of the function created
/// @param texture_name name of the texture to be sampled
/// @param sampler_name name of the sampler to use
/// @param coords_name name of the coords variable to use
/// @param base_type sampler base type
/// @param attributes the function attributes
/// @returns a function that references all of the values specified
const ast::Function* MakeSamplerReferenceBodyFunction(const std::string& func_name,
const std::string& texture_name,
const std::string& sampler_name,
const std::string& coords_name,
const ast::Type* base_type,
ast::AttributeList attributes);
/// Generates a function that references a specific sampler variable
/// @param func_name name of the function created
/// @param texture_name name of the texture to be sampled
/// @param sampler_name name of the sampler to use
/// @param coords_name name of the coords variable to use
/// @param array_index name of the array index variable to use
/// @param base_type sampler base type
/// @param attributes the function attributes
/// @returns a function that references all of the values specified
const ast::Function* MakeSamplerReferenceBodyFunction(
const std::string& func_name,
const std::string& texture_name,
const std::string& sampler_name,
const std::string& coords_name,
const std::string& array_index,
const ast::Type* base_type,
ast::AttributeList attributes);
/// Generates a function that references a specific sampler variable
/// @param func_name name of the function created
/// @param texture_name name of the texture to be sampled
/// @param sampler_name name of the sampler to use
/// @param coords_name name of the coords variable to use
/// @param array_index name of the array index variable to use
/// @param base_type sampler base type
/// @param attributes the function attributes
/// @returns a function that references all of the values specified
const ast::Function* MakeSamplerReferenceBodyFunction(const std::string& func_name,
const std::string& texture_name,
const std::string& sampler_name,
const std::string& coords_name,
const std::string& array_index,
const ast::Type* base_type,
ast::AttributeList attributes);
/// Generates a function that references a specific comparison sampler
/// variable.
/// @param func_name name of the function created
/// @param texture_name name of the depth texture to use
/// @param sampler_name name of the sampler to use
/// @param coords_name name of the coords variable to use
/// @param depth_name name of the depth reference to use
/// @param base_type sampler base type
/// @param attributes the function attributes
/// @returns a function that references all of the values specified
const ast::Function* MakeComparisonSamplerReferenceBodyFunction(
const std::string& func_name,
const std::string& texture_name,
const std::string& sampler_name,
const std::string& coords_name,
const std::string& depth_name,
const ast::Type* base_type,
ast::AttributeList attributes);
/// Generates a function that references a specific comparison sampler
/// variable.
/// @param func_name name of the function created
/// @param texture_name name of the depth texture to use
/// @param sampler_name name of the sampler to use
/// @param coords_name name of the coords variable to use
/// @param depth_name name of the depth reference to use
/// @param base_type sampler base type
/// @param attributes the function attributes
/// @returns a function that references all of the values specified
const ast::Function* MakeComparisonSamplerReferenceBodyFunction(const std::string& func_name,
const std::string& texture_name,
const std::string& sampler_name,
const std::string& coords_name,
const std::string& depth_name,
const ast::Type* base_type,
ast::AttributeList attributes);
/// Gets an appropriate type for the data in a given texture type.
/// @param sampled_kind type of in the texture
/// @returns a pointer to a type appropriate for the coord param
const ast::Type* GetBaseType(ResourceBinding::SampledKind sampled_kind);
/// Gets an appropriate type for the data in a given texture type.
/// @param sampled_kind type of in the texture
/// @returns a pointer to a type appropriate for the coord param
const ast::Type* GetBaseType(ResourceBinding::SampledKind sampled_kind);
/// Gets an appropriate type for the coords parameter depending the the
/// dimensionality of the texture being sampled.
/// @param dim dimensionality of the texture being sampled
/// @param scalar the scalar type
/// @returns a pointer to a type appropriate for the coord param
const ast::Type* GetCoordsType(ast::TextureDimension dim,
const ast::Type* scalar);
/// Gets an appropriate type for the coords parameter depending the the
/// dimensionality of the texture being sampled.
/// @param dim dimensionality of the texture being sampled
/// @param scalar the scalar type
/// @returns a pointer to a type appropriate for the coord param
const ast::Type* GetCoordsType(ast::TextureDimension dim, const ast::Type* scalar);
/// Generates appropriate types for a Read-Only StorageTexture
/// @param dim the texture dimension of the storage texture
/// @param format the texel format of the storage texture
/// @returns the storage texture type
const ast::Type* MakeStorageTextureTypes(ast::TextureDimension dim,
ast::TexelFormat format);
/// Generates appropriate types for a Read-Only StorageTexture
/// @param dim the texture dimension of the storage texture
/// @param format the texel format of the storage texture
/// @returns the storage texture type
const ast::Type* MakeStorageTextureTypes(ast::TextureDimension dim, ast::TexelFormat format);
/// Adds a storage texture variable to the program
/// @param name the name of the variable
/// @param type the type to use
/// @param group the binding/group to use for the sampled texture
/// @param binding the binding57 number to use for the sampled texture
void AddStorageTexture(const std::string& name,
const ast::Type* type,
uint32_t group,
uint32_t binding);
/// Adds a storage texture variable to the program
/// @param name the name of the variable
/// @param type the type to use
/// @param group the binding/group to use for the sampled texture
/// @param binding the binding57 number to use for the sampled texture
void AddStorageTexture(const std::string& name,
const ast::Type* type,
uint32_t group,
uint32_t binding);
/// Generates a function that references a storage texture variable.
/// @param func_name name of the function created
/// @param st_name name of the storage texture to use
/// @param dim_type type expected by textureDimensons to return
/// @param attributes the function attributes
/// @returns a function that references all of the values specified
const ast::Function* MakeStorageTextureBodyFunction(
const std::string& func_name,
const std::string& st_name,
const ast::Type* dim_type,
ast::AttributeList attributes);
/// Generates a function that references a storage texture variable.
/// @param func_name name of the function created
/// @param st_name name of the storage texture to use
/// @param dim_type type expected by textureDimensons to return
/// @param attributes the function attributes
/// @returns a function that references all of the values specified
const ast::Function* MakeStorageTextureBodyFunction(const std::string& func_name,
const std::string& st_name,
const ast::Type* dim_type,
ast::AttributeList attributes);
/// Get a generator function that returns a type appropriate for a stage
/// variable with the given combination of component and composition type.
/// @param component component type of the stage variable
/// @param composition composition type of the stage variable
/// @returns a generator function for the stage variable's type.
std::function<const ast::Type*()> GetTypeFunction(
ComponentType component,
CompositionType composition);
/// Get a generator function that returns a type appropriate for a stage
/// variable with the given combination of component and composition type.
/// @param component component type of the stage variable
/// @param composition composition type of the stage variable
/// @returns a generator function for the stage variable's type.
std::function<const ast::Type*()> GetTypeFunction(ComponentType component,
CompositionType composition);
/// Build the Program given all of the previous methods called and return an
/// Inspector for it.
/// Should only be called once per test.
/// @returns a reference to the Inspector for the built Program.
Inspector& Build();
/// Build the Program given all of the previous methods called and return an
/// Inspector for it.
/// Should only be called once per test.
/// @returns a reference to the Inspector for the built Program.
Inspector& Build();
/// @returns the type for a SamplerKind::kSampler
const ast::Sampler* sampler_type() {
return ty.sampler(ast::SamplerKind::kSampler);
}
/// @returns the type for a SamplerKind::kSampler
const ast::Sampler* sampler_type() { return ty.sampler(ast::SamplerKind::kSampler); }
/// @returns the type for a SamplerKind::kComparison
const ast::Sampler* comparison_sampler_type() {
return ty.sampler(ast::SamplerKind::kComparisonSampler);
}
/// @returns the type for a SamplerKind::kComparison
const ast::Sampler* comparison_sampler_type() {
return ty.sampler(ast::SamplerKind::kComparisonSampler);
}
protected:
/// Program built by this builder.
std::unique_ptr<Program> program_;
/// Inspector for |program_|
std::unique_ptr<Inspector> inspector_;
protected:
/// Program built by this builder.
std::unique_ptr<Program> program_;
/// Inspector for |program_|
std::unique_ptr<Inspector> inspector_;
};
} // namespace tint::inspector

View File

@@ -20,18 +20,17 @@ InspectorRunner::InspectorRunner() = default;
InspectorRunner::~InspectorRunner() = default;
Inspector& InspectorRunner::Initialize(std::string shader) {
if (inspector_) {
return *inspector_;
}
if (inspector_) {
return *inspector_;
}
file_ = std::make_unique<Source::File>("test", shader);
program_ = std::make_unique<Program>(reader::wgsl::Parse(file_.get()));
[&]() {
ASSERT_TRUE(program_->IsValid())
<< diag::Formatter().format(program_->Diagnostics());
}();
inspector_ = std::make_unique<Inspector>(program_.get());
return *inspector_;
file_ = std::make_unique<Source::File>("test", shader);
program_ = std::make_unique<Program>(reader::wgsl::Parse(file_.get()));
[&]() {
ASSERT_TRUE(program_->IsValid()) << diag::Formatter().format(program_->Diagnostics());
}();
inspector_ = std::make_unique<Inspector>(program_.get());
return *inspector_;
}
} // namespace tint::inspector

View File

@@ -25,23 +25,23 @@ namespace tint::inspector {
/// Utility class for running shaders in inspector tests
class InspectorRunner {
public:
InspectorRunner();
virtual ~InspectorRunner();
public:
InspectorRunner();
virtual ~InspectorRunner();
/// Create a Program with Inspector from the provided WGSL shader.
/// Should only be called once per test.
/// @param shader a WGSL shader
/// @returns a reference to the Inspector for the built Program.
Inspector& Initialize(std::string shader);
/// Create a Program with Inspector from the provided WGSL shader.
/// Should only be called once per test.
/// @param shader a WGSL shader
/// @returns a reference to the Inspector for the built Program.
Inspector& Initialize(std::string shader);
protected:
/// File created from input shader and used to create Program.
std::unique_ptr<Source::File> file_;
/// Program created by this runner.
std::unique_ptr<Program> program_;
/// Inspector for |program_|
std::unique_ptr<Inspector> inspector_;
protected:
/// File created from input shader and used to create Program.
std::unique_ptr<Source::File> file_;
/// Program created by this runner.
std::unique_ptr<Program> program_;
/// Inspector for |program_|
std::unique_ptr<Inspector> inspector_;
};
} // namespace tint::inspector