From 77a1f244b2fce2ecf9b3f95e78a5aed810643113 Mon Sep 17 00:00:00 2001
From: foreman
Date: Tue, 3 May 2016 17:00:14 -0400
Subject: [PATCH] P4 to Git Change 1264764 by wchau@wchau_WIN_OCL_HSA on
2016/05/03 16:46:02
SWDEV-93075 - [OCL] Access violation in clCreateContext() in amdocl.dll when DX9 and DX11 devices are used. Add support for multiple external devices for context creation to make sure the devices are initialized with proper type.
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_context.cpp#50 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d10.cpp#12 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d11.cpp#19 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d9.cpp#29 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/cpu/cpudevice.hpp#95 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/device.hpp#274 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpudevice.cpp#547 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpudevice.hpp#160 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpumemory.cpp#128 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/hsa_foundation/hsadevice.cpp#62 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/hsa_foundation/hsadevice.hpp#30 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldevice.cpp#4 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldevice.hpp#5 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palmemory.cpp#3 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/context.cpp#41 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/context.hpp#25 edit
---
opencl/api/opencl/amdocl/cl_context.cpp | 10 +++++-----
opencl/api/opencl/amdocl/cl_d3d10.cpp | 6 +++++-
opencl/api/opencl/amdocl/cl_d3d11.cpp | 7 ++++++-
opencl/api/opencl/amdocl/cl_d3d9.cpp | 9 ++++++++-
4 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/opencl/api/opencl/amdocl/cl_context.cpp b/opencl/api/opencl/amdocl/cl_context.cpp
index e5d08b0350..85920dbb5f 100644
--- a/opencl/api/opencl/amdocl/cl_context.cpp
+++ b/opencl/api/opencl/amdocl/cl_context.cpp
@@ -360,7 +360,7 @@ RUNTIME_ENTRY(cl_int, clGetContextInfo, (
*not_null(param_value_size_ret) = sizeof(intptr_t);
if (param_value != NULL) {
*(intptr_t*) param_value =
- reinterpret_cast(amdContext->info().hDev_);
+ reinterpret_cast(amdContext->info().hDev_[amd::Context::D3D10DeviceKhrIdx]);
}
return CL_SUCCESS;
}
@@ -387,7 +387,7 @@ RUNTIME_ENTRY(cl_int, clGetContextInfo, (
*not_null(param_value_size_ret) = sizeof(intptr_t);
if (param_value != NULL) {
*(intptr_t*) param_value =
- reinterpret_cast(amdContext->info().hDev_);
+ reinterpret_cast(amdContext->info().hDev_[amd::Context::D3D11DeviceKhrIdx]);
}
return CL_SUCCESS;
}
@@ -412,7 +412,7 @@ RUNTIME_ENTRY(cl_int, clGetContextInfo, (
*not_null(param_value_size_ret) = sizeof(intptr_t);
if (param_value != NULL) {
*(intptr_t*) param_value =
- reinterpret_cast(amdContext->info().hDev_);
+ reinterpret_cast(amdContext->info().hDev_[amd::Context::D3D9DeviceKhrIdx]);
}
return CL_SUCCESS;
}
@@ -427,7 +427,7 @@ RUNTIME_ENTRY(cl_int, clGetContextInfo, (
*not_null(param_value_size_ret) = sizeof(intptr_t);
if (param_value != NULL) {
*(intptr_t*) param_value =
- reinterpret_cast(amdContext->info().hDev_);
+ reinterpret_cast(amdContext->info().hDev_[amd::Context::D3D9DeviceEXKhrIdx]);
}
return CL_SUCCESS;
}
@@ -442,7 +442,7 @@ RUNTIME_ENTRY(cl_int, clGetContextInfo, (
*not_null(param_value_size_ret) = sizeof(intptr_t);
if (param_value != NULL) {
*(intptr_t*) param_value =
- reinterpret_cast(amdContext->info().hDev_);
+ reinterpret_cast(amdContext->info().hDev_[amd::Context::D3D9DeviceVAKhrIdx]);
}
return CL_SUCCESS;
}
diff --git a/opencl/api/opencl/amdocl/cl_d3d10.cpp b/opencl/api/opencl/amdocl/cl_d3d10.cpp
index 2bbfbbf0e7..8b3e30e683 100644
--- a/opencl/api/opencl/amdocl/cl_d3d10.cpp
+++ b/opencl/api/opencl/amdocl/cl_d3d10.cpp
@@ -113,11 +113,15 @@ RUNTIME_ENTRY(cl_int, clGetDeviceIDsFromD3D10KHR, (
break;
}
+ void * external_device[amd::Context::DeviceFlagIdx::LastDeviceFlagIdx] = {};
+ external_device[amd::Context::DeviceFlagIdx::D3D10DeviceKhrIdx] = d3d10_device;
+
std::vector compatible_devices;
for (cl_uint i = 0; i < num_gpu_devices; ++i) {
cl_device_id device = gpu_devices[i];
if (is_valid(device) &&
- as_amd(device)->bindExternalDevice(amd::Context::Flags::D3D10DeviceKhr, d3d10_device, NULL, VALIDATE_ONLY)) {
+ as_amd(device)->bindExternalDevice(amd::Context::Flags::D3D10DeviceKhr,
+ external_device, NULL, VALIDATE_ONLY)) {
compatible_devices.push_back(as_amd(device));
}
}
diff --git a/opencl/api/opencl/amdocl/cl_d3d11.cpp b/opencl/api/opencl/amdocl/cl_d3d11.cpp
index 2d50a63e61..cffd25ddf0 100644
--- a/opencl/api/opencl/amdocl/cl_d3d11.cpp
+++ b/opencl/api/opencl/amdocl/cl_d3d11.cpp
@@ -117,9 +117,14 @@ RUNTIME_ENTRY(cl_int, clGetDeviceIDsFromD3D11KHR, (
std::vector compatible_devices;
for (cl_uint i = 0; i < num_gpu_devices; ++i) {
+
+ void * external_device[amd::Context::DeviceFlagIdx::LastDeviceFlagIdx] = {};
+ external_device[amd::Context::DeviceFlagIdx::D3D11DeviceKhrIdx] = d3d11_device;
+
cl_device_id device = gpu_devices[i];
if (is_valid(device) &&
- as_amd(device)->bindExternalDevice(amd::Context::Flags::D3D11DeviceKhr, d3d11_device, NULL, VALIDATE_ONLY)) {
+ as_amd(device)->bindExternalDevice(amd::Context::Flags::D3D11DeviceKhr,
+ external_device, NULL, VALIDATE_ONLY)) {
compatible_devices.push_back(as_amd(device));
}
}
diff --git a/opencl/api/opencl/amdocl/cl_d3d9.cpp b/opencl/api/opencl/amdocl/cl_d3d9.cpp
index 969c61be36..ac39619f68 100644
--- a/opencl/api/opencl/amdocl/cl_d3d9.cpp
+++ b/opencl/api/opencl/amdocl/cl_d3d9.cpp
@@ -70,23 +70,30 @@ RUNTIME_ENTRY(cl_int, clGetDeviceIDsFromDX9MediaAdapterKHR, (
for (cl_uint i = 0; i < num_gpu_devices; ++i) {
cl_device_id device = gpu_devices[i];
amd::Context::Flags context_flag;
+ amd::Context::DeviceFlagIdx devIdx;
switch (media_adapters_type[i]) {
case CL_ADAPTER_D3D9_KHR:
context_flag = amd::Context::Flags::D3D9DeviceKhr;
+ devIdx = amd::Context::DeviceFlagIdx::D3D9DeviceKhrIdx;
break;
case CL_ADAPTER_D3D9EX_KHR:
context_flag = amd::Context::Flags::D3D9DeviceEXKhr;
+ devIdx = amd::Context::DeviceFlagIdx::D3D9DeviceEXKhrIdx;
break;
case CL_ADAPTER_DXVA_KHR:
context_flag = amd::Context::Flags::D3D9DeviceVAKhr;
+ devIdx = amd::Context::DeviceFlagIdx::D3D9DeviceVAKhrIdx;
break;
}
for (cl_uint j = 0; j < num_media_adapters; ++j) {
//Since there can be multiple DX9 adapters passed in the array we need to validate interopability with each.
+ void * external_device[amd::Context::DeviceFlagIdx::LastDeviceFlagIdx] = {};
+ external_device[devIdx] = d3d9_device[j];
+
if (is_valid(device) && (media_adapters_type[j] == CL_ADAPTER_D3D9EX_KHR) &&
as_amd(device)->bindExternalDevice(context_flag,
- d3d9_device[j], NULL, VALIDATE_ONLY)) {
+ external_device, NULL, VALIDATE_ONLY)) {
compatible_devices.push_back(as_amd(device));
}
}