Skip to content

Commit

Permalink
Skip functions that that are not compatible with entry point's stage
Browse files Browse the repository at this point in the history
  • Loading branch information
teoxoy committed Oct 13, 2023
1 parent 30539d7 commit bc73279
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 66 deletions.
5 changes: 5 additions & 0 deletions src/back/glsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,11 @@ impl<'a, W: Write> Writer<'a, W> {

let fun_info = &self.info[handle];

// Skip functions that that are not compatible with this entry point's stage
if !fun_info.available_stages.contains(ep_info.available_stages) {
continue;
}

// Write the function
self.write_function(back::FunctionType::Function(handle), function, fun_info)?;

Expand Down
5 changes: 5 additions & 0 deletions src/back/spv/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1952,6 +1952,11 @@ impl Writer {
log::info!("Skip function {:?}", ir_function.name);
continue;
}

// Skip functions that that are not compatible with this entry point's stage
if !info.available_stages.contains(ep_info.available_stages) {
continue;
}
}
let id = self.write_function(ir_function, info, ir_module, None, &debug_info_inner)?;
self.lookup_function.insert(handle, id);
Expand Down
6 changes: 0 additions & 6 deletions tests/out/glsl/separate-entry-points.compute.Compute.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ precision highp int;
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;


void derivatives() {
float x = dFdx(0.0);
float y = dFdy(0.0);
float width = fwidth(0.0);
}

void barriers() {
memoryBarrierBuffer();
barrier();
Expand Down
8 changes: 0 additions & 8 deletions tests/out/glsl/separate-entry-points.fragment.Fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ void derivatives() {
float width = fwidth(0.0);
}

void barriers() {
memoryBarrierBuffer();
barrier();
memoryBarrierShared();
barrier();
return;
}

void main() {
derivatives();
_fs2p_location0 = vec4(0.0);
Expand Down
44 changes: 17 additions & 27 deletions tests/out/spv/separate-entry-points.compute.spvasm
Original file line number Diff line number Diff line change
@@ -1,43 +1,33 @@
; SPIR-V
; Version: 1.0
; Generator: rspirv
; Bound: 25
; Bound: 18
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %22 "compute"
OpExecutionMode %22 LocalSize 1 1 1
OpEntryPoint GLCompute %15 "compute"
OpExecutionMode %15 LocalSize 1 1 1
%2 = OpTypeVoid
%4 = OpTypeFloat 32
%3 = OpTypeVector %4 4
%7 = OpTypeFunction %2
%8 = OpConstant %4 0.0
%17 = OpTypeInt 32 0
%16 = OpConstant %17 2
%18 = OpConstant %17 1
%19 = OpConstant %17 72
%20 = OpConstant %17 264
%10 = OpTypeInt 32 0
%9 = OpConstant %10 2
%11 = OpConstant %10 1
%12 = OpConstant %10 72
%13 = OpConstant %10 264
%6 = OpFunction %2 None %7
%5 = OpLabel
OpBranch %9
%9 = OpLabel
%10 = OpDPdx %4 %8
%11 = OpDPdy %4 %8
%12 = OpFwidth %4 %8
OpBranch %8
%8 = OpLabel
OpControlBarrier %9 %11 %12
OpControlBarrier %9 %9 %13
OpReturn
OpFunctionEnd
%14 = OpFunction %2 None %7
%13 = OpLabel
OpBranch %15
%15 = OpLabel
OpControlBarrier %16 %18 %19
OpControlBarrier %16 %16 %20
OpReturn
OpFunctionEnd
%22 = OpFunction %2 None %7
%21 = OpLabel
OpBranch %23
%23 = OpLabel
%24 = OpFunctionCall %2 %14
%15 = OpFunction %2 None %7
%14 = OpLabel
OpBranch %16
%16 = OpLabel
%17 = OpFunctionCall %2 %6
OpReturn
OpFunctionEnd
37 changes: 12 additions & 25 deletions tests/out/spv/separate-entry-points.fragment.spvasm
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
; SPIR-V
; Version: 1.0
; Generator: rspirv
; Bound: 28
; Bound: 20
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %24 "fragment" %22
OpExecutionMode %24 OriginUpperLeft
OpDecorate %22 Location 0
OpEntryPoint Fragment %16 "fragment" %14
OpExecutionMode %16 OriginUpperLeft
OpDecorate %14 Location 0
%2 = OpTypeVoid
%4 = OpTypeFloat 32
%3 = OpTypeVector %4 4
%7 = OpTypeFunction %2
%8 = OpConstant %4 0.0
%17 = OpTypeInt 32 0
%16 = OpConstant %17 2
%18 = OpConstant %17 1
%19 = OpConstant %17 72
%20 = OpConstant %17 264
%23 = OpTypePointer Output %3
%22 = OpVariable %23 Output
%25 = OpConstantNull %3
%15 = OpTypePointer Output %3
%14 = OpVariable %15 Output
%17 = OpConstantNull %3
%6 = OpFunction %2 None %7
%5 = OpLabel
OpBranch %9
Expand All @@ -30,19 +25,11 @@ OpBranch %9
%12 = OpFwidth %4 %8
OpReturn
OpFunctionEnd
%14 = OpFunction %2 None %7
%16 = OpFunction %2 None %7
%13 = OpLabel
OpBranch %15
%15 = OpLabel
OpControlBarrier %16 %18 %19
OpControlBarrier %16 %16 %20
OpReturn
OpFunctionEnd
%24 = OpFunction %2 None %7
%21 = OpLabel
OpBranch %26
%26 = OpLabel
%27 = OpFunctionCall %2 %6
OpStore %22 %25
OpBranch %18
%18 = OpLabel
%19 = OpFunctionCall %2 %6
OpStore %14 %17
OpReturn
OpFunctionEnd

0 comments on commit bc73279

Please sign in to comment.