Skip to main content

FULLSCREEN

Constant FULLSCREEN 

Source
pub const FULLSCREEN: &str = "// Fullscreen-triangle vertex stage, shared by every screen-space post pass.\n//\n// Three SV_VertexID-generated vertices cover the framebuffer, so these passes\n// need no vertex buffer and no vertex descriptor. Pairing is by semantic:\n// a post fragment declares `[[vk::location(0)]] float2 uv : TEXCOORD0` and\n// slangc emits the matching `[[user(TEXCOORD)]]` varying on both sides, so the\n// vertex compiles once and every fragment links against it.\n//\n// The Y flip is the one genuinely target-specific line, and Vulkan is the\n// exception rather than the rule: it rasterises its HDR targets through a\n// negative-height viewport, so the sampled image is already upright there and a\n// plain [0,1] map is correct. Metal and DirectX both have a top-left texture\n// origin and no such flip, so they map it here.\n\n// `uv` leads deliberately. D3D packs a stage signature in declaration order and\n// links the two stages by matching semantic *and* register, so with SV_Position\n// first the vertex would hand TEXCOORD0 out on register 1 while a fragment that\n// declares only `uv` reads it from register 0, and every PSO fails to create.\n// Metal and Vulkan are order-blind here (both varyings carry an attribute or an\n// explicit location), so the order costs them nothing.\nstruct FullscreenVertex\n{\n    [[vk::location(0)]] float2 uv : TEXCOORD0;\n    float4 position : SV_Position;\n};\n\nfloat2 fullscreen_uv(float2 pos)\n{\n    __target_switch\n    {\n    case spirv:\n        return (pos + 1.0) * 0.5;\n    default:\n        return float2((pos.x + 1.0) * 0.5, 1.0 - (pos.y + 1.0) * 0.5);\n    }\n}\n\n[shader(\"vertex\")]\nFullscreenVertex fullscreen_vertex(uint vid : SV_VertexID)\n{\n    float2 pos = float2((vid == 2) ? 3.0 : -1.0, (vid == 1) ? 3.0 : -1.0);\n    FullscreenVertex o;\n    o.position = float4(pos, 0.0, 1.0);\n    o.uv = fullscreen_uv(pos);\n    return o;\n}\n";
Expand description

fullscreen.slang.