Skip to content

Commit

Permalink
Fix WGSL emit for '&' and add bindings for thread group size (#5557)
Browse files Browse the repository at this point in the history
Co-authored-by: Yong He <[email protected]>
  • Loading branch information
saipraveenb25 and csyonghe authored Nov 14, 2024
1 parent f7149b9 commit 5cb960a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
14 changes: 14 additions & 0 deletions source/slang-wasm/slang-wasm-bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ EMSCRIPTEN_BINDINGS(slang)
allow_raw_pointers())
.function("getBindingIndex", &slang::wgsl::VariableLayoutReflection::getBindingIndex);

class_<slang::wgsl::EntryPointReflection>("EntryPointReflection")
.function(
"getComputeThreadGroupSize",
&slang::wgsl::EntryPointReflection::getComputeThreadGroupSize);

class_<slang::wgsl::EntryPointReflection::ThreadGroupSize>("ThreadGroupSize")
.property("x", &slang::wgsl::EntryPointReflection::ThreadGroupSize::x)
.property("y", &slang::wgsl::EntryPointReflection::ThreadGroupSize::y)
.property("z", &slang::wgsl::EntryPointReflection::ThreadGroupSize::z);

class_<slang::wgsl::ProgramLayout>("ProgramLayout")
.function("toJsonObject", &slang::wgsl::ProgramLayout::toJsonObject)
.function("getParameterCount", &slang::wgsl::ProgramLayout::getParameterCount)
Expand All @@ -63,6 +73,10 @@ EMSCRIPTEN_BINDINGS(slang)
.function(
"getGlobalParamsTypeLayout",
&slang::wgsl::ProgramLayout::getGlobalParamsTypeLayout,
allow_raw_pointers())
.function(
"findEntryPointByName",
&slang::wgsl::ProgramLayout::findEntryPointByName,
allow_raw_pointers());

enum_<slang::BindingType>("BindingType")
Expand Down
12 changes: 12 additions & 0 deletions source/slang-wasm/slang-wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,18 @@ TypeLayoutReflection* ProgramLayout::getGlobalParamsTypeLayout()
return (slang::wgsl::TypeLayoutReflection*)(interface()->getGlobalParamsTypeLayout());
}

EntryPointReflection* ProgramLayout::findEntryPointByName(std::string name)
{
return (slang::wgsl::EntryPointReflection*)(interface()->findEntryPointByName(name.c_str()));
}

EntryPointReflection::ThreadGroupSize EntryPointReflection::getComputeThreadGroupSize()
{
SlangUInt size[3];
interface()->getComputeThreadGroupSize(3, size);
return {size[0], size[1], size[2]};
}

BindingType TypeLayoutReflection::getDescriptorSetDescriptorRangeType(
unsigned int setIndex,
unsigned int rangeIndex)
Expand Down
16 changes: 16 additions & 0 deletions source/slang-wasm/slang-wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ class VariableLayoutReflection
}
};

class EntryPointReflection
{

public:
struct ThreadGroupSize
{
unsigned int x;
unsigned int y;
unsigned int z;
};

ThreadGroupSize getComputeThreadGroupSize();
slang::EntryPointReflection* interface() const { return (slang::EntryPointReflection*)this; }
};

class ProgramLayout
{
Expand All @@ -81,6 +95,8 @@ class ProgramLayout

slang::wgsl::TypeLayoutReflection* getGlobalParamsTypeLayout();

slang::wgsl::EntryPointReflection* findEntryPointByName(std::string name);

slang::ProgramLayout* interface() const { return (slang::ProgramLayout*)this; }

emscripten::val toJsonObject();
Expand Down
1 change: 1 addition & 0 deletions source/slang/slang-emit-wgsl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,7 @@ bool WGSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu
}
case kIROp_BitXor:
case kIROp_BitOr:
case kIROp_BitAnd:
{
// Emit bitwise operators with paranthesis to avoid precedence issues
const auto emitOp = getEmitOpForOp(inst->getOp());
Expand Down

0 comments on commit 5cb960a

Please sign in to comment.