On Wed, 18 Aug 2021 at 06:28, Atharva Nimbalkar atharvakn@gmail.com wrote:
+/* Generate a GLSL parameter that does the input modifier computation and return the input register/mask to use */ +static void shader_glsl_gen_modifier(struct vkd3d_glsl_generator *gen,
enum vkd3d_shader_src_modifier src_modifier,
const char *in_reg, const struct vkd3d_string_buffer *in_regswizzle,
struct vkd3d_string_buffer *out_str)
+{
- switch (src_modifier)
- {
case VKD3DSPSM_DZ: /* Need to handle this in the instructions itself (texld & texcrd). */
case VKD3DSPSM_DW:
case VKD3DSPSM_NONE:
vkd3d_string_buffer_printf(out_str, "%s%s", in_reg, in_regswizzle->buffer);
break;
case VKD3DSPSM_NEG:
vkd3d_string_buffer_printf(out_str, "-%s%s", in_reg, in_regswizzle->buffer);
break;
case VKD3DSPSM_NOT:
vkd3d_string_buffer_printf(out_str, "!%s%s", in_reg, in_regswizzle->buffer);
break;
case VKD3DSPSM_BIAS:
vkd3d_string_buffer_printf(out_str, "(%s%s - vec4(0.5)%s)", in_reg, in_regswizzle->buffer, in_regswizzle->buffer);
break;
case VKD3DSPSM_BIASNEG:
vkd3d_string_buffer_printf(out_str, "-(%s%s - vec4(0.5)%s)", in_reg, in_regswizzle->buffer, in_regswizzle->buffer);
break;
case VKD3DSPSM_SIGN:
vkd3d_string_buffer_printf(out_str, "(2.0 * (%s%s - 0.5))", in_reg, in_regswizzle->buffer);
break;
case VKD3DSPSM_SIGNNEG:
vkd3d_string_buffer_printf(out_str, "-(2.0 * (%s%s - 0.5))", in_reg, in_regswizzle->buffer);
break;
case VKD3DSPSM_COMP:
vkd3d_string_buffer_printf(out_str, "(1.0 - %s%s)", in_reg, in_regswizzle->buffer);
break;
case VKD3DSPSM_X2:
vkd3d_string_buffer_printf(out_str, "(2.0 * %s%s)", in_reg, in_regswizzle->buffer);
break;
case VKD3DSPSM_X2NEG:
vkd3d_string_buffer_printf(out_str, "-(2.0 * %s%s)", in_reg, in_regswizzle->buffer);
break;
case VKD3DSPSM_ABS:
vkd3d_string_buffer_printf(out_str, "abs(%s%s)", in_reg, in_regswizzle->buffer);
break;
case VKD3DSPSM_ABSNEG:
vkd3d_string_buffer_printf(out_str, "-abs(%s%s)", in_reg, in_regswizzle->buffer);
break;
default:
vkd3d_glsl_compiler_error(gen, VKD3D_SHADER_ERROR_GLSL_INTERNAL,
"Unhandled modifier %#x\n", src_modifier);
vkd3d_string_buffer_printf(out_str, "%s%s", in_reg, in_regswizzle->buffer);
- }
+}
We can defer most modifier handling to a later patch; the only cases we really need to handle in this patch are VKD3DSPSM_NONE and "default".
@@ -211,14 +349,50 @@ static void glsl_src_param_init_ext(struct vkd3d_glsl_generator *gen, const struct vkd3d_shader_src_param *vkd3d_src, uint32_t mask, struct glsl_src_param *glsl_src, enum vkd3d_data_type data_type) {
- /*
* TODO: Add implementation
* Sets an error state as of now.
*/
struct vkd3d_string_buffer *param_str = vkd3d_string_buffer_get(&gen->string_buffers);
struct vkd3d_string_buffer *reg_name = vkd3d_string_buffer_get(&gen->string_buffers);
struct vkd3d_string_buffer *swizzle_str = vkd3d_string_buffer_get(&gen->string_buffers);
enum vkd3d_data_type param_data_type;
bool is_color = false;
unsigned int size;
glsl_src->param_str = vkd3d_string_buffer_get(&gen->string_buffers);
- vkd3d_glsl_compiler_error(gen, VKD3D_SHADER_ERROR_GLSL_INTERNAL,
"Internal compiler error: Unhandled parameter token.");
- shader_glsl_get_register_name(gen, &vkd3d_src->reg, data_type, reg_name, &is_color);
- shader_glsl_get_swizzle(vkd3d_src, false, mask, swizzle_str);
We should pass "is_color" to shader_glsl_get_swizzle() here.