Open csyonghe opened 2 weeks ago
We should be able to reuse the EntryPointVaryingParamLegalizeContext
pass to first hoist, flatten and SOA-ize all the nested attributes and fragment stage_in inputs into individual top level parameters, and then pack these parameters into a struct decorated with `[[stage_in``.
We can first translate vertexMain
into something like
[attribute(0)] in float3 position;
[attribute(1)] in float3 color;
[attribute(2)] in float2 uv;
float4 vertexMain() : SV_Position
{
}
The EntryPointVaryingParamLegalizeContext
should have everything we need to do this transform.
Then we pack them all into a struct, and pass that struct as [stage_in]
parameter:
struct StageIn_vertexMain
{
[attribute(0)] float3 position;
[attribute(1)] float3 color;
[attribute(2)] float2 uv;
};
float4 vertexMain(StageIn_vertexMain stageIn [[stage_in]]) : SV_Position
{
...
}
I see. That make sense.
Note for implementing:
from legalizeEntryPointForMetal
:
hoistEntryPointParameterFromStruct(entryPoint);
packStageInParameters(entryPoint);
legalizeSystemValueParameters(entryPoint, sink);
wrapReturnValueInStruct(sink, entryPoint);
require to be integrated (and reimplemented in some cases) into EntryPointVaryingParamLegalizeContext
of slang-ir-legalize-varying-params.cpp
Update:
Reuse of EntryPointVaryingParamLegalizeContext
likely needs to be a separate "clean up" PR since the current state of EntryPointVaryingParamLegalizeContext
is quite underdeveloped and will require reworks to work with the Metal backend.
Limitations of EntryPointVaryingParamLegalizeContext
:
Fixing the Metal code-gen issues first and then cleanup is likely the easiest course of action.
We should be able to reuse the
EntryPointVaryingParamLegalizeContext
pass to first hoist, flatten and SOA-ize all the nested attributes and fragment stage_in inputs into individual top level parameters, and then pack these parameters into a struct decorated with `[[stage_in``.We can first translate
vertexMain
into something like[attribute(0)] in float3 position; [attribute(1)] in float3 color; [attribute(2)] in float2 uv; float4 vertexMain() : SV_Position { }
The
EntryPointVaryingParamLegalizeContext
should have everything we need to do this transform.Then we pack them all into a struct, and pass that struct as
[stage_in]
parameter:struct StageIn_vertexMain { [attribute(0)] float3 position; [attribute(1)] float3 color; [attribute(2)] float2 uv; }; float4 vertexMain(StageIn_vertexMain stageIn [[stage_in]]) : SV_Position { ... }
There are 3 suggested steps:
Since legalization of varying outputs currently requires flattening a struct (without hoisting logic), step 1 can be skipped for now (start at step 2) by reusing the struct-flattening and legalization logic varying outputs need.
Given
We generate this:
Metal does not allow defining
[[attribute]]
on composite types. We need to hoist all vertex attributes out to the top level of the vertex input struct.