[D3D] Some lock / unlock fixes

Lionel Ulmer lionel.ulmer at free.fr
Mon May 19 15:07:55 CDT 2003


All,

With this patch, DungeonSiege demo is now playable (albeit awfully slow on
my puny configuration (P2 333 / TNT2U)). There are still some graphical
corruptions but it does not prevent one to play the game (note : if someone
can do for me screenshots of the start of the game in real Windows, I would
be happy to see how it really should look like ;-) ).

Changelog:
 - some tracing fixes
 - flush the right buffer to the screen
 
-- 
		 Lionel Ulmer - http://www.bbrox.org/
-------------- next part --------------
--- dlls/ddraw_CVS/d3d_private.h	Mon May 19 10:20:20 2003
+++ dlls/ddraw/d3d_private.h	Mon May 19 21:48:28 2003
@@ -253,7 +253,7 @@
     void (*matrices_updated)(IDirect3DDeviceImpl *This, DWORD matrices);
     void (*set_matrices)(IDirect3DDeviceImpl *This, DWORD matrices,
 			 D3DMATRIX *world_mat, D3DMATRIX *view_mat, D3DMATRIX *proj_mat);
-    void (*flush_to_framebuffer)(IDirect3DDeviceImpl *This, LPCRECT pRect);
+    void (*flush_to_framebuffer)(IDirect3DDeviceImpl *This, LPCRECT pRect, IDirectDrawSurfaceImpl *surf);
 
     STATEBLOCK state_block;
 
--- dlls/ddraw_CVS/d3ddevice/mesa.c	Mon May 19 17:33:56 2003
+++ dlls/ddraw/d3ddevice/mesa.c	Mon May 19 22:04:20 2003
@@ -113,7 +113,7 @@
     TRACE("(%p, %ld)\n", gl_d3d_dev->display,(Drawable)drawable);
     ENTER_GL();
     if (gl_d3d_dev->state == SURFACE_MEMORY_DIRTY) {
-        d3d_dev->flush_to_framebuffer(d3d_dev, NULL);
+        d3d_dev->flush_to_framebuffer(d3d_dev, NULL, gl_d3d_dev->lock_surf);
     }
     gl_d3d_dev->state = SURFACE_GL;
     gl_d3d_dev->front_state = SURFACE_GL;
@@ -1101,7 +1101,7 @@
 
     ENTER_GL();
     if (glThis->state == SURFACE_MEMORY_DIRTY) {
-        This->flush_to_framebuffer(This, NULL);
+        This->flush_to_framebuffer(This, NULL, glThis->lock_surf);
     }
     LEAVE_GL();
 
@@ -2439,7 +2439,7 @@
 
     if (glThis->state == SURFACE_MEMORY_DIRTY) {
         /* TODO: optimize here the case where Clear changes all the screen... */
-        This->flush_to_framebuffer(This, NULL);
+        This->flush_to_framebuffer(This, NULL, glThis->lock_surf);
     }
     glThis->state = SURFACE_GL;
 
