Skip to content

Commit fea9090

Browse files
committed
implement component limiting in Builder.useGPU
1 parent 7b18df9 commit fea9090

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

gsdf.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,13 @@ type Builder struct {
4545
limVecGPU int
4646
}
4747

48-
func (bld *Builder) useGPU(_ int) bool {
49-
return bld.flags&FlagUseShaderBuffers != 0 // bld.limVecGPU != 0 && n > bld.limVecGPU || n > 1
48+
// useGPU enables selection of GPU over CPU algorithm depending on Builder configuration.
49+
func (bld *Builder) useGPU(components int) bool {
50+
lim := bld.limVecGPU
51+
if lim == 0 {
52+
lim = 1024 // Typically older GPUs support a maximum of 1024 components (float32s).
53+
}
54+
return bld.flags&FlagUseShaderBuffers != 0 || components > lim
5055
}
5156

5257
func makeHashName[T any](dst []byte, name string, vec []T) []byte {

gsdf2d.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ func (bld *Builder) NewPolygon(vertices []ms2.Vec) glbuild.Shader2D {
587587
bld.shapeErrorf(err.Error())
588588
}
589589
poly := poly2D{vert: vertices}
590-
if bld.useGPU(len(vertices)) {
590+
if bld.useGPU(len(vertices) * 2) {
591591
return &polyGPU{poly2D: poly, bufname: makeHashName(nil, "ssboPoly", vertices)}
592592
}
593593
return &poly

0 commit comments

Comments
 (0)