Skip to content

Commit

Permalink
Supporting gl_PointCoord (#2180)
Browse files Browse the repository at this point in the history
  • Loading branch information
Neo-Zhixing committed Dec 21, 2022
1 parent 37be4df commit 8e1b052
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/back/glsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3723,6 +3723,7 @@ const fn glsl_built_in(
Bi::VertexIndex => "uint(gl_VertexID)",
// fragment
Bi::FragDepth => "gl_FragDepth",
Bi::PointCoord => "gl_PointCoord",
Bi::FrontFacing => "gl_FrontFacing",
Bi::PrimitiveIndex => "uint(gl_PrimitiveID)",
Bi::SampleIndex => "gl_SampleID",
Expand Down
2 changes: 1 addition & 1 deletion src/back/hlsl/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl crate::BuiltIn {
Self::BaseInstance | Self::BaseVertex | Self::WorkGroupSize => {
return Err(Error::Unimplemented(format!("builtin {:?}", self)))
}
Self::ViewIndex => {
Self::ViewIndex | Self::PointCoord => {
return Err(Error::Custom(format!("Unsupported builtin {:?}", self)))
}
})
Expand Down
1 change: 1 addition & 0 deletions src/back/msl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ impl ResolvedBinding {
Bi::VertexIndex => "vertex_id",
// fragment
Bi::FragDepth => "depth(any)",
Bi::PointCoord => "point_coord",
Bi::FrontFacing => "front_facing",
Bi::PrimitiveIndex => "primitive_id",
Bi::SampleIndex => "sample_id",
Expand Down
1 change: 1 addition & 0 deletions src/back/spv/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,7 @@ impl Writer {
Bi::VertexIndex => BuiltIn::VertexIndex,
// fragment
Bi::FragDepth => BuiltIn::FragDepth,
Bi::PointCoord => BuiltIn::PointCoord,
Bi::FrontFacing => BuiltIn::FrontFacing,
Bi::PrimitiveIndex => {
self.require_any(
Expand Down
10 changes: 10 additions & 0 deletions src/front/glsl/variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ impl Parser {
mutable: false,
storage: StorageQualifier::Input,
},
"gl_PointCoord" => BuiltInData {
inner: TypeInner::Vector {
size: VectorSize::Bi,
kind: ScalarKind::Float,
width: 4,
},
builtin: BuiltIn::PointCoord,
mutable: false,
storage: StorageQualifier::Input,
},
"gl_GlobalInvocationID"
| "gl_NumWorkGroups"
| "gl_WorkGroupSize"
Expand Down
1 change: 1 addition & 0 deletions src/front/spv/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ pub(super) fn map_builtin(word: spirv::Word, invariant: bool) -> Result<crate::B
Some(Bi::VertexIndex) => crate::BuiltIn::VertexIndex,
// fragment
Some(Bi::FragDepth) => crate::BuiltIn::FragDepth,
Some(Bi::PointCoord) => crate::BuiltIn::PointCoord,
Some(Bi::FrontFacing) => crate::BuiltIn::FrontFacing,
Some(Bi::PrimitiveId) => crate::BuiltIn::PrimitiveIndex,
Some(Bi::SampleId) => crate::BuiltIn::SampleIndex,
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ pub enum BuiltIn {
VertexIndex,
// fragment
FragDepth,
PointCoord,
FrontFacing,
PrimitiveIndex,
SampleIndex,
Expand Down
9 changes: 9 additions & 0 deletions src/valid/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ impl VaryingContext<'_> {
width,
},
),
Bi::PointCoord => (
self.stage == St::Fragment && !self.output,
*ty_inner
== Ti::Vector {
size: Vs::Bi,
kind: Sk::Float,
width,
},
),
Bi::Position { .. } => (
match self.stage {
St::Vertex => self.output,
Expand Down

0 comments on commit 8e1b052

Please sign in to comment.