From 1b5679f9556b65c65146123ce98ca4f62fe71d72 Mon Sep 17 00:00:00 2001 From: arya <64514807+arya3d@users.noreply.github.com> Date: Tue, 24 Dec 2024 09:34:59 -0800 Subject: Reflection API Wasm Bindings Part1 (#5936) * add a lot of missing classes, functios and enums * typescript defintion generation * formatting * format code --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- source/slang-wasm/slang-wasm.cpp | 199 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 190 insertions(+), 9 deletions(-) (limited to 'source/slang-wasm/slang-wasm.cpp') diff --git a/source/slang-wasm/slang-wasm.cpp b/source/slang-wasm/slang-wasm.cpp index a1ce2920d..9c705e5ad 100644 --- a/source/slang-wasm/slang-wasm.cpp +++ b/source/slang-wasm/slang-wasm.cpp @@ -5,7 +5,6 @@ #include "../slang/slang-language-server.h" #include -#include #include using namespace slang; @@ -144,7 +143,6 @@ emscripten::val Module::findEntryPointByName(const std::string& name) return emscripten::val(EntryPoint(entryPoint.get(), m_session)); } - emscripten::val Module::findAndCheckEntryPoint(const std::string& name, int stage) { Slang::ComPtr entryPoint; @@ -409,12 +407,12 @@ emscripten::val ComponentType::loadStrings() return emscripten::val::array(result); } -ProgramLayout* ComponentType::getLayout(unsigned int targetIndex) +ProgramLayout* ComponentType::getLayout(uint32_t targetIndex) { return (slang::wgsl::ProgramLayout*)interface()->getLayout(targetIndex); } -unsigned int ProgramLayout::getParameterCount() +uint32_t ProgramLayout::getParameterCount() { return interface()->getParameterCount(); } @@ -432,7 +430,7 @@ emscripten::val ProgramLayout::toJsonObject() return parsedObject; } -VariableLayoutReflection* ProgramLayout::getParameterByIndex(unsigned int index) +VariableLayoutReflection* ProgramLayout::getParameterByIndex(uint32_t index) { return (slang::wgsl::VariableLayoutReflection*)(interface()->getParameterByIndex(index)); } @@ -442,6 +440,11 @@ TypeLayoutReflection* ProgramLayout::getGlobalParamsTypeLayout() return (slang::wgsl::TypeLayoutReflection*)(interface()->getGlobalParamsTypeLayout()); } +FunctionReflection* ProgramLayout::findFunctionByName(std::string name) +{ + return (slang::wgsl::FunctionReflection*)(interface()->findFunctionByName(name.c_str())); +} + EntryPointReflection* ProgramLayout::findEntryPointByName(std::string name) { return (slang::wgsl::EntryPointReflection*)(interface()->findEntryPointByName(name.c_str())); @@ -455,27 +458,203 @@ EntryPointReflection::ThreadGroupSize EntryPointReflection::getComputeThreadGrou } BindingType TypeLayoutReflection::getDescriptorSetDescriptorRangeType( - unsigned int setIndex, - unsigned int rangeIndex) + uint32_t setIndex, + uint32_t rangeIndex) { return interface()->getDescriptorSetDescriptorRangeType(setIndex, rangeIndex); } +std::string DeclReflection::getName() +{ + return interface()->getName(); +} + + +slang::DeclReflection::Kind DeclReflection::getKind() +{ + return interface()->getKind(); +} + +uint32_t DeclReflection::getChildrenCount() +{ + return interface()->getChildrenCount(); +}; + +slang::wgsl::DeclReflection* DeclReflection::getChild(uint32_t index) +{ + return (slang::wgsl::DeclReflection*)interface()->getChild(index); +} + +slang::wgsl::TypeReflection* DeclReflection::getType() +{ + return (slang::wgsl::TypeReflection*)interface()->getType(); +} +slang::wgsl::VariableReflection* DeclReflection::asVariable() +{ + return (slang::wgsl::VariableReflection*)interface()->asVariable(); +} +slang::wgsl::FunctionReflection* DeclReflection::asFunction() +{ + return (slang::wgsl::FunctionReflection*)interface()->asFunction(); +} +slang::wgsl::GenericReflection* DeclReflection::asGeneric() +{ + return (slang::wgsl::GenericReflection*)interface()->asGeneric(); +} +slang::wgsl::DeclReflection* DeclReflection::getParent() +{ + return (slang::wgsl::DeclReflection*)interface()->getParent(); +} + + +std::string GenericReflection::getName() +{ + return interface()->getName(); +} + +slang::wgsl::DeclReflection* GenericReflection::asDecl() +{ + return (slang::wgsl::DeclReflection*)interface()->asDecl(); +} + +uint32_t GenericReflection::getTypeParameterCount() +{ + return interface()->getTypeParameterCount(); +} +slang::wgsl::VariableReflection* GenericReflection::getTypeParameter(unsigned index) +{ + return (slang::wgsl::VariableReflection*)interface()->getTypeParameter(index); +} +uint32_t GenericReflection::getValueParameterCount() +{ + return interface()->getValueParameterCount(); +} +slang::wgsl::VariableReflection* GenericReflection::getValueParameter(unsigned index) +{ + return (slang::wgsl::VariableReflection*)interface()->getValueParameter(index); +} + +slang::wgsl::DeclReflection* GenericReflection::getInnerDecl() +{ + return (slang::wgsl::DeclReflection*)interface()->getInnerDecl(); +} + +SlangDeclKind GenericReflection::getInnerKind() +{ + return interface()->getInnerKind(); +} + +slang::wgsl::GenericReflection* GenericReflection::getOuterGenericContainer() +{ + return (slang::wgsl::GenericReflection*)interface()->getOuterGenericContainer(); +} + std::string VariableLayoutReflection::getName() { return interface()->getName(); } -TypeLayoutReflection* VariableLayoutReflection::getTypeLayout() +slang::wgsl::TypeLayoutReflection* VariableLayoutReflection::getTypeLayout() { return (slang::wgsl::TypeLayoutReflection*)(interface()->getTypeLayout()); } -unsigned int VariableLayoutReflection::getBindingIndex() +uint32_t VariableLayoutReflection::getBindingIndex() { return interface()->getBindingIndex(); } +std::string VariableReflection::getName() +{ + return interface()->getName(); +} + +uint32_t VariableReflection::getUserAttributeCount() +{ + return interface()->getUserAttributeCount(); +} + +slang::wgsl::UserAttribute* VariableReflection::getUserAttributeByIndex(uint32_t index) +{ + return (slang::wgsl::UserAttribute*)interface()->getUserAttributeByIndex(index); +} + +bool VariableReflection::hasDefaultValue() +{ + return interface()->hasDefaultValue(); +} + +slang::wgsl::TypeReflection* VariableReflection::getType() +{ + return (slang::wgsl::TypeReflection*)interface()->getType(); +} + +Modifier* VariableReflection::findModifier(Modifier::ID id) +{ + return interface()->findModifier(id); +} + +slang::wgsl::VariableReflection* TypeReflection::getFieldByIndex(uint32_t index) +{ + return (slang::wgsl::VariableReflection*)interface()->getFieldByIndex(index); +} + +slang::TypeReflection::ScalarType TypeReflection::getScalarType() +{ + return interface()->getScalarType(); +} + +slang::TypeReflection::Kind TypeReflection::getKind() +{ + return interface()->getKind(); +} + + +std::string UserAttribute::getName() +{ + return interface()->getName(); +} + +float UserAttribute::getArgumentValueFloat(uint32_t index) +{ + float value; + interface()->getArgumentValueFloat(index, &value); + return value; +} + +std::string UserAttribute::getArgumentValueString(uint32_t index) +{ + size_t len = 0; + const char* out = interface()->getArgumentValueString(index, &len); + return std::string(out, len); +} + + +slang::wgsl::TypeReflection* UserAttribute::getArgumentType(uint32_t index) +{ + return (slang::wgsl::TypeReflection*)interface()->getArgumentType(index); +} + + +uint32_t UserAttribute::getArgumentCount() +{ + return interface()->getArgumentCount(); +} + +std::string FunctionReflection::getName() +{ + return interface()->getName(); +} + +uint32_t FunctionReflection::getUserAttributeCount() +{ + return interface()->getUserAttributeCount(); +} + +slang::wgsl::UserAttribute* FunctionReflection::getUserAttributeByIndex(uint32_t index) +{ + return (slang::wgsl::UserAttribute*)interface()->getUserAttributeByIndex(index); +} namespace lsp { @@ -666,8 +845,10 @@ std::optional LanguageServer::completionResolve(lsp::Comple editItem.documentation.kind = coreArgs.documentation.kind; editItem.documentation.value = coreArgs.documentation.value; editItem.data = coreArgs.data; + for (auto character : coreArgs.commitCharacters) editItem.commitCharacters.add(character); + auto coreResult = m_core->completionResolve(coreArgs, editItem); if (coreResult.isNull) return std::nullopt; -- cgit v1.2.3