Skip to content

Commit

Permalink
chore: This is v1.21.1
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartcarnie committed May 15, 2022
1 parent b561cab commit c1ef44b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 54 deletions.
4 changes: 2 additions & 2 deletions OpenEmuShaders.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@
"$(PROJECT_DIR)/3rdparty/SPIRV-Tools/build/source",
"$(PROJECT_DIR)/3rdparty/SPIRV-Tools/build/source/opt",
);
MARKETING_VERSION = 1.20.3;
MARKETING_VERSION = 1.21.1;
PRODUCT_BUNDLE_IDENTIFIER = org.openemu.OpenEmuShaders;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -808,7 +808,7 @@
"$(PROJECT_DIR)/3rdparty/SPIRV-Tools/build/source",
"$(PROJECT_DIR)/3rdparty/SPIRV-Tools/build/source/opt",
);
MARKETING_VERSION = 1.20.3;
MARKETING_VERSION = 1.21.1;
PRODUCT_BUNDLE_IDENTIFIER = org.openemu.OpenEmuShaders;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
6 changes: 2 additions & 4 deletions Source/OEShaderPassCompiler.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,15 @@ - (NSData *)irForPass:(ShaderPass *)pass ofType:(ShaderType)type options:(Shader
NSString *source = type == ShaderTypeVertex ? pass.source.vertexSource : pass.source.fragmentSource;
SlangCompiler *c = [SlangCompiler new];
NSError *err;
ShaderProgram *prog = [c compileSource:source ofType:type error:&err];
if (prog == nil || err != nil) {
data = [c compileSource:source ofType:type error:&err];
if (data == nil || err != nil) {
if (error != nil)
{
*error = err;
}
return nil;
}

data = [NSData dataWithBytes:(void *)prog.spirv length:prog.spirvLengthBytes];

if (filename != nil)
{
[data writeToURL:filename atomically:YES];
Expand Down
10 changes: 1 addition & 9 deletions Source/SlangCompiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,12 @@ typedef NS_ENUM(NSUInteger, ShaderType)
ShaderTypeFragment,
};

@interface ShaderProgram : NSObject

@property (nonatomic, readonly) SpvId const *spirv;
@property (nonatomic, readonly) size_t spirvLength;
@property (nonatomic, readonly) size_t spirvLengthBytes;

@end

/*!
* SlangCompiler is responsible for compiling a glsl shader program into SPIRV
*/
@interface SlangCompiler : NSObject

- (ShaderProgram *)compileSource:(NSString *)source ofType:(ShaderType)type error:(NSError **)error;
- (NSData *)compileSource:(NSString *)source ofType:(ShaderType)type error:(NSError **)error;

@end

Expand Down
60 changes: 21 additions & 39 deletions Source/SlangCompiler.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
#import <CSPIRVTools/CSPIRVTools.h>
#include "OELogging.h"

__attribute__((constructor))
static void initialize_glslang()
{
glslang_initialize_process();
}

@interface ShaderProgram()
- (instancetype)initWithData:(NSData *)spirv;
@end

@implementation SlangCompiler

Expand All @@ -42,7 +44,7 @@ - (instancetype)init
return self;
}

- (ShaderProgram *)compileSource:(NSString *)source ofType:(ShaderType)type error:(NSError **)error
- (NSData *)compileSource:(NSString *)source ofType:(ShaderType)type error:(NSError **)error
{
switch (type)
{
Expand All @@ -53,7 +55,7 @@ - (ShaderProgram *)compileSource:(NSString *)source ofType:(ShaderType)type erro
}
}

- (ShaderProgram *)compileSPIRV:(NSString *)src stage:(glslang_stage_t)stage error:(NSError **)error
- (NSData *)compileSPIRV:(NSString *)src stage:(glslang_stage_t)stage error:(NSError **)error
{
const int DEFAULT_VERSION = 110;

Expand Down Expand Up @@ -95,6 +97,7 @@ - (ShaderProgram *)compileSPIRV:(NSString *)src stage:(glslang_stage_t)stage err
}

os_log_error(OE_LOG_DEFAULT, "error preprocessing shader: %{public}s", msg);
glslang_shader_delete(shader);
return nil;
}

Expand All @@ -114,6 +117,7 @@ - (ShaderProgram *)compileSPIRV:(NSString *)src stage:(glslang_stage_t)stage err
}

os_log_error(OE_LOG_DEFAULT, "error parsing shader info log: %{public}s", infoLog);
glslang_shader_delete(shader);
return nil;
}

Expand All @@ -138,6 +142,9 @@ - (ShaderProgram *)compileSPIRV:(NSString *)src stage:(glslang_stage_t)stage err

os_log_error(OE_LOG_DEFAULT, "error linking shader info log: %{public}s", infoLog);
os_log_error(OE_LOG_DEFAULT, "error linking shader info debug log: %{public}s", infoDebugLog);

glslang_program_delete(program);
glslang_shader_delete(shader);
return nil;
}

Expand All @@ -155,7 +162,11 @@ - (ShaderProgram *)compileSPIRV:(NSString *)src stage:(glslang_stage_t)stage err
uint32_t ** spirv = nil;
size_t spirv_len_bytes = 0;

spvt_vector vec = spvt_optimizer_run(opt, glslang_program_SPIRV_get_ptr(program), glslang_program_SPIRV_get_size(program));
spv_optimizer_options opts = spvOptimizerOptionsCreate();
spvOptimizerOptionsSetRunValidator(opts, false);
spvt_vector vec = spvt_optimizer_run_options(opt, glslang_program_SPIRV_get_ptr(program), glslang_program_SPIRV_get_size(program), opts);
spvOptimizerOptionsDestroy(opts);

if (vec != nil)
{
spirv_len_bytes = spvt_vector_get_size(vec);
Expand All @@ -170,40 +181,11 @@ - (ShaderProgram *)compileSPIRV:(NSString *)src stage:(glslang_stage_t)stage err
glslang_program_SPIRV_get(program, (unsigned int *)spirv);
}

NSData *data = [[NSData alloc] initWithBytesNoCopy:spirv length:spirv_len_bytes freeWhenDone:YES];

return [[ShaderProgram alloc] initWithData:data];
}

@end

@implementation ShaderProgram
{
NSData *_spirv;
}

- (instancetype)initWithData:(NSData *)spirv
{
self = [super init];

_spirv = spirv;
spvt_optimizer_destroy(opt);
glslang_program_delete(program);
glslang_shader_delete(shader);

return self;
}

- (SpvId const *)spirv
{
return (SpvId const *)_spirv.bytes;
}

- (size_t)spirvLength
{
return _spirv.length / sizeof(uint32_t);
}

- (size_t)spirvLengthBytes
{
return _spirv.length;
return [[NSData alloc] initWithBytesNoCopy:spirv length:spirv_len_bytes freeWhenDone:YES];
}

@end
Expand Down

0 comments on commit c1ef44b

Please sign in to comment.