shader-slang / slang

Making it easier to work with shaders
http://shader-slang.com
MIT License
2.16k stars 186 forks source link

WGSL: Add support for all intrinsics #5053

Closed aleino-nv closed 1 month ago

aleino-nv commented 1 month ago
csyonghe commented 1 month ago

You can search for "metal" in hlsl.meta.slang and core.meta.slang and make sure there is a "wgsl" case.

aleino-nv commented 1 month ago

Thanks Yong, I'll make a list and split it tomorrow. FYI @bmillsNV, this is the task we could put an extra resource on to help hit WGSL milestone 1 on time.

aleino-nv commented 1 month ago

@csyonghe I see about 20k lines that contain "metal" in hlsl.meta.slang. The vast majority apply to 0.5 functions, so let's say 10k lines that need to be visited and considered for wgsl.

I'm not about to paste 10k entries here just so we can have something to point at when splitting this task.

@jkwak-work If you feel like you want to split this one, I guess you can split it into chunks

csyonghe commented 1 month ago

I doubt there are 20k of them. You are probably looking at HLSL.meta.slang.h which is the expanded version of it that contains one line for every combination of different texture type parameterization. Actual changes won't be that many.

csyonghe commented 1 month ago

We added all metal intrinsics over the course of 2 weeks.

jkwak-work commented 1 month ago

The spec document lists all built-in functions for WGSL. We should apply them in hlsl.meta.slang from this list.

  1. easy ones numeric (63 functions) data packing (9 functions), unpacking (7 functions)

  2. little tricky ones constructor (19 functions) texture (15 functions) derivative (9 functions), bitcast, all, any, select, arrayLength

  3. potentially tricky ones atomic (3 functions) synchronization (4 functions)

aleino-nv commented 1 month ago

@jkwak-work Shouldn't we mainly be looking at the list of intrinsics that Slang needs to support? I think we just need to visit all of the places in hlsl.meta.slang and plug in the corresponding WGSL intrinsics (if any) where we can. In places we can't I suppose it gets a little trickier.

jkwak-work commented 1 month ago

I assume that there will be many functions that WGSL don't have. For those functions, we will need to rely on the generic version of the implementation.

As an example, hlsl has a function called "sincos" and WGSL don't have anything directly same one. We will need to use the "default" implementation as you can see below.

void sincos(matrix<T,N,M> x, out matrix<T,N,M,L1> s, out matrix<T,N,M,L2> c)
{
    __target_switch
    {
    case hlsl: __intrinsic_asm "sincos";
    default:
        s = sin(x);
        c = cos(x);
    }
}

I think it will be easier if we go down a list by what WGSL has rather than what Slang needs. Once that step is done, we can run down all Slang functions and make sure that the default version works for WGSL.

jkwak-work commented 1 month ago

I have a PR that covers "numeric" part of WGSL functions. https://github.com/shader-slang/slang/pull/5078

aleino-nv commented 1 month ago

The spec document lists all built-in functions for WGSL. We should apply them in hlsl.meta.slang from this list.

  1. easy ones numeric (63 functions) data packing (9 functions), unpacking (7 functions)
  2. little tricky ones constructor (19 functions) texture (15 functions) derivative (9 functions), bitcast, all, any, select, arrayLength
  3. potentially tricky ones atomic (3 functions) synchronization (4 functions)

Splitting into subtasks based on this list:

5079, #5080, #5081, #5082, #5083, #5084, #5085