From f66b046e2767cd7a38acec8c0f988e5937f062e7 Mon Sep 17 00:00:00 2001 From: Sai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com> Date: Fri, 8 Nov 2024 13:03:42 -0500 Subject: [WGSL] [WASM] Add reflection endpoints + Fix bit manipulation operations (#5499) * Add key reflection endpoints for WASM * Fix WGSL output around bit-manipulation operators * format code * Fix pointer ownership * fix formatting --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> Co-authored-by: Yong He --- source/slang-wasm/slang-wasm-bindings.cpp | 33 ++++++++++++++++++++++++ source/slang-wasm/slang-wasm.cpp | 43 +++++++++++++++++++++++++++++++ source/slang-wasm/slang-wasm.h | 36 ++++++++++++++++++++++++++ 3 files changed, 112 insertions(+) (limited to 'source/slang-wasm') diff --git a/source/slang-wasm/slang-wasm-bindings.cpp b/source/slang-wasm/slang-wasm-bindings.cpp index 326ef9ff2..e980cd608 100644 --- a/source/slang-wasm/slang-wasm-bindings.cpp +++ b/source/slang-wasm/slang-wasm-bindings.cpp @@ -43,11 +43,44 @@ EMSCRIPTEN_BINDINGS(slang) .function("getEntryPointCodeBlob", &slang::wgsl::ComponentType::getEntryPointCodeBlob) .function("getTargetCodeBlob", &slang::wgsl::ComponentType::getTargetCodeBlob) .function("getTargetCode", &slang::wgsl::ComponentType::getTargetCode) + .function("getLayout", &slang::wgsl::ComponentType::getLayout, allow_raw_pointers()) .function( "loadStrings", &slang::wgsl::ComponentType::loadStrings, return_value_policy::take_ownership()); + class_("TypeLayoutReflection") + .function( + "getDescriptorSetDescriptorRangeType", + &slang::wgsl::TypeLayoutReflection::getDescriptorSetDescriptorRangeType); + + class_("VariableLayoutReflection") + .function("getName", &slang::wgsl::VariableLayoutReflection::getName) + .function( + "getTypeLayout", + &slang::wgsl::VariableLayoutReflection::getTypeLayout, + allow_raw_pointers()) + .function("getBindingIndex", &slang::wgsl::VariableLayoutReflection::getBindingIndex); + + class_("ProgramLayout") + .function("getParameterCount", &slang::wgsl::ProgramLayout::getParameterCount) + .function( + "getParameterByIndex", + &slang::wgsl::ProgramLayout::getParameterByIndex, + allow_raw_pointers()) + .function( + "getGlobalParamsTypeLayout", + &slang::wgsl::ProgramLayout::getGlobalParamsTypeLayout, + allow_raw_pointers()); + + enum_("BindingType") + .value("Unknown", slang::BindingType::Unknown) + .value("Texture", slang::BindingType::Texture) + .value("ConstantBuffer", slang::BindingType::ConstantBuffer) + .value("MutableRawBuffer", slang::BindingType::MutableRawBuffer) + .value("MutableTypedBuffer", slang::BindingType::MutableTypedBuffer) + .value("MutableTexture", slang::BindingType::MutableTexture); + class_>("Module") .function( "findEntryPointByName", diff --git a/source/slang-wasm/slang-wasm.cpp b/source/slang-wasm/slang-wasm.cpp index be30f8394..f73e70ba0 100644 --- a/source/slang-wasm/slang-wasm.cpp +++ b/source/slang-wasm/slang-wasm.cpp @@ -386,6 +386,49 @@ HashedString* ComponentType::loadStrings() return hashedStrings; } +ProgramLayout* ComponentType::getLayout(unsigned int targetIndex) +{ + return (slang::wgsl::ProgramLayout*)interface()->getLayout(targetIndex); +} + +unsigned int ProgramLayout::getParameterCount() +{ + return interface()->getParameterCount(); +} + +VariableLayoutReflection* ProgramLayout::getParameterByIndex(unsigned int index) +{ + return (slang::wgsl::VariableLayoutReflection*)(interface()->getParameterByIndex(index)); +} + +TypeLayoutReflection* ProgramLayout::getGlobalParamsTypeLayout() +{ + return (slang::wgsl::TypeLayoutReflection*)(interface()->getGlobalParamsTypeLayout()); +} + +BindingType TypeLayoutReflection::getDescriptorSetDescriptorRangeType( + unsigned int setIndex, + unsigned int rangeIndex) +{ + return interface()->getDescriptorSetDescriptorRangeType(setIndex, rangeIndex); +} + +std::string VariableLayoutReflection::getName() +{ + return interface()->getName(); +} + +TypeLayoutReflection* VariableLayoutReflection::getTypeLayout() +{ + return (slang::wgsl::TypeLayoutReflection*)(interface()->getTypeLayout()); +} + +unsigned int VariableLayoutReflection::getBindingIndex() +{ + return interface()->getBindingIndex(); +} + + namespace lsp { Position translate(Slang::LanguageServerProtocol::Position p) diff --git a/source/slang-wasm/slang-wasm.h b/source/slang-wasm/slang-wasm.h index c82976659..9e1e023a9 100644 --- a/source/slang-wasm/slang-wasm.h +++ b/source/slang-wasm/slang-wasm.h @@ -50,6 +50,40 @@ private: CompileTargets* getCompileTargets(); + +class TypeLayoutReflection +{ +public: + BindingType getDescriptorSetDescriptorRangeType(unsigned int setIndex, unsigned int rangeIndex); + + slang::TypeLayoutReflection* interface() const { return (slang::TypeLayoutReflection*)this; } +}; + +class VariableLayoutReflection +{ +public: + std::string getName(); + slang::wgsl::TypeLayoutReflection* getTypeLayout(); + unsigned int getBindingIndex(); + + slang::VariableLayoutReflection* interface() const + { + return (slang::VariableLayoutReflection*)this; + } +}; + + +class ProgramLayout +{ +public: + unsigned int getParameterCount(); + slang::wgsl::VariableLayoutReflection* getParameterByIndex(unsigned int index); + + slang::wgsl::TypeLayoutReflection* getGlobalParamsTypeLayout(); + + slang::ProgramLayout* interface() const { return (slang::ProgramLayout*)this; } +}; + class ComponentType { public: @@ -65,6 +99,8 @@ public: std::string getTargetCode(int targetIndex); emscripten::val getTargetCodeBlob(int targetIndex); + slang::wgsl::ProgramLayout* getLayout(unsigned int targetIndex); + slang::IComponentType* interface() const { return m_interface; } HashedString* loadStrings(); -- cgit v1.2.3