mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-06-18 04:23:36 +00:00
Add texture_external to inspector
Adds texture_external to the inspector, allowing us to recognize the type and return provide binding information. Includes a basic test. Bug: Dawn:728 Change-Id: Ib0f39998359dc22a530ad222141229f9ba30552f Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/51161 Reviewed-by: Ryan Harrison <rharrison@chromium.org> Commit-Queue: Brandon Jones <brandon1.jones@intel.com> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
parent
a965ad4d3a
commit
7b25769aed
@ -337,6 +337,8 @@ std::string ResourceTypeToString(
|
|||||||
return "WriteOnlyStorageTexture";
|
return "WriteOnlyStorageTexture";
|
||||||
case tint::inspector::ResourceBinding::ResourceType::kDepthTexture:
|
case tint::inspector::ResourceBinding::ResourceType::kDepthTexture:
|
||||||
return "DepthTexture";
|
return "DepthTexture";
|
||||||
|
case tint::inspector::ResourceBinding::ResourceType::kExternalTexture:
|
||||||
|
return "ExternalTexture";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "Unknown";
|
return "Unknown";
|
||||||
|
@ -381,7 +381,8 @@ std::vector<ResourceBinding> Inspector::GetResourceBindings(
|
|||||||
AppendResourceBindings(
|
AppendResourceBindings(
|
||||||
&result, GetWriteOnlyStorageTextureResourceBindings(entry_point));
|
&result, GetWriteOnlyStorageTextureResourceBindings(entry_point));
|
||||||
AppendResourceBindings(&result, GetDepthTextureResourceBindings(entry_point));
|
AppendResourceBindings(&result, GetDepthTextureResourceBindings(entry_point));
|
||||||
|
AppendResourceBindings(&result,
|
||||||
|
GetExternalTextureResourceBindings(entry_point));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -531,6 +532,33 @@ std::vector<ResourceBinding> Inspector::GetDepthTextureResourceBindings(
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<ResourceBinding> Inspector::GetExternalTextureResourceBindings(
|
||||||
|
const std::string& entry_point) {
|
||||||
|
auto* func = FindEntryPointByName(entry_point);
|
||||||
|
if (!func) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<ResourceBinding> result;
|
||||||
|
auto* func_sem = program_->Sem().Get(func);
|
||||||
|
for (auto& ref : func_sem->ReferencedExternalTextureVariables()) {
|
||||||
|
auto* var = ref.first;
|
||||||
|
auto binding_info = ref.second;
|
||||||
|
|
||||||
|
ResourceBinding entry;
|
||||||
|
entry.resource_type = ResourceBinding::ResourceType::kExternalTexture;
|
||||||
|
entry.bind_group = binding_info.group->value();
|
||||||
|
entry.binding = binding_info.binding->value();
|
||||||
|
|
||||||
|
auto* texture_type = var->Type()->UnwrapAccess()->As<sem::Texture>();
|
||||||
|
entry.dim = TypeTextureDimensionToResourceBindingTextureDimension(
|
||||||
|
texture_type->dim());
|
||||||
|
|
||||||
|
result.push_back(entry);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
ast::Function* Inspector::FindEntryPointByName(const std::string& name) {
|
ast::Function* Inspector::FindEntryPointByName(const std::string& name) {
|
||||||
auto* func = program_->AST().Functions().Find(program_->Symbols().Get(name));
|
auto* func = program_->AST().Functions().Find(program_->Symbols().Get(name));
|
||||||
if (!func) {
|
if (!func) {
|
||||||
|
@ -104,6 +104,7 @@ struct ResourceBinding {
|
|||||||
kReadOnlyStorageTexture,
|
kReadOnlyStorageTexture,
|
||||||
kWriteOnlyStorageTexture,
|
kWriteOnlyStorageTexture,
|
||||||
kDepthTexture,
|
kDepthTexture,
|
||||||
|
kExternalTexture
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Type of resource that is bound.
|
/// Type of resource that is bound.
|
||||||
@ -209,6 +210,11 @@ class Inspector {
|
|||||||
std::vector<ResourceBinding> GetDepthTextureResourceBindings(
|
std::vector<ResourceBinding> GetDepthTextureResourceBindings(
|
||||||
const std::string& entry_point);
|
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);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const Program* program_;
|
const Program* program_;
|
||||||
std::string error_;
|
std::string error_;
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "src/ast/struct_block_decoration.h"
|
#include "src/ast/struct_block_decoration.h"
|
||||||
#include "src/ast/workgroup_decoration.h"
|
#include "src/ast/workgroup_decoration.h"
|
||||||
#include "src/sem/depth_texture_type.h"
|
#include "src/sem/depth_texture_type.h"
|
||||||
|
#include "src/sem/external_texture_type.h"
|
||||||
#include "src/sem/multisampled_texture_type.h"
|
#include "src/sem/multisampled_texture_type.h"
|
||||||
#include "src/sem/sampled_texture_type.h"
|
#include "src/sem/sampled_texture_type.h"
|
||||||
#include "src/sem/variable.h"
|
#include "src/sem/variable.h"
|
||||||
@ -380,6 +381,12 @@ class InspectorHelper : public ProgramBuilder {
|
|||||||
return ty.multisampled_texture(dim, type);
|
return ty.multisampled_texture(dim, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Generates an ExternalTexture appropriate for the params
|
||||||
|
/// @returns the generated ExternalTexture
|
||||||
|
typ::ExternalTexture MakeExternalTextureType() {
|
||||||
|
return ty.external_texture();
|
||||||
|
}
|
||||||
|
|
||||||
/// Adds a sampled texture variable to the program
|
/// Adds a sampled texture variable to the program
|
||||||
/// @param name the name of the variable
|
/// @param name the name of the variable
|
||||||
/// @param type the type to use
|
/// @param type the type to use
|
||||||
@ -420,6 +427,18 @@ class InspectorHelper : public ProgramBuilder {
|
|||||||
AddBinding(name, type, ast::StorageClass::kNone, group, binding);
|
AddBinding(name, type, ast::StorageClass::kNone, group, binding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Adds an external 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 external texture
|
||||||
|
/// @param binding the binding number to use for the external texture
|
||||||
|
void AddExternalTexture(const std::string& name,
|
||||||
|
ast::Type* type,
|
||||||
|
uint32_t group,
|
||||||
|
uint32_t binding) {
|
||||||
|
AddBinding(name, type, ast::StorageClass::kNone, group, binding);
|
||||||
|
}
|
||||||
|
|
||||||
/// Generates a function that references a specific sampler variable
|
/// Generates a function that references a specific sampler variable
|
||||||
/// @param func_name name of the function created
|
/// @param func_name name of the function created
|
||||||
/// @param texture_name name of the texture to be sampled
|
/// @param texture_name name of the texture to be sampled
|
||||||
@ -697,6 +716,9 @@ class InspectorGetStorageTextureResourceBindingsTestWithParam
|
|||||||
: public InspectorHelper,
|
: public InspectorHelper,
|
||||||
public testing::TestWithParam<GetStorageTextureTestParams> {};
|
public testing::TestWithParam<GetStorageTextureTestParams> {};
|
||||||
|
|
||||||
|
class InspectorGetExternalTextureResourceBindingsTest : public InspectorHelper,
|
||||||
|
public testing::Test {};
|
||||||
|
|
||||||
TEST_F(InspectorGetEntryPointTest, NoFunctions) {
|
TEST_F(InspectorGetEntryPointTest, NoFunctions) {
|
||||||
Inspector& inspector = Build();
|
Inspector& inspector = Build();
|
||||||
|
|
||||||
@ -2936,6 +2958,30 @@ INSTANTIATE_TEST_SUITE_P(
|
|||||||
ast::TextureDimension::kCubeArray,
|
ast::TextureDimension::kCubeArray,
|
||||||
inspector::ResourceBinding::TextureDimension::kCubeArray}));
|
inspector::ResourceBinding::TextureDimension::kCubeArray}));
|
||||||
|
|
||||||
|
TEST_F(InspectorGetExternalTextureResourceBindingsTest, Simple) {
|
||||||
|
auto external_texture_type = MakeExternalTextureType();
|
||||||
|
AddExternalTexture("et", external_texture_type, 0, 0);
|
||||||
|
|
||||||
|
Func("ep", ast::VariableList(), ty.void_(),
|
||||||
|
ast::StatementList{
|
||||||
|
create<ast::CallStatement>(Call("textureDimensions", "et")),
|
||||||
|
},
|
||||||
|
ast::DecorationList{
|
||||||
|
Stage(ast::PipelineStage::kFragment),
|
||||||
|
});
|
||||||
|
|
||||||
|
Inspector& inspector = Build();
|
||||||
|
|
||||||
|
auto result = inspector.GetExternalTextureResourceBindings("ep");
|
||||||
|
ASSERT_FALSE(inspector.has_error()) << inspector.error();
|
||||||
|
EXPECT_EQ(ResourceBinding::ResourceType::kExternalTexture,
|
||||||
|
result[0].resource_type);
|
||||||
|
|
||||||
|
ASSERT_EQ(1u, result.size());
|
||||||
|
EXPECT_EQ(0u, result[0].bind_group);
|
||||||
|
EXPECT_EQ(0u, result[0].binding);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace inspector
|
} // namespace inspector
|
||||||
} // namespace tint
|
} // namespace tint
|
||||||
|
@ -869,6 +869,12 @@ class ProgramBuilder {
|
|||||||
dims, format, ast::AccessControl::kInvalid, sem_subtype)};
|
dims, format, ast::AccessControl::kInvalid, sem_subtype)};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @returns the external texture
|
||||||
|
typ::ExternalTexture external_texture() const {
|
||||||
|
return {builder->create<ast::ExternalTexture>(),
|
||||||
|
builder->create<sem::ExternalTexture>()};
|
||||||
|
}
|
||||||
|
|
||||||
/// @param source the Source of the node
|
/// @param source the Source of the node
|
||||||
/// @returns the external texture
|
/// @returns the external texture
|
||||||
typ::ExternalTexture external_texture(const Source& source) const {
|
typ::ExternalTexture external_texture(const Source& source) const {
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
#include "src/ast/function.h"
|
#include "src/ast/function.h"
|
||||||
#include "src/sem/depth_texture_type.h"
|
#include "src/sem/depth_texture_type.h"
|
||||||
|
#include "src/sem/external_texture_type.h"
|
||||||
#include "src/sem/multisampled_texture_type.h"
|
#include "src/sem/multisampled_texture_type.h"
|
||||||
#include "src/sem/sampled_texture_type.h"
|
#include "src/sem/sampled_texture_type.h"
|
||||||
#include "src/sem/storage_texture_type.h"
|
#include "src/sem/storage_texture_type.h"
|
||||||
@ -168,6 +169,24 @@ Function::VariableBindings Function::ReferencedDepthTextureVariables() const {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Function::VariableBindings Function::ReferencedExternalTextureVariables()
|
||||||
|
const {
|
||||||
|
VariableBindings ret;
|
||||||
|
|
||||||
|
for (auto* var : ReferencedModuleVariables()) {
|
||||||
|
auto* unwrapped_type = var->Type()->UnwrapAccess();
|
||||||
|
auto* external_texture = unwrapped_type->As<sem::ExternalTexture>();
|
||||||
|
if (external_texture == nullptr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (auto binding_point = var->Declaration()->binding_point()) {
|
||||||
|
ret.push_back({var, binding_point});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
bool Function::HasAncestorEntryPoint(Symbol symbol) const {
|
bool Function::HasAncestorEntryPoint(Symbol symbol) const {
|
||||||
for (const auto& point : ancestor_entry_points_) {
|
for (const auto& point : ancestor_entry_points_) {
|
||||||
if (point == symbol) {
|
if (point == symbol) {
|
||||||
|
@ -135,9 +135,14 @@ class Function : public Castable<Function, CallTarget> {
|
|||||||
|
|
||||||
/// Retrieves any referenced depth texture variables. Note, the variables
|
/// Retrieves any referenced depth texture variables. Note, the variables
|
||||||
/// must be decorated with both binding and group decorations.
|
/// must be decorated with both binding and group decorations.
|
||||||
/// @returns the referenced storage textures
|
/// @returns the referenced depth textures
|
||||||
VariableBindings ReferencedDepthTextureVariables() const;
|
VariableBindings ReferencedDepthTextureVariables() const;
|
||||||
|
|
||||||
|
/// Retrieves any referenced external texture variables. Note, the variables
|
||||||
|
/// must be decorated with both binding and group decorations.
|
||||||
|
/// @returns the referenced external textures
|
||||||
|
VariableBindings ReferencedExternalTextureVariables() const;
|
||||||
|
|
||||||
/// Checks if the given entry point is an ancestor
|
/// Checks if the given entry point is an ancestor
|
||||||
/// @param sym the entry point symbol
|
/// @param sym the entry point symbol
|
||||||
/// @returns true if `sym` is an ancestor entry point of this function
|
/// @returns true if `sym` is an ancestor entry point of this function
|
||||||
|
Loading…
x
Reference in New Issue
Block a user