Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gamax92/ae548bfd3c55c44826802109f21674ba to your computer and use it in GitHub Desktop.
Save gamax92/ae548bfd3c55c44826802109f21674ba to your computer and use it in GitHub Desktop.
From 2268caf86cd7ef1469bd3c535d06724c129e77e2 Mon Sep 17 00:00:00 2001
From: gamax92 <[email protected]>
Date: Thu, 18 May 2017 19:16:13 -0600
Subject: [PATCH] Experimental flat interpolation patch
Causing heavily flickering objects ...
---
dlls/wined3d/glsl_shader.c | 117 +++++++++++++++++++++++++++++++++++----------
1 file changed, 93 insertions(+), 24 deletions(-)
diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c
index 4b11fdefda..27b1510d8e 100644
--- a/dlls/wined3d/glsl_shader.c
+++ b/dlls/wined3d/glsl_shader.c
@@ -809,7 +809,7 @@ static void shader_glsl_generate_transform_feedback_varyings(const struct wined3
continue;
}
- string_buffer_sprintf(buffer, "shader_in_out.reg[%u]", e->register_idx);
+ string_buffer_sprintf(buffer, "shader_in_out.reg%u", e->register_idx);
append_transform_feedback_varying(varyings, &count, &strings, &length, buffer);
}
@@ -2097,21 +2097,68 @@ static const char *shader_glsl_shader_output_name(const struct wined3d_gl_info *
}
static void shader_glsl_declare_shader_inputs(const struct wined3d_gl_info *gl_info,
- struct wined3d_string_buffer *buffer, unsigned int element_count)
+ struct wined3d_string_buffer *buffer, unsigned int element_count,
+ const struct wined3d_shader *shader)
{
+ unsigned int i;
+
if (shader_glsl_use_interface_blocks(gl_info))
- shader_addline(buffer, "in shader_in_out { vec4 reg[%u]; } shader_in;\n", element_count);
+ {
+ shader_addline(buffer, "in shader_in_out {\n");
+ for (i = 0; i < element_count; i++)
+ {
+ shader_addline(buffer, " %svec4 reg%u;\n",
+ (shader->u.ps.interpolation_mode[i] == WINED3DSIM_CONSTANT) ? "flat " : "",
+ i);
+ if (shader->u.ps.interpolation_mode[i] > WINED3DSIM_LINEAR)
+ FIXME("Unhandled interpolation mode shader_in.reg%u (%u).\n", i,
+ shader->u.ps.interpolation_mode[i]);
+ }
+ shader_addline(buffer, "} shader_in;\n");
+ }
else
- declare_in_varying(gl_info, buffer, FALSE, "vec4 ps_link[%u];\n", element_count);
+ {
+ for (i = 0; i < element_count; i++)
+ {
+ declare_in_varying(gl_info, buffer, shader->u.ps.interpolation_mode[i] == WINED3DSIM_CONSTANT,
+ "vec4 ps_link%u;\n", i);
+ if (shader->u.ps.interpolation_mode[i] > WINED3DSIM_LINEAR)
+ FIXME("Unhandled interpolation mode ps_link%u (%u).\n", i,
+ shader->u.ps.interpolation_mode[i]);
+ }
+ }
}
static void shader_glsl_declare_shader_outputs(const struct wined3d_gl_info *gl_info,
- struct wined3d_string_buffer *buffer, unsigned int element_count)
+ struct wined3d_string_buffer *buffer, unsigned int element_count,
+ const enum wined3d_shader_interpolation_mode *interpolation_mode)
{
+ unsigned int i;
+
if (shader_glsl_use_interface_blocks(gl_info))
- shader_addline(buffer, "out shader_in_out { vec4 reg[%u]; } shader_out;\n", element_count);
+ {
+ shader_addline(buffer, "out shader_in_out {\n");
+ for (i = 0; i < element_count; i++)
+ {
+ shader_addline(buffer, " %svec4 reg%u;\n",
+ (interpolation_mode ? interpolation_mode[i] == WINED3DSIM_CONSTANT : FALSE) ? "flat " : "",
+ i);
+ if (interpolation_mode[i] > WINED3DSIM_LINEAR)
+ FIXME("Unhandled interpolation mode ps_link%u (%u).\n", i, interpolation_mode[i]);
+ }
+ shader_addline(buffer, "} shader_out;\n");
+ }
else
- declare_out_varying(gl_info, buffer, FALSE, "vec4 ps_link[%u];\n", element_count);
+ {
+ for (i = 0; i < element_count; i++)
+ {
+ declare_out_varying(gl_info, buffer,
+ interpolation_mode ? interpolation_mode[i] == WINED3DSIM_CONSTANT : FALSE,
+ "vec4 ps_link%u;\n", i);
+ if (interpolation_mode[i] > WINED3DSIM_LINEAR)
+ FIXME("Unhandled interpolation mode ps_link%u (%u).\n", i, interpolation_mode[i]);
+ }
+ }
}
static const char *get_fragment_output(const struct wined3d_gl_info *gl_info)
@@ -2741,7 +2788,7 @@ static void shader_glsl_get_register_name(const struct wined3d_shader_register *
rel_param0.param_str, reg->idx[0].offset,
rel_param1.param_str, reg->idx[1].offset);
else
- sprintf(register_name, "shader_in[%s + %u].reg[%u]",
+ sprintf(register_name, "shader_in[%s + %u].reg%u",
rel_param0.param_str, reg->idx[0].offset,
reg->idx[1].offset);
}
@@ -2749,7 +2796,7 @@ static void shader_glsl_get_register_name(const struct wined3d_shader_register *
sprintf(register_name, "shader_in[%u].reg[%s + %u]", reg->idx[0].offset,
rel_param1.param_str, reg->idx[1].offset);
else
- sprintf(register_name, "shader_in[%u].reg[%u]",
+ sprintf(register_name, "shader_in[%u].reg%u",
reg->idx[0].offset, reg->idx[1].offset);
break;
}
@@ -6432,7 +6479,7 @@ static void shader_glsl_input_pack(const struct wined3d_shader *shader, struct w
{
if (input->sysval_semantic)
FIXME("Unhandled sysval semantic %#x.\n", input->sysval_semantic);
- shader_addline(buffer, "ps_in[%u]%s = %s[%u]%s;\n",
+ shader_addline(buffer, "ps_in[%u]%s = %s%u%s;\n",
shader->u.ps.input_reg_map[input->register_idx], reg_mask,
shader_glsl_shader_input_name(gl_info),
shader->u.ps.input_reg_map[input->register_idx], reg_mask);
@@ -6519,7 +6566,7 @@ static void shader_glsl_setup_vs3_output(struct shader_glsl_priv *priv,
const struct wined3d_shader_signature *input_signature,
const struct wined3d_shader_reg_maps *reg_maps_in,
const struct wined3d_shader_signature *output_signature,
- const struct wined3d_shader_reg_maps *reg_maps_out)
+ const struct wined3d_shader_reg_maps *reg_maps_out, BOOL is_array)
{
struct wined3d_string_buffer *destination = string_buffer_get(&priv->string_buffers);
const char *out_array_name = shader_glsl_shader_output_name(gl_info);
@@ -6553,8 +6600,10 @@ static void shader_glsl_setup_vs3_output(struct shader_glsl_priv *priv,
string_buffer_sprintf(destination, "gl_FrontColor");
else if (in_idx == in_count + 1)
string_buffer_sprintf(destination, "gl_FrontSecondaryColor");
- else
+ else if (is_array)
string_buffer_sprintf(destination, "%s[%u]", out_array_name, in_idx);
+ else
+ string_buffer_sprintf(destination, "%s%u", out_array_name, in_idx);
if (!set[in_idx])
set[in_idx] = ~0u;
@@ -6605,8 +6654,10 @@ static void shader_glsl_setup_vs3_output(struct shader_glsl_priv *priv,
string_buffer_sprintf(destination, "gl_FrontColor");
else if (i == in_count + 1)
string_buffer_sprintf(destination, "gl_FrontSecondaryColor");
- else
+ else if (is_array)
string_buffer_sprintf(destination, "%s[%u]", out_array_name, i);
+ else
+ string_buffer_sprintf(destination, "%s%u", out_array_name, i);
if (size == 1)
shader_addline(buffer, "%s.%s = 0.0;\n", destination->buffer, reg_mask);
@@ -6641,7 +6692,7 @@ static void shader_glsl_setup_sm4_shader_output(struct shader_glsl_priv *priv,
shader_glsl_write_mask_to_str(output->mask, reg_mask);
- shader_addline(buffer, "shader_out.reg[%u]%s = outputs[%u]%s;\n",
+ shader_addline(buffer, "shader_out.reg%u%s = outputs[%u]%s;\n",
output->register_idx, reg_mask, output->register_idx, reg_mask);
}
}
@@ -6698,7 +6749,7 @@ static void shader_glsl_setup_sm3_rasterizer_input(struct shader_glsl_priv *priv
/* Then, setup the pixel shader input. */
if (reg_maps_out->shader_version.major < 4)
shader_glsl_setup_vs3_output(priv, gl_info, map, input_signature, reg_maps_in,
- output_signature, reg_maps_out);
+ output_signature, reg_maps_out, FALSE);
else
shader_glsl_setup_sm4_shader_output(priv, input_count, output_signature, reg_maps_out);
}
@@ -6832,7 +6883,7 @@ static GLuint shader_glsl_generate_vs3_rasterizer_input_setup(struct shader_glsl
{
unsigned int in_count = min(vec4_varyings(ps_major, gl_info), ps->limits->packed_input);
- shader_glsl_declare_shader_outputs(gl_info, buffer, in_count);
+ shader_glsl_declare_shader_outputs(gl_info, buffer, in_count, NULL);
shader_addline(buffer, "void setup_vs_output(in vec4 outputs[%u])\n{\n", vs->limits->packed_output);
shader_glsl_setup_sm3_rasterizer_input(priv, gl_info, ps->u.ps.input_reg_map, &ps->input_signature,
&ps->reg_maps, 0, &vs->output_signature, &vs->reg_maps, per_vertex_point_size);
@@ -6849,6 +6900,7 @@ static GLuint shader_glsl_generate_vs3_rasterizer_input_setup(struct shader_glsl
static void shader_glsl_generate_sm4_output_setup(struct shader_glsl_priv *priv,
const struct wined3d_shader *shader, unsigned int input_count,
+ const enum wined3d_shader_interpolation_mode *interpolation_mode,
const struct wined3d_gl_info *gl_info, BOOL rasterizer_setup)
{
const char *prefix = shader_glsl_get_prefix(shader->reg_maps.shader_version.type);
@@ -6857,8 +6909,7 @@ static void shader_glsl_generate_sm4_output_setup(struct shader_glsl_priv *priv,
if (rasterizer_setup)
input_count = min(vec4_varyings(4, gl_info), input_count);
- if (input_count)
- shader_glsl_declare_shader_outputs(gl_info, buffer, input_count);
+ shader_glsl_declare_shader_outputs(gl_info, buffer, input_count, interpolation_mode);
shader_addline(buffer, "void setup_%s_output(in vec4 outputs[%u])\n{\n",
prefix, shader->limits->packed_output);
@@ -7111,7 +7162,7 @@ static GLuint shader_glsl_generate_pshader(const struct wined3d_context *context
unsigned int in_count = min(vec4_varyings(version->major, gl_info), shader->limits->packed_input);
if (args->vp_mode == vertexshader)
- shader_glsl_declare_shader_inputs(gl_info, buffer, in_count);
+ shader_glsl_declare_shader_inputs(gl_info, buffer, in_count, shader);
shader_addline(buffer, "vec4 %s_in[%u];\n", prefix, in_count);
if (args->dual_source_blend)
@@ -7369,7 +7420,7 @@ static GLuint shader_glsl_generate_vshader(const struct wined3d_context *context
if (reg_maps->shader_version.major >= 4)
shader_glsl_generate_sm4_output_setup(priv, shader, args->next_shader_input_count,
- gl_info, args->next_shader_type == WINED3D_SHADER_TYPE_PIXEL);
+ args->interpolation_mode, gl_info, args->next_shader_type == WINED3D_SHADER_TYPE_PIXEL);
shader_addline(buffer, "void main()\n{\n");
@@ -7400,6 +7451,7 @@ static GLuint shader_glsl_generate_geometry_shader(const struct wined3d_context
const struct wined3d_gl_info *gl_info = context->gl_info;
struct shader_glsl_ctx_priv priv_ctx;
GLuint shader_id;
+ unsigned int i;
memset(&priv_ctx, 0, sizeof(priv_ctx));
priv_ctx.string_buffers = string_buffers;
@@ -7416,12 +7468,19 @@ static GLuint shader_glsl_generate_geometry_shader(const struct wined3d_context
shader_addline(buffer, ") in;\n");
shader_addline(buffer, "layout(%s, max_vertices = %u) out;\n",
glsl_primitive_type_from_d3d(shader->u.gs.output_type), shader->u.gs.vertices_out);
- shader_addline(buffer, "in shader_in_out { vec4 reg[%u]; } shader_in[];\n", shader->limits->packed_input);
+ shader_addline(buffer, "in shader_in_out {\n");
+ for (i = 0; i < shader->limits->packed_input; i++)
+ {
+ shader_addline(buffer, " %svec4 reg%u;\n",
+ (args->interpolation_mode ? args->interpolation_mode[i] == WINED3DSIM_CONSTANT : FALSE) ? "flat " : "", i);
+ }
+ shader_addline(buffer, "} shader_in[];\n");
if (!gl_info->supported[ARB_CLIP_CONTROL])
shader_addline(buffer, "uniform vec4 pos_fixup;\n");
- shader_glsl_generate_sm4_output_setup(priv, shader, args->output_count, gl_info, TRUE);
+ shader_glsl_generate_sm4_output_setup(priv, shader, args->output_count, args->interpolation_mode,
+ gl_info, TRUE);
shader_addline(buffer, "void main()\n{\n");
if (FAILED(shader_generate_main(shader, buffer, reg_maps, &priv_ctx)))
return 0;
@@ -7579,6 +7638,8 @@ static GLuint find_glsl_pshader(const struct wined3d_context *context,
static inline BOOL vs_args_equal(const struct vs_compile_args *stored, const struct vs_compile_args *new,
const DWORD use_map)
{
+ unsigned int i;
+
if((stored->swizzle_map & use_map) != new->swizzle_map) return FALSE;
if((stored->clip_enabled) != new->clip_enabled) return FALSE;
if (stored->point_size != new->point_size)
@@ -7591,7 +7652,15 @@ static inline BOOL vs_args_equal(const struct vs_compile_args *stored, const str
return FALSE;
if (stored->next_shader_input_count != new->next_shader_input_count)
return FALSE;
- return stored->fog_src == new->fog_src;
+ if (stored->fog_src != new->fog_src)
+ return FALSE;
+
+ for (i = 0; i < stored->next_shader_input_count; i++)
+ {
+ if (stored->interpolation_mode[i] != new->interpolation_mode[i])
+ return FALSE;
+ }
+ return TRUE;
}
static GLuint find_glsl_vshader(const struct wined3d_context *context, struct shader_glsl_priv *priv,
@@ -10075,7 +10144,7 @@ static const SHADER_HANDLER shader_glsl_instruction_handler_table[WINED3DSIH_TAB
/* WINED3DSIH_DCL_INPUT */ shader_glsl_nop,
/* WINED3DSIH_DCL_INPUT_CONTROL_POINT_COUNT */ NULL,
/* WINED3DSIH_DCL_INPUT_PRIMITIVE */ shader_glsl_nop,
- /* WINED3DSIH_DCL_INPUT_PS */ NULL,
+ /* WINED3DSIH_DCL_INPUT_PS */ shader_glsl_nop,
/* WINED3DSIH_DCL_INPUT_PS_SGV */ NULL,
/* WINED3DSIH_DCL_INPUT_PS_SIV */ NULL,
/* WINED3DSIH_DCL_INPUT_SGV */ shader_glsl_nop,
--
2.13.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment