forked from MoonsideGames/Refresh
				
			Removed D3D11_Clear, added pWidth/pHeight to AcquireSwapchainImage, fixed(?) threading crash with swapchain Present
							parent
							
								
									e44aee7101
								
							
						
					
					
						commit
						4a1e4a49a8
					
				|  | @ -310,7 +310,7 @@ typedef struct D3D11Renderer | |||
| 	IDXGIAdapter1* adapter; | ||||
| 	void *d3d11_dll; | ||||
| 	void *dxgi_dll; | ||||
| 	SDL_mutex *immediateContextMutex; | ||||
| 	SDL_mutex *contextLock; | ||||
| 
 | ||||
| 	D3D11CommandBufferPool *commandBufferPool; | ||||
| 	SDL_mutex *commandBufferAcquisitionMutex; | ||||
|  | @ -629,65 +629,6 @@ static void D3D11_DestroyDevice( | |||
| 
 | ||||
| /* Drawing */ | ||||
| 
 | ||||
| static void D3D11_Clear( | ||||
| 	Refresh_Renderer* driverData, | ||||
| 	Refresh_CommandBuffer* commandBuffer, | ||||
| 	Refresh_Rect* clearRect, | ||||
| 	Refresh_ClearOptions options, | ||||
| 	Refresh_Vec4* colors, | ||||
| 	uint32_t colorCount, | ||||
| 	Refresh_DepthStencilValue depthStencil | ||||
| ) { | ||||
| 	D3D11Renderer *renderer = (D3D11Renderer*) driverData; | ||||
| 	D3D11CommandBuffer *cmdbuf = (D3D11CommandBuffer*) commandBuffer; | ||||
| 	D3D11_CLEAR_FLAG dsClearFlags; | ||||
| 	float clearColors[4]; | ||||
| 	uint32_t i; | ||||
| 
 | ||||
| 	/* FIXME: What should we do about clearRect? */ | ||||
| 	/* FIXME: Do we need to use colorCount or is it always the number of bound RTs? */ | ||||
| 
 | ||||
| 	if (options & REFRESH_CLEAROPTIONS_COLOR) | ||||
| 	{ | ||||
| 		/* Clear color attachments */ | ||||
| 		for (i = 0; i < cmdbuf->numBoundColorAttachments; i += 1) | ||||
| 		{ | ||||
| 			clearColors[0] = colors[i].x; | ||||
| 			clearColors[1] = colors[i].y; | ||||
| 			clearColors[2] = colors[i].z; | ||||
| 			clearColors[3] = colors[i].w; | ||||
| 
 | ||||
| 			ID3D11DeviceContext_ClearRenderTargetView( | ||||
| 				cmdbuf->context, | ||||
| 				cmdbuf->rtViews[i], | ||||
| 				clearColors | ||||
| 			); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/* Check which of depth/stencil need to be cleared (if either) */ | ||||
| 	dsClearFlags = 0; | ||||
| 	if (options & REFRESH_CLEAROPTIONS_DEPTH) | ||||
| 	{ | ||||
| 		dsClearFlags |= D3D11_CLEAR_DEPTH; | ||||
| 	} | ||||
| 	if (options & REFRESH_CLEAROPTIONS_STENCIL) | ||||
| 	{ | ||||
| 		dsClearFlags |= D3D11_CLEAR_STENCIL; | ||||
| 	} | ||||
| 
 | ||||
| 	if (dsClearFlags != 0) | ||||
| 	{ | ||||
| 		ID3D11DeviceContext_ClearDepthStencilView( | ||||
| 			cmdbuf->context, | ||||
| 			cmdbuf->dsView, | ||||
| 			dsClearFlags, | ||||
| 			depthStencil.depth, | ||||
| 			(uint8_t) depthStencil.stencil | ||||
| 		); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| static void D3D11_DrawInstancedPrimitives( | ||||
| 	Refresh_Renderer* driverData, | ||||
| 	Refresh_CommandBuffer* commandBuffer, | ||||
|  | @ -1202,10 +1143,12 @@ static D3D11SwapchainData* D3D11_INTERNAL_FetchSwapchainData( | |||
| 	return swapchainData; | ||||
| } | ||||
| 
 | ||||
| Refresh_Texture* D3D11_AcquireSwapchainTexture( | ||||
| static Refresh_Texture* D3D11_AcquireSwapchainTexture( | ||||
| 	Refresh_Renderer *driverData, | ||||
| 	Refresh_CommandBuffer *commandBuffer, | ||||
| 	void *windowHandle | ||||
| 	void *windowHandle, | ||||
| 	uint32_t *pWidth, | ||||
| 	uint32_t *pHeight | ||||
| ) { | ||||
| 	D3D11Renderer *renderer = (D3D11Renderer*) driverData; | ||||
| 	D3D11CommandBuffer *cmdbuf = (D3D11CommandBuffer*) commandBuffer; | ||||
|  | @ -1241,6 +1184,10 @@ Refresh_Texture* D3D11_AcquireSwapchainTexture( | |||
| 	/* Let the command buffer know it's associated with this swapchain. */ | ||||
| 	cmdbuf->swapchainData = swapchainData; | ||||
| 
 | ||||
| 	/* Send the dimensions to the out parameters. */ | ||||
| 	*pWidth = swapchainData->refreshTexture.twod.width; | ||||
| 	*pHeight = swapchainData->refreshTexture.twod.height; | ||||
| 
 | ||||
| 	/* Return the swapchain texture */ | ||||
| 	return (Refresh_Texture*) &swapchainData->refreshTexture; | ||||
| } | ||||
|  | @ -1285,13 +1232,13 @@ static void D3D11_Submit( | |||
| 		} | ||||
| 
 | ||||
| 		/* Submit the command list to the immediate context */ | ||||
| 		SDL_LockMutex(renderer->immediateContextMutex); | ||||
| 		SDL_LockMutex(renderer->contextLock); | ||||
| 		ID3D11DeviceContext_ExecuteCommandList( | ||||
| 			renderer->immediateContext, | ||||
| 			commandList, | ||||
| 			0 | ||||
| 		); | ||||
| 		SDL_UnlockMutex(renderer->immediateContextMutex); | ||||
| 		SDL_UnlockMutex(renderer->contextLock); | ||||
| 
 | ||||
| 		/* Now that we're done, either save the command list or release it. */ | ||||
| 		if (commandBuffer->fixed) | ||||
|  | @ -1309,11 +1256,13 @@ static void D3D11_Submit( | |||
| 		/* Present, if applicable */ | ||||
| 		if (commandBuffer->swapchainData) | ||||
| 		{ | ||||
| 			SDL_LockMutex(renderer->contextLock); | ||||
| 			IDXGISwapChain_Present( | ||||
| 				commandBuffer->swapchainData->swapchain, | ||||
| 				1, /* FIXME: Assumes vsync! */ | ||||
| 				0 | ||||
| 			); | ||||
| 			SDL_UnlockMutex(renderer->contextLock); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | @ -1458,7 +1407,7 @@ tryCreateDevice: | |||
| 	SDL_memset(renderer->commandBufferPool, 0, sizeof(D3D11CommandBufferPool)); | ||||
| 
 | ||||
| 	/* Create mutexes */ | ||||
| 	renderer->immediateContextMutex = SDL_CreateMutex(); | ||||
| 	renderer->contextLock = SDL_CreateMutex(); | ||||
| 	renderer->commandBufferAcquisitionMutex = SDL_CreateMutex(); | ||||
| 
 | ||||
| 	/* Initialize miscellaneous renderer members */ | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue