mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-02-20 02:42:43 +00:00
[spv-out] add a flag to adjust the coordinate space
This commit is contained in:
parent
ead052b773
commit
410c242daf
@ -13,7 +13,10 @@ use spirv::Word;
|
||||
|
||||
bitflags::bitflags! {
|
||||
pub struct WriterFlags: u32 {
|
||||
/// Include debug labels for everything.
|
||||
const DEBUG = 0x1;
|
||||
/// Flip Y coordinate of `BuiltIn::Position` output.
|
||||
const ADJUST_COORDINATE_SPACE = 0x2;
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,7 +63,7 @@ pub struct Options {
|
||||
|
||||
impl Default for Options {
|
||||
fn default() -> Self {
|
||||
let mut flags = WriterFlags::empty();
|
||||
let mut flags = WriterFlags::ADJUST_COORDINATE_SPACE;
|
||||
if cfg!(debug_assertions) {
|
||||
flags |= WriterFlags::DEBUG;
|
||||
}
|
||||
|
@ -2041,7 +2041,9 @@ impl Writer {
|
||||
|
||||
// Flip Y coordinate to adjust for coordinate space difference
|
||||
// between SPIR-V and our IR.
|
||||
if res_member.built_in == Some(crate::BuiltIn::Position) {
|
||||
if self.flags.contains(WriterFlags::ADJUST_COORDINATE_SPACE)
|
||||
&& res_member.built_in == Some(crate::BuiltIn::Position)
|
||||
{
|
||||
let access_id = self.id_gen.next();
|
||||
let float_ptr_type_id = self.get_type_id(
|
||||
type_arena,
|
||||
|
@ -2,6 +2,8 @@
|
||||
spv_flow_dump_prefix: "",
|
||||
spv_version: (1, 0),
|
||||
spv_capabilities: [ Shader ],
|
||||
spv_debug: true,
|
||||
spv_adjust_coordinate_space: false,
|
||||
mtl_bindings: {
|
||||
(stage: Compute, group: 0, binding: 0): (buffer: Some(0), mutable: false),
|
||||
(stage: Compute, group: 0, binding: 1): (buffer: Some(1), mutable: true),
|
||||
|
@ -2,6 +2,8 @@
|
||||
spv_flow_dump_prefix: "",
|
||||
spv_version: (1, 0),
|
||||
spv_capabilities: [ Shader ],
|
||||
spv_debug: true,
|
||||
spv_adjust_coordinate_space: false,
|
||||
mtl_bindings: {
|
||||
(stage: Compute, group: 0, binding: 0): (buffer: Some(0), mutable: true),
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
(
|
||||
spv_version: (1, 1),
|
||||
spv_capabilities: [ Shader ],
|
||||
spv_debug: false,
|
||||
spv_adjust_coordinate_space: false,
|
||||
mtl_bindings: {
|
||||
}
|
||||
)
|
||||
|
@ -1,6 +1,8 @@
|
||||
(
|
||||
spv_version: (1, 1),
|
||||
spv_capabilities: [ Shader, Image1D, Sampled1D ],
|
||||
spv_debug: true,
|
||||
spv_adjust_coordinate_space: false,
|
||||
mtl_bindings: {
|
||||
(stage: Compute, group: 0, binding: 1): (texture: Some(0), mutable: false),
|
||||
(stage: Compute, group: 0, binding: 2): (texture: Some(1), mutable: true),
|
||||
|
@ -1,5 +1,7 @@
|
||||
(
|
||||
spv_version: (1, 0),
|
||||
spv_capabilities: [ Shader ],
|
||||
spv_debug: true,
|
||||
spv_adjust_coordinate_space: true,
|
||||
mtl_bindings: {}
|
||||
)
|
||||
|
@ -1,6 +1,8 @@
|
||||
(
|
||||
spv_version: (1, 0),
|
||||
spv_capabilities: [ Shader ],
|
||||
spv_debug: true,
|
||||
spv_adjust_coordinate_space: true,
|
||||
mtl_bindings: {
|
||||
(stage: Fragment, group: 0, binding: 0): (texture: Some(0)),
|
||||
(stage: Fragment, group: 0, binding: 1): (sampler: Some(0)),
|
||||
|
@ -2,6 +2,8 @@
|
||||
spv_flow_dump_prefix: "",
|
||||
spv_version: (1, 2),
|
||||
spv_capabilities: [ Shader ],
|
||||
spv_debug: true,
|
||||
spv_adjust_coordinate_space: true,
|
||||
mtl_bindings: {
|
||||
(stage: Fragment, group: 0, binding: 0): (buffer: Some(0), mutable: false),
|
||||
(stage: Fragment, group: 0, binding: 1): (buffer: Some(1), mutable: false),
|
||||
|
@ -2,6 +2,8 @@
|
||||
spv_flow_dump_prefix: "",
|
||||
spv_version: (1, 0),
|
||||
spv_capabilities: [ Shader ],
|
||||
spv_debug: false,
|
||||
spv_adjust_coordinate_space: false,
|
||||
mtl_bindings: {
|
||||
(stage: Vertex, group: 0, binding: 0): (buffer: Some(0)),
|
||||
(stage: Fragment, group: 0, binding: 1): (texture: Some(0)),
|
||||
|
@ -2,6 +2,8 @@
|
||||
spv_flow_dump_prefix: "",
|
||||
spv_version: (1, 5),
|
||||
spv_capabilities: [ Shader ],
|
||||
spv_debug: true,
|
||||
spv_adjust_coordinate_space: false,
|
||||
mtl_bindings: {
|
||||
(stage: Fragment, group: 0, binding: 0): (texture: Some(0)),
|
||||
(stage: Fragment, group: 0, binding: 1): (texture: Some(1)),
|
||||
|
@ -11,9 +11,6 @@ OpCapability Shader
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint GLCompute %4 "main"
|
||||
OpExecutionMode %4 LocalSize 1 1 1
|
||||
OpSource GLSL 450
|
||||
OpName %4 "main"
|
||||
OpName %4 "main"
|
||||
%2 = OpTypeVoid
|
||||
%5 = OpTypeFunction %2
|
||||
%4 = OpFunction %2 None %5
|
||||
|
@ -5,35 +5,13 @@ expression: dis
|
||||
; SPIR-V
|
||||
; Version: 1.0
|
||||
; Generator: rspirv
|
||||
; Bound: 115
|
||||
; Bound: 111
|
||||
OpCapability Shader
|
||||
%1 = OpExtInstImport "GLSL.std.450"
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint Vertex %38 "vs_main" %31 %34 %36
|
||||
OpEntryPoint Fragment %107 "fs_main" %100 %103 %106
|
||||
OpExecutionMode %107 OriginUpperLeft
|
||||
OpSource GLSL 450
|
||||
OpName %12 "VertexOutput"
|
||||
OpMemberName %12 0 "position"
|
||||
OpMemberName %12 1 "uv"
|
||||
OpName %14 "Data"
|
||||
OpMemberName %14 0 "proj_inv"
|
||||
OpMemberName %14 1 "view"
|
||||
OpName %19 "r_data"
|
||||
OpName %21 "r_texture"
|
||||
OpName %23 "r_sampler"
|
||||
OpName %25 "tmp1"
|
||||
OpName %27 "tmp2"
|
||||
OpName %28 "out"
|
||||
OpName %31 "vertex_index"
|
||||
OpName %34 "position"
|
||||
OpName %36 "uv"
|
||||
OpName %38 "vs_main"
|
||||
OpName %38 "vs_main"
|
||||
OpName %100 "position"
|
||||
OpName %103 "uv"
|
||||
OpName %107 "fs_main"
|
||||
OpName %107 "fs_main"
|
||||
OpEntryPoint Fragment %103 "fs_main" %96 %99 %102
|
||||
OpExecutionMode %103 OriginUpperLeft
|
||||
OpMemberDecorate %12 0 Offset 0
|
||||
OpMemberDecorate %12 1 Offset 16
|
||||
OpDecorate %14 Block
|
||||
@ -52,9 +30,9 @@ OpDecorate %23 Binding 2
|
||||
OpDecorate %31 BuiltIn VertexIndex
|
||||
OpDecorate %34 BuiltIn Position
|
||||
OpDecorate %36 Location 0
|
||||
OpDecorate %100 BuiltIn FragCoord
|
||||
OpDecorate %103 Location 0
|
||||
OpDecorate %106 Location 0
|
||||
OpDecorate %96 BuiltIn FragCoord
|
||||
OpDecorate %99 Location 0
|
||||
OpDecorate %102 Location 0
|
||||
%2 = OpTypeVoid
|
||||
%4 = OpTypeInt 32 1
|
||||
%3 = OpConstant %4 2
|
||||
@ -91,13 +69,12 @@ OpDecorate %106 Location 0
|
||||
%78 = OpConstant %4 0
|
||||
%82 = OpTypePointer Function %11
|
||||
%89 = OpTypePointer Function %10
|
||||
%94 = OpTypePointer Output %7
|
||||
%101 = OpTypePointer Input %10
|
||||
%100 = OpVariable %101 Input
|
||||
%104 = OpTypePointer Input %11
|
||||
%103 = OpVariable %104 Input
|
||||
%106 = OpVariable %35 Output
|
||||
%112 = OpTypeSampledImage %17
|
||||
%97 = OpTypePointer Input %10
|
||||
%96 = OpVariable %97 Input
|
||||
%100 = OpTypePointer Input %11
|
||||
%99 = OpVariable %100 Input
|
||||
%102 = OpVariable %35 Output
|
||||
%108 = OpTypeSampledImage %17
|
||||
%38 = OpFunction %2 None %39
|
||||
%30 = OpLabel
|
||||
%25 = OpVariable %26 Function
|
||||
@ -159,26 +136,22 @@ OpStore %90 %53
|
||||
%91 = OpLoad %12 %28
|
||||
%92 = OpCompositeExtract %10 %91 0
|
||||
OpStore %34 %92
|
||||
%93 = OpAccessChain %94 %34 %5
|
||||
%95 = OpLoad %7 %93
|
||||
%96 = OpFNegate %7 %95
|
||||
OpStore %93 %96
|
||||
%97 = OpCompositeExtract %11 %91 1
|
||||
OpStore %36 %97
|
||||
%93 = OpCompositeExtract %11 %91 1
|
||||
OpStore %36 %93
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
%107 = OpFunction %2 None %39
|
||||
%98 = OpLabel
|
||||
%102 = OpLoad %10 %100
|
||||
%105 = OpLoad %11 %103
|
||||
%99 = OpCompositeConstruct %12 %102 %105
|
||||
%108 = OpLoad %17 %21
|
||||
%109 = OpLoad %18 %23
|
||||
OpBranch %110
|
||||
%110 = OpLabel
|
||||
%111 = OpCompositeExtract %11 %99 1
|
||||
%113 = OpSampledImage %112 %108 %109
|
||||
%114 = OpImageSampleImplicitLod %10 %113 %111
|
||||
OpStore %106 %114
|
||||
%103 = OpFunction %2 None %39
|
||||
%94 = OpLabel
|
||||
%98 = OpLoad %10 %96
|
||||
%101 = OpLoad %11 %99
|
||||
%95 = OpCompositeConstruct %12 %98 %101
|
||||
%104 = OpLoad %17 %21
|
||||
%105 = OpLoad %18 %23
|
||||
OpBranch %106
|
||||
%106 = OpLabel
|
||||
%107 = OpCompositeExtract %11 %95 1
|
||||
%109 = OpSampledImage %108 %104 %105
|
||||
%110 = OpImageSampleImplicitLod %10 %109 %107
|
||||
OpStore %102 %110
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
|
@ -45,6 +45,10 @@ struct Parameters {
|
||||
spv_version: (u8, u8),
|
||||
#[cfg_attr(not(feature = "spv-out"), allow(dead_code))]
|
||||
spv_capabilities: naga::FastHashSet<spirv::Capability>,
|
||||
#[cfg_attr(not(feature = "spv-out"), allow(dead_code))]
|
||||
spv_debug: bool,
|
||||
#[cfg_attr(not(feature = "spv-out"), allow(dead_code))]
|
||||
spv_adjust_coordinate_space: bool,
|
||||
#[cfg_attr(not(feature = "msl-out"), allow(dead_code))]
|
||||
mtl_bindings: naga::FastHashMap<BindSource, BindTarget>,
|
||||
}
|
||||
@ -126,9 +130,16 @@ fn check_output_spv(
|
||||
use naga::back::spv;
|
||||
use rspirv::binary::Disassemble;
|
||||
|
||||
let mut flags = spv::WriterFlags::empty();
|
||||
if params.spv_debug {
|
||||
flags |= spv::WriterFlags::DEBUG;
|
||||
}
|
||||
if params.spv_adjust_coordinate_space {
|
||||
flags |= spv::WriterFlags::ADJUST_COORDINATE_SPACE;
|
||||
}
|
||||
let options = spv::Options {
|
||||
lang_version: params.spv_version,
|
||||
flags: spv::WriterFlags::DEBUG,
|
||||
flags,
|
||||
capabilities: params.spv_capabilities.clone(),
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user