mirror of
https://github.com/armory3d/armorpaint.git
synced 2026-10-02 02:54:34 +08:00
base: remove numbered shader built-ins
This commit is contained in:
+61
-125
@@ -771,6 +771,37 @@ opcode *emit_op(opcodes *code, opcode *o) {
|
||||
return (opcode *)location;
|
||||
}
|
||||
|
||||
static bool is_component_wise(name_id func) {
|
||||
static const char *names[] = {"abs", "frac", "floor", "ceil", "round", "trunc", "sin", "cos", "tan", "asin", "acos", "atan",
|
||||
"atan2", "sinh", "cosh", "tanh", "exp", "log", "sign", "sqrt", "rsqrt", "radians", "degrees", "saturate",
|
||||
"ddx", "ddy", "min", "max", "clamp", "step", "pow", "lerp", "smoothstep", "normalize"};
|
||||
for (size_t i = 0; i < sizeof(names) / sizeof(names[0]); ++i) {
|
||||
if (func == add_name((char *)names[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static variable emit_splat(opcodes *code, variable scalar, type_id to) {
|
||||
type_ref t;
|
||||
init_type_ref(&t, NO_NAME);
|
||||
t.type = to;
|
||||
variable v = allocate_variable(t, VARIABLE_INTERNAL);
|
||||
|
||||
opcode o;
|
||||
o.type = OPCODE_CALL;
|
||||
o.size = OP_SIZE(o, op_call);
|
||||
o.op_call.func = get_type(to)->name;
|
||||
o.op_call.var = v;
|
||||
o.op_call.parameters_size = (uint8_t)vector_size(to);
|
||||
for (uint8_t i = 0; i < o.op_call.parameters_size; ++i) {
|
||||
o.op_call.parameters[i] = scalar;
|
||||
}
|
||||
emit_op(code, &o);
|
||||
return v;
|
||||
}
|
||||
|
||||
variable emit_expression(opcodes *code, block *parent, expression *e) {
|
||||
switch (e->kind) {
|
||||
case EXPRESSION_BINARY: {
|
||||
@@ -1149,8 +1180,12 @@ variable emit_expression(opcodes *code, block *parent, expression *e) {
|
||||
|
||||
debug_context context = {0};
|
||||
check(e->call.parameters.size <= sizeof(o.op_call.parameters) / sizeof(variable), context, "Call parameters missized");
|
||||
bool splat = is_component_wise(e->call.func_name) && is_vector(t.type);
|
||||
for (size_t i = 0; i < e->call.parameters.size; ++i) {
|
||||
o.op_call.parameters[i] = emit_expression(code, parent, e->call.parameters.e[i]);
|
||||
if (splat && o.op_call.parameters[i].type.type == float_id) {
|
||||
o.op_call.parameters[i] = emit_splat(code, o.op_call.parameters[i], t.type);
|
||||
}
|
||||
}
|
||||
o.op_call.parameters_size = (uint8_t)e->call.parameters.size;
|
||||
|
||||
@@ -1633,84 +1668,6 @@ void check_function(bool test, debug_context context, const char *message, ...)
|
||||
}
|
||||
}
|
||||
|
||||
static void add_func_float2_float2(char *name) {
|
||||
function_id func = add_function(add_name(name));
|
||||
function *f = get_function(func);
|
||||
init_type_ref(&f->return_type, add_name("float2"));
|
||||
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("float2"));
|
||||
f->parameter_types[0].type = find_type_by_ref(&f->parameter_types[0]);
|
||||
f->parameters_size = 1;
|
||||
f->block = NULL;
|
||||
}
|
||||
|
||||
static void add_func_float3_float3_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("float3"));
|
||||
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("float3"));
|
||||
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->parameter_names[2] = add_name("c");
|
||||
init_type_ref(&f->parameter_types[2], add_name("float"));
|
||||
f->parameter_types[2].type = find_type_by_ref(&f->parameter_types[2]);
|
||||
|
||||
f->parameters_size = 3;
|
||||
f->block = NULL;
|
||||
}
|
||||
|
||||
static void add_func_float3_float3_float3_float(char *name) {
|
||||
function_id func = add_function(add_name(name));
|
||||
function *f = get_function(func);
|
||||
init_type_ref(&f->return_type, add_name("float3"));
|
||||
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("float3"));
|
||||
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("float3"));
|
||||
f->parameter_types[1].type = find_type_by_ref(&f->parameter_types[1]);
|
||||
|
||||
f->parameter_names[2] = add_name("c");
|
||||
init_type_ref(&f->parameter_types[2], add_name("float"));
|
||||
f->parameter_types[2].type = find_type_by_ref(&f->parameter_types[2]);
|
||||
|
||||
f->parameters_size = 3;
|
||||
f->block = NULL;
|
||||
}
|
||||
|
||||
static void add_func_float4_float4_float4_float(char *name) {
|
||||
function_id func = add_function(add_name(name));
|
||||
function *f = get_function(func);
|
||||
init_type_ref(&f->return_type, add_name("float4"));
|
||||
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("float4"));
|
||||
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("float4"));
|
||||
f->parameter_types[1].type = find_type_by_ref(&f->parameter_types[1]);
|
||||
|
||||
f->parameter_names[2] = add_name("c");
|
||||
init_type_ref(&f->parameter_types[2], add_name("float"));
|
||||
f->parameter_types[2].type = find_type_by_ref(&f->parameter_types[2]);
|
||||
|
||||
f->parameters_size = 3;
|
||||
f->block = NULL;
|
||||
}
|
||||
|
||||
static void add_func_float3x3_float3x3(char *name) {
|
||||
function_id func = add_function(add_name(name));
|
||||
function *f = get_function(func);
|
||||
@@ -1909,24 +1866,6 @@ static void add_func_float3_float3_float3(char *name) {
|
||||
f->block = NULL;
|
||||
}
|
||||
|
||||
static void add_func_float4_float4_float4(char *name) {
|
||||
function_id func = add_function(add_name(name));
|
||||
function *f = get_function(func);
|
||||
init_type_ref(&f->return_type, add_name("float4"));
|
||||
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("float4"));
|
||||
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("float4"));
|
||||
f->parameter_types[1].type = find_type_by_ref(&f->parameter_types[1]);
|
||||
|
||||
f->parameters_size = 2;
|
||||
f->block = NULL;
|
||||
}
|
||||
|
||||
static void add_func_void_uint_uint(char *name) {
|
||||
function_id func = add_function(add_name(name));
|
||||
function *f = get_function(func);
|
||||
@@ -2440,11 +2379,7 @@ void functions_init(void) {
|
||||
add_func_int("group_index");
|
||||
add_func_int("instance_id");
|
||||
add_func_int("vertex_id");
|
||||
|
||||
////
|
||||
// add_func_float3_float_float_float("lerp");
|
||||
add_func_float_float_float_float("lerp");
|
||||
////
|
||||
add_func_float3("world_ray_origin");
|
||||
add_func_float3("world_ray_direction");
|
||||
add_func_float("ray_length");
|
||||
@@ -2463,8 +2398,6 @@ void functions_init(void) {
|
||||
add_func_float3x3("object_to_world3x3");
|
||||
add_func_float3_float3_float3("reflect");
|
||||
add_func_uint("primitive_index");
|
||||
////
|
||||
// add_func_float3_float3("abs");
|
||||
add_func_float_float("abs");
|
||||
add_func_float_float("tan");
|
||||
add_func_float_float("log");
|
||||
@@ -2476,7 +2409,6 @@ void functions_init(void) {
|
||||
add_func_float_float("tanh");
|
||||
add_func_float_float("radians");
|
||||
add_func_float_float("degrees");
|
||||
////
|
||||
add_func_float_float_float("floor");
|
||||
add_func_float_float_float("ceil");
|
||||
add_func_float_float_float("round");
|
||||
@@ -2490,33 +2422,11 @@ void functions_init(void) {
|
||||
add_func_float_float_float("pow");
|
||||
add_func_float_float3_float3("dot");
|
||||
add_func_float3_float3_float3("cross");
|
||||
add_func_float3_float3("saturate3");
|
||||
add_func_float_float("saturate");
|
||||
add_func_float_float("ddx");
|
||||
add_func_float_float("ddy");
|
||||
|
||||
////
|
||||
|
||||
add_func_float2_float2("ddx2");
|
||||
add_func_float2_float2("ddy2");
|
||||
add_func_float3_float3("ddx3");
|
||||
add_func_float3_float3("ddy3");
|
||||
add_func_float3_float3_float_float("clamp3");
|
||||
add_func_float3_float3_float3("min3");
|
||||
add_func_float3_float3_float3("max3");
|
||||
add_func_float4_float4_float4("max4");
|
||||
add_func_float3_float3_float3("step3");
|
||||
add_func_float3_float3_float3("pow3");
|
||||
add_func_float3_float3_float3("floor3");
|
||||
add_func_float3_float3_float3("ceil3");
|
||||
add_func_float3_float3("abs3");
|
||||
add_func_float3_float3("frac3");
|
||||
add_func_float3_float3_float3_float("lerp3");
|
||||
add_func_float4_float4_float4_float("lerp4");
|
||||
add_func_float3x3_float3x3("transpose");
|
||||
|
||||
////
|
||||
|
||||
add_func_void_uint_uint("set_mesh_output_counts");
|
||||
|
||||
{
|
||||
@@ -5482,6 +5392,32 @@ void resolve_types_in_expression(statement *parent, expression *e) {
|
||||
}
|
||||
}
|
||||
|
||||
if (called != NULL && is_component_wise(e->call.func_name)) {
|
||||
uint32_t size = 1;
|
||||
for (size_t i = 0; i < e->call.parameters.size; ++i) {
|
||||
resolve_types_in_expression(parent, e->call.parameters.e[i]);
|
||||
type_id t = e->call.parameters.e[i]->type.type;
|
||||
if (is_vector_or_scalar(t) && vector_size(t) > size) {
|
||||
size = vector_size(t);
|
||||
}
|
||||
}
|
||||
for (size_t i = 0; i < e->call.parameters.size; ++i) {
|
||||
expression *p = e->call.parameters.e[i];
|
||||
type_id t = p->type.type;
|
||||
if (!is_vector_or_scalar(t) || (vector_size(t) != 1 && vector_size(t) != size)) {
|
||||
debug_context context = {0};
|
||||
error(context, "Parameter %zu of %s has type %s, expected a scalar or a vector of size %u", i, get_name(e->call.func_name),
|
||||
t == NO_TYPE ? "unknown" : get_name(get_type(t)->name), size);
|
||||
}
|
||||
type_ref to;
|
||||
init_type_ref(&to, NO_NAME);
|
||||
to.type = vector_to_size(float_id, vector_size(t));
|
||||
convert_to_float(p, to);
|
||||
}
|
||||
e->type.type = vector_to_size(float_id, size);
|
||||
break;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < e->call.parameters.size; ++i) {
|
||||
resolve_types_in_expression(parent, e->call.parameters.e[i]);
|
||||
if (called != NULL && i < called->parameters_size) {
|
||||
|
||||
@@ -1052,81 +1052,6 @@ static void write_functions(char *hlsl, size_t *offset, shader_stage stage, func
|
||||
check(o->op_call.parameters_size == 0, context, "primitive_index can not have a parameter");
|
||||
*offset += sprintf(&hlsl[*offset], "%s _%" PRIu64 " = PrimitiveIndex();\n", type_string(o->op_call.var.type.type), o->op_call.var.index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("saturate3")) {
|
||||
check(o->op_call.parameters_size == 1, context, "saturate3 requires one parameter");
|
||||
*offset += sprintf(&hlsl[*offset], "%s _%" PRIu64 " = saturate(_%" PRIu64 ");\n", type_string(o->op_call.var.type.type),
|
||||
o->op_call.var.index, o->op_call.parameters[0].index);
|
||||
}
|
||||
|
||||
////
|
||||
|
||||
else if (o->op_call.func == add_name("lerp3")) {
|
||||
*offset +=
|
||||
sprintf(&hlsl[*offset], "%s _%" PRIu64 " = lerp(_%" PRIu64 ", _%" PRIu64 ", _%" PRIu64 ");\n", type_string(o->op_call.var.type.type),
|
||||
o->op_call.var.index, o->op_call.parameters[0].index, o->op_call.parameters[1].index, o->op_call.parameters[2].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("lerp4")) {
|
||||
*offset +=
|
||||
sprintf(&hlsl[*offset], "%s _%" PRIu64 " = lerp(_%" PRIu64 ", _%" PRIu64 ", _%" PRIu64 ");\n", type_string(o->op_call.var.type.type),
|
||||
o->op_call.var.index, o->op_call.parameters[0].index, o->op_call.parameters[1].index, o->op_call.parameters[2].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("frac3")) {
|
||||
*offset += sprintf(&hlsl[*offset], "%s _%" PRIu64 " = frac(_%" PRIu64 ");\n", type_string(o->op_call.var.type.type), o->op_call.var.index,
|
||||
o->op_call.parameters[0].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("abs3")) {
|
||||
*offset += sprintf(&hlsl[*offset], "%s _%" PRIu64 " = abs(_%" PRIu64 ");\n", type_string(o->op_call.var.type.type), o->op_call.var.index,
|
||||
o->op_call.parameters[0].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("clamp3")) {
|
||||
*offset +=
|
||||
sprintf(&hlsl[*offset], "%s _%" PRIu64 " = clamp(_%" PRIu64 ", _%" PRIu64 ", _%" PRIu64 ");\n", type_string(o->op_call.var.type.type),
|
||||
o->op_call.var.index, o->op_call.parameters[0].index, o->op_call.parameters[1].index, o->op_call.parameters[2].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("min3")) {
|
||||
*offset += sprintf(&hlsl[*offset], "%s _%" PRIu64 " = min(_%" PRIu64 ", _%" PRIu64 ");\n", type_string(o->op_call.var.type.type),
|
||||
o->op_call.var.index, o->op_call.parameters[0].index, o->op_call.parameters[1].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("max3")) {
|
||||
*offset += sprintf(&hlsl[*offset], "%s _%" PRIu64 " = max(_%" PRIu64 ", _%" PRIu64 ");\n", type_string(o->op_call.var.type.type),
|
||||
o->op_call.var.index, o->op_call.parameters[0].index, o->op_call.parameters[1].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("max4")) {
|
||||
*offset += sprintf(&hlsl[*offset], "%s _%" PRIu64 " = max(_%" PRIu64 ", _%" PRIu64 ");\n", type_string(o->op_call.var.type.type),
|
||||
o->op_call.var.index, o->op_call.parameters[0].index, o->op_call.parameters[1].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("step3")) {
|
||||
*offset += sprintf(&hlsl[*offset], "%s _%" PRIu64 " = step(_%" PRIu64 ", _%" PRIu64 ");\n", type_string(o->op_call.var.type.type),
|
||||
o->op_call.var.index, o->op_call.parameters[0].index, o->op_call.parameters[1].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("pow3")) {
|
||||
*offset += sprintf(&hlsl[*offset], "%s _%" PRIu64 " = pow(_%" PRIu64 ", _%" PRIu64 ");\n", type_string(o->op_call.var.type.type),
|
||||
o->op_call.var.index, o->op_call.parameters[0].index, o->op_call.parameters[1].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("floor3")) {
|
||||
*offset += sprintf(&hlsl[*offset], "%s _%" PRIu64 " = floor(_%" PRIu64 ");\n", type_string(o->op_call.var.type.type), o->op_call.var.index,
|
||||
o->op_call.parameters[0].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("ceil3")) {
|
||||
*offset += sprintf(&hlsl[*offset], "%s _%" PRIu64 " = ceil(_%" PRIu64 ");\n", type_string(o->op_call.var.type.type), o->op_call.var.index,
|
||||
o->op_call.parameters[0].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("ddx2")) {
|
||||
*offset += sprintf(&hlsl[*offset], "%s _%" PRIu64 " = ddx(_%" PRIu64 ");\n", type_string(o->op_call.var.type.type), o->op_call.var.index,
|
||||
o->op_call.parameters[0].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("ddy2")) {
|
||||
*offset += sprintf(&hlsl[*offset], "%s _%" PRIu64 " = ddy(_%" PRIu64 ");\n", type_string(o->op_call.var.type.type), o->op_call.var.index,
|
||||
o->op_call.parameters[0].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("ddx3")) {
|
||||
*offset += sprintf(&hlsl[*offset], "%s _%" PRIu64 " = ddx(_%" PRIu64 ");\n", type_string(o->op_call.var.type.type), o->op_call.var.index,
|
||||
o->op_call.parameters[0].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("ddy3")) {
|
||||
*offset += sprintf(&hlsl[*offset], "%s _%" PRIu64 " = ddy(_%" PRIu64 ");\n", type_string(o->op_call.var.type.type), o->op_call.var.index,
|
||||
o->op_call.parameters[0].index);
|
||||
}
|
||||
|
||||
////
|
||||
|
||||
|
||||
@@ -650,76 +650,6 @@ static void write_functions(char *code, size_t *offset) {
|
||||
|
||||
////
|
||||
|
||||
else if (o->op_call.func == add_name("lerp3")) {
|
||||
*offset +=
|
||||
sprintf(&code[*offset], "%s _%" PRIu64 " = mix(_%" PRIu64 ", _%" PRIu64 ", _%" PRIu64 ");\n", type_string(o->op_call.var.type.type),
|
||||
o->op_call.var.index, o->op_call.parameters[0].index, o->op_call.parameters[1].index, o->op_call.parameters[2].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("lerp4")) {
|
||||
*offset +=
|
||||
sprintf(&code[*offset], "%s _%" PRIu64 " = mix(_%" PRIu64 ", _%" PRIu64 ", _%" PRIu64 ");\n", type_string(o->op_call.var.type.type),
|
||||
o->op_call.var.index, o->op_call.parameters[0].index, o->op_call.parameters[1].index, o->op_call.parameters[2].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("frac3")) {
|
||||
*offset += sprintf(&code[*offset], "%s _%" PRIu64 " = fract(_%" PRIu64 ");\n", type_string(o->op_call.var.type.type), o->op_call.var.index,
|
||||
o->op_call.parameters[0].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("abs3")) {
|
||||
*offset += sprintf(&code[*offset], "%s _%" PRIu64 " = abs(_%" PRIu64 ");\n", type_string(o->op_call.var.type.type), o->op_call.var.index,
|
||||
o->op_call.parameters[0].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("clamp3")) {
|
||||
*offset +=
|
||||
sprintf(&code[*offset], "%s _%" PRIu64 " = clamp(_%" PRIu64 ", _%" PRIu64 ", _%" PRIu64 ");\n", type_string(o->op_call.var.type.type),
|
||||
o->op_call.var.index, o->op_call.parameters[0].index, o->op_call.parameters[1].index, o->op_call.parameters[2].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("min3")) {
|
||||
*offset += sprintf(&code[*offset], "%s _%" PRIu64 " = min(_%" PRIu64 ", _%" PRIu64 ");\n", type_string(o->op_call.var.type.type),
|
||||
o->op_call.var.index, o->op_call.parameters[0].index, o->op_call.parameters[1].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("max3")) {
|
||||
*offset += sprintf(&code[*offset], "%s _%" PRIu64 " = max(_%" PRIu64 ", _%" PRIu64 ");\n", type_string(o->op_call.var.type.type),
|
||||
o->op_call.var.index, o->op_call.parameters[0].index, o->op_call.parameters[1].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("max4")) {
|
||||
*offset += sprintf(&code[*offset], "%s _%" PRIu64 " = max(_%" PRIu64 ", _%" PRIu64 ");\n", type_string(o->op_call.var.type.type),
|
||||
o->op_call.var.index, o->op_call.parameters[0].index, o->op_call.parameters[1].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("step3")) {
|
||||
*offset += sprintf(&code[*offset], "%s _%" PRIu64 " = step(_%" PRIu64 ", _%" PRIu64 ");\n", type_string(o->op_call.var.type.type),
|
||||
o->op_call.var.index, o->op_call.parameters[0].index, o->op_call.parameters[1].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("pow3")) {
|
||||
*offset += sprintf(&code[*offset], "%s _%" PRIu64 " = pow(_%" PRIu64 ", _%" PRIu64 ");\n", type_string(o->op_call.var.type.type),
|
||||
o->op_call.var.index, o->op_call.parameters[0].index, o->op_call.parameters[1].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("floor3")) {
|
||||
*offset += sprintf(&code[*offset], "%s _%" PRIu64 " = floor(_%" PRIu64 ");\n", type_string(o->op_call.var.type.type), o->op_call.var.index,
|
||||
o->op_call.parameters[0].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("ceil3")) {
|
||||
*offset += sprintf(&code[*offset], "%s _%" PRIu64 " = ceil(_%" PRIu64 ");\n", type_string(o->op_call.var.type.type), o->op_call.var.index,
|
||||
o->op_call.parameters[0].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("ddx2")) {
|
||||
*offset += sprintf(&code[*offset], "%s _%" PRIu64 " = dfdx(_%" PRIu64 ");\n", type_string(o->op_call.var.type.type), o->op_call.var.index,
|
||||
o->op_call.parameters[0].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("ddy2")) {
|
||||
*offset += sprintf(&code[*offset], "%s _%" PRIu64 " = dfdy(_%" PRIu64 ");\n", type_string(o->op_call.var.type.type), o->op_call.var.index,
|
||||
o->op_call.parameters[0].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("ddx3")) {
|
||||
*offset += sprintf(&code[*offset], "%s _%" PRIu64 " = dfdx(_%" PRIu64 ");\n", type_string(o->op_call.var.type.type), o->op_call.var.index,
|
||||
o->op_call.parameters[0].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("ddy3")) {
|
||||
*offset += sprintf(&code[*offset], "%s _%" PRIu64 " = dfdy(_%" PRIu64 ");\n", type_string(o->op_call.var.type.type), o->op_call.var.index,
|
||||
o->op_call.parameters[0].index);
|
||||
}
|
||||
|
||||
////
|
||||
|
||||
else {
|
||||
*offset += sprintf(&code[*offset], "%s _%" PRIu64 " = %s(", type_string(o->op_call.var.type.type), o->op_call.var.index,
|
||||
function_string(o->op_call.func));
|
||||
|
||||
+75
-147
@@ -1727,6 +1727,13 @@ static spirv_id get_var(instructions_buffer *instructions, variable param) {
|
||||
return id;
|
||||
}
|
||||
|
||||
static spirv_id get_constituent(instructions_buffer *instructions, opcode *o, spirv_id *constituents, int i) {
|
||||
if (i > 0 && o->op_call.parameters[i].index == o->op_call.parameters[i - 1].index) {
|
||||
return constituents[i - 1];
|
||||
}
|
||||
return get_var(instructions, o->op_call.parameters[i]);
|
||||
}
|
||||
|
||||
static void write_function(instructions_buffer *instructions, function *f, spirv_id result_type, spirv_id fun_type, spirv_id fun_id, shader_stage stage,
|
||||
bool main, type_id output) {
|
||||
write_op_function_preallocated(instructions, result_type, FUNCTION_CONTROL_NONE, fun_type, fun_id);
|
||||
@@ -2091,7 +2098,7 @@ static void write_function(instructions_buffer *instructions, function *f, spirv
|
||||
else if (o->op_call.parameters_size == 2) {
|
||||
spirv_id constituents[2];
|
||||
for (int i = 0; i < o->op_call.parameters_size; ++i) {
|
||||
constituents[i] = get_var(instructions, o->op_call.parameters[i]);
|
||||
constituents[i] = get_constituent(instructions, o, constituents, i);
|
||||
}
|
||||
spirv_id id = write_op_composite_construct(instructions, spirv_float2_type, constituents, o->op_call.parameters_size);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
@@ -2111,7 +2118,7 @@ static void write_function(instructions_buffer *instructions, function *f, spirv
|
||||
else if (func == add_name("float3")) {
|
||||
spirv_id constituents[3];
|
||||
for (int i = 0; i < o->op_call.parameters_size; ++i) {
|
||||
constituents[i] = get_var(instructions, o->op_call.parameters[i]);
|
||||
constituents[i] = get_constituent(instructions, o, constituents, i);
|
||||
}
|
||||
spirv_id id = write_op_composite_construct(instructions, spirv_float3_type, constituents, o->op_call.parameters_size);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
@@ -2127,7 +2134,7 @@ static void write_function(instructions_buffer *instructions, function *f, spirv
|
||||
else if (func == add_name("float4")) {
|
||||
spirv_id constituents[4];
|
||||
for (int i = 0; i < o->op_call.parameters_size; ++i) {
|
||||
constituents[i] = get_var(instructions, o->op_call.parameters[i]);
|
||||
constituents[i] = get_constituent(instructions, o, constituents, i);
|
||||
}
|
||||
spirv_id id = write_op_composite_construct(instructions, spirv_float4_type, constituents, o->op_call.parameters_size);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
@@ -2135,7 +2142,7 @@ static void write_function(instructions_buffer *instructions, function *f, spirv
|
||||
else if (func == add_name("float3x3")) {
|
||||
spirv_id constituents[3];
|
||||
for (int i = 0; i < o->op_call.parameters_size; ++i) {
|
||||
constituents[i] = get_var(instructions, o->op_call.parameters[i]);
|
||||
constituents[i] = get_constituent(instructions, o, constituents, i);
|
||||
}
|
||||
spirv_id id = write_op_composite_construct(instructions, spirv_float3x3_type, constituents, o->op_call.parameters_size);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
@@ -2143,7 +2150,7 @@ static void write_function(instructions_buffer *instructions, function *f, spirv
|
||||
else if (func == add_name("float4x4")) {
|
||||
spirv_id constituents[4];
|
||||
for (int i = 0; i < o->op_call.parameters_size; ++i) {
|
||||
constituents[i] = get_var(instructions, o->op_call.parameters[i]);
|
||||
constituents[i] = get_constituent(instructions, o, constituents, i);
|
||||
}
|
||||
spirv_id id = write_op_composite_construct(instructions, spirv_float4x4_type, constituents, o->op_call.parameters_size);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
@@ -2176,7 +2183,7 @@ static void write_function(instructions_buffer *instructions, function *f, spirv
|
||||
kong_assert(o->op_call.parameters_size == 2);
|
||||
spirv_id constituents[2];
|
||||
for (int i = 0; i < o->op_call.parameters_size; ++i) {
|
||||
constituents[i] = get_var(instructions, o->op_call.parameters[i]);
|
||||
constituents[i] = get_constituent(instructions, o, constituents, i);
|
||||
}
|
||||
spirv_id id = write_op_composite_construct(instructions, spirv_int2_type, constituents, o->op_call.parameters_size);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
@@ -2185,7 +2192,7 @@ static void write_function(instructions_buffer *instructions, function *f, spirv
|
||||
else if (func == add_name("int3")) {
|
||||
spirv_id constituents[3];
|
||||
for (int i = 0; i < o->op_call.parameters_size; ++i) {
|
||||
constituents[i] = get_var(instructions, o->op_call.parameters[i]);
|
||||
constituents[i] = get_constituent(instructions, o, constituents, i);
|
||||
}
|
||||
spirv_id id = write_op_composite_construct(instructions, spirv_int3_type, constituents, o->op_call.parameters_size);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
@@ -2193,7 +2200,7 @@ static void write_function(instructions_buffer *instructions, function *f, spirv
|
||||
else if (func == add_name("int4")) {
|
||||
spirv_id constituents[4];
|
||||
for (int i = 0; i < o->op_call.parameters_size; ++i) {
|
||||
constituents[i] = get_var(instructions, o->op_call.parameters[i]);
|
||||
constituents[i] = get_constituent(instructions, o, constituents, i);
|
||||
}
|
||||
spirv_id id = write_op_composite_construct(instructions, spirv_int4_type, constituents, o->op_call.parameters_size);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
@@ -2214,7 +2221,7 @@ static void write_function(instructions_buffer *instructions, function *f, spirv
|
||||
else if (func == add_name("uint2")) {
|
||||
spirv_id constituents[2];
|
||||
for (int i = 0; i < o->op_call.parameters_size; ++i) {
|
||||
constituents[i] = get_var(instructions, o->op_call.parameters[i]);
|
||||
constituents[i] = get_constituent(instructions, o, constituents, i);
|
||||
}
|
||||
spirv_id id = write_op_composite_construct(instructions, spirv_uint2_type, constituents, o->op_call.parameters_size);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
@@ -2222,7 +2229,7 @@ static void write_function(instructions_buffer *instructions, function *f, spirv
|
||||
else if (func == add_name("uint3")) {
|
||||
spirv_id constituents[3];
|
||||
for (int i = 0; i < o->op_call.parameters_size; ++i) {
|
||||
constituents[i] = get_var(instructions, o->op_call.parameters[i]);
|
||||
constituents[i] = get_constituent(instructions, o, constituents, i);
|
||||
}
|
||||
spirv_id id = write_op_composite_construct(instructions, spirv_uint3_type, constituents, o->op_call.parameters_size);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
@@ -2230,7 +2237,7 @@ static void write_function(instructions_buffer *instructions, function *f, spirv
|
||||
else if (func == add_name("uint4")) {
|
||||
spirv_id constituents[4];
|
||||
for (int i = 0; i < o->op_call.parameters_size; ++i) {
|
||||
constituents[i] = get_var(instructions, o->op_call.parameters[i]);
|
||||
constituents[i] = get_constituent(instructions, o, constituents, i);
|
||||
}
|
||||
spirv_id id = write_op_composite_construct(instructions, spirv_uint4_type, constituents, o->op_call.parameters_size);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
@@ -2259,32 +2266,32 @@ static void write_function(instructions_buffer *instructions, function *f, spirv
|
||||
}
|
||||
else if (func == add_name("ddx")) {
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id id = write_op_dpdx(instructions, spirv_float_type, operand);
|
||||
spirv_id id = write_op_dpdx(instructions, convert_type_to_spirv_id(o->op_call.var.type.type), operand);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("ddy")) {
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id id = write_op_dpdy(instructions, spirv_float_type, operand);
|
||||
spirv_id id = write_op_dpdy(instructions, convert_type_to_spirv_id(o->op_call.var.type.type), operand);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("round")) {
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id id = write_op_ext_inst(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_ROUND, operand);
|
||||
spirv_id id = write_op_ext_inst(instructions, convert_type_to_spirv_id(o->op_call.var.type.type), glsl_import, SPIRV_GLSL_STD_ROUND, operand);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("floor")) {
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id id = write_op_ext_inst(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_FLOOR, operand);
|
||||
spirv_id id = write_op_ext_inst(instructions, convert_type_to_spirv_id(o->op_call.var.type.type), glsl_import, SPIRV_GLSL_STD_FLOOR, operand);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("sin")) {
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id id = write_op_ext_inst(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_SIN, operand);
|
||||
spirv_id id = write_op_ext_inst(instructions, convert_type_to_spirv_id(o->op_call.var.type.type), glsl_import, SPIRV_GLSL_STD_SIN, operand);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("cos")) {
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id id = write_op_ext_inst(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_COS, operand);
|
||||
spirv_id id = write_op_ext_inst(instructions, convert_type_to_spirv_id(o->op_call.var.type.type), glsl_import, SPIRV_GLSL_STD_COS, operand);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("length")) {
|
||||
@@ -2294,93 +2301,116 @@ static void write_function(instructions_buffer *instructions, function *f, spirv
|
||||
}
|
||||
else if (func == add_name("abs")) {
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id id = write_op_ext_inst(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_FABS, operand);
|
||||
spirv_id id = write_op_ext_inst(instructions, convert_type_to_spirv_id(o->op_call.var.type.type), glsl_import, SPIRV_GLSL_STD_FABS, operand);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("ceil")) {
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id id = write_op_ext_inst(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_CEIL, operand);
|
||||
spirv_id id = write_op_ext_inst(instructions, convert_type_to_spirv_id(o->op_call.var.type.type), glsl_import, SPIRV_GLSL_STD_CEIL, operand);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("frac")) {
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id id = write_op_ext_inst(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_FRACT, operand);
|
||||
spirv_id id = write_op_ext_inst(instructions, convert_type_to_spirv_id(o->op_call.var.type.type), glsl_import, SPIRV_GLSL_STD_FRACT, operand);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("asin")) {
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id id = write_op_ext_inst(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_ASIN, operand);
|
||||
spirv_id id = write_op_ext_inst(instructions, convert_type_to_spirv_id(o->op_call.var.type.type), glsl_import, SPIRV_GLSL_STD_ASIN, operand);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("acos")) {
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id id = write_op_ext_inst(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_ACOS, operand);
|
||||
spirv_id id = write_op_ext_inst(instructions, convert_type_to_spirv_id(o->op_call.var.type.type), glsl_import, SPIRV_GLSL_STD_ACOS, operand);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("atan")) {
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id id = write_op_ext_inst(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_ATAN, operand);
|
||||
spirv_id id = write_op_ext_inst(instructions, convert_type_to_spirv_id(o->op_call.var.type.type), glsl_import, SPIRV_GLSL_STD_ATAN, operand);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("atan2")) {
|
||||
spirv_id operand1 = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id operand2 = get_var(instructions, o->op_call.parameters[1]);
|
||||
spirv_id id = write_op_ext_inst2(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_ATAN2, operand1, operand2);
|
||||
spirv_id id =
|
||||
write_op_ext_inst2(instructions, convert_type_to_spirv_id(o->op_call.var.type.type), glsl_import, SPIRV_GLSL_STD_ATAN2, operand1, operand2);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("pow")) {
|
||||
spirv_id operand1 = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id operand2 = get_var(instructions, o->op_call.parameters[1]);
|
||||
spirv_id id = write_op_ext_inst2(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_POW, operand1, operand2);
|
||||
spirv_id id =
|
||||
write_op_ext_inst2(instructions, convert_type_to_spirv_id(o->op_call.var.type.type), glsl_import, SPIRV_GLSL_STD_POW, operand1, operand2);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("sqrt")) {
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id id = write_op_ext_inst(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_SQRT, operand);
|
||||
spirv_id id = write_op_ext_inst(instructions, convert_type_to_spirv_id(o->op_call.var.type.type), glsl_import, SPIRV_GLSL_STD_SQRT, operand);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("rsqrt")) {
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id id = write_op_ext_inst(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_INVERSE_SQRT, operand);
|
||||
spirv_id id =
|
||||
write_op_ext_inst(instructions, convert_type_to_spirv_id(o->op_call.var.type.type), glsl_import, SPIRV_GLSL_STD_INVERSE_SQRT, operand);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("min")) {
|
||||
spirv_id operand1 = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id operand2 = get_var(instructions, o->op_call.parameters[1]);
|
||||
spirv_id id = write_op_ext_inst2(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_FMIN, operand1, operand2);
|
||||
spirv_id id =
|
||||
write_op_ext_inst2(instructions, convert_type_to_spirv_id(o->op_call.var.type.type), glsl_import, SPIRV_GLSL_STD_FMIN, operand1, operand2);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("max")) {
|
||||
spirv_id operand1 = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id operand2 = get_var(instructions, o->op_call.parameters[1]);
|
||||
spirv_id id = write_op_ext_inst2(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_FMAX, operand1, operand2);
|
||||
spirv_id id =
|
||||
write_op_ext_inst2(instructions, convert_type_to_spirv_id(o->op_call.var.type.type), glsl_import, SPIRV_GLSL_STD_FMAX, operand1, operand2);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("clamp")) {
|
||||
spirv_id operand1 = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id operand2 = get_var(instructions, o->op_call.parameters[1]);
|
||||
spirv_id operand3 = get_var(instructions, o->op_call.parameters[2]);
|
||||
spirv_id id = write_op_ext_inst3(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_FCLAMP, operand1, operand2, operand3);
|
||||
spirv_id id = write_op_ext_inst3(instructions, convert_type_to_spirv_id(o->op_call.var.type.type), glsl_import, SPIRV_GLSL_STD_FCLAMP, operand1,
|
||||
operand2, operand3);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("saturate")) {
|
||||
type_id t = o->op_call.var.type.type;
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id zero = get_float_constant(0.0f);
|
||||
spirv_id one = get_float_constant(1.0f);
|
||||
if (t != float_id) {
|
||||
spirv_id zeros[4] = {zero, zero, zero, zero};
|
||||
spirv_id ones[4] = {one, one, one, one};
|
||||
zero = write_op_composite_construct(instructions, convert_type_to_spirv_id(t), zeros, vector_size(t));
|
||||
one = write_op_composite_construct(instructions, convert_type_to_spirv_id(t), ones, vector_size(t));
|
||||
}
|
||||
spirv_id id = write_op_ext_inst3(instructions, convert_type_to_spirv_id(t), glsl_import, SPIRV_GLSL_STD_FCLAMP, operand, zero, one);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("lerp")) {
|
||||
spirv_id operand1 = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id operand2 = get_var(instructions, o->op_call.parameters[1]);
|
||||
spirv_id operand3 = get_var(instructions, o->op_call.parameters[2]);
|
||||
spirv_id id = write_op_ext_inst3(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_FMIX, operand1, operand2, operand3);
|
||||
spirv_id id = write_op_ext_inst3(instructions, convert_type_to_spirv_id(o->op_call.var.type.type), glsl_import, SPIRV_GLSL_STD_FMIX, operand1,
|
||||
operand2, operand3);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("step")) {
|
||||
spirv_id operand1 = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id operand2 = get_var(instructions, o->op_call.parameters[1]);
|
||||
spirv_id id = write_op_ext_inst2(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_STEP, operand1, operand2);
|
||||
spirv_id id =
|
||||
write_op_ext_inst2(instructions, convert_type_to_spirv_id(o->op_call.var.type.type), glsl_import, SPIRV_GLSL_STD_STEP, operand1, operand2);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("smoothstep")) {
|
||||
spirv_id operand1 = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id operand2 = get_var(instructions, o->op_call.parameters[1]);
|
||||
spirv_id operand3 = get_var(instructions, o->op_call.parameters[2]);
|
||||
spirv_id id = write_op_ext_inst3(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_SMOOTHSTEP, operand1, operand2, operand3);
|
||||
spirv_id id = write_op_ext_inst3(instructions, convert_type_to_spirv_id(o->op_call.var.type.type), glsl_import, SPIRV_GLSL_STD_SMOOTHSTEP,
|
||||
operand1, operand2, operand3);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("distance")) {
|
||||
@@ -2397,7 +2427,8 @@ static void write_function(instructions_buffer *instructions, function *f, spirv
|
||||
}
|
||||
else if (func == add_name("normalize")) {
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id id = write_op_ext_inst(instructions, spirv_float3_type, glsl_import, SPIRV_GLSL_STD_NORMALIZE, operand);
|
||||
spirv_id id =
|
||||
write_op_ext_inst(instructions, convert_type_to_spirv_id(o->op_call.var.type.type), glsl_import, SPIRV_GLSL_STD_NORMALIZE, operand);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("reflect")) {
|
||||
@@ -2411,158 +2442,55 @@ static void write_function(instructions_buffer *instructions, function *f, spirv
|
||||
|
||||
else if (func == add_name("tan")) {
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id id = write_op_ext_inst(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_TAN, operand);
|
||||
spirv_id id = write_op_ext_inst(instructions, convert_type_to_spirv_id(o->op_call.var.type.type), glsl_import, SPIRV_GLSL_STD_TAN, operand);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("log")) {
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id id = write_op_ext_inst(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_LOG, operand);
|
||||
spirv_id id = write_op_ext_inst(instructions, convert_type_to_spirv_id(o->op_call.var.type.type), glsl_import, SPIRV_GLSL_STD_LOG, operand);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("exp")) {
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id id = write_op_ext_inst(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_EXP, operand);
|
||||
spirv_id id = write_op_ext_inst(instructions, convert_type_to_spirv_id(o->op_call.var.type.type), glsl_import, SPIRV_GLSL_STD_EXP, operand);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("sign")) {
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id id = write_op_ext_inst(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_FSIGN, operand);
|
||||
spirv_id id = write_op_ext_inst(instructions, convert_type_to_spirv_id(o->op_call.var.type.type), glsl_import, SPIRV_GLSL_STD_FSIGN, operand);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("trunc")) {
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id id = write_op_ext_inst(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_TRUNC, operand);
|
||||
spirv_id id = write_op_ext_inst(instructions, convert_type_to_spirv_id(o->op_call.var.type.type), glsl_import, SPIRV_GLSL_STD_TRUNC, operand);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("sinh")) {
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id id = write_op_ext_inst(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_SINH, operand);
|
||||
spirv_id id = write_op_ext_inst(instructions, convert_type_to_spirv_id(o->op_call.var.type.type), glsl_import, SPIRV_GLSL_STD_SINH, operand);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("cosh")) {
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id id = write_op_ext_inst(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_COSH, operand);
|
||||
spirv_id id = write_op_ext_inst(instructions, convert_type_to_spirv_id(o->op_call.var.type.type), glsl_import, SPIRV_GLSL_STD_COSH, operand);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("tanh")) {
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id id = write_op_ext_inst(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_TANH, operand);
|
||||
spirv_id id = write_op_ext_inst(instructions, convert_type_to_spirv_id(o->op_call.var.type.type), glsl_import, SPIRV_GLSL_STD_TANH, operand);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("radians")) {
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id id = write_op_ext_inst(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_RADIANS, operand);
|
||||
spirv_id id = write_op_ext_inst(instructions, convert_type_to_spirv_id(o->op_call.var.type.type), glsl_import, SPIRV_GLSL_STD_RADIANS, operand);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("degrees")) {
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id id = write_op_ext_inst(instructions, spirv_float_type, glsl_import, SPIRV_GLSL_STD_DEGREES, operand);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("ddx2")) {
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id id = write_op_dpdx(instructions, spirv_float2_type, operand);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("ddy2")) {
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id id = write_op_dpdy(instructions, spirv_float2_type, operand);
|
||||
spirv_id id = write_op_ext_inst(instructions, convert_type_to_spirv_id(o->op_call.var.type.type), glsl_import, SPIRV_GLSL_STD_DEGREES, operand);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
|
||||
else if (func == add_name("ddx3")) {
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id id = write_op_dpdx(instructions, spirv_float3_type, operand);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("ddy3")) {
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id id = write_op_dpdy(instructions, spirv_float3_type, operand);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("clamp3")) {
|
||||
spirv_id operand1 = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id operand2 = get_var(instructions, o->op_call.parameters[1]);
|
||||
spirv_id operand3 = get_var(instructions, o->op_call.parameters[2]);
|
||||
spirv_id id = write_op_ext_inst3(instructions, spirv_float3_type, glsl_import, SPIRV_GLSL_STD_FCLAMP, operand1, operand2, operand3);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("min3")) {
|
||||
spirv_id operand1 = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id operand2 = get_var(instructions, o->op_call.parameters[1]);
|
||||
spirv_id id = write_op_ext_inst2(instructions, spirv_float3_type, glsl_import, SPIRV_GLSL_STD_FMIN, operand1, operand2);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("max3")) {
|
||||
spirv_id operand1 = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id operand2 = get_var(instructions, o->op_call.parameters[1]);
|
||||
spirv_id id = write_op_ext_inst2(instructions, spirv_float3_type, glsl_import, SPIRV_GLSL_STD_FMAX, operand1, operand2);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("max4")) {
|
||||
spirv_id operand1 = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id operand2 = get_var(instructions, o->op_call.parameters[1]);
|
||||
spirv_id id = write_op_ext_inst2(instructions, spirv_float4_type, glsl_import, SPIRV_GLSL_STD_FMAX, operand1, operand2);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("step3")) {
|
||||
spirv_id operand1 = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id operand2 = get_var(instructions, o->op_call.parameters[1]);
|
||||
spirv_id id = write_op_ext_inst2(instructions, spirv_float3_type, glsl_import, SPIRV_GLSL_STD_STEP, operand1, operand2);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("pow3")) {
|
||||
spirv_id operand1 = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id operand2 = get_var(instructions, o->op_call.parameters[1]);
|
||||
spirv_id id = write_op_ext_inst2(instructions, spirv_float3_type, glsl_import, SPIRV_GLSL_STD_POW, operand1, operand2);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("floor3")) {
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id id = write_op_ext_inst(instructions, spirv_float3_type, glsl_import, SPIRV_GLSL_STD_FLOOR, operand);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("ceil3")) {
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id id = write_op_ext_inst(instructions, spirv_float3_type, glsl_import, SPIRV_GLSL_STD_CEIL, operand);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("abs3")) {
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id id = write_op_ext_inst(instructions, spirv_float3_type, glsl_import, SPIRV_GLSL_STD_FABS, operand);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("frac3")) {
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id id = write_op_ext_inst(instructions, spirv_float3_type, glsl_import, SPIRV_GLSL_STD_FRACT, operand);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("lerp3")) {
|
||||
spirv_id operand1 = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id operand2 = get_var(instructions, o->op_call.parameters[1]);
|
||||
spirv_id operand3 = get_var(instructions, o->op_call.parameters[2]);
|
||||
|
||||
if (o->op_call.parameters[2].type.type == float_id) {
|
||||
spirv_id operands[3] = {operand3, operand3, operand3};
|
||||
operand3 = write_op_composite_construct(instructions, spirv_float3_type, operands, 3);
|
||||
}
|
||||
|
||||
spirv_id id = write_op_ext_inst3(instructions, spirv_float3_type, glsl_import, SPIRV_GLSL_STD_FMIX, operand1, operand2, operand3);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("lerp4")) {
|
||||
spirv_id operand1 = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id operand2 = get_var(instructions, o->op_call.parameters[1]);
|
||||
spirv_id operand3 = get_var(instructions, o->op_call.parameters[2]);
|
||||
|
||||
if (o->op_call.parameters[2].type.type == float_id) {
|
||||
spirv_id operands[4] = {operand3, operand3, operand3, operand3};
|
||||
operand3 = write_op_composite_construct(instructions, spirv_float4_type, operands, 4);
|
||||
}
|
||||
|
||||
spirv_id id = write_op_ext_inst3(instructions, spirv_float4_type, glsl_import, SPIRV_GLSL_STD_FMIX, operand1, operand2, operand3);
|
||||
hmput(index_map, o->op_call.var.index, id);
|
||||
}
|
||||
else if (func == add_name("transpose")) {
|
||||
spirv_id operand = get_var(instructions, o->op_call.parameters[0]);
|
||||
spirv_id id = write_op_transpose(instructions, spirv_float3x3_type, operand);
|
||||
|
||||
@@ -907,76 +907,6 @@ static void write_functions(char *code, size_t *offset, shader_stage stage, func
|
||||
|
||||
////
|
||||
|
||||
else if (o->op_call.func == add_name("lerp3")) {
|
||||
*offset += sprintf(&code[*offset], "var _%" PRIu64 ": %s = mix(_%" PRIu64 ", _%" PRIu64 ", _%" PRIu64 ");\n", o->op_call.var.index,
|
||||
type_string(o->op_call.var.type.type), o->op_call.parameters[0].index, o->op_call.parameters[1].index,
|
||||
o->op_call.parameters[2].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("lerp4")) {
|
||||
*offset += sprintf(&code[*offset], "var _%" PRIu64 ": %s = mix(_%" PRIu64 ", _%" PRIu64 ", _%" PRIu64 ");\n", o->op_call.var.index,
|
||||
type_string(o->op_call.var.type.type), o->op_call.parameters[0].index, o->op_call.parameters[1].index,
|
||||
o->op_call.parameters[2].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("frac3")) {
|
||||
*offset += sprintf(&code[*offset], "var _%" PRIu64 ": %s = fract(_%" PRIu64 ");\n", o->op_call.var.index,
|
||||
type_string(o->op_call.var.type.type), o->op_call.parameters[0].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("abs3")) {
|
||||
*offset += sprintf(&code[*offset], "var _%" PRIu64 ": %s = abs(_%" PRIu64 ");\n", o->op_call.var.index,
|
||||
type_string(o->op_call.var.type.type), o->op_call.parameters[0].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("clamp3")) {
|
||||
*offset += sprintf(&code[*offset], "var _%" PRIu64 ": %s = clamp(_%" PRIu64 ", _%" PRIu64 ", _%" PRIu64 ");\n", o->op_call.var.index,
|
||||
type_string(o->op_call.var.type.type), o->op_call.parameters[0].index, o->op_call.parameters[1].index,
|
||||
o->op_call.parameters[2].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("min3")) {
|
||||
*offset += sprintf(&code[*offset], "var _%" PRIu64 ": %s = min(_%" PRIu64 ", _%" PRIu64 ");\n", o->op_call.var.index,
|
||||
type_string(o->op_call.var.type.type), o->op_call.parameters[0].index, o->op_call.parameters[1].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("max3")) {
|
||||
*offset += sprintf(&code[*offset], "var _%" PRIu64 ": %s = max(_%" PRIu64 ", _%" PRIu64 ");\n", o->op_call.var.index,
|
||||
type_string(o->op_call.var.type.type), o->op_call.parameters[0].index, o->op_call.parameters[1].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("max4")) {
|
||||
*offset += sprintf(&code[*offset], "var _%" PRIu64 ": %s = max(_%" PRIu64 ", _%" PRIu64 ");\n", o->op_call.var.index,
|
||||
type_string(o->op_call.var.type.type), o->op_call.parameters[0].index, o->op_call.parameters[1].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("step3")) {
|
||||
*offset += sprintf(&code[*offset], "var _%" PRIu64 ": %s = step(_%" PRIu64 ", _%" PRIu64 ");\n", o->op_call.var.index,
|
||||
type_string(o->op_call.var.type.type), o->op_call.parameters[0].index, o->op_call.parameters[1].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("pow3")) {
|
||||
*offset += sprintf(&code[*offset], "var _%" PRIu64 ": %s = pow(_%" PRIu64 ", _%" PRIu64 ");\n", o->op_call.var.index,
|
||||
type_string(o->op_call.var.type.type), o->op_call.parameters[0].index, o->op_call.parameters[1].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("floor3")) {
|
||||
*offset += sprintf(&code[*offset], "var _%" PRIu64 ": %s = floor(_%" PRIu64 ");\n", o->op_call.var.index,
|
||||
type_string(o->op_call.var.type.type), o->op_call.parameters[0].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("ceil3")) {
|
||||
*offset += sprintf(&code[*offset], "var _%" PRIu64 ": %s = ceil(_%" PRIu64 ");\n", o->op_call.var.index,
|
||||
type_string(o->op_call.var.type.type), o->op_call.parameters[0].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("ddx2")) {
|
||||
*offset += sprintf(&code[*offset], "var _%" PRIu64 ": %s = dpdx(_%" PRIu64 ");\n", o->op_call.var.index,
|
||||
type_string(o->op_call.var.type.type), o->op_call.parameters[0].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("ddy2")) {
|
||||
*offset += sprintf(&code[*offset], "var _%" PRIu64 ": %s = dpdy(_%" PRIu64 ");\n", o->op_call.var.index,
|
||||
type_string(o->op_call.var.type.type), o->op_call.parameters[0].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("ddx3")) {
|
||||
*offset += sprintf(&code[*offset], "var _%" PRIu64 ": %s = dpdx(_%" PRIu64 ");\n", o->op_call.var.index,
|
||||
type_string(o->op_call.var.type.type), o->op_call.parameters[0].index);
|
||||
}
|
||||
else if (o->op_call.func == add_name("ddy3")) {
|
||||
*offset += sprintf(&code[*offset], "var _%" PRIu64 ": %s = dpdy(_%" PRIu64 ");\n", o->op_call.var.index,
|
||||
type_string(o->op_call.var.type.type), o->op_call.parameters[0].index);
|
||||
}
|
||||
|
||||
////
|
||||
|
||||
else {
|
||||
name_id func_name_id = o->op_call.func;
|
||||
const char *func_name = get_name(o->op_call.func);
|
||||
|
||||
Reference in New Issue
Block a user