Skip to content

[SPIRV] Add PreLegalizer pattern matching for faceforward GL extension #137255

@kmpeng

Description

@kmpeng

Follow up to #99114.

The codegen for faceforward looks something like

faceforward(p1, p2, p3) ->
  dResult       = dot(p2, p3)
  cmpResult  = fcmp dResult, 0.0
  subResult   = fsub -0.0 p1
  select(cmpResult, p1, subResult)

which means we can pattern match in SPIRVCombine.td and SPIRVPreLegalizerCombiner.cpp to

select(
    fcmp(
        dot(p2, p3), 
        0),
    p1,
    0 - p1) 

This would allow us to change select(fcmp(dot(p2, p3), 0), p1, 0 - p1) to faceforward(p1, p2, p3) so that we use the right SPIR-V extension function.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Active

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions