I have a simple program that determines (somewhat) available video memory by repeatedly creating images and holding a reference to it until I run out of memory.
I call this in succession for various scenarios (wanted to see the gain in using DDS).
The scenarios are "Load a png", "Create an image of the size of said png", and "load the same image as DDS"
As expected I can load a lot more of the DDS as of the PNG - 623 of the png (it's pretty big).
When I create the imageData and image I can create 624 of them. When I do it after loading the PNGs (and force freeing them) I can create 623. Not sure, but seems there's a slight resource leak there.
When I load the DDS (of the same image) I can load 2430 of them.
However, when I try to load or create the PNGs after loading -and freeing- the DDS's I can only load 371 of them, so *something* is being held in memory when destroying the DDS.
Find code below. The PNG I use is 500x583 32 bit. The DDS of the same image is DXT5. Unfortunately I can't share the image.
Seems my free VRAM is in the 800mb range (yikes)
If anyone has an idea, or if I'm missing a step, please let me know.
Code: Select all
LoadImagesPNG = function(settings)
local images = {}
settings.total = 0
settings.count = 0
while true do
local img = love.graphics.newImage("test.png")
images[#images+1] = img
local data = img:getData()
local size = data:getSize()
--print("size ",size)
settings.total = settings.total + size
settings.count = settings.count + 1
collectgarbage()
end
end
LoadImagesDDS = function(settings)
local images = {}
settings.total = 0
settings.count = 0
while true do
local img = love.graphics.newImage("test.dds")
images[#images+1] = img
local data = img:getData()
local size = data:getSize()
--print("size ",size)
settings.total = settings.total + size
settings.count = settings.count + 1
collectgarbage()
end
end
CreateImageData = function(settings)
local images = {}
settings.total = 0
settings.count = 0
while true do
local imgdata = love.image.newImageData(500,583)
local image = love.graphics.newImage(imgdata)
imgdata = nil
images[#images+1] = image
local data = image:getData()
local size = data:getSize()
-- print(settings.count,"size ",size)
settings.total = settings.total + size
settings.count = settings.count + 1
collectgarbage()
end
end
function handle()
print("yeah, had an error")
end
-- Keep calling a function till we err, to catch out of memory.
-- Just to see how much vram we have.
TestGfxMemory = function(message, fn)
print(message)
local settings = {}
local status, error = pcall(fn, settings)
if not status then
collectgarbage()
for i,v in pairs(settings) do
print("",i,v)
end
print()
end
end
TestGfxMemory("loading images in dds", LoadImagesDDS) -- 2430
TestGfxMemory("loading images in png", LoadImagesPNG) -- 623 ( but not after loading DDS )
TestGfxMemory("creating images in memory", CreateImageData) -- 624 ( but not after LoadImageDDS )