gfx-rs / gfx

[maintenance mode] A low-overhead Vulkan-like GPU API for Rust.
http://gfx-rs.github.io/
Apache License 2.0
5.35k stars 547 forks source link

[pre-ll] Support HLSL semantic indexes #2748

Open tangmi opened 5 years ago

tangmi commented 5 years ago

Short info header:

I'm wondering how to correctly support HLSL semantics with indexes like these:

struct SPIRV_Cross_Input
{
    float2 in_var_POSITION : TEXCOORD0;
    float2 in_var_UV : TEXCOORD1;
};

// Vertex main
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
    // ..
}

I've made an attempt here: https://github.com/gfx-rs/gfx/pull/2747, but I can tell this solution is pretty sketchy.

My best guess is that Structure<Format>::query needs to take a shade::AttributeVar instead of a &str and the gfx_defines! macros should generate a query implementation that is aware of indexed semantics?

Thanks for your time!

msiglreith commented 5 years ago

I wonder if we could employ reflection capabilties of d3d11 here and pick the semantic index as we already do with the semantic name. Currently not sure if there will be conflicts. See https://github.com/gfx-rs/gfx/blob/pre-ll/src/backend/dx11/src/mirror.rs#L108

tangmi commented 5 years ago

I've found a (hacky) solution that seems to work: https://github.com/gfx-rs/gfx/pull/2747/files. The idea is to try both TEXCOORD and TEXCOORD0 to see if one sticks.

msiglreith commented 5 years ago

Thinking a bit of this, I would see supporting either location indices or strings as two variants for the pipeline vertex macros would be a way to go here. Trying to infer the locations from the order sounds really scary to me. As location is the only information from SPIR-V for the shader interface it's difficult with information we provide on the host side to do the necessary reflection/generating binding information.

A possible variant:

vertex TerrainVertex {
        pos: [f32; 3] = 0,
        normal: [f32; 3] = 1,
        color: [f32; 3] = 2,
}

I don't know how difficult this would be to integrate with the currently pipeline macros as I don't really looked into these.