This repository has been archived by the owner on Jan 29, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[spv-in] Convert conditional backedges to
break if
.
- Loading branch information
Showing
10 changed files
with
304 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
;; Ensure that `do`-`while`-style loops, with conditional backedges, are properly | ||
;; supported, via `break if` (as `continuing { ... if c { break; } }` is illegal). | ||
;; | ||
;; The SPIR-V below was compiled from this GLSL fragment shader: | ||
;; ```glsl | ||
;; #version 450 | ||
;; | ||
;; void f(bool cond) { | ||
;; do {} while(cond); | ||
;; } | ||
;; | ||
;; void main() { | ||
;; f(true); | ||
;; } | ||
;; ``` | ||
|
||
OpCapability Shader | ||
%1 = OpExtInstImport "GLSL.std.450" | ||
OpMemoryModel Logical GLSL450 | ||
OpEntryPoint Fragment %main "main" | ||
OpExecutionMode %main OriginUpperLeft | ||
OpSource GLSL 450 | ||
OpName %main "main" | ||
OpName %f_b1_ "f(b1;" | ||
OpName %cond "cond" | ||
OpName %param "param" | ||
%void = OpTypeVoid | ||
%3 = OpTypeFunction %void | ||
%bool = OpTypeBool | ||
%_ptr_Function_bool = OpTypePointer Function %bool | ||
%8 = OpTypeFunction %void %_ptr_Function_bool | ||
%true = OpConstantTrue %bool | ||
|
||
%main = OpFunction %void None %3 | ||
%5 = OpLabel | ||
%param = OpVariable %_ptr_Function_bool Function | ||
OpStore %param %true | ||
%19 = OpFunctionCall %void %f_b1_ %param | ||
OpReturn | ||
OpFunctionEnd | ||
|
||
%f_b1_ = OpFunction %void None %8 | ||
%cond = OpFunctionParameter %_ptr_Function_bool | ||
|
||
%11 = OpLabel | ||
OpBranch %12 | ||
|
||
%12 = OpLabel | ||
OpLoopMerge %14 %15 None | ||
OpBranch %13 | ||
|
||
%13 = OpLabel | ||
OpBranch %15 | ||
|
||
;; This is the "continuing" block, and it contains a conditional branch between | ||
;; the backedge (back to the loop header) and the loop merge ("break") target. | ||
%15 = OpLabel | ||
%16 = OpLoad %bool %cond | ||
OpBranchConditional %16 %12 %14 | ||
|
||
%14 = OpLabel | ||
OpReturn | ||
|
||
OpFunctionEnd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#version 310 es | ||
|
||
precision highp float; | ||
precision highp int; | ||
|
||
|
||
void fb1_(inout bool cond) { | ||
bool loop_init = true; | ||
while(true) { | ||
if (!loop_init) { | ||
bool _e6 = cond; | ||
bool unnamed = !(_e6); | ||
if (unnamed) { | ||
break; | ||
} | ||
} | ||
loop_init = false; | ||
continue; | ||
} | ||
return; | ||
} | ||
|
||
void main_1() { | ||
bool param = false; | ||
param = true; | ||
fb1_(param); | ||
return; | ||
} | ||
|
||
void main() { | ||
main_1(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
void fb1_(inout bool cond) | ||
{ | ||
bool loop_init = true; | ||
while(true) { | ||
if (!loop_init) { | ||
bool _expr6 = cond; | ||
bool unnamed = !(_expr6); | ||
if (unnamed) { | ||
break; | ||
} | ||
} | ||
loop_init = false; | ||
continue; | ||
} | ||
return; | ||
} | ||
|
||
void main_1() | ||
{ | ||
bool param = (bool)0; | ||
|
||
param = true; | ||
fb1_(param); | ||
return; | ||
} | ||
|
||
void main() | ||
{ | ||
main_1(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
vertex=() | ||
fragment=(main:ps_5_1 ) | ||
compute=() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// language: metal2.0 | ||
#include <metal_stdlib> | ||
#include <simd/simd.h> | ||
|
||
using metal::uint; | ||
|
||
|
||
void fb1_( | ||
thread bool& cond | ||
) { | ||
bool loop_init = true; | ||
while(true) { | ||
if (!loop_init) { | ||
bool _e6 = cond; | ||
bool unnamed = !(_e6); | ||
if (!(cond)) { | ||
break; | ||
} | ||
} | ||
loop_init = false; | ||
continue; | ||
} | ||
return; | ||
} | ||
|
||
void main_1( | ||
) { | ||
bool param = {}; | ||
param = true; | ||
fb1_(param); | ||
return; | ||
} | ||
|
||
fragment void main_( | ||
) { | ||
main_1(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
fn fb1_(cond: ptr<function, bool>) { | ||
loop { | ||
continue; | ||
continuing { | ||
let _e6 = (*cond); | ||
_ = !(_e6); | ||
break if !(_e6); | ||
} | ||
} | ||
return; | ||
} | ||
|
||
fn main_1() { | ||
var param: bool; | ||
|
||
param = true; | ||
fb1_((¶m)); | ||
return; | ||
} | ||
|
||
@fragment | ||
fn main() { | ||
main_1(); | ||
} |
Oops, something went wrong.