Browse Source

libobs-d3d11: Add optional macro to log shader disassembly

jp9000 9 years ago
parent
commit
d2bb7157c2

+ 16 - 0
libobs-d3d11/d3d11-shader.cpp

@@ -201,6 +201,22 @@ void gs_shader::Compile(const char *shaderString, const char *file,
 		else
 			throw HRError("Failed to compile shader", hr);
 	}
+
+#ifdef DISASSEMBLE_SHADERS
+	ComPtr<ID3D10Blob> asmBlob;
+
+	if (!device->d3dDisassemble)
+		return;
+
+	hr = device->d3dDisassemble((*shader)->GetBufferPointer(),
+			(*shader)->GetBufferSize(), 0, nullptr, &asmBlob);
+
+	if (SUCCEEDED(hr) && !!asmBlob && asmBlob->GetBufferSize()) {
+		blog(LOG_INFO, "=============================================");
+		blog(LOG_INFO, "Disassembly output for shader '%s':\n%s",
+				file, asmBlob->GetBufferPointer());
+	}
+#endif
 }
 
 inline void gs_shader::UpdateParam(vector<uint8_t> &constData,

+ 5 - 0
libobs-d3d11/d3d11-subsystem.cpp

@@ -181,6 +181,11 @@ void gs_device::InitCompiler()
 		if (module) {
 			d3dCompile = (pD3DCompile)GetProcAddress(module,
 					"D3DCompile");
+
+#ifdef DISASSEMBLE_SHADERS
+			d3dDisassemble = (pD3DDisassemble)GetProcAddress(
+					module, "D3DDisassemble");
+#endif
 			if (d3dCompile) {
 				return;
 			}

+ 5 - 0
libobs-d3d11/d3d11-subsystem.hpp

@@ -37,6 +37,8 @@
 #include <util/windows/ComPtr.hpp>
 #include <util/windows/HRError.hpp>
 
+// #define DISASSEMBLE_SHADERS
+
 struct shader_var;
 struct shader_sampler;
 struct gs_vertex_shader;
@@ -801,6 +803,9 @@ struct gs_device {
 	D3D11_PRIMITIVE_TOPOLOGY    curToplogy;
 
 	pD3DCompile                 d3dCompile = nullptr;
+#ifdef DISASSEMBLE_SHADERS
+	pD3DDisassemble             d3dDisassemble = nullptr;
+#endif
 
 	gs_rect                     viewport;