]> git.cworth.org Git - apitrace/blobdiff - helpers/d3dsize.hpp
Preserve both D3D9 shader byte code, and disassembly.
[apitrace] / helpers / d3dsize.hpp
index 79095011873501ad6791988fbb25247775102b16..ef3bdff85e69f6f5b1e9ae6c260aa85652bec186 100644 (file)
@@ -37,6 +37,8 @@
 /* We purposedly don't include any D3D header, so that this header can be used
  * with all D3D versions. */
 
+#include <assert.h>
+
 #include "os.hpp"
 
 
@@ -87,4 +89,34 @@ _indexDataSize(D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, D3DFORMAT In
 }
 
 
+#if DIRECT3D_VERSION >= 0x0800
+
+/*
+ * Return the number of tokens for a given shader.
+ */
+static inline size_t
+_shaderSize(const DWORD *pFunction)
+{
+    DWORD dwLength = 0;
+
+    while (true) {
+        DWORD dwToken = pFunction[dwLength++];
+
+        switch (dwToken & D3DSI_OPCODE_MASK) {
+        case D3DSIO_COMMENT:
+            dwLength += (dwToken & D3DSI_COMMENTSIZE_MASK) >> D3DSI_COMMENTSIZE_SHIFT;
+            break;
+
+        case D3DSIO_END:
+            if (dwToken != D3DSIO_END) {
+                os::log("apitrace: warning: %s: malformed END token\n", __FUNCTION__);
+            }
+            return dwLength * sizeof *pFunction;
+        }
+    }
+}
+
+#endif /* DIRECT3D_VERSION >= 0x0800 */
+
+
 #endif /* _D3D_SIZE_HPP_ */