kong test
This commit is contained in:
@@ -153,10 +153,17 @@ void draw_init(buffer_t *image_vert, buffer_t *image_frag, buffer_t *colored_ver
|
||||
image_pipeline.blend_destination = IRON_GPU_BLEND_INV_SOURCE_ALPHA;
|
||||
image_pipeline.alpha_blend_source = IRON_GPU_BLEND_ONE;
|
||||
image_pipeline.alpha_blend_destination = IRON_GPU_BLEND_INV_SOURCE_ALPHA;
|
||||
|
||||
image_pipeline.kong = true;
|
||||
|
||||
iron_gpu_pipeline_compile(&image_pipeline);
|
||||
|
||||
image_tex_unit = iron_gpu_pipeline_get_texture_unit(&image_pipeline, "tex");
|
||||
image_tex_unit.stages[IRON_GPU_SHADER_TYPE_FRAGMENT] = 0;
|
||||
|
||||
image_proj_loc = iron_gpu_pipeline_get_constant_location(&image_pipeline, "P");
|
||||
image_proj_loc.impl.vertexOffset = 0;
|
||||
image_proj_loc.impl.fragmentOffset = -1;
|
||||
|
||||
gpu_vertex_buffer_init(&image_vertex_buffer, DRAW_BUFFER_SIZE * 4, &structure, GPU_USAGE_DYNAMIC);
|
||||
image_rect_verts = gpu_vertex_buffer_lock_all(&image_vertex_buffer);
|
||||
@@ -248,9 +255,17 @@ void draw_init(buffer_t *image_vert, buffer_t *image_frag, buffer_t *colored_ver
|
||||
text_pipeline.blend_destination = IRON_GPU_BLEND_INV_SOURCE_ALPHA;
|
||||
text_pipeline.alpha_blend_source = IRON_GPU_BLEND_SOURCE_ALPHA;
|
||||
text_pipeline.alpha_blend_destination = IRON_GPU_BLEND_INV_SOURCE_ALPHA;
|
||||
|
||||
text_pipeline.kong = true;
|
||||
|
||||
iron_gpu_pipeline_compile(&text_pipeline);
|
||||
|
||||
text_tex_unit = iron_gpu_pipeline_get_texture_unit(&text_pipeline, "tex");
|
||||
text_tex_unit.stages[IRON_GPU_SHADER_TYPE_FRAGMENT] = 0;
|
||||
|
||||
text_proj_loc = iron_gpu_pipeline_get_constant_location(&text_pipeline, "P");
|
||||
text_proj_loc.impl.vertexOffset = 0;
|
||||
text_proj_loc.impl.fragmentOffset = -1;
|
||||
|
||||
iron_gpu_pipeline_init(&text_pipeline_rt);
|
||||
text_pipeline_rt.input_layout = &structure;
|
||||
@@ -260,6 +275,9 @@ void draw_init(buffer_t *image_vert, buffer_t *image_frag, buffer_t *colored_ver
|
||||
text_pipeline_rt.blend_destination = IRON_GPU_BLEND_INV_SOURCE_ALPHA;
|
||||
text_pipeline_rt.alpha_blend_source = IRON_GPU_BLEND_ONE;
|
||||
text_pipeline_rt.alpha_blend_destination = IRON_GPU_BLEND_INV_SOURCE_ALPHA;
|
||||
|
||||
text_pipeline_rt.kong = true;
|
||||
|
||||
iron_gpu_pipeline_compile(&text_pipeline_rt);
|
||||
|
||||
gpu_vertex_buffer_init(&text_vertex_buffer, DRAW_BUFFER_SIZE * 4, &structure, GPU_USAGE_DYNAMIC);
|
||||
|
||||
@@ -24,6 +24,10 @@ void cstyle_write_opcode(char *code, size_t *offset, opcode *o, type_string_func
|
||||
*offset += sprintf(&code[*offset], "%s _%" PRIu64 ";\n", type_string(o->op_var.var.type.type), o->op_var.var.index);
|
||||
}
|
||||
break;
|
||||
case OPCODE_NEGATE:
|
||||
indent(code, offset, *indentation);
|
||||
*offset += sprintf(&code[*offset], "%s _%" PRIu64 " = -_%" PRIu64 ";\n", type_string(o->op_negate.to.type.type), o->op_negate.to.index, o->op_negate.from.index);
|
||||
break;
|
||||
case OPCODE_NOT:
|
||||
indent(code, offset, *indentation);
|
||||
*offset += sprintf(&code[*offset], "%s _%" PRIu64 " = !_%" PRIu64 ";\n", type_string(o->op_not.to.type.type), o->op_not.to.index, o->op_not.from.index);
|
||||
|
||||
@@ -380,8 +380,16 @@ variable emit_expression(opcodes *code, block *parent, expression *e) {
|
||||
error(context, "not implemented");
|
||||
case OPERATOR_LESS_EQUAL:
|
||||
error(context, "not implemented");
|
||||
case OPERATOR_MINUS:
|
||||
error(context, "not implemented");
|
||||
case OPERATOR_MINUS: {
|
||||
variable v = emit_expression(code, parent, e->unary.right);
|
||||
opcode o;
|
||||
o.type = OPCODE_NEGATE;
|
||||
o.size = OP_SIZE(o, op_negate);
|
||||
o.op_negate.from = v;
|
||||
o.op_negate.to = allocate_variable(v.type, VARIABLE_LOCAL);
|
||||
emit_op(code, &o);
|
||||
return o.op_negate.to;
|
||||
}
|
||||
case OPERATOR_PLUS:
|
||||
error(context, "not implemented");
|
||||
case OPERATOR_DIVIDE:
|
||||
|
||||
@@ -18,6 +18,7 @@ typedef struct opcode {
|
||||
enum {
|
||||
OPCODE_VAR,
|
||||
OPCODE_NOT,
|
||||
OPCODE_NEGATE,
|
||||
OPCODE_STORE_VARIABLE,
|
||||
OPCODE_SUB_AND_STORE_VARIABLE,
|
||||
OPCODE_ADD_AND_STORE_VARIABLE,
|
||||
@@ -62,6 +63,10 @@ typedef struct opcode {
|
||||
struct {
|
||||
variable var;
|
||||
} op_var;
|
||||
struct {
|
||||
variable from;
|
||||
variable to;
|
||||
} op_negate;
|
||||
struct {
|
||||
variable from;
|
||||
variable to;
|
||||
|
||||
@@ -92,6 +92,24 @@ static void add_func_float_float(char *name) {
|
||||
f->block = NULL;
|
||||
}
|
||||
|
||||
static void add_func_float_float_float(char *name) {
|
||||
function_id func = add_function(add_name(name));
|
||||
function *f = get_function(func);
|
||||
init_type_ref(&f->return_type, add_name("float"));
|
||||
f->return_type.type = find_type_by_ref(&f->return_type);
|
||||
|
||||
f->parameter_names[0] = add_name("a");
|
||||
init_type_ref(&f->parameter_types[0], add_name("float"));
|
||||
f->parameter_types[0].type = find_type_by_ref(&f->parameter_types[0]);
|
||||
|
||||
f->parameter_names[1] = add_name("b");
|
||||
init_type_ref(&f->parameter_types[1], add_name("float"));
|
||||
f->parameter_types[1].type = find_type_by_ref(&f->parameter_types[1]);
|
||||
|
||||
f->parameters_size = 2;
|
||||
f->block = NULL;
|
||||
}
|
||||
|
||||
static void add_func_float_float2(char *name) {
|
||||
function_id func = add_function(add_name(name));
|
||||
function *f = get_function(func);
|
||||
@@ -585,6 +603,10 @@ void functions_init(void) {
|
||||
add_func_float3_float3("normalize");
|
||||
add_func_float_float("sin");
|
||||
add_func_float_float("cos");
|
||||
add_func_float_float("asin");
|
||||
add_func_float_float("acos");
|
||||
add_func_float_float("atan");
|
||||
add_func_float_float_float("atan2");
|
||||
add_func_float_float2("length");
|
||||
add_func_uint3("ray_index");
|
||||
add_func_float3("ray_dimensions");
|
||||
|
||||
@@ -142,6 +142,13 @@ function shader_context_compile(raw: shader_context_t): shader_context_t {
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
if (starts_with(raw.fragment_shader, "_")) {
|
||||
raw.fragment_shader = substring(raw.fragment_shader, 1, raw.fragment_shader.length);
|
||||
raw.vertex_shader = substring(raw.vertex_shader, 1, raw.vertex_shader.length);
|
||||
raw._.pipe_state.kong = true;
|
||||
}
|
||||
|
||||
///if arm_embed
|
||||
raw._.pipe_state.fragment_shader = sys_get_shader(raw.fragment_shader);
|
||||
raw._.pipe_state.vertex_shader = sys_get_shader(raw.vertex_shader);
|
||||
@@ -158,20 +165,46 @@ function shader_context_compile(raw: shader_context_t): shader_context_t {
|
||||
return shader_context_finish_compile(raw);
|
||||
}
|
||||
|
||||
function shader_context_type_offset(t: string): i32 {
|
||||
if (t == "int") {
|
||||
return 4;
|
||||
}
|
||||
if (t == "float") {
|
||||
return 4;
|
||||
}
|
||||
if (t == "vec2") {
|
||||
return 8;
|
||||
}
|
||||
if (t == "vec3") {
|
||||
return 12;
|
||||
}
|
||||
if (t == "vec4") {
|
||||
return 16;
|
||||
}
|
||||
if (t == "mat4") {
|
||||
return 64;
|
||||
}
|
||||
if (t == "mat3") {
|
||||
return 36;
|
||||
}
|
||||
}
|
||||
|
||||
function shader_context_finish_compile(raw: shader_context_t): shader_context_t {
|
||||
gpu_compile_pipeline(raw._.pipe_state);
|
||||
|
||||
if (raw.constants != null) {
|
||||
let offset: i32 = 0;
|
||||
for (let i: i32 = 0; i < raw.constants.length; ++i) {
|
||||
let c: shader_const_t = raw.constants[i];
|
||||
shader_context_add_const(raw, c);
|
||||
shader_context_add_const(raw, c, offset);
|
||||
offset += shader_context_type_offset(c.type);
|
||||
}
|
||||
}
|
||||
|
||||
if (raw.texture_units != null) {
|
||||
for (let i: i32 = 0; i < raw.texture_units.length; ++i) {
|
||||
let tu: tex_unit_t = raw.texture_units[i];
|
||||
shader_context_add_tex(raw, tu);
|
||||
shader_context_add_tex(raw, tu, i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -343,12 +376,21 @@ function shader_context_get_tex_format(s: string): tex_format_t {
|
||||
return tex_format_t.RGBA32;
|
||||
}
|
||||
|
||||
function shader_context_add_const(raw: shader_context_t, c: shader_const_t) {
|
||||
array_push(raw._.constants, gpu_get_constant_location(raw._.pipe_state, c.name));
|
||||
function shader_context_add_const(raw: shader_context_t, c: shader_const_t, offset: i32) {
|
||||
let cl: iron_gpu_constant_location_t = gpu_get_constant_location(raw._.pipe_state, c.name);
|
||||
if (raw._.pipe_state.kong) {
|
||||
let ptr: gpu_constant_location_impl_t = ADDRESS(cl.impl);
|
||||
ptr.vertexOffset = offset;
|
||||
ptr.fragmentOffset = offset;
|
||||
}
|
||||
array_push(raw._.constants, cl);
|
||||
}
|
||||
|
||||
function shader_context_add_tex(raw: shader_context_t, tu: tex_unit_t) {
|
||||
let unit: any = gpu_get_texture_unit(raw._.pipe_state, tu.name);
|
||||
function shader_context_add_tex(raw: shader_context_t, tu: tex_unit_t, i: i32) {
|
||||
let unit: iron_gpu_texture_unit_t = gpu_get_texture_unit(raw._.pipe_state, tu.name);
|
||||
if (raw._.pipe_state.kong) {
|
||||
ARRAY_ACCESS(unit.stages, IRON_GPU_SHADER_TYPE_FRAGMENT) = i;
|
||||
}
|
||||
array_push(raw._.tex_units, unit);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user