Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading all texture data from HDD when we only need the lowest mipmap. #775

Open
bryanedds opened this issue Apr 8, 2024 · 0 comments
Open
Assignees
Labels
enhancement performance issues or potential issues relating to performance

Comments

@bryanedds
Copy link
Owner

Here it seems we need to load all the bytes from HDD in order to make even a single lowest mipmap image -

elif fileExtension = ".dds" then
try let config = PfimConfig (decompress = false)
use fileStream = File.OpenRead filePath
use dds = Dds.Create (fileStream, config)
let metadata = TextureMetadata.make dds.Width dds.Height
if dds.Compressed then
let mutable dims = v2i dds.Width dds.Height
let mutable size = ((dims.X + 3) / 4) * ((dims.Y + 3) / 4) * 16
let mutable index = 0
let bytes = dds.Data.AsSpan(index, size).ToArray()
let mipmapBytesArray =
[|for _ in 1u .. dec dds.Header.MipMapCount do
dims <- dims / 2
index <- index + size
size <- size / 4
if size >= 16 then (dims, dds.Data.AsSpan(index, size).ToArray())|]
if minimal then
match Array.tryLast mipmapBytesArray with
| Some (mipmapMinimalResolution, mipmapMinimalBytes) ->
let metadataMinimal = TextureMetadata.make mipmapMinimalResolution.X mipmapMinimalResolution.Y
Some (TextureDataMipmap (metadataMinimal, true, mipmapMinimalBytes, [||]))
| None -> Some (TextureDataMipmap (metadata, true, bytes, mipmapBytesArray))
else Some (TextureDataMipmap (metadata, true, bytes, mipmapBytesArray))
else
match TryFormatUncompressedPfimageData dds with
| Some (bytes, mipmapBytesArray) ->
if minimal then
match Array.tryLast mipmapBytesArray with
| Some (mipmapMinimalResolution, mipmapMinimalBytes) ->
let metadataMinimal = TextureMetadata.make mipmapMinimalResolution.X mipmapMinimalResolution.Y
Some (TextureDataMipmap (metadataMinimal, false, mipmapMinimalBytes, [||]))
| None -> Some (TextureDataMipmap (metadata, false, bytes, mipmapBytesArray))
else Some (TextureDataMipmap (metadata, false, bytes, mipmapBytesArray))
| None -> None
with _ -> None

I've made a query with the maintainer here -

nickbabcock/Pfim#116 (comment)

Let's follow up and see if we can't come up with a reasonable API!

@bryanedds bryanedds added enhancement performance issues or potential issues relating to performance labels Apr 8, 2024
@bryanedds bryanedds self-assigned this Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement performance issues or potential issues relating to performance
Projects
None yet
Development

No branches or pull requests

1 participant