Skip to content

Handle the rest of ScalarType for wgpu as Undefined#698

Merged
jkwak-work merged 1 commit into
shader-slang:mainfrom
jkwak-work:fix/build-warning-wgpu-ScalarType
Mar 30, 2026
Merged

Handle the rest of ScalarType for wgpu as Undefined#698
jkwak-work merged 1 commit into
shader-slang:mainfrom
jkwak-work:fix/build-warning-wgpu-ScalarType

Conversation

@jkwak-work
Copy link
Copy Markdown
Contributor

@jkwak-work jkwak-work commented Mar 30, 2026

We are trying to add more types to ScalarType: IntPtr, UIntPtr and
BFloat16; in shader-slang/slang#10643
And slang-rhi build prints a warning that the new types are not handled
in a switch-statement for WGPU.

Because WGPU cannot represent those types, this PR converts the new
types as Undefined and avoid the compilation warnings, which is treated
an errors on CI machines.

We are trying to add more types to ScalarType: IntPtr, UIntPtr and
BFloat16; in shader-slang/slang#10643
And slang-rhi build prints a warning that the new types are not handled
in a switch-statement for WGPU.

Because WGPU cannot represent those types, this PR converts the new
types as Undefined and avoid the compilation warnings, which is treated
an errors on CI machines.
@jkwak-work jkwak-work requested a review from skallweitNV March 30, 2026 17:01
@jkwak-work jkwak-work self-assigned this Mar 30, 2026
@jkwak-work jkwak-work requested a review from a team as a code owner March 30, 2026 17:01
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 30, 2026

📝 Walkthrough

Walkthrough

Internal helper functions in the WGPU shader object layout were refactored to consolidate their return statements. The getViewDimension and getSampleType functions now use a single trailing return for their default cases instead of immediate returns, eliminating code duplication.

Changes

Cohort / File(s) Summary
Helper Function Refactoring
src/wgpu/wgpu-shader-object-layout.cpp
Consolidated return statements in getViewDimension and getSampleType functions to use a single trailing return for unrecognized cases, removing duplicate return logic.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 The code hops cleaner, paths align,
One return to end the line,
No duplication left behind,
Just trailing returns refined!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: handling previously unhandled ScalarType variants in wgpu by mapping them to Undefined.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/wgpu/wgpu-shader-object-layout.cpp (1)

35-37: ⚠️ Potential issue | 🟠 Major

Switch discriminator is wrong; normalized scalar type is ignored.

Line 35 should switch on scalarType, not type->getScalarType(). Right now the fallback normalization on Lines 31-34 is bypassed, so None-typed results are misclassified (e.g., forced to Float at Line 37).

Suggested fix
-    switch (type->getScalarType())
+    switch (scalarType)
     {
     case slang::TypeReflection::ScalarType::None:
         return WGPUTextureSampleType_Float;
     case slang::TypeReflection::ScalarType::Void:
     case slang::TypeReflection::ScalarType::Bool:
         return WGPUTextureSampleType_Undefined;
@@
+    case slang::TypeReflection::ScalarType::IntPtr:
+    case slang::TypeReflection::ScalarType::UIntPtr:
+    case slang::TypeReflection::ScalarType::BFloat16:
+        return WGPUTextureSampleType_Undefined;
     default:
         break;
     }

Also applies to: 56-57

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/wgpu/wgpu-shader-object-layout.cpp` around lines 35 - 37, The switch is
using type->getScalarType() directly and thus ignores the normalized variable
scalarType; change the switch to use the normalized scalarType (the local
scalarType variable computed just above) so the fallback normalization is
respected in cases like None; update both switch sites (the one handling the
first scalar mapping and the second occurrence around the later mapping) to
switch on scalarType instead of calling type->getScalarType() so values like
None are classified correctly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/wgpu/wgpu-shader-object-layout.cpp`:
- Around line 35-37: The switch is using type->getScalarType() directly and thus
ignores the normalized variable scalarType; change the switch to use the
normalized scalarType (the local scalarType variable computed just above) so the
fallback normalization is respected in cases like None; update both switch sites
(the one handling the first scalar mapping and the second occurrence around the
later mapping) to switch on scalarType instead of calling type->getScalarType()
so values like None are classified correctly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 271c5363-d6c0-4b2a-bbe2-52c3dde7d842

📥 Commits

Reviewing files that changed from the base of the PR and between 99f1818 and dba7061.

📒 Files selected for processing (1)
  • src/wgpu/wgpu-shader-object-layout.cpp

@jkwak-work jkwak-work merged commit 9eb7734 into shader-slang:main Mar 30, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants