hajimehoshi / ebiten

Ebitengine - A dead simple 2D game engine for Go
https://ebitengine.org
Apache License 2.0
10.74k stars 649 forks source link

internal/graphicsdriver/directx: crash when compiling a regular shader #2694

Open hajimehoshi opened 1 year ago

hajimehoshi commented 1 year ago

Ebitengine Version

v2.6.0-alpha.3

Operating System

Go Version (go version)

1.20.4

What steps will reproduce the problem?

Just launch a game on Windows?

What is the expected result?

No crash when compiling a shader

What happens instead?

directx: D3DCompile for PSMain failed, original source: struct Varyings {
    float4 Position : SV_POSITION;
    float2 M0 : TEXCOORD0;
    float4 M1 : COLOR;
};

float mod(float x, float y) {
    return x - y * floor(x/y);
}

float2 mod(float2 x, float2 y) {
    return x - y * floor(x/y);
}

float3 mod(float3 x, float3 y) {
    return x - y * floor(x/y);
}

float4 mod(float4 x, float4 y) {
    return x - y * floor(x/y);
}

float2x2 float2x2FromScalar(float x) {
    return float2x2(x, 0, 0, x);
}

float3x3 float3x3FromScalar(float x) {
    return float3x3(x, 0, 0, 0, x, 0, 0, 0, x);
}

float4x4 float4x4FromScalar(float x) {
    return float4x4(x, 0, 0, 0, 0, x, 0, 0, 0, 0, x, 0, 0, 0, 0, x);
}

cbuffer Uniforms : register(b0) {
    float2 U0 : packoffset(c0);
    float2 U1[4] : packoffset(c1);
    float2 U2 : packoffset(c4.z);
    float2 U3 : packoffset(c5);
    float2 U4[3] : packoffset(c6);
    float2 U5 : packoffset(c8.z);
    float2 U6 : packoffset(c9);
    float4x4 U7 : packoffset(c10);
}

Texture2D T0 : register(t0);
Texture2D T1 : register(t1);
Texture2D T2 : register(t2);
Texture2D T3 : register(t3);

float4 F4(in float2 l0);

float4 F4(in float2 l0) {
    return T0.Load(int3(l0, 0));
}

float4 PSMain(Varyings varyings) : SV_TARGET {
    float4 l0 = 0.0;
    l0 = F4(varyings.M0);
    l0 = (l0) * (varyings.M1);
    return l0;
}
, directx: D3DCompile failed: shader:36:24: E5000: syntax error, unexpected '(', expecting ';' or ','
: HANDLE(2147500037)

Anything else you feel useful to add?

This was reported from a game with Ebitengine.

/CC @wasedaigo

hajimehoshi commented 1 year ago

DirectX 11: 78d76945adb0e463e1fec9a75c4a11525606e8ac v2.6.0-alpha.3: e3ab7b979f50cf640cf168801752f4e028e89cc5

hajimehoshi commented 1 year ago

packoffset should be available in the shader model v4 https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-constants so this is pretty odd.