Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid HLSL generated when function is marked [Differentiable] #5218

Open
tunabrain opened this issue Oct 2, 2024 · 1 comment
Open

Invalid HLSL generated when function is marked [Differentiable] #5218

tunabrain opened this issue Oct 2, 2024 · 1 comment
Assignees
Labels
goal:client support Feature or fix needed for a current slang user. Needs reporter feedback Bugs awaiting more information from the reporter

Comments

@tunabrain
Copy link

The following code:

struct ContainsBuffer
{
    StructuredBuffer<float> buffer;
    int dummy;
}
ParameterBlock<ContainsBuffer> call_data;
[Differentiable]
void takesBuffer(ContainsBuffer x)
{
}
[shader("compute")]
void main()
{
    ContainsBuffer cloned = { call_data.buffer, call_data.dummy };
    takesBuffer(cloned);
}

generates invalid HLSL (no known conversion from 'ContainsBuffer_0' to 'ContainsBuffer_1'). It looks like slang generates two different implementations of ContainsBuffer.

This seems to be connected with auto-diff: The bug goes away when removing [Differentiable] from takesBuffer, or changing the first line to struct ContainsBuffer : IDifferential.

@saipraveenb25
Copy link
Collaborator

@tunabrain: I'm not able to reproduce this issue with top-of-tree Slang. Can you check if the issue persists in the latest build here from 3 days ago? https://github.com/shader-slang/slang/releases/tag/v2024.13

We fixed a related issue in that build.

This is the output I'm seeing with v2024.13

#pragma pack_matrix(column_major)
#ifdef SLANG_HLSL_ENABLE_NVAPI
#include "nvHLSLExtns.h"
#endif

#ifndef __DXC_VERSION_MAJOR
    // warning X3557: loop doesn't seem to do anything, forcing loop to unroll
    #pragma warning(disable: 3557)
#endif

struct ContainsBuffer_0
{
    int dummy_0;
};

cbuffer call_data_0 : register(b0)
{
    ContainsBuffer_0 call_data_0;
}
RWStructuredBuffer<float > call_data_buffer_0 : register(u1);

void takesBuffer_0(ContainsBuffer_0 x_0, RWStructuredBuffer<float > x_buffer_0)
{
    x_buffer_0[int(0)] = 1.0;
    return;
}

[numthreads(1, 1, 1)]
void computeMain(uint3 dispatchThreadID_0 : SV_DispatchThreadID)
{
    ContainsBuffer_0 _S1 = { call_data_0.dummy_0 };
    takesBuffer_0(_S1, call_data_buffer_0);
    return;
}

@bmillsNV bmillsNV added goal:client support Feature or fix needed for a current slang user. Needs reporter feedback Bugs awaiting more information from the reporter labels Oct 3, 2024
@bmillsNV bmillsNV added this to the Q4 2024 (Fall) milestone Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
goal:client support Feature or fix needed for a current slang user. Needs reporter feedback Bugs awaiting more information from the reporter
Projects
None yet
Development

No branches or pull requests

3 participants