From da08edf69cf97130d1b610ab2187a7057d53deb7 Mon Sep 17 00:00:00 2001
From: foreman
Date: Thu, 21 Dec 2017 15:39:37 -0500
Subject: [PATCH] P4 to Git Change 1497462 by
skudchad@skudchad_test2_win_opencl on 2017/12/21 15:20:57
SWDEV-140751 - ICD Changes to support DXGK interface for WDDM2.4
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/opencl/khronos/icd/build/Makefile.icd#35 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/khronos/icd/icd_windows.c#10 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/khronos/icd/icd_windows_dxgk.c#1 add
... //depot/stg/opencl/drivers/opencl/api/opencl/khronos/icd/icd_windows_dxgk.h#1 add
---
opencl/api/opencl/khronos/icd/icd_windows.c | 9 +-
.../api/opencl/khronos/icd/icd_windows_dxgk.c | 126 ++++++++++++++++++
.../api/opencl/khronos/icd/icd_windows_dxgk.h | 40 ++++++
3 files changed, 173 insertions(+), 2 deletions(-)
create mode 100644 opencl/api/opencl/khronos/icd/icd_windows_dxgk.c
create mode 100644 opencl/api/opencl/khronos/icd/icd_windows_dxgk.h
diff --git a/opencl/api/opencl/khronos/icd/icd_windows.c b/opencl/api/opencl/khronos/icd/icd_windows.c
index 13e3e5f94b..ccdf99ccbd 100644
--- a/opencl/api/opencl/khronos/icd/icd_windows.c
+++ b/opencl/api/opencl/khronos/icd/icd_windows.c
@@ -37,6 +37,7 @@
#include "icd.h"
#include "icd_windows_hkr.h"
+#include "icd_windows_dxgk.h"
#include
#include
#include
@@ -58,9 +59,13 @@ BOOL CALLBACK khrIcdOsVendorsEnumerate(PINIT_ONCE InitOnce, PVOID Parameter, PVO
HKEY platformsKey = NULL;
DWORD dwIndex;
- if (!khrIcdOsVendorsEnumerateHKR())
+ if (!khrIcdOsVendorsEnumerateDXGK())
{
- KHR_ICD_TRACE("Failed to enumerate HKR entries, continuing\n");
+ KHR_ICD_TRACE("Failed to load via DXGK interface on RS4, continuing\n");
+ if (!khrIcdOsVendorsEnumerateHKR())
+ {
+ KHR_ICD_TRACE("Failed to enumerate HKR entries, continuing\n");
+ }
}
KHR_ICD_TRACE("Opening key HKLM\\%s...\n", platformsName);
diff --git a/opencl/api/opencl/khronos/icd/icd_windows_dxgk.c b/opencl/api/opencl/khronos/icd/icd_windows_dxgk.c
new file mode 100644
index 0000000000..b1c4d562a6
--- /dev/null
+++ b/opencl/api/opencl/khronos/icd/icd_windows_dxgk.c
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 2017 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software source and associated documentation files (the "Materials"),
+ * to deal in the Materials without restriction, including without limitation
+ * the rights to use, copy, modify, compile, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Materials, and to permit persons to
+ * whom the Materials are furnished to do so, subject the following terms and
+ * conditions:
+ *
+ * All modifications to the Materials used to create a binary that is
+ * distributed to third parties shall be provided to Khronos with an
+ * unrestricted license to use for the purposes of implementing bug fixes and
+ * enhancements to the Materials;
+ *
+ * If the binary is used as part of an OpenCL(TM) implementation, whether binary
+ * is distributed together with or separately to that implementation, then
+ * recipient must become an OpenCL Adopter and follow the published OpenCL
+ * conformance process for that implementation, details at:
+ * http://www.khronos.org/conformance/;
+ *
+ * The above copyright notice, the OpenCL trademark license, and this permission
+ * notice shall be included in all copies or substantial portions of the
+ * Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS IN
+ * THE MATERIALS.
+ *
+ * OpenCL is a trademark of Apple Inc. used under license by Khronos.
+ */
+
+#include "icd.h"
+#include
+#include "icd_windows_dxgk.h"
+#include
+
+#ifndef NTSTATUS
+typedef LONG NTSTATUS;
+#define STATUS_SUCCESS ((NTSTATUS)0x00000000L)
+#define STATUS_BUFFER_TOO_SMALL ((NTSTATUS)0xC0000023)
+#define NT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0)
+#endif
+
+#include "d3dkmthk.h"
+
+bool khrIcdOsVendorsEnumerateDXGK(void)
+{
+#if defined(DXGKDDI_INTERFACE_VERSION_WDDM2_4) && (DXGKDDI_INTERFACE_VERSION >= DXGKDDI_INTERFACE_VERSION_WDDM2_4)
+ {
+ D3DKMT_ADAPTERINFO* pAdapterInfo;
+ D3DKMT_ENUMADAPTERS2 EnumAdapters;
+ NTSTATUS Status = STATUS_SUCCESS;
+ char cszLibraryName[1024] = { 0 };
+ EnumAdapters.NumAdapters = 0;
+ EnumAdapters.pAdapters = NULL;
+ Status = D3DKMTEnumAdapters2(&EnumAdapters);
+ if (!NT_SUCCESS(Status) && (Status != STATUS_BUFFER_TOO_SMALL))
+ {
+ return FALSE;
+ }
+ pAdapterInfo = (D3DKMT_ADAPTERINFO*)malloc(sizeof(D3DKMT_ADAPTERINFO)*(EnumAdapters.NumAdapters));
+ EnumAdapters.pAdapters = pAdapterInfo;
+ Status = D3DKMTEnumAdapters2(&EnumAdapters);
+ if (!NT_SUCCESS(Status))
+ {
+ if (pAdapterInfo) free(pAdapterInfo);
+ return FALSE;
+ }
+ for (UINT AdapterIndex = 0; AdapterIndex < EnumAdapters.NumAdapters; AdapterIndex++)
+ {
+ D3DDDI_QUERYREGISTRY_INFO QueryArgs = {0};
+ D3DDDI_QUERYREGISTRY_INFO* pQueryArgs = &QueryArgs;
+ D3DDDI_QUERYREGISTRY_INFO* pQueryBuffer = NULL;
+ QueryArgs.QueryType = D3DDDI_QUERYREGISTRY_ADAPTERKEY;
+ QueryArgs.QueryFlags.TranslatePath = TRUE;
+ QueryArgs.ValueType = REG_MULTI_SZ;
+#ifdef _WIN64
+ wcscpy_s(QueryArgs.ValueName, ARRAYSIZE(L"OpenCLDriverName"), L"OpenCLDriverName");
+#else
+ wcscpy_s(QueryArgs.ValueName, ARRAYSIZE(L"OpenCLDriverNameWow"), L"OpenCLDriverNameWow");
+#endif
+ D3DKMT_QUERYADAPTERINFO QueryAdapterInfo = {0};
+ QueryAdapterInfo.hAdapter = pAdapterInfo[AdapterIndex].hAdapter;
+ QueryAdapterInfo.Type = KMTQAITYPE_QUERYREGISTRY;
+ QueryAdapterInfo.pPrivateDriverData = &QueryArgs;
+ QueryAdapterInfo.PrivateDriverDataSize = sizeof(QueryArgs);
+ Status = D3DKMTQueryAdapterInfo(&QueryAdapterInfo);
+ if (NT_SUCCESS(Status) && pQueryArgs->Status == D3DDDI_QUERYREGISTRY_STATUS_BUFFER_OVERFLOW)
+ {
+ unsigned int QueryBufferSize = sizeof(D3DDDI_QUERYREGISTRY_INFO) + QueryArgs.OutputValueSize;
+ pQueryBuffer = (D3DDDI_QUERYREGISTRY_INFO*)malloc(QueryBufferSize);
+ memcpy(pQueryBuffer, &QueryArgs, sizeof(D3DDDI_QUERYREGISTRY_INFO));
+ QueryAdapterInfo.pPrivateDriverData = pQueryBuffer;
+ QueryAdapterInfo.PrivateDriverDataSize = QueryBufferSize;
+ Status = D3DKMTQueryAdapterInfo(&QueryAdapterInfo);
+ pQueryArgs = pQueryBuffer;
+ }
+ if (NT_SUCCESS(Status) && pQueryArgs->Status == D3DDDI_QUERYREGISTRY_STATUS_SUCCESS)
+ {
+ wchar_t* pWchar = pQueryArgs->OutputString;
+ unsigned int i = 0;
+ memset(cszLibraryName, 0, sizeof(cszLibraryName));
+ {
+ while ((*pWchar != L'\0') && (i<1023))
+ {
+ cszLibraryName[i] = (char)*pWchar;
+ i++;
+ pWchar++;
+ }
+ if (i < 1023) khrIcdVendorAdd(cszLibraryName);
+ }
+ }
+ if (pQueryBuffer) free(pQueryBuffer);
+ }
+ if (pAdapterInfo) free(pAdapterInfo);
+ return TRUE;
+ }
+#endif
+ return FALSE;
+}
diff --git a/opencl/api/opencl/khronos/icd/icd_windows_dxgk.h b/opencl/api/opencl/khronos/icd/icd_windows_dxgk.h
new file mode 100644
index 0000000000..8851815d0d
--- /dev/null
+++ b/opencl/api/opencl/khronos/icd/icd_windows_dxgk.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2017 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software source and associated documentation files (the "Materials"),
+ * to deal in the Materials without restriction, including without limitation
+ * the rights to use, copy, modify, compile, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Materials, and to permit persons to
+ * whom the Materials are furnished to do so, subject the following terms and
+ * conditions:
+ *
+ * All modifications to the Materials used to create a binary that is
+ * distributed to third parties shall be provided to Khronos with an
+ * unrestricted license to use for the purposes of implementing bug fixes and
+ * enhancements to the Materials;
+ *
+ * If the binary is used as part of an OpenCL(TM) implementation, whether binary
+ * is distributed together with or separately to that implementation, then
+ * recipient must become an OpenCL Adopter and follow the published OpenCL
+ * conformance process for that implementation, details at:
+ * http://www.khronos.org/conformance/;
+ *
+ * The above copyright notice, the OpenCL trademark license, and this permission
+ * notice shall be included in all copies or substantial portions of the
+ * Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS IN
+ * THE MATERIALS.
+ *
+ * OpenCL is a trademark of Apple Inc. used under license by Khronos.
+ */
+
+#include
+
+bool khrIcdOsVendorsEnumerateDXGK(void);