Skip to content

Fix entry_point() crash on generic compute shaders with integer generic parameters#791

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/fix-generic-compute-shader-issue
Draft

Fix entry_point() crash on generic compute shaders with integer generic parameters#791
Copilot wants to merge 4 commits intomainfrom
copilot/fix-generic-compute-shader-issue

Conversation

Copy link
Contributor

Copilot AI commented Feb 11, 2026

module.entry_point() throws an untranslatable nanobind exception on generic compute shaders with integer generic parameters (e.g., <int N>). The Slang API's getLayout() cannot be called on unspecialized generic entry points—it throws an internal exception that bypasses nanobind's exception translation.

module = device.load_module('shader.slang')
# Crashes: "exception could not be translated!"
entry = module.entry_point("my_compute")  # where my_compute<int N>(...)

Changes

  • SlangEntryPoint::init(): Check getSpecializationParamCount() > 0 before calling getLayout(). For unspecialized generics, use the descriptor name and ShaderStage::none as temporaries—both are resolved correctly when specialize() is later called.
  • SlangModule::entry_points(): Replace getLayout()->getEntryPointByIndex(0)->getName() with getFunctionReflection()->getName(). The latter is available directly on IEntryPoint and works for generic entry points without requiring layout computation.
  • Tests: Add integer-generic entry point shader and two tests covering entry_point() and entry_points with <int N> generics.
Original prompt

This section details on the original issue you should resolve

<issue_title>module.entry_point() raises on generic compute shader with generic parameters</issue_title>
<issue_description>Invoking module.entry_point() on a generic compute shader that takes one or more generic parameters raises a nanobind exception.

Interestingly, accessing module.entry_points prior to calling entry_point() works around the issue, even though doing so raises itself.

Repro shader and script:

// Generic entry point with generic struct parameter

struct MyData<int N>
{
    float value;
}

[shader("compute")]
[numthreads(8, 1, 1)]
void my_compute<int N>(
    uint3 tid: SV_DispatchThreadID,
    RWStructuredBuffer<MyData<N>> output
)
{
    MyData<N> data;
    data.value = float(tid.x);
    output[tid.x] = data;
}
import slangpy as spy
from pathlib import Path

device = spy.Device(
    compiler_options={
        "include_paths": [spy.SHADER_PATH, Path(__file__).parent.absolute()]
    }
)

print(f"Using device: {device.info.adapter_name}\n")

# Don't use workaround; expect failure
print("1: Call entry_point() directly")
try:
    module = device.load_module('entrypoint.slang')
    entry = module.entry_point("my_compute")
    print("Result: SUCCESS (issue not reproduced)\n")
except Exception as e:
    print(f"Result: FAILED with {e} (issue reproduced)\n")

# Use workaround; expect success
print("2: Call entry_point() after accessing entry_points")
try:
    module = device.load_module('entrypoint.slang')
    try:
        _ = module.entry_points
    except:
        pass
    entry = module.entry_point("my_compute")
    specialized = entry.specialize([spy.SpecializationArg.from_expr("4")])
    program = device.link_program(modules=[module], entry_points=[specialized])
    kernel = device.create_compute_kernel(program)
    print("Result: SUCCESS (workaround succeeded)\n")
except Exception as e:
    print(f"Result: FAILED - {e}\n")

Current output:

Using device: NVIDIA RTX PRO 6000 Blackwell Workstation Edition

1: Call entry_point() directly
Result: FAILED with nanobind::detail::nb_func_error_except(): exception could not be translated! (issue reproduced)

2: Call entry_point() after accessing entry_points
Result: SUCCESS (workaround succeeded)
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits February 11, 2026 18:52
…meters

For unspecialized generic entry points (e.g. with integer generic parameters
like `<int N>`), calling getLayout() on the Slang entry point throws an
internal Slang exception that nanobind cannot translate.

Two fixes:
1. In SlangEntryPoint::init(), check getSpecializationParamCount() before
   calling getLayout(). For unspecialized generics, use the descriptor name
   and ShaderStage::none as fallback. The proper name/stage will be set
   when specialize() is called.

2. In SlangModule::entry_points(), use getFunctionReflection()->getName()
   instead of getLayout()->getEntryPointByIndex(0)->getName() to get the
   entry point name, avoiding the getLayout() call entirely.

Co-authored-by: bmillsNV <163073245+bmillsNV@users.noreply.github.com>
…ation to test

Co-authored-by: bmillsNV <163073245+bmillsNV@users.noreply.github.com>
Co-authored-by: bmillsNV <163073245+bmillsNV@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix nanobind exception in module.entry_point() for generic shaders Fix entry_point() crash on generic compute shaders with integer generic parameters Feb 11, 2026
Copilot AI requested a review from bmillsNV February 11, 2026 18:57
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.

module.entry_point() raises on generic compute shader with generic parameters

2 participants

Comments