Fixed D3DQUERYTYPE_TIMESTAMP behaviour.

A timestamp query records the current time when it's issued, not when
the data is being retrieved.

Change-Id: Idb6e7fe6736a5b54bd23ef1613eaf953da86aa08
Reviewed-on: https://swiftshader-review.googlesource.com/5771
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/D3D9/Direct3DQuery9.cpp b/src/D3D9/Direct3DQuery9.cpp
index f5d52a5..31d249e 100644
--- a/src/D3D9/Direct3DQuery9.cpp
+++ b/src/D3D9/Direct3DQuery9.cpp
@@ -169,7 +169,13 @@
 				device->setOcclusionEnabled(false);
 			}
 			break;
-		case D3DQUERYTYPE_TIMESTAMP:			if(flags != D3DISSUE_END) return INVALIDCALL(); break;
+		case D3DQUERYTYPE_TIMESTAMP:
+			if(flags == D3DISSUE_END)
+			{
+				timestamp = sw::Timer::counter();
+			}
+			else return INVALIDCALL();
+			break;
 		case D3DQUERYTYPE_TIMESTAMPDISJOINT:	if(flags != D3DISSUE_BEGIN && flags != D3DISSUE_END) return INVALIDCALL(); break;
 		case D3DQUERYTYPE_TIMESTAMPFREQ:		if(flags != D3DISSUE_END) return INVALIDCALL(); break;
 		case D3DQUERYTYPE_PIPELINETIMINGS:		if(flags != D3DISSUE_BEGIN && flags != D3DISSUE_END) return INVALIDCALL(); break;
@@ -227,7 +233,7 @@
 			case D3DQUERYTYPE_OCCLUSION:
 				*(DWORD*)data = query->data;
 				break;
-			case D3DQUERYTYPE_TIMESTAMP:			*(UINT64*)data = sw::Timer::counter(); break;     // FIXME: Verify behaviour
+			case D3DQUERYTYPE_TIMESTAMP:			*(UINT64*)data = timestamp; break;                // FIXME: Verify behaviour
 			case D3DQUERYTYPE_TIMESTAMPDISJOINT:	*(BOOL*)data = FALSE; break;                      // FIXME: Verify behaviour
 			case D3DQUERYTYPE_TIMESTAMPFREQ:		*(UINT64*)data = sw::Timer::frequency(); break;   // FIXME: Verify behaviour
 			case D3DQUERYTYPE_PIPELINETIMINGS:		UNIMPLEMENTED(); break;
diff --git a/src/D3D9/Direct3DQuery9.hpp b/src/D3D9/Direct3DQuery9.hpp
index 7c522f6..70778cf 100644
--- a/src/D3D9/Direct3DQuery9.hpp
+++ b/src/D3D9/Direct3DQuery9.hpp
@@ -49,7 +49,9 @@
 		Direct3DDevice9 *const device;
 		const D3DQUERYTYPE type;
 
-		sw::Query *query;
+		// TODO: create a union, or subclasses for each type.
+		sw::Query *query;   // D3DQUERYTYPE_OCCLUSION
+		UINT64 timestamp;   // D3DQUERYTYPE_TIMESTAMP
 	};
 }