45#define WINED3D_MAX_FBO_ENTRIES 64
46#define WINED3D_ALL_LAYERS (~0u)
60 if (
context->fbo_read_binding == fbo)
return;
61 context->fbo_read_binding = fbo;
65 if (
context->fbo_draw_binding == fbo)
return;
66 context->fbo_draw_binding = fbo;
70 if (
context->fbo_read_binding == fbo
71 &&
context->fbo_draw_binding == fbo)
return;
72 context->fbo_read_binding = fbo;
73 context->fbo_draw_binding = fbo;
90 for (
i = 0;
i < gl_info->
limits.buffers; ++
i)
111 gl_info->
fbo_ops.glDeleteFramebuffers(1, &fbo);
142 if (!gl_info->
fbo_ops.glFramebufferTexture)
144 FIXME(
"OpenGL implementation doesn't support glFramebufferTexture().\n");
154 if (!gl_info->
fbo_ops.glFramebufferTextureLayer)
156 FIXME(
"OpenGL implementation doesn't support glFramebufferTextureLayer().\n");
210 TRACE(
"Attach depth stencil 0.\n");
265 const char *tex_type_str;
278 if (gl_info->
limits.samples > 1)
283 FIXME(
" %s: renderbuffer %d, %dx%d, %d samples, format %#x.\n",
293 if (gl_info->
gl_ops.ext.p_glGetTextureParameteriv)
299 if (texture_type[
i].
target == tex_target)
301 tex_type_str = texture_type[
i].str;
314 tex_type_str =
"cube";
322 if (!gl_info->
supported[texture_type[
i].extension])
325 gl_info->
gl_ops.gl.p_glGetIntegerv(texture_type[
i].binding, &old_texture);
326 while (gl_info->
gl_ops.gl.p_glGetError());
329 if (!gl_info->
gl_ops.gl.p_glGetError())
331 tex_target = texture_type[
i].target;
332 tex_type_str = texture_type[
i].str;
335 gl_info->
gl_ops.gl.p_glBindTexture(texture_type[
i].
target, old_texture);
340 FIXME(
"Cannot find type of texture %d.\n",
name);
345 if (gl_info->
gl_ops.ext.p_glGetTextureParameteriv)
362 gl_info->
gl_ops.gl.p_glBindTexture(tex_target, old_texture);
365 FIXME(
" %s: %s texture %d, %dx%d, %d samples, format %#x.\n",
392 TRACE(
"FBO complete.\n");
402 ERR(
"FBO 0 is incomplete, driver bug?\n");
409 for (
i = 0;
i < gl_info->
limits.buffers; ++
i)
443 key->objects[
idx].object = 0;
444 key->objects[
idx].target = 0;
449 if (render_target->
gl_view.name)
453 key->objects[
idx].level = 0;
466 key->objects[
idx].target = 0;
468 key->rb_namespace |= 1 <<
idx;
473 key->objects[
idx].level = sub_resource_idx %
texture->level_count;
474 key->objects[
idx].layer = sub_resource_idx /
texture->level_count;
491 key->objects[
idx].target = 0;
493 key->rb_namespace |= 1 <<
idx;
498 key->objects[
idx].target = 0;
500 key->rb_namespace |= 1 <<
idx;
512 key->rb_namespace = 0;
588 struct wined3d_fbo_entry_key fbo_key;
589 unsigned int i, ds_level, rt_level;
605 WARN(
"Depth stencil is smaller than the primary color buffer, disabling.\n");
606 depth_stencil = &ds_null;
608 else if (ds_texture->
resource.multisample_type != rt_texture->
resource.multisample_type
609 || ds_texture->
resource.multisample_quality != rt_texture->
resource.multisample_quality)
611 WARN(
"Color multisample type %u and quality %u, depth stencil has %u and %u, disabling ds buffer.\n",
612 rt_texture->
resource.multisample_type, rt_texture->
resource.multisample_quality,
613 ds_texture->
resource.multisample_type, ds_texture->
resource.multisample_quality);
614 depth_stencil = &ds_null;
631 const char *resource_type;
633 TRACE(
"Dumping FBO attachments:\n");
634 for (
i = 0;
i < gl_info->
limits.buffers; ++
i)
642 resource_type =
"buffer";
650 resource_type =
"texture";
653 TRACE(
" Color attachment %u: %p, %u format %s, %s %u, %ux%u, %u samples.\n",
655 fbo_key.rb_namespace & (1 << (
i + 1)) ?
"renderbuffer" : resource_type,
665 resource_type =
"buffer";
673 resource_type =
"texture";
676 TRACE(
" Depth attachment: %p, %u format %s, %s %u, %ux%u, %u samples.\n",
678 fbo_key.rb_namespace & (1 << 0) ?
"renderbuffer" : resource_type,
685 if (
memcmp(&fbo_key, &
entry->key,
sizeof(fbo_key)))
714 GLuint read_binding, draw_binding;
723 read_binding =
context->fbo_read_binding;
724 draw_binding =
context->fbo_draw_binding;
738 for (
i = 0;
i < gl_info->
limits.buffers; ++
i)
741 entry->key.rb_namespace & (1 << (
i + 1)));
796 render_targets, &
ds, color_location, ds_location);
810 context->blit_targets[0].layer_count = 1;
820 if (
context->free_occlusion_query_count)
835 WARN(
"Occlusion queries not supported, not allocating query id.\n");
852 &
context->free_occlusion_query_size,
context->free_occlusion_query_count + 1,
853 sizeof(*
context->free_occlusion_queries)))
855 ERR(
"Failed to grow free list, leaking query %u in context %p.\n",
query->id,
context);
877 TRACE(
"Allocated sync object in context %p.\n",
context);
895 WARN(
"Fences not supported, not allocating fence.\n");
913 sizeof(*
context->free_fences)))
915 ERR(
"Failed to grow free list, leaking fence %u in context %p.\n", fence->
object.
id,
context);
927 if (
context->free_timestamp_query_count)
951 &
context->free_timestamp_query_size,
context->free_timestamp_query_count + 1,
952 sizeof(*
context->free_timestamp_queries)))
954 ERR(
"Failed to grow free list, leaking query %u in context %p.\n",
query->id,
context);
966 if (
context->free_so_statistics_query_count)
975 TRACE(
"Allocated SO statistics queries %u, %u in context %p.\n",
991 &
context->free_so_statistics_query_size,
context->free_so_statistics_query_count + 1,
992 sizeof(*
context->free_so_statistics_queries)))
994 ERR(
"Failed to grow free list, leaking GL queries %u, %u in context %p.\n",
1007 if (
context->free_pipeline_statistics_query_count)
1009 query->u =
context->free_pipeline_statistics_queries[--
context->free_pipeline_statistics_query_count];
1029 &
context->free_pipeline_statistics_query_size,
context->free_pipeline_statistics_query_count + 1,
1030 sizeof(*
context->free_pipeline_statistics_queries)))
1032 ERR(
"Failed to grow free list, leaking GL queries in context %p.\n",
context);
1036 context->free_pipeline_statistics_queries[
context->free_pipeline_statistics_query_count++] =
query->u;
1046 for (
i = 0;
i <
device->context_count; ++
i)
1054 for (
j = 0;
j < gl_info->
limits.buffers + 1; ++
j)
1057 && !(
entry->key.rb_namespace & (1 <<
j)) == !rb_namespace)
1079 if (!
device->d3d_initialized)
1088 for (
i = 0;
i <
device->context_count; ++
i)
1094 context->current_rt.sub_resource_idx = 0;
1118 for (
i = 0;
i < gl_info->
limits.buffers + 1; ++
i)
1120 if (surface->
container->texture_rgb.name ==
entry->key.objects[
i].object
1121 || surface->
container->texture_srgb.name ==
entry->key.objects[
i].object)
1123 TRACE(
"Updated surface %p is bound as attachment %u to the current FBO.\n", surface,
i);
1144 ERR(
"wglSetPixelFormatWINE failed to restore pixel format %d on window %p.\n",
1145 ctx->restore_pf,
ctx->restore_pf_win);
1152 ERR(
"can't restore pixel format %d on window %p\n",
ctx->restore_pf,
ctx->restore_pf_win);
1156 ctx->restore_pf = 0;
1169 if (
private &&
context->hdc_has_format)
1183 WARN(
"Failed to set pixel format %d on device context %p, last error %#x.\n",
1203 ERR(
"wglSetPixelFormatWINE failed to set pixel format %d on device context %p.\n",
1224 ERR(
"Unable to set pixel format %d on device context %p. Already using format %d.\n",
1241 WARN(
"Failed to set pixel format %d on device context %p.\n",
1242 ctx->pixel_format,
ctx->hdc);
1248 WARN(
"Failed to make GL context %p current on device context %p, last error %#x.\n",
1251 WARN(
"Trying fallback to the backup window.\n");
1257 if (
ctx->destroyed || !swapchain)
1259 FIXME(
"Unable to get backup dc for destroyed context %p.\n",
ctx);
1275 ERR(
"Failed to set pixel format %d on device context %p.\n",
1276 ctx->pixel_format,
ctx->hdc);
1283 ERR(
"Fallback to backup window (dc %p) failed too, last error %#x.\n",
1299 ERR(
"Failed to restore GL context %p on device context %p, last error %#x.\n",
1313 TRACE(
"Updating context %p window from %p to %p.\n",
1327 ERR(
"Failed to get a device context for window %p.\n",
context->win_handle);
1348 if (restore_ctx ==
context->glCtx)
1418 if (
context->dummy_arbfp_prog)
1425 for (
i = 0;
i <
context->free_so_statistics_query_count; ++
i)
1434 for (
i = 0;
i <
context->free_pipeline_statistics_query_count; ++
i)
1449 for (
i = 0;
i <
context->free_fence_count; ++
i)
1456 for (
i = 0;
i <
context->free_fence_count; ++
i)
1463 for (
i = 0;
i <
context->free_fence_count; ++
i)
1485 ERR(
"Failed to disable GL context.\n");
1493 ERR(
"wglDeleteContext(%p) failed, last error %#x.\n",
context->glCtx,
err);
1518 TRACE(
"Already using D3D context %p.\n",
ctx);
1526 TRACE(
"Switching away from destroyed context %p.\n", old);
1536 TRACE(
"Flushing context %p before switching to %p.\n", old,
ctx);
1537 gl_info->
gl_ops.gl.p_glFlush();
1547 ERR(
"Trying to make invalid context %p current\n",
ctx);
1551 TRACE(
"Switching to D3D context %p, GL context %p, device context %p.\n",
ctx,
ctx->glCtx,
ctx->hdc);
1558 TRACE(
"Clearing current D3D context.\n");
1562 ERR(
"Failed to clear current GL context, last error %#x.\n",
err);
1580 WARN(
"Context %p is not the current context.\n",
context);
1589 TRACE(
"Restoring GL context %p on device context %p.\n",
context->restore_ctx,
context->restore_dc);
1628 if (current_gl && (!current_context || current_context->
glCtx != current_gl))
1630 TRACE(
"Another GL context (%p on device context %p) is already current.\n",
1632 context->restore_ctx = current_gl;
1671 unsigned int cfg_count =
device->adapter->cfg_count;
1672 unsigned int current_value;
1677 TRACE(
"device %p, dc %p, color_format %s, ds_format %s, aux_buffers %#x.\n",
1682 for (
i = 0;
i < cfg_count; ++
i)
1727 if (
value > current_value)
1730 current_value =
value;
1736 ERR(
"Trying to locate a compatible pixel format because an exact match failed.\n");
1753 ERR(
"Can't find a suitable pixel format.\n");
1758 TRACE(
"Found iPixelFormat=%d for ColorFormat=%s, DepthStencilFormat=%s.\n",
1770 for (
i = 0;
i < gl_info->
limits.combined_samplers; ++
i)
1820 ERR(
">>>>>>> %s (%#x) from %s @ %s / %u.\n",
1822 err = gl_info->
gl_ops.gl.p_glGetError();
1860 unsigned int ctx_attrib_idx = 0;
1861 GLint ctx_attribs[7], ctx_flags = 0;
1874 ctx_attribs[ctx_attrib_idx++] = ctx_flags;
1876 ctx_attribs[ctx_attrib_idx] = 0;
1878 if (!(
ctx = gl_info->p_wglCreateContextAttribsARB(
hdc, share_ctx, ctx_attribs)))
1882 ctx_attribs[ctx_attrib_idx - 1] &= ~WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
1883 if (!(
ctx = gl_info->p_wglCreateContextAttribsARB(
hdc, share_ctx, ctx_attribs)))
1884 WARN(
"Failed to create a WGL context with wglCreateContextAttribsARB, last error %#x.\n",
1909 if (!(
ret = heap_alloc_zero(
sizeof(*
ret))))
1912 ret->free_timestamp_query_size = 4;
1914 sizeof(*
ret->free_timestamp_queries))))
1918 ret->free_occlusion_query_size = 4;
1920 sizeof(*
ret->free_occlusion_queries))))
1924 ret->free_fence_size = 4;
1936 if (!
device->shader_backend->shader_allocate_context_data(
ret))
1938 ERR(
"Failed to allocate shader backend context data.\n");
1941 if (!
device->adapter->fragment_pipe->allocate_context_data(
ret))
1943 ERR(
"Failed to allocate fragment pipeline context data.\n");
1959 ERR(
"Unexpected texture unit base index %u.\n",
base);
1971 ERR(
"Unexpected texture unit base index %u.\n",
base);
1982 sizeof(*
ret->texture_type))))
1987 WARN(
"Failed to retrieve device context, trying swapchain backup.\n");
1993 ERR(
"Failed to retrieve a device context.\n");
1998 color_format =
target->resource.format;
1999 target_usage =
target->resource.usage;
2047 ERR(
"Failed to set pixel format %d on device context %p.\n",
ret->pixel_format,
ret->hdc);
2053 if (
gl_info->p_wglCreateContextAttribsARB)
2062 ERR(
"Failed to create a WGL context.\n");
2069 ERR(
"wglShareLists(%p, %p) failed, last error %#x.\n", share_ctx,
ctx,
GetLastError());
2079 ERR(
"Failed to add the newly created context to the context list\n");
2100 ret->current_rt.sub_resource_idx = 0;
2114 ERR(
"Cannot activate context to set up defaults.\n");
2152 TRACE(
"Setting up the screen\n");
2157 checkGLcall(
"glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);");
2160 checkGLcall(
"glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);");
2163 checkGLcall(
"glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);");
2175 checkGLcall(
"glPixelStorei(GL_PACK_ALIGNMENT, device->surface_alignment);");
2177 checkGLcall(
"glPixelStorei(GL_UNPACK_ALIGNMENT, 1);");
2193 for (
i = 1;
i <
gl_info->limits.textures; ++
i)
2198 checkGLcall(
"glTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, ...");
2212 static const char dummy_program[] =
2214 "MOV result.color, fragment.color.primary;\n"
2223 for (
i = 0;
i <
gl_info->limits.textures; ++
i)
2227 checkGLcall(
"glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE)");
2244 checkGLcall(
"enable GL_PRIMITIVE_RESTART_FIXED_INDEX");
2248 FIXME(
"OpenGL implementation does not support GL_PRIMITIVE_RESTART_FIXED_INDEX.\n");
2255 checkGLcall(
"enable seamless cube map filtering");
2259 device->shader_backend->shader_init_context_state(
ret);
2270 if (
device->dummy_textures.tex_2d)
2273 TRACE(
"Created context %p.\n",
ret);
2280 device->shader_backend->shader_free_context_data(
ret);
2281 device->adapter->fragment_pipe->free_context_data(
ret);
2302 TRACE(
"Delaying destruction of context %p.\n",
context);
2339 if (!shader_version)
2346 if (shader_version->
major >= 4)
2352 switch (shader_version->
type)
2363 ERR(
"Unhandled shader type %#x.\n", shader_version->
type);
2376 2.0 /
width, 0.0, 0.0, 0.0,
2377 0.0, 2.0 /
height, 0.0, 0.0,
2379 -1.0, -1.0, -1.0, 1.0,
2386 gl_info->
gl_ops.gl.p_glLoadMatrixd(projection);
2417 unsigned int clip_distance_count = gl_info->
limits.user_clip_distances;
2418 unsigned int i, disable_mask, current_mask;
2420 disable_mask = ~enable_mask;
2421 enable_mask &= (1u << clip_distance_count) - 1;
2422 disable_mask &= (1u << clip_distance_count) - 1;
2423 current_mask =
context->clip_distance_mask;
2424 context->clip_distance_mask = enable_mask;
2426 enable_mask &= ~current_mask;
2432 disable_mask &= current_mask;
2433 while (disable_mask)
2465 TRACE(
"Setting up context %p for blitting\n",
context);
2479 TRACE(
"Context is already set up for blitting, nothing to do\n");
2492 for (
i = gl_info->
limits.textures - 1;
i > 0 ; --
i)
2507 checkGLcall(
"glDisable GL_TEXTURE_RECTANGLE_ARB");
2513 checkGLcall(
"glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);");
2534 checkGLcall(
"glDisable GL_TEXTURE_RECTANGLE_ARB");
2543 gl_info->
gl_ops.gl.p_glLoadIdentity();
2550 checkGLcall(
"glTexEnvf GL_TEXTURE_LOD_BIAS_EXT ...");
2556 gl_info->
gl_ops.gl.p_glLoadIdentity();
2643 return rt_mask & (1u << 31);
2648 return rt_mask & ~(1u << 31);
2688 gl_info->
gl_ops.gl.p_glDrawBuffer(draw_buffers[0]);
2693 ERR(
"Unexpected draw buffers mask with backbuffer ORM.\n");
2707 if (new_mask == *current_mask)
2713 *current_mask = new_mask;
2750 if (old_texture_type !=
target)
2752 switch (old_texture_type)
2793 ERR(
"Unexpected texture target %#x.\n", old_texture_type);
2808 if (!
data->buffer_object)
2836 if (!
data->buffer_object)
2851 BYTE *dst_ptr, *src_ptr;
2855 if (
dst->buffer_object &&
src->buffer_object)
2876 else if (!
dst->buffer_object &&
src->buffer_object)
2882 else if (
dst->buffer_object && !
src->buffer_object)
2896 if (
context->render_offscreen == offscreen)
2910 context->render_offscreen = offscreen;
2916 if (existing == required)
2937 if (
context->render_offscreen || !depth_stencil)
return;
2943 WARN(
"Depth stencil format is not supported by WGL, rendering the backbuffer in an FBO\n");
2948 ERR(
"Failed to load location.\n");
2985 DWORD rt_mask, *cur_mask;
2989 if (
context->render_offscreen)
3014 if (rt_mask != *cur_mask)
3017 *cur_mask = rt_mask;
3037 for (
i = 0;
i < rt_count; ++
i)
3053 DWORD rt_mask = 0, *cur_mask;
3057 || rt_count != gl_info->
limits.buffers)
3061 WARN(
"Invalid render target config, need at least one attachment.\n");
3072 for (
i = 0;
i < rt_count; ++
i)
3082 rt_mask |= (1u <<
i);
3086 rt_count ? rts[0]->
resource->draw_binding : 0,
3087 dsv ? dsv->
resource->draw_binding : 0);
3110 for (
i = 0;
i < rt_count; ++
i)
3113 rt_mask |= (1u <<
i);
3124 if (rt_mask != *cur_mask)
3127 *cur_mask = rt_mask;
3169 else if (!
context->render_offscreen)
3177 rt_mask =
ps ?
ps->reg_maps.rt_mask : 1;
3179 rt_mask &=
context->d3d_info->valid_dual_rt_mask;
3181 rt_mask &=
context->d3d_info->valid_rt_mask;
3189 rt_mask &= ~(1u <<
i);
3200 DWORD color_location = 0;
3205 if (!
context->render_offscreen)
3215 for (
i = 0;
i <
context->gl_info->limits.buffers; ++
i)
3225 if (!color_location)
3235 if (rt_mask != *cur_mask)
3238 *cur_mask = rt_mask;
3248 TRACE(
"Mapping stage %u to unit %u.\n", stage,
unit);
3271 context->fixed_function_usage_map = 0;
3295 context->fixed_function_usage_map |= (1u <<
i);
3299 context->fixed_function_usage_map |= (1u << (
i + 1));
3302 if (i < context->lowest_disabled_stage)
3313 context->lowest_disabled_stage =
i;
3324 unsigned int i, tex;
3327 ffu_map =
context->fixed_function_usage_map;
3329 if (d3d_info->
limits.ffp_textures == d3d_info->
limits.ffp_blend_stages
3330 ||
context->lowest_disabled_stage <= d3d_info->
limits.ffp_textures)
3332 for (
i = 0; ffu_map; ffu_map >>= 1, ++
i)
3349 for (
i = 0; ffu_map; ffu_map >>= 1, ++
i)
3354 if (
context->tex_unit_map[
i] != tex)
3378 if (i < d3d_info->limits.ffp_blend_stages)
3397 if (!ps_resource_info)
3400 return current_mapping >=
MAX_TEXTURES || !(
context->fixed_function_usage_map & (1u << current_mapping));
3404 return !ps_resource_info[current_mapping].
type;
3428 if (vs_resource_info[
i].
type)
3447 WARN(
"Couldn't find a free texture unit for vertex sampler %u.\n",
i);
3481 DWORD rt_mask, *cur_mask;
3487 if (rt_mask != *cur_mask)
3490 *cur_mask = rt_mask;
3562 stride_used =
FALSE;
3580 if (!generic_attributes && !
element->ffp_valid)
3582 WARN(
"Skipping unsupported fixed function element of format %s and usage %s.\n",
3584 stride_used =
FALSE;
3594 TRACE(
"Load %s array %u [usage %s, usage_idx %u, "
3595 "input_slot %u, offset %u, stride %u, format %s, class %s, step_rate %u].\n",
3596 use_vshader ?
"shader":
"fixed function",
idx,
3613 if (!
element->instance_data_step_rate)
3614 FIXME(
"Instance step rate 0 not implemented.\n");
3644 context->buffer_fence_count = 0;
3665 if (
state->load_base_vertex_index < 0)
3667 WARN_(d3d_perf)(
"load_base_vertex_index is < 0 (%d), not using VBOs.\n",
3668 state->load_base_vertex_index);
3669 element->data.buffer_object = 0;
3672 FIXME(
"System memory vertex data load offset is negative!\n");
3682 if (!
element->data.buffer_object)
3701 if (
state->vertex_declaration->half_float_conv_needed)
3703 TRACE(
"Using immediate mode draw with vertex shaders for FLOAT16 conversion.\n");
3757 for (
i = 0; ffu_map; ffu_map >>= 1, ++
i)
3766 unsigned int shader_mask)
3775 if (!(shader_mask & (1u <<
i)))
3787 for (
j = 0;
j <
shader->reg_maps.sampler_map.count; ++
j)
3805 unsigned int bind_idx, shader_sampler_count,
base,
count,
i;
3811 const DWORD *tex_unit_map;
3819 shader_sampler_count =
shader->reg_maps.sampler_map.count;
3820 if (shader_sampler_count >
count)
3821 FIXME(
"Shader %p needs %u samplers, but only %u are supported.\n",
3830 bind_idx = tex_unit_map[bind_idx];