Skip to content

Commit

Permalink
llpc: disable spilling of SGPR spill VGPRs
Browse files Browse the repository at this point in the history
Add function attribute amdgpu-prealloc-sgpr-spill-vgprs to prevent
spilling of SGPR spill VGPRs.
This occurs in shaders with extremely high VGPR pressure,
e.g. large RT shaders, and can yield unpredictable results.

This is an interim workaround and should be removed when backend
support for these spills is fully implemented.
  • Loading branch information
perlfu committed Nov 13, 2023
1 parent 4320b9c commit bfd2d2c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
4 changes: 4 additions & 0 deletions lgc/patch/PatchEntryPointMutate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,10 @@ void PatchEntryPointMutate::setFuncAttrs(Function *entryPoint) {
builder.addAttribute("amdgpu-memory-bound", shaderOptions->favorLatencyHiding ? "true" : "false");
builder.addAttribute("amdgpu-wave-limiter", "false");

// Prevent spilling of VGPRs holding SGPR spills as this can have undefined behaviour in callee functions.
// Note: this is an intermediate workaround and should be removed when backend support is complete.
builder.addAttribute("amdgpu-prealloc-sgpr-spill-vgprs");

entryPoint->addFnAttrs(builder);

// NOTE: Remove "readnone" attribute for entry-point. If GS is empty, this attribute will allow
Expand Down
2 changes: 1 addition & 1 deletion lgc/test/Transforms/CpsLowering/cps-stack-lowering.lgc
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ define void @test.2({ ptr addrspace(32) } %state) !lgc.cps !{i32 1} !lgc.shaders
;
;.
; CHECK: attributes #[[ATTR0:[0-9]+]] = { noreturn }
; CHECK: attributes #[[ATTR1]] = { memory(readwrite) "amdgpu-memory-bound"="false" "amdgpu-unroll-threshold"="700" "amdgpu-wave-limiter"="false" }
; CHECK: attributes #[[ATTR1]] = { memory(readwrite) "amdgpu-memory-bound"="false" "amdgpu-prealloc-sgpr-spill-vgprs" "amdgpu-unroll-threshold"="700" "amdgpu-wave-limiter"="false" }
; CHECK: attributes #[[ATTR2:[0-9]+]] = { convergent nocallback nofree nounwind willreturn memory(none) }
; CHECK: attributes #[[ATTR3:[0-9]+]] = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
; CHECK: attributes #[[ATTR4:[0-9]+]] = { convergent nocallback nofree nounwind speculatable willreturn memory(none) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ options.ldsSpillLimitDwords = 1024
; CHECK-NEXT: ret void
;
;.
; CHECK: attributes #[[ATTR0:[0-9]+]] = { nounwind memory(readwrite) "amdgpu-flat-work-group-size"="66,66" "amdgpu-lds-spill-limit-dwords"="1024" "amdgpu-memory-bound"="false" "amdgpu-no-workgroup-id-x" "amdgpu-no-workgroup-id-y" "amdgpu-no-workgroup-id-z" "amdgpu-unroll-threshold"="700" "amdgpu-wave-limiter"="false" "amdgpu-work-group-info-arg-no"="1" "denormal-fp-math-f32"="preserve-sign" "target-features"=",+wavefrontsize64,+cumode,+enable-flat-scratch" }
; CHECK: attributes #[[ATTR0:[0-9]+]] = { nounwind memory(readwrite) "amdgpu-flat-work-group-size"="66,66" "amdgpu-lds-spill-limit-dwords"="1024" "amdgpu-memory-bound"="false" "amdgpu-no-workgroup-id-x" "amdgpu-no-workgroup-id-y" "amdgpu-no-workgroup-id-z" "amdgpu-prealloc-sgpr-spill-vgprs" "amdgpu-unroll-threshold"="700" "amdgpu-wave-limiter"="false" "amdgpu-work-group-info-arg-no"="1" "denormal-fp-math-f32"="preserve-sign" "target-features"=",+wavefrontsize64,+cumode,+enable-flat-scratch" }
;.
5 changes: 3 additions & 2 deletions llpc/test/shaderdb/general/TestWorkgroupIdOpt.comp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ void main()
// CHECK-NEXT: ret void
//
//.
// CHECK: attributes #[[ATTR0]] = { nounwind memory(readwrite) "amdgpu-flat-work-group-size"="256,256" "amdgpu-memory-bound"="false" "amdgpu-no-workgroup-id-y" "amdgpu-no-workgroup-id-z" "amdgpu-unroll-threshold"="700" "amdgpu-wave-limiter"="false" "amdgpu-work-group-info-arg-no"="3" "denormal-fp-math-f32"="preserve-sign" "target-features"=",+wavefrontsize64,+cumode,+enable-flat-scratch" }
// CHECK: attributes #[[ATTR1:[0-9]+]] = { nounwind willreturn memory(none) }
// CHECK: attributes #[[ATTR0]] = { nounwind memory(readwrite) "amdgpu-flat-work-group-size"="256,256" "amdgpu-memory-bound"="false" "amdgpu-no-workgroup-id-y" "amdgpu-no-workgroup-id-z" "amdgpu-prealloc-sgpr-spill-vgprs" "amdgpu-unroll-threshold"="700" "amdgpu-wave-limiter"="false" "amdgpu-work-group-info-arg-no"="3" "denormal-fp-math-f32"="preserve-sign" "target-features"=",+wavefrontsize64,+cumode,+enable-flat-scratch" }
// CHECK: attributes #[[ATTR1:[0-9]+]] = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
// CHECK: attributes #[[ATTR2:[0-9]+]] = { nounwind willreturn memory(none) }
// CHECK: attributes #[[ATTR3:[0-9]+]] = { nocallback nofree nosync nounwind willreturn memory(write) }
//.

0 comments on commit bfd2d2c

Please sign in to comment.