mirror of
https://github.com/godotengine/godot.git
synced 2025-12-07 22:00:10 +00:00
Add shader baker to project exporter.
Metal Support contributed by Migeran (https://migeran.com) and Stuart Carnie. Co-authored-by: Stuart Carnie <stuart.carnie@gmail.com> Co-authored-by: Gergely Kis <gergely.kis@migeran.com>
This commit is contained in:
parent
99f5a3d665
commit
5a30a7e7cd
112 changed files with 5786 additions and 4203 deletions
|
|
@ -53,6 +53,7 @@
|
|||
#import "metal_utils.h"
|
||||
#import "pixel_formats.h"
|
||||
#import "rendering_device_driver_metal.h"
|
||||
#import "rendering_shader_container_metal.h"
|
||||
|
||||
#import <os/signpost.h>
|
||||
|
||||
|
|
@ -1941,7 +1942,11 @@ void ShaderCacheEntry::notify_free() const {
|
|||
}
|
||||
|
||||
@interface MDLibrary ()
|
||||
- (instancetype)initWithCacheEntry:(ShaderCacheEntry *)entry;
|
||||
- (instancetype)initWithCacheEntry:(ShaderCacheEntry *)entry
|
||||
#ifdef DEV_ENABLED
|
||||
source:(NSString *)source;
|
||||
#endif
|
||||
;
|
||||
@end
|
||||
|
||||
/// Loads the MTLLibrary when the library is first accessed.
|
||||
|
|
@ -1975,6 +1980,18 @@ void ShaderCacheEntry::notify_free() const {
|
|||
options:(MTLCompileOptions *)options;
|
||||
@end
|
||||
|
||||
@interface MDBinaryLibrary : MDLibrary {
|
||||
id<MTLLibrary> _library;
|
||||
NSError *_error;
|
||||
}
|
||||
- (instancetype)initWithCacheEntry:(ShaderCacheEntry *)entry
|
||||
device:(id<MTLDevice>)device
|
||||
#ifdef DEV_ENABLED
|
||||
source:(NSString *)source
|
||||
#endif
|
||||
data:(dispatch_data_t)data;
|
||||
@end
|
||||
|
||||
@implementation MDLibrary
|
||||
|
||||
+ (instancetype)newLibraryWithCacheEntry:(ShaderCacheEntry *)entry
|
||||
|
|
@ -1992,6 +2009,26 @@ void ShaderCacheEntry::notify_free() const {
|
|||
}
|
||||
}
|
||||
|
||||
+ (instancetype)newLibraryWithCacheEntry:(ShaderCacheEntry *)entry
|
||||
device:(id<MTLDevice>)device
|
||||
#ifdef DEV_ENABLED
|
||||
source:(NSString *)source
|
||||
#endif
|
||||
data:(dispatch_data_t)data {
|
||||
return [[MDBinaryLibrary alloc] initWithCacheEntry:entry
|
||||
device:device
|
||||
#ifdef DEV_ENABLED
|
||||
source:source
|
||||
#endif
|
||||
data:data];
|
||||
}
|
||||
|
||||
#ifdef DEV_ENABLED
|
||||
- (NSString *)originalSource {
|
||||
return _original_source;
|
||||
}
|
||||
#endif
|
||||
|
||||
- (id<MTLLibrary>)library {
|
||||
CRASH_NOW_MSG("Not implemented");
|
||||
return nil;
|
||||
|
|
@ -2005,10 +2042,17 @@ void ShaderCacheEntry::notify_free() const {
|
|||
- (void)setLabel:(NSString *)label {
|
||||
}
|
||||
|
||||
- (instancetype)initWithCacheEntry:(ShaderCacheEntry *)entry {
|
||||
- (instancetype)initWithCacheEntry:(ShaderCacheEntry *)entry
|
||||
#ifdef DEV_ENABLED
|
||||
source:(NSString *)source
|
||||
#endif
|
||||
{
|
||||
self = [super init];
|
||||
_entry = entry;
|
||||
_entry->library = self;
|
||||
#ifdef DEV_ENABLED
|
||||
_original_source = source;
|
||||
#endif
|
||||
return self;
|
||||
}
|
||||
|
||||
|
|
@ -2024,7 +2068,11 @@ void ShaderCacheEntry::notify_free() const {
|
|||
device:(id<MTLDevice>)device
|
||||
source:(NSString *)source
|
||||
options:(MTLCompileOptions *)options {
|
||||
self = [super initWithCacheEntry:entry];
|
||||
self = [super initWithCacheEntry:entry
|
||||
#ifdef DEV_ENABLED
|
||||
source:source
|
||||
#endif
|
||||
];
|
||||
_complete = false;
|
||||
_ready = false;
|
||||
|
||||
|
|
@ -2076,7 +2124,11 @@ void ShaderCacheEntry::notify_free() const {
|
|||
device:(id<MTLDevice>)device
|
||||
source:(NSString *)source
|
||||
options:(MTLCompileOptions *)options {
|
||||
self = [super initWithCacheEntry:entry];
|
||||
self = [super initWithCacheEntry:entry
|
||||
#ifdef DEV_ENABLED
|
||||
source:source
|
||||
#endif
|
||||
];
|
||||
_device = device;
|
||||
_source = source;
|
||||
_options = options;
|
||||
|
|
@ -2121,3 +2173,36 @@ void ShaderCacheEntry::notify_free() const {
|
|||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation MDBinaryLibrary
|
||||
|
||||
- (instancetype)initWithCacheEntry:(ShaderCacheEntry *)entry
|
||||
device:(id<MTLDevice>)device
|
||||
#ifdef DEV_ENABLED
|
||||
source:(NSString *)source
|
||||
#endif
|
||||
data:(dispatch_data_t)data {
|
||||
self = [super initWithCacheEntry:entry
|
||||
#ifdef DEV_ENABLED
|
||||
source:source
|
||||
#endif
|
||||
];
|
||||
NSError *error = nil;
|
||||
_library = [device newLibraryWithData:data error:&error];
|
||||
if (error != nil) {
|
||||
_error = error;
|
||||
NSString *desc = [error description];
|
||||
ERR_PRINT(vformat("Unable to load shader library: %s", desc.UTF8String));
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id<MTLLibrary>)library {
|
||||
return _library;
|
||||
}
|
||||
|
||||
- (NSError *)error {
|
||||
return _error;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue