wined3d: Use pure integer vertex attributes for SM4+ shaders.

Signed-off-by: Józef Kucia <jkucia@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Józef Kucia 2016-05-31 23:29:50 +02:00 committed by Alexandre Julliard
parent 4f3607f754
commit 4dfd79d336
5 changed files with 77 additions and 27 deletions

View File

@ -3080,6 +3080,7 @@ static void load_gl_funcs(struct wined3d_gl_info *gl_info)
USE_GL_FUNC(glVertexAttrib4sv) /* OpenGL 2.0 */
USE_GL_FUNC(glVertexAttrib4ubv) /* OpenGL 2.0 */
USE_GL_FUNC(glVertexAttribDivisor) /* OpenGL 3.3 */
USE_GL_FUNC(glVertexAttribIPointer) /* OpenGL 3.0 */
USE_GL_FUNC(glVertexAttribPointer) /* OpenGL 2.0 */
#undef USE_GL_FUNC
@ -3194,6 +3195,7 @@ static void load_gl_funcs(struct wined3d_gl_info *gl_info)
MAP_GL_FUNCTION(glVertexAttrib4sv, glVertexAttrib4svARB);
MAP_GL_FUNCTION(glVertexAttrib4ubv, glVertexAttrib4ubvARB);
MAP_GL_FUNCTION(glVertexAttribDivisor, glVertexAttribDivisorARB);
MAP_GL_FUNCTION(glVertexAttribIPointer, glVertexAttribIPointerEXT);
MAP_GL_FUNCTION(glVertexAttribPointer, glVertexAttribPointerARB);
#undef MAP_GL_FUNCTION
#undef MAP_GL_FUNCTION_CAST

View File

@ -1705,6 +1705,16 @@ static BOOL glsl_is_shadow_sampler(const struct wined3d_shader *shader,
return version->type == WINED3D_SHADER_TYPE_PIXEL && (ps_args->shadow & (1u << resource_idx));
}
static void shader_glsl_declare_typed_vertex_attribute(struct wined3d_string_buffer *buffer,
const struct wined3d_gl_info *gl_info, const char *vector_type, const char *scalar_type,
unsigned int index)
{
shader_addline(buffer, "%s %s4 vs_in_%s%u;\n",
get_attribute_keyword(gl_info), vector_type, scalar_type, index);
shader_addline(buffer, "vec4 vs_in%u = %sBitsToFloat(vs_in_%s%u);\n",
index, scalar_type, scalar_type, index);
}
/** Generate the variable & register declarations for the GLSL output target */
static void shader_generate_glsl_declarations(const struct wined3d_context *context,
struct wined3d_string_buffer *buffer, const struct wined3d_shader *shader,
@ -1957,14 +1967,30 @@ static void shader_generate_glsl_declarations(const struct wined3d_context *cont
{
const struct wined3d_shader_signature_element *e = &shader->input_signature.elements[i];
if (e->sysval_semantic == WINED3D_SV_VERTEX_ID)
{
shader_addline(buffer, "vec4 %s_in%u = vec4(intBitsToFloat(gl_VertexID), 0.0, 0.0, 0.0);\n",
prefix, e->register_idx);
}
else if (e->sysval_semantic == WINED3D_SV_INSTANCE_ID)
{
shader_addline(buffer, "vec4 %s_in%u = vec4(intBitsToFloat(gl_InstanceID), 0.0, 0.0, 0.0);\n",
prefix, e->register_idx);
}
else if (e->component_type == WINED3D_TYPE_UINT)
{
shader_glsl_declare_typed_vertex_attribute(buffer, gl_info, "uvec", "uint", e->register_idx);
}
else if (e->component_type == WINED3D_TYPE_INT)
{
shader_glsl_declare_typed_vertex_attribute(buffer, gl_info, "ivec", "int", e->register_idx);
}
else
{
if (e->component_type && e->component_type != WINED3D_TYPE_FLOAT)
FIXME("Unhandled type %#x.\n", e->component_type);
shader_addline(buffer, "%s vec4 %s_in%u;\n",
get_attribute_keyword(gl_info), prefix, e->register_idx);
}
}
if (vs_args->point_size && !vs_args->per_vertex_point_size)
@ -7596,6 +7622,13 @@ static void set_glsl_shader_program(const struct wined3d_context *context, const
string_buffer_sprintf(tmp_name, "vs_in%u", i);
GL_EXTCALL(glBindAttribLocation(program_id, i, tmp_name->buffer));
if (vshader && vshader->reg_maps.shader_version.major >= 4)
{
string_buffer_sprintf(tmp_name, "vs_in_uint%u", i);
GL_EXTCALL(glBindAttribLocation(program_id, i, tmp_name->buffer));
string_buffer_sprintf(tmp_name, "vs_in_int%u", i);
GL_EXTCALL(glBindAttribLocation(program_id, i, tmp_name->buffer));
}
}
checkGLcall("glBindAttribLocation");
string_buffer_release(&priv->string_buffers, tmp_name);

View File

@ -308,7 +308,7 @@ static void shader_signature_from_semantic(struct wined3d_shader_signature_eleme
e->semantic_name = shader_semantic_name_from_usage(s->usage);
e->semantic_idx = s->usage_idx;
e->sysval_semantic = shader_sysval_semantic_from_usage(s->usage);
e->component_type = 0;
e->component_type = WINED3D_TYPE_FLOAT;
e->register_idx = s->reg.reg.idx[0].offset;
e->mask = s->reg.write_mask;
}
@ -319,7 +319,7 @@ static void shader_signature_from_usage(struct wined3d_shader_signature_element
e->semantic_name = shader_semantic_name_from_usage(usage);
e->semantic_idx = usage_idx;
e->sysval_semantic = shader_sysval_semantic_from_usage(usage);
e->component_type = 0;
e->component_type = WINED3D_TYPE_FLOAT;
e->register_idx = reg_idx;
e->mask = write_mask;
}

View File

@ -3963,15 +3963,17 @@ static void unload_numbered_arrays(struct wined3d_context *context)
static void load_numbered_arrays(struct wined3d_context *context,
const struct wined3d_stream_info *stream_info, const struct wined3d_state *state)
{
const struct wined3d_shader *vs = state->shader[WINED3D_SHADER_TYPE_VERTEX];
const struct wined3d_gl_info *gl_info = context->gl_info;
GLuint curVBO = gl_info->supported[ARB_VERTEX_BUFFER_OBJECT] ? ~0U : 0;
int i;
unsigned int i;
/* Default to no instancing */
context->instance_count = 0;
for (i = 0; i < MAX_ATTRIBS; i++)
for (i = 0; i < MAX_ATTRIBS; ++i)
{
const struct wined3d_stream_info_element *element = &stream_info->elements[i];
const struct wined3d_stream_state *stream;
if (!(stream_info->use_map & (1u << i)))
@ -3985,16 +3987,16 @@ static void load_numbered_arrays(struct wined3d_context *context,
continue;
}
stream = &state->streams[stream_info->elements[i].stream_idx];
stream = &state->streams[element->stream_idx];
if ((stream->flags & WINED3DSTREAMSOURCE_INSTANCEDATA) && !context->instance_count)
context->instance_count = state->streams[0].frequency ? state->streams[0].frequency : 1;
if (gl_info->supported[ARB_INSTANCED_ARRAYS])
{
GL_EXTCALL(glVertexAttribDivisor(i, stream_info->elements[i].divisor));
GL_EXTCALL(glVertexAttribDivisor(i, element->divisor));
}
else if (stream_info->elements[i].divisor)
else if (element->divisor)
{
/* Unload instanced arrays, they will be loaded using
* immediate mode instead. */
@ -4003,25 +4005,32 @@ static void load_numbered_arrays(struct wined3d_context *context,
continue;
}
TRACE_(d3d_shader)("Loading array %u [VBO=%u]\n", i, stream_info->elements[i].data.buffer_object);
TRACE_(d3d_shader)("Loading array %u [VBO=%u].\n", i, element->data.buffer_object);
if (stream_info->elements[i].stride)
if (element->stride)
{
if (curVBO != stream_info->elements[i].data.buffer_object)
if (curVBO != element->data.buffer_object)
{
GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, stream_info->elements[i].data.buffer_object));
GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, element->data.buffer_object));
checkGLcall("glBindBuffer");
curVBO = stream_info->elements[i].data.buffer_object;
curVBO = element->data.buffer_object;
}
/* Use the VBO to find out if a vertex buffer exists, not the vb
* pointer. vb can point to a user pointer data blob. In that case
* curVBO will be 0. If there is a vertex buffer but no vbo we
* won't be load converted attributes anyway. */
GL_EXTCALL(glVertexAttribPointer(i, stream_info->elements[i].format->gl_vtx_format,
stream_info->elements[i].format->gl_vtx_type,
stream_info->elements[i].format->gl_normalized,
stream_info->elements[i].stride, stream_info->elements[i].data.addr
+ state->load_base_vertex_index * stream_info->elements[i].stride));
if (vs && vs->reg_maps.shader_version.major >= 4
&& (element->format->flags[WINED3D_GL_RES_TYPE_BUFFER] & WINED3DFMT_FLAG_INTEGER))
{
GL_EXTCALL(glVertexAttribIPointer(i, element->format->gl_vtx_format, element->format->gl_vtx_type,
element->stride, element->data.addr + state->load_base_vertex_index * element->stride));
}
else
{
GL_EXTCALL(glVertexAttribPointer(i, element->format->gl_vtx_format, element->format->gl_vtx_type,
element->format->gl_normalized, element->stride,
element->data.addr + state->load_base_vertex_index * element->stride));
}
if (!(context->numbered_array_mask & (1u << i)))
{
@ -4035,15 +4044,14 @@ static void load_numbered_arrays(struct wined3d_context *context,
* glVertexAttribPointer doesn't do that. Instead disable the
* pointer and set up the attribute statically. But we have to
* figure out the system memory address. */
const BYTE *ptr = stream_info->elements[i].data.addr;
if (stream_info->elements[i].data.buffer_object)
{
const BYTE *ptr = element->data.addr;
if (element->data.buffer_object)
ptr += (ULONG_PTR)buffer_get_sysmem(stream->buffer, context);
}
if (context->numbered_array_mask & (1u << i)) unload_numbered_array(context, i);
if (context->numbered_array_mask & (1u << i))
unload_numbered_array(context, i);
switch (stream_info->elements[i].format->id)
switch (element->format->id)
{
case WINED3DFMT_R32_FLOAT:
GL_EXTCALL(glVertexAttrib1fv(i, (const GLfloat *)ptr));
@ -4103,11 +4111,11 @@ static void load_numbered_arrays(struct wined3d_context *context,
break;
case WINED3DFMT_R10G10B10A2_UINT:
FIXME("Unsure about WINED3DDECLTYPE_UDEC3\n");
FIXME("Unsure about WINED3DDECLTYPE_UDEC3.\n");
/*glVertexAttrib3usvARB(i, (const GLushort *)ptr); Does not exist */
break;
case WINED3DFMT_R10G10B10A2_SNORM:
FIXME("Unsure about WINED3DDECLTYPE_DEC3N\n");
FIXME("Unsure about WINED3DDECLTYPE_DEC3N.\n");
/*glVertexAttrib3NusvARB(i, (const GLushort *)ptr); Does not exist */
break;
@ -4141,7 +4149,7 @@ static void load_numbered_arrays(struct wined3d_context *context,
break;
default:
ERR("Unexpected declaration in stride 0 attributes\n");
ERR("Unexpected declaration in stride 0 attributes.\n");
break;
}

View File

@ -763,6 +763,13 @@ enum wined3d_sysval_semantic
WINED3D_SV_LINE_DENSITY_TESS_FACTOR = 22,
};
enum wined3d_component_type
{
WINED3D_TYPE_UINT = 1,
WINED3D_TYPE_INT = 2,
WINED3D_TYPE_FLOAT = 3,
};
enum wined3d_scanline_ordering
{
WINED3D_SCANLINE_ORDERING_UNKNOWN = 0,
@ -1915,7 +1922,7 @@ struct wined3d_shader_signature_element
const char *semantic_name;
UINT semantic_idx;
enum wined3d_sysval_semantic sysval_semantic;
DWORD component_type;
enum wined3d_component_type component_type;
UINT register_idx;
DWORD mask;
};