Handle shader compilation error
This commit is contained in:
@@ -938,6 +938,7 @@ extern size_t fragment_functions_size;
|
||||
extern struct { char *key; name_id value; } *hash;
|
||||
extern int expression_index;
|
||||
extern int statement_index;
|
||||
extern bool kong_error;
|
||||
|
||||
uint64_t _next_variable_id;
|
||||
size_t _allocated_globals_size;
|
||||
@@ -955,6 +956,7 @@ int _expression_index;
|
||||
int _statement_index;
|
||||
void hlsl_export2(char **vs, char **fs, api_kind d3d, bool debug);
|
||||
void spirv_export2(char **vs, char **fs, int *vs_size, int *fs_size, bool debug);
|
||||
void console_info(char *s);
|
||||
|
||||
static struct { char *key; name_id value; } *_clone_hash(struct { char *key; name_id value; } *hash) {
|
||||
struct { char *key; name_id value; } *clone = NULL;
|
||||
@@ -1008,10 +1010,16 @@ void gpu_create_shaders_from_kong(char *kong, char **vs, char **fs, int *vs_size
|
||||
statement_index = _statement_index;
|
||||
}
|
||||
|
||||
kong_error = false;
|
||||
char *from = "";
|
||||
tokens tokens = tokenize(from, kong);
|
||||
parse(from, &tokens);
|
||||
resolve_types();
|
||||
if (kong_error) {
|
||||
console_info("Warning: Shader compilation failed");
|
||||
free(tokens.t);
|
||||
return;
|
||||
}
|
||||
allocate_globals();
|
||||
for (function_id i = 0; get_function(i) != NULL; ++i) {
|
||||
compile_function_block(&get_function(i)->code, get_function(i)->block);
|
||||
|
||||
@@ -23,6 +23,10 @@ static void debug_break(void) {
|
||||
#endif
|
||||
}
|
||||
|
||||
////
|
||||
bool kong_error = false;
|
||||
////
|
||||
|
||||
void error_args(debug_context context, const char *message, va_list args) {
|
||||
char buffer[4096];
|
||||
|
||||
@@ -37,15 +41,20 @@ void error_args(debug_context context, const char *message, va_list args) {
|
||||
|
||||
kong_log_args(LOG_LEVEL_ERROR, buffer, args);
|
||||
|
||||
debug_break();
|
||||
|
||||
exit(1);
|
||||
////
|
||||
// debug_break();
|
||||
// exit(1);
|
||||
kong_error = true;
|
||||
////
|
||||
}
|
||||
|
||||
void error_args_no_context(const char *message, va_list args) {
|
||||
kong_log_args(LOG_LEVEL_ERROR, message, args);
|
||||
|
||||
exit(1);
|
||||
////
|
||||
// exit(1);
|
||||
kong_error = true;
|
||||
////
|
||||
}
|
||||
|
||||
void error(debug_context context, const char *message, ...) {
|
||||
|
||||
@@ -18,7 +18,8 @@ let uniforms_pos_unpack: f32 = 1.0;
|
||||
let uniforms_tex_unpack: f32 = 1.0;
|
||||
|
||||
function uniforms_set_context_consts(context: shader_context_t, bind_params: string[]) {
|
||||
if (context.constants != null) {
|
||||
// On shader compile error, _.constants.length will be 0
|
||||
if (context.constants != null && context.constants.length == context._.constants.length) {
|
||||
for (let i: i32 = 0; i < context.constants.length; ++i) {
|
||||
let c: shader_const_t = context.constants[i];
|
||||
uniforms_set_context_const(context._.constants[i], c);
|
||||
@@ -37,7 +38,7 @@ function uniforms_set_context_consts(context: shader_context_t, bind_params: str
|
||||
}
|
||||
|
||||
// Texture links
|
||||
if (context.texture_units != null) {
|
||||
if (context.texture_units != null && context.texture_units.length == context._.tex_units.length) {
|
||||
for (let j: i32 = 0; j < context.texture_units.length; ++j) {
|
||||
let tulink: string = context.texture_units[j].link;
|
||||
if (tulink == null) {
|
||||
@@ -94,7 +95,7 @@ function uniforms_set_context_consts(context: shader_context_t, bind_params: str
|
||||
}
|
||||
|
||||
function uniforms_set_obj_consts(context: shader_context_t, object: object_t) {
|
||||
if (context.constants != null) {
|
||||
if (context.constants != null && context.constants.length == context._.constants.length) {
|
||||
for (let i: i32 = 0; i < context.constants.length; ++i) {
|
||||
let c: shader_const_t = context.constants[i];
|
||||
uniforms_set_obj_const(object, context._.constants[i], c);
|
||||
@@ -103,7 +104,7 @@ function uniforms_set_obj_consts(context: shader_context_t, object: object_t) {
|
||||
|
||||
// Texture object constants
|
||||
// External
|
||||
if (uniforms_tex_links != null && context.texture_units != null) {
|
||||
if (uniforms_tex_links != null && context.texture_units != null && context.texture_units.length == context._.tex_units.length) {
|
||||
for (let j: i32 = 0; j < context.texture_units.length; ++j) {
|
||||
let tu: tex_unit_t = context.texture_units[j];
|
||||
if (tu.link == null) {
|
||||
@@ -123,10 +124,11 @@ function uniforms_bind_render_target(rt: render_target_t, context: shader_contex
|
||||
return;
|
||||
}
|
||||
|
||||
let tus: tex_unit_t[] = context.texture_units;
|
||||
for (let j: i32 = 0; j < tus.length; ++j) { // Set texture
|
||||
if (sampler_id == tus[j].name) {
|
||||
gpu_set_texture(context._.tex_units[j], rt._image);
|
||||
if (context.texture_units != null && context.texture_units.length == context._.tex_units.length) {
|
||||
for (let j: i32 = 0; j < context.texture_units.length; ++j) { // Set texture
|
||||
if (sampler_id == context.texture_units[j].name) {
|
||||
gpu_set_texture(context._.tex_units[j], rt._image);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user