Skip to content

Commit b514b4f

Browse files
committed
More clang reflection data.
1 parent d402e02 commit b514b4f

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

include/luisa/clangcxx/build_arguments.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
#include <luisa/core/stl/string.h>
33
#include <luisa/core/stl/vector.h>
44
#include <luisa/ast/type.h>
5+
#include <luisa/ast/usage.h>
56
namespace luisa::clangcxx {
67
struct BuildArgument {
7-
compute::Type const *type;
8+
compute::Type const *type{};
89
string var_name;
10+
uint resource_var_id{~0u};
11+
compute::Usage var_usage{compute::Usage::NONE};
912
};
1013
struct ShaderReflection {
1114
uint dimension;
15+
uint3 block_size;
1216
luisa::vector<BuildArgument> kernel_args;
1317
};
1418
}// namespace luisa::clangcxx

src/clangcxx/src/llvm/ASTConsumer.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1453,8 +1453,10 @@ auto FunctionBuilderBuilder::build(const clang::FunctionDecl *S, bool allowKerne
14531453
// LUISA_WARNING("Set kernel arg. {}", luisa::string_view{});
14541454
// }
14551455
if (auto lcType = db->FindOrAddType(Ty, param->getBeginLoc())) {
1456+
BuildArgument *build_arg = nullptr;
14561457
if (is_kernel) {
1457-
db->refl.kernel_args.emplace_back(lcType, luisa::string{param->getName().data(), param->getName().size()});
1458+
db->refl.kernel_args.emplace_back(lcType, luisa::string{param->getName().data(), param->getName().size()}, ~0u);
1459+
build_arg = &db->refl.kernel_args.back();
14581460
}
14591461
const luisa::compute::RefExpr *local = nullptr;
14601462
switch (lcType->tag()) {
@@ -1485,6 +1487,9 @@ auto FunctionBuilderBuilder::build(const clang::FunctionDecl *S, bool allowKerne
14851487
local = LC_ArgOrRef(Ty, builder, lcType);
14861488
} break;
14871489
}
1490+
if (build_arg && local) {
1491+
build_arg->resource_var_id = local->variable().uid();
1492+
}
14881493
stack.SetLocal(param, local);
14891494
return local;
14901495
} else {
@@ -1692,6 +1697,10 @@ ASTConsumer::~ASTConsumer() {
16921697
} else {
16931698
if (kernel_arg_reflect) {
16941699
*kernel_arg_reflect = std::move(db.refl);
1700+
kernel_arg_reflect->block_size = db.kernel_builder->block_size();
1701+
for (auto &i : kernel_arg_reflect->kernel_args) {
1702+
i.var_usage = db.kernel_builder->variable_usage(i.resource_var_id);
1703+
}
16951704
}
16961705
device->impl()->create_shader(option, luisa::compute::Function{db.kernel_builder.get()});
16971706
}

0 commit comments

Comments
 (0)