mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-16 00:17:03 +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:
committed by
Commit Bot service account
parent
a965ad4d3a
commit
7b25769aed
@@ -381,7 +381,8 @@ std::vector<ResourceBinding> Inspector::GetResourceBindings(
|
||||
AppendResourceBindings(
|
||||
&result, GetWriteOnlyStorageTextureResourceBindings(entry_point));
|
||||
AppendResourceBindings(&result, GetDepthTextureResourceBindings(entry_point));
|
||||
|
||||
AppendResourceBindings(&result,
|
||||
GetExternalTextureResourceBindings(entry_point));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -531,6 +532,33 @@ std::vector<ResourceBinding> Inspector::GetDepthTextureResourceBindings(
|
||||
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) {
|
||||
auto* func = program_->AST().Functions().Find(program_->Symbols().Get(name));
|
||||
if (!func) {
|
||||
|
||||
@@ -104,6 +104,7 @@ struct ResourceBinding {
|
||||
kReadOnlyStorageTexture,
|
||||
kWriteOnlyStorageTexture,
|
||||
kDepthTexture,
|
||||
kExternalTexture
|
||||
};
|
||||
|
||||
/// Type of resource that is bound.
|
||||
@@ -209,6 +210,11 @@ class Inspector {
|
||||
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 external textures.
|
||||
std::vector<ResourceBinding> GetExternalTextureResourceBindings(
|
||||
const std::string& entry_point);
|
||||
|
||||
private:
|
||||
const Program* program_;
|
||||
std::string error_;
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "src/ast/struct_block_decoration.h"
|
||||
#include "src/ast/workgroup_decoration.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/sampled_texture_type.h"
|
||||
#include "src/sem/variable.h"
|
||||
@@ -380,6 +381,12 @@ class InspectorHelper : public ProgramBuilder {
|
||||
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
|
||||
/// @param name the name of the variable
|
||||
/// @param type the type to use
|
||||
@@ -420,6 +427,18 @@ class InspectorHelper : public ProgramBuilder {
|
||||
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
|
||||
/// @param func_name name of the function created
|
||||
/// @param texture_name name of the texture to be sampled
|
||||
@@ -697,6 +716,9 @@ class InspectorGetStorageTextureResourceBindingsTestWithParam
|
||||
: public InspectorHelper,
|
||||
public testing::TestWithParam<GetStorageTextureTestParams> {};
|
||||
|
||||
class InspectorGetExternalTextureResourceBindingsTest : public InspectorHelper,
|
||||
public testing::Test {};
|
||||
|
||||
TEST_F(InspectorGetEntryPointTest, NoFunctions) {
|
||||
Inspector& inspector = Build();
|
||||
|
||||
@@ -2936,6 +2958,30 @@ INSTANTIATE_TEST_SUITE_P(
|
||||
ast::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 inspector
|
||||
} // namespace tint
|
||||
|
||||
Reference in New Issue
Block a user