@@ -2711,8 +2711,18 @@
     
     if ((This->surface_desc.ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER|DDSCAPS_PRIMARYSURFACE)) != 0) {
         is_front = TRUE;
+	if ((gl_d3d_dev->front_state != SURFACE_GL) &&
+	    (gl_d3d_dev->front_lock_surf != This)) {
+	    ERR("Change of front buffer.. Expect graphic corruptions !\n");
+	}
+	gl_d3d_dev->front_lock_surf = This;
     } else if ((This->surface_desc.ddsCaps.dwCaps & (DDSCAPS_BACKBUFFER)) == (DDSCAPS_BACKBUFFER)) {
         is_front = FALSE;
+	if ((gl_d3d_dev->state != SURFACE_GL) &&
+	    (gl_d3d_dev->lock_surf != This)) {
+	    ERR("Change of back buffer.. Expect graphic corruptions !\n");
+	}
+	gl_d3d_dev->lock_surf = This;
     } else {
         ERR("Wrong surface type for locking !\n");
 	return;
@@ -2821,10 +2831,9 @@
 
 #define UNLOCK_TEX_SIZE 256
 
-static void d3ddevice_flush_to_frame_buffer(IDirect3DDeviceImpl *d3d_dev, LPCRECT pRect) {
+static void d3ddevice_flush_to_frame_buffer(IDirect3DDeviceImpl *d3d_dev, LPCRECT pRect, IDirectDrawSurfaceImpl *surf) {
     GLenum buffer_type, buffer_color;
     RECT loc_rect;
-    IDirectDrawSurfaceImpl *surf = d3d_dev->surface;
     IDirect3DDeviceGLImpl* gl_d3d_dev = (IDirect3DDeviceGLImpl*) d3d_dev;
     GLint depth_test, alpha_test, cull_face, lighting, min_tex, max_tex, tex_env, blend, stencil_test;
     GLuint initial_texture;
@@ -2989,7 +2998,7 @@
 	    ENTER_GL();
 	    glGetIntegerv(GL_DRAW_BUFFER, &prev_draw);
 	    glDrawBuffer(GL_FRONT);
-	    d3d_dev->flush_to_framebuffer(d3d_dev, pRect);
+	    d3d_dev->flush_to_framebuffer(d3d_dev, pRect, gl_d3d_dev->front_lock_surf);
 	    glDrawBuffer(prev_draw);
 	    LEAVE_GL();
 	} else {
--- dlls/ddraw_CVS/d3dexecutebuffer.c	Mon May 19 17:33:56 2003
+++ dlls/ddraw/d3dexecutebuffer.c	Mon May 19 21:48:41 2003
@@ -208,7 +208,7 @@
     ENTER_GL();
     
     if (((IDirect3DDeviceGLImpl *) lpDevice)->state == SURFACE_MEMORY_DIRTY) {
-        lpDevice->flush_to_framebuffer(lpDevice, NULL);
+        lpDevice->flush_to_framebuffer(lpDevice, NULL, ((IDirect3DDeviceGLImpl *) lpDevice)->lock_surf);
     }
     ((IDirect3DDeviceGLImpl *) lpDevice)->state = SURFACE_GL;
     
--- dlls/ddraw_CVS/d3dvertexbuffer.c	Sat Mar 15 21:47:04 2003
+++ dlls/ddraw/d3dvertexbuffer.c	Mon May 19 21:30:44 2003
@@ -30,6 +30,7 @@
 #include "mesa_private.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
+WINE_DECLARE_DEBUG_CHANNEL(ddraw_geom);
 
 HRESULT WINAPI
 Main_IDirect3DVertexBufferImpl_7_1T_QueryInterface(LPDIRECT3DVERTEXBUFFER7 iface,
@@ -352,46 +353,46 @@
 	    copy_and_next(dest_ptr, tex_coord, 2 * sizeof(D3DVALUE));
 	}
 
-	if (TRACE_ON(ddraw)) {
+	if (TRACE_ON(ddraw_geom)) {
 	    if ((dwVertexTypeDesc & D3DFVF_POSITION_MASK) == D3DFVF_XYZ) {
 	        D3DVALUE *position =
 		  (D3DVALUE *) (((char *) lpStrideData->position.lpvData) + i * lpStrideData->position.dwStride);
-		TRACE(" %f %f %f", position[0], position[1], position[2]);
+		TRACE_(ddraw_geom)(" %f %f %f", position[0], position[1], position[2]);
 	    } else if ((dwVertexTypeDesc & D3DFVF_POSITION_MASK) == D3DFVF_XYZRHW) {
 	        D3DVALUE *position =
 		  (D3DVALUE *) (((char *) lpStrideData->position.lpvData) + i * lpStrideData->position.dwStride);
-		TRACE(" %f %f %f %f", position[0], position[1], position[2], position[3]);
+		TRACE_(ddraw_geom)(" %f %f %f %f", position[0], position[1], position[2], position[3]);
 	    }
 	    if (dwVertexTypeDesc & D3DFVF_NORMAL) { 
 	        D3DVALUE *normal = 
 		  (D3DVALUE *) (((char *) lpStrideData->normal.lpvData) + i * lpStrideData->normal.dwStride);	    
-		TRACE(" / %f %f %f", normal[0], normal[1], normal[2]);
+		TRACE_(ddraw_geom)(" / %f %f %f", normal[0], normal[1], normal[2]);
 	    }
 	    if (dwVertexTypeDesc & D3DFVF_DIFFUSE) {
 	        DWORD *color_d = 
 		  (DWORD *) (((char *) lpStrideData->diffuse.lpvData) + i * lpStrideData->diffuse.dwStride);
-		TRACE(" / %02lx %02lx %02lx %02lx",
-			(*color_d >> 16) & 0xFF,
-			(*color_d >>  8) & 0xFF,
-			(*color_d >>  0) & 0xFF,
-			(*color_d >> 24) & 0xFF);
+		TRACE_(ddraw_geom)(" / %02lx %02lx %02lx %02lx",
+				   (*color_d >> 16) & 0xFF,
+				   (*color_d >>  8) & 0xFF,
+				   (*color_d >>  0) & 0xFF,
+				   (*color_d >> 24) & 0xFF);
 	    }
 	    if (dwVertexTypeDesc & D3DFVF_SPECULAR) { 
 	        DWORD *color_s = 
 		  (DWORD *) (((char *) lpStrideData->specular.lpvData) + i * lpStrideData->specular.dwStride);
-		TRACE(" / %02lx %02lx %02lx %02lx",
-			(*color_s >> 16) & 0xFF,
-			(*color_s >>  8) & 0xFF,
-			(*color_s >>  0) & 0xFF,
-			(*color_s >> 24) & 0xFF);
+		TRACE_(ddraw_geom)(" / %02lx %02lx %02lx %02lx",
+				   (*color_s >> 16) & 0xFF,
+				   (*color_s >>  8) & 0xFF,
+				   (*color_s >>  0) & 0xFF,
+				   (*color_s >> 24) & 0xFF);
 	    }
 	    for (tex_index = 0; tex_index < ((dwVertexTypeDesc & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT); tex_index++) {
 	        D3DVALUE *tex_coord =
 		  (D3DVALUE *) (((char *) lpStrideData->textureCoords[tex_index].lpvData) + 
 				i * lpStrideData->textureCoords[tex_index].dwStride);
-		TRACE(" / %f %f", tex_coord[0], tex_coord[1]);
+		TRACE_(ddraw_geom)(" / %f %f", tex_coord[0], tex_coord[1]);
 	    }
-	    TRACE("\n");
+	    TRACE_(ddraw_geom)("\n");
 	}
     }
 
--- dlls/ddraw_CVS/dsurface/main.c	Fri May 16 09:53:44 2003
+++ dlls/ddraw/dsurface/main.c	Mon May 19 21:14:04 2003
@@ -1016,9 +1016,6 @@
     /* First, copy the Surface description */
     DD_STRUCT_COPY_BYSIZE(pDDSD,&(This->surface_desc));
 
-    TRACE("locked surface returning description : \n");
-    if (TRACE_ON(ddraw)) DDRAW_dump_surface_desc(pDDSD);
-
     /* Used to optimize the D3D Device locking */
     This->lastlocktype = flags & (DDLOCK_READONLY|DDLOCK_WRITEONLY);
     
@@ -1026,15 +1023,14 @@
      * (Not documented.) */
     if (prect != NULL) {
 	TRACE("	lprect: %ldx%ld-%ldx%ld\n",
-		prect->top,prect->left,prect->bottom,prect->right
-	);
+		prect->top,prect->left,prect->bottom,prect->right);
 	if ((prect->top < 0) ||
 	    (prect->left < 0) ||
 	    (prect->bottom < 0) ||
 	    (prect->right < 0)) {
-	  ERR(" Negative values in LPRECT !!!\n");
-	  return DDERR_INVALIDPARAMS;
-       }
+	    ERR(" Negative values in LPRECT !!!\n");
+	    return DDERR_INVALIDPARAMS;
+	}
 
 	This->lock_update(This, prect, flags);
 
@@ -1045,6 +1041,9 @@
 	This->lock_update(This, NULL, flags);
     }
 
+    TRACE("locked surface returning description : \n");
+    if (TRACE_ON(ddraw)) DDRAW_dump_surface_desc(pDDSD);
+    
     return DD_OK;
 }
 
--- dlls/ddraw_CVS/mesa_private.h	Mon May 19 17:33:56 2003
+++ dlls/ddraw/mesa_private.h	Mon May 19 21:42:53 2003
@@ -123,6 +123,7 @@
 
     GLuint unlock_tex;
     SURFACE_STATE state, front_state;
+    IDirectDrawSurfaceImpl *lock_surf, *front_lock_surf;
 } IDirect3DDeviceGLImpl;
 
 /* This is for the OpenGL additions... */


More information about the wine-patches mailing list