Skip to content

Commit 6512c21

Browse files
authored
Merge pull request #3762 from Eiton/Vulkan-Texture-Memory-Allocator
feat: Vulkan texture memory allocator
2 parents 46def2c + 01c4b7b commit 6512c21

7 files changed

Lines changed: 761 additions & 104 deletions

File tree

src/config.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ type Config struct {
163163
KeepAspect bool `ini:"KeepAspect"`
164164
RendererDebugMode bool `ini:"RendererDebugMode"`
165165
EnableModel bool `ini:"EnableModel"`
166-
EnableModelShadow bool `ini:"EnableModelShadow"`
166+
EnableModelShadow bool `ini:"EnableModelShadow"`
167+
ImageSuballocThresholdKB int `ini:"ImageSuballocThresholdKB"` // ≤ this (KB) suballocated; 0 to disable
168+
ImageSuballocBlockSizeMB int `ini:"ImageSuballocBlockSizeMB"` // block size (MB) for suballocation pool
167169
} `ini:"Video"`
168170
Sound struct {
169171
SampleRate int32 `ini:"SampleRate"`
@@ -369,6 +371,13 @@ func (c *Config) normalize() {
369371
default:
370372
c.SetValueUpdate("Video.MSAA", 0)
371373
}
374+
375+
if c.Video.ImageSuballocThresholdKB < 0 {
376+
c.SetValueUpdate("Video.ImageSuballocThresholdKB", 256)
377+
}
378+
if c.Video.ImageSuballocBlockSizeMB < 1 {
379+
c.SetValueUpdate("Video.ImageSuballocBlockSizeMB", 64)
380+
}
372381
}
373382

374383
// Sets system values

src/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,9 @@ func handlePanic(r interface{}) {
354354
memory := fmt.Sprintf("RAM in Use: %v MB / OS Reserved: %v MB", mem.Alloc/1024/1024, mem.Sys/1024/1024)
355355
threads := fmt.Sprintf("Active Goroutines: %d", runtime.NumGoroutine())
356356

357+
// Renderer debug info (GPU memory stats, etc.)
358+
rendererDebug := gfx.DebugInfo()
359+
357360
// Identify the crash type
358361
crashType := "Fatal runtime error" // Default for unsafe crashes
359362
if _, ok := r.(*lua.ApiError); ok {
@@ -371,6 +374,9 @@ func handlePanic(r interface{}) {
371374
// Optional: print error to terminal
372375
// We have to do this manually now because we recover() from the actual panic
373376
fmt.Fprintf(os.Stderr, "Panic: %s\n\n%s\n", errStr, goStack)
377+
if rendererDebug != "" {
378+
fmt.Fprintf(os.Stderr, "\nRenderer Debug Info:\n%s\n", rendererDebug)
379+
}
374380

375381
// Write to log file
376382
logDir := filepath.Join(sys.baseDir, "save", "logs")
@@ -382,6 +388,9 @@ func handlePanic(r interface{}) {
382388
fmt.Fprintf(f, "%s\n%s\n%s\n%s\n%s\n%s\nTimestamp: %s\n\n%s\n\nError: %s\n\n%s",
383389
version, buildTime, platform, render, memory, threads,
384390
now.Format("2006-01-02 15:04:05"), crashType, errStr, goStack)
391+
if rendererDebug != "" {
392+
fmt.Fprintf(f, "\n\nRenderer Debug Info:\n%s", rendererDebug)
393+
}
385394
f.Close()
386395
}
387396

src/render.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type Texture interface {
2121

2222
type Renderer interface {
2323
GetName() string
24+
DebugInfo() string
2425
Init()
2526
Close()
2627
BeginFrame(clearColor bool)

src/render_gl33.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,10 @@ func (r *Renderer_GL33) GetName() string {
498498
return "OpenGL 3.3"
499499
}
500500

501+
func (r *Renderer_GL33) DebugInfo() string {
502+
return "" // No OOM tracking — GL driver manages memory
503+
}
504+
501505
// init 3D model shader
502506
func (r *Renderer_GL33) InitModelShader() error {
503507
var err error

src/render_gles32.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,10 @@ func (r *Renderer_GLES32) GetName() string {
596596
return "OpenGL ES 3.2"
597597
}
598598

599+
func (r *Renderer_GLES32) DebugInfo() string {
600+
return "" // No OOM tracking — GLES driver manages memory
601+
}
602+
599603
// init 3D model shader
600604
func (r *Renderer_GLES32) InitModelShader() error {
601605
var err error

0 commit comments

Comments
 (0)