Nominom / BCnEncoder.NET

Cross-platform texture encoding libary for .NET. With support for BC1-3/DXT, BC4-5/RGTC and BC6-7/BPTC compression. Outputs files in ktx or dds formats.
The Unlicense
108 stars 16 forks source link

Add Progress #24

Closed onepiecefreak3 closed 3 years ago

onepiecefreak3 commented 3 years ago

This adds the progress feature based on the IProgress interface. It's not much but enough. Maybe it can be done more memory efficient?

Nominom commented 3 years ago

For the memory efficiency, just making the ProgressElement into a struct would make it allocate on the stack and remove some GC pressure. Also only reporting every 100 blocks or so (and last block) would make it take less processing and still maintain good progress estimate (if UI needs to be refreshed on every call to Report).

Should this have tests? Like launch a thread that monitors the progress and assert that the progress is always greater than or equal to the previous value. Then assert that progress is 100% once the operation is done.

Nominom commented 3 years ago

Another thing I was thinking of is, wouldn't it now show progress for only the current mipmap level? Might need to calculate the totalblocks from all mipmaps first, then keep a cumulative count that stays between mipmap level encodes.

onepiecefreak3 commented 3 years ago

This adds a wrapper for the IProgress to the OperationContext that can be aware of its current mipmap progress. I also did some more refactoring regarding usage of the 3 different format enums. Namely I implemented using only CompressionFormat where possible by converting GlInternalFormat and DxgiFormat properly. While doing that I found out how to solve issue #25 since dwFlags contains a flag regarding this behaviour it seems. I will fix that with this PR as well.

I don't know if the progress behaviour is testable. Any ideas how that can be done?

Nominom commented 3 years ago

The test can launch an async encoding method, and run a while loop afterwards. In the while loop the progress is checked that it is always equal to or greater than the previous progress values. After the operation is done, assert that progressed blocks is same as total blocks.

Also, the code looks good to me now. 👍

EDIT: ah you just pushed, I'll look again.

onepiecefreak3 commented 3 years ago

I think this feature can be merged now.

Nominom commented 3 years ago

Yeah, it looks good to me.