Skip to content

Commit

Permalink
kramv - update fast load path from staging MTLBuffer to MTLTexture, f…
Browse files Browse the repository at this point in the history
…ix archive increment

This decompresses, aliases, or copies directly from blocks and compressed blocks.
The blit encoder is used to go direct to private textures via a 128MB staging MTLBuffer.
This allows the entire level to be copied at once, and the the blits reference offsets into the buffer.
The buffer is just a linear allocator right now, no circular usage.
Use completion handler.  Loader really needs a queue of pending textures, and also avoid level allocation on the copy path, and use a part of staging texture.
Fix isInfoOnly handling since levelSize was divided by length twice.
  • Loading branch information
alecazam committed May 24, 2021
1 parent 885d36d commit 2b74354
Show file tree
Hide file tree
Showing 7 changed files with 301 additions and 206 deletions.
19 changes: 5 additions & 14 deletions kramv/KramLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
#import <Foundation/Foundation.h>

// protocol requires imports
#import <Metal/MTLPixelFormat.h>
#import <Metal/MTLTexture.h>
#import <Metal/MTLBlitCommandEncoder.h>
#import <Metal/MTLCommandBuffer.h>
#import <Metal/MTLDevice.h>
#import <Metal/MTLPixelFormat.h>
#import <Metal/MTLTexture.h>

#endif

Expand All @@ -31,18 +32,8 @@
// from url (mmap)
- (nullable id<MTLTexture>)loadTextureFromURL:(nonnull NSURL *)url originalFormat:(nullable MTLPixelFormat*)originalFormat;

@property (retain, nonatomic, readwrite, nonnull) id<MTLDevice> device;

// test this after load, and use a MTLBlitEncoder to autogen mips
@property (nonatomic, readwrite, getter=isMipgenNeeded) BOOL mipgenNeeded;

@end

//-------------------------------------

// This loads KTX and PNG data synchronously. Will likely move to only loading KTX files, with a png -> ktx conversion.
// The underlying KTXImage is not yet returned to the caller, but would be useful for prop queries.
@interface KramBlitLoader : NSObject
// handle auto-mipgen and upload mips from staging MTLBuffer to mips of various private MTLTexture
- (void)uploadTexturesIfNeeded:(nonnull id<MTLBlitCommandEncoder>)blitEncoder commandBuffer:(nonnull id<MTLCommandBuffer>)commandBuffer;

@property (retain, nonatomic, readwrite, nonnull) id<MTLDevice> device;

Expand Down
Loading

0 comments on commit 2b74354

Please sign in to comment.