Skip to content

Commit

Permalink
[opencl-on-dx12] more patches
Browse files Browse the repository at this point in the history
  • Loading branch information
luncliff committed Oct 4, 2024
1 parent 4ddd3d1 commit b373365
Show file tree
Hide file tree
Showing 3 changed files with 198 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 96e0b0f..aec47e9 100644
index 96e0b0f..3f40cc2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,7 +2,7 @@
Expand All @@ -11,10 +11,14 @@ index 96e0b0f..aec47e9 100644

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
@@ -17,30 +17,10 @@ file(GLOB TRANS_SRC CONFIGURE_DEPENDS src/d3d12translationlayer/*.cpp)
file(GLOB TRANS_INC include/d3d12translationlayer/*.*)
file(GLOB TRANS_INL include/d3d12translationlayer/*.inl src/d3d12translationlayer/*.inl)
@@ -13,58 +13,31 @@ file(GLOB_RECURSE MAIN_SRC CONFIGURE_DEPENDS src/openclon12/*.cpp src/compilers/
file(GLOB MAIN_INC src/openclon12/*.h src/openclon12/*.hpp)
file(GLOB_RECURSE EXTERNAL_INC external/*.h external/*.hpp)

-file(GLOB TRANS_SRC CONFIGURE_DEPENDS src/d3d12translationlayer/*.cpp)
-file(GLOB TRANS_INC include/d3d12translationlayer/*.*)
-file(GLOB TRANS_INL include/d3d12translationlayer/*.inl src/d3d12translationlayer/*.inl)
-
-include(FetchContent)
-FetchContent_Declare(
- DirectX-Headers
Expand All @@ -39,24 +43,35 @@ index 96e0b0f..aec47e9 100644
- GIT_TAG ed429e64eb3b91848bf19c17e1431c1b0f2c6d2b
-)
-FetchContent_MakeAvailable(wil)
-
-add_library(d3d12translationlayer STATIC ${TRANS_SRC} ${TRANS_INC} ${TRANS_INL})
-target_include_directories(d3d12translationlayer
- PUBLIC include/d3d12translationlayer
- PRIVATE external)
-
-target_link_libraries(d3d12translationlayer Microsoft::DirectX-Headers d3d12 dxgi atls dxcore)
-
-target_compile_definitions(d3d12translationlayer PRIVATE $<$<CONFIG:DEBUG>:DBG>)
-target_compile_definitions(d3d12translationlayer PUBLIC $<$<CONFIG:DEBUG>:TRANSLATION_LAYER_DBG=1>)
+find_path(D3D12TRANSLATIONLAYER_INCLUDE_DIR NAMES D3D12TranslationLayer/D3D12TranslationLayerIncludes.h REQUIRED)
+find_library(D3D12TRANSLATIONLAYER_LIB NAMES d3d12translationlayer REQUIRED)
+find_path(OpenCL_INCLUDE_DIR NAMES CL/cl.h REQUIRED)
+find_package(wil CONFIG REQUIRED) # WIL::WIL
+find_package(directx-headers CONFIG REQUIRED) # Microsoft::DirectX-Headers

add_library(d3d12translationlayer STATIC ${TRANS_SRC} ${TRANS_INC} ${TRANS_INL})
target_include_directories(d3d12translationlayer
@@ -56,15 +36,18 @@ add_library(openclon12 SHARED ${MAIN_SRC} ${MAIN_INC} ${EXTERNAL_INC})
add_library(openclon12 SHARED ${MAIN_SRC} ${MAIN_INC} ${EXTERNAL_INC})
target_include_directories(openclon12
PRIVATE src/openclon12
PRIVATE external
- PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+ PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${D3D12TRANSLATIONLAYER_INCLUDE_DIR}/D3D12TranslationLayer ${OpenCL_INCLUDE_DIR})
PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+target_include_directories(openclon12 PRIVATE ${D3D12TRANSLATIONLAYER_INCLUDE_DIR}/D3D12TranslationLayer ${OpenCL_INCLUDE_DIR})
target_link_libraries(openclon12
- d3d12translationlayer
- OpenCL::Headers
- WIL
+ PRIVATE ${D3D12TRANSLATIONLAYER_LIB} WIL::WIL dxcore d3d12 dxgi
+ ${D3D12TRANSLATIONLAYER_LIB} dxcore d3d12 dxgi
+ Microsoft::DirectX-Headers
+ WIL::WIL
user32
gdi32)
source_group("Header Files\\External" FILES ${EXTERNAL_INC})
Expand Down
166 changes: 166 additions & 0 deletions ports/opencl-on-dx12/fix-sources.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
diff --git a/src/openclon12/device.hpp b/src/openclon12/device.hpp
index 05ce280..0600ace 100644
--- a/src/openclon12/device.hpp
+++ b/src/openclon12/device.hpp
@@ -7,7 +7,7 @@
#include <vector>
#include <mutex>

-#include "ImmediateContext.hpp"
+#include <D3D12TranslationLayerIncludes.h>
using ImmCtx = D3D12TranslationLayer::ImmediateContext;

class Task;
diff --git a/src/openclon12/platform.hpp b/src/openclon12/platform.hpp
index d29c17a..56d5625 100644
--- a/src/openclon12/platform.hpp
+++ b/src/openclon12/platform.hpp
@@ -13,6 +13,14 @@
#define CL_TARGET_OPENCL_VERSION 300
#define CLON12_SUPPORT_3_0 1

+#include <atlbase.h>
+#include <comdef.h>
+#include <d3d11_3.h>
+#include <dxgi1_4.h>
+#include <d3d11on12.h>
+#include <d3d12compatibility.h>
+#include <d3dkmthk.h>
+#include <d3d12video.h>
#include <directx/d3dx12.h>
#include <directx/dxcore.h>

@@ -30,6 +38,13 @@
#include <atomic>
#include <map>
#include <algorithm>
+#include <functional>
+#include <mutex>
+#include <bitset>
+#include <deque>
+#include <queue>
+#include <optional>
+#include <set>
#ifndef assert
#include <assert.h>
#endif
@@ -42,7 +57,7 @@ using Microsoft::WRL::ComPtr;

#define WIL_ENABLE_EXCEPTIONS
#include <wil/result_macros.h>
-#include "XPlatHelpers.h"
+#include <D3D12TranslationLayerIncludes.h>

#include <scheduler.hpp>

diff --git a/src/openclon12/gl_tasks.cpp b/src/openclon12/gl_tasks.cpp
index 891bcd6..0d4b2a2 100644
--- a/src/openclon12/gl_tasks.cpp
+++ b/src/openclon12/gl_tasks.cpp
@@ -188,7 +188,6 @@ private:
TransitionResource(res->GetActiveUnderlyingResource(),
D3D12_RESOURCE_STATE_COMMON,
D3D12TranslationLayer::SubresourceTransitionFlags::StateMatchExact |
- D3D12TranslationLayer::SubresourceTransitionFlags::ForceWriteState |
D3D12TranslationLayer::SubresourceTransitionFlags::NotUsedInCommandListIfNoStateChange);
}
ImmCtx.GetResourceStateManager().ApplyAllResourceTransitions();
diff --git a/src/openclon12/kernel_tasks.cpp b/src/openclon12/kernel_tasks.cpp
index 7de0674..9134b96 100644
--- a/src/openclon12/kernel_tasks.cpp
+++ b/src/openclon12/kernel_tasks.cpp
@@ -653,8 +653,8 @@ void ExecuteKernel::RecordImpl()
SrcDescriptors.reserve(std::max(NumViewDescriptors - 2, NumSamplerDescriptors));

ID3D12GraphicsCommandList *pCmdList = ImmCtx.GetGraphicsCommandList();
- pCmdList->SetComputeRootSignature(m_Specialized->m_RS->GetForUse());
- pCmdList->SetPipelineState(m_Specialized->m_PSO->GetForUse());
+ //pCmdList->SetComputeRootSignature(m_Specialized->m_RS->GetForUse());
+ //pCmdList->SetPipelineState(m_Specialized->m_PSO->GetForUse());

if (NumSamplerDescriptors)
{
@@ -681,7 +681,7 @@ void ExecuteKernel::RecordImpl()
}
else
{
- SrcDescriptors.push_back(ImmCtx.m_NullUAV);
+ //SrcDescriptors.push_back(ImmCtx.m_NullUAV);
}
}
for (auto &SrvRes : m_KernelArgSRVs)
@@ -697,7 +697,7 @@ void ExecuteKernel::RecordImpl()
else
{
// CL doesn't provide defined behavior for accessing a null texture so it doesn't matter what this is.
- SrcDescriptors.push_back(ImmCtx.m_NullUAV);
+ //SrcDescriptors.push_back(ImmCtx.m_NullUAV);
}
}
if (m_PrintfUAV.Get())
diff --git a/src/openclon12/platform.hpp b/src/openclon12/platform.hpp
index 56d5625..fb2fc67 100644
--- a/src/openclon12/platform.hpp
+++ b/src/openclon12/platform.hpp
@@ -21,6 +21,7 @@
#include <d3d12compatibility.h>
#include <d3dkmthk.h>
#include <d3d12video.h>
+#include <TraceLoggingProvider.h>
#include <directx/d3dx12.h>
#include <directx/dxcore.h>

@@ -58,6 +59,7 @@ using Microsoft::WRL::ComPtr;
#define WIL_ENABLE_EXCEPTIONS
#include <wil/result_macros.h>
#include <D3D12TranslationLayerIncludes.h>
+#include <D3D12TranslationLayerDependencyIncludes.h>

#include <scheduler.hpp>

diff --git a/src/openclon12/task.cpp b/src/openclon12/task.cpp
index d1cfd51..3db0e2d 100644
--- a/src/openclon12/task.cpp
+++ b/src/openclon12/task.cpp
@@ -401,8 +401,8 @@ void Task::Record()
try
{
// TODO: Maybe share a start timestamp with the end of the previous command?
- m_StartTimestamp.reset(new D3D12TranslationLayer::TimestampQuery(pImmCtx));
- m_StopTimestamp.reset(new D3D12TranslationLayer::TimestampQuery(pImmCtx));
+ m_StartTimestamp.reset(new D3D12TranslationLayer::Query(pImmCtx, D3D12TranslationLayer::EQueryType::e_QUERY_TIMESTAMP, 0));
+ m_StopTimestamp.reset(new D3D12TranslationLayer::Query(pImmCtx, D3D12TranslationLayer::EQueryType::e_QUERY_TIMESTAMP, 0));
}
catch(...) { /* Do nothing, just don't capture timestamps */ }
}
@@ -623,13 +623,13 @@ void Task::Complete(cl_int error, TaskPoolLock const& lock)
UINT64 GPUTimestamp;
if (m_StartTimestamp)
{
- GPUTimestamp = m_StartTimestamp->GetData();
+ //GPUTimestamp = m_StartTimestamp->GetData();
GetTimestamp(CL_PROFILING_COMMAND_START) =
TimestampToNanoseconds(GPUTimestamp, Frequency) + m_D3DDevice->GPUToQPCTimestampOffset();
}
if (m_StopTimestamp)
{
- GPUTimestamp = m_StopTimestamp->GetData();
+ //GPUTimestamp = m_StopTimestamp->GetData();
GetTimestamp(CL_PROFILING_COMMAND_END) =
TimestampToNanoseconds(GPUTimestamp, Frequency) + m_D3DDevice->GPUToQPCTimestampOffset();
}
diff --git a/src/openclon12/task.hpp b/src/openclon12/task.hpp
index bf4674a..4b163e9 100644
--- a/src/openclon12/task.hpp
+++ b/src/openclon12/task.hpp
@@ -135,8 +135,8 @@ protected:
std::promise<void> m_CompletionPromise;
std::future<void> m_CompletionFuture{ m_CompletionPromise.get_future() };

- std::shared_ptr<D3D12TranslationLayer::TimestampQuery> m_StartTimestamp;
- std::shared_ptr<D3D12TranslationLayer::TimestampQuery> m_StopTimestamp;
+ std::shared_ptr<D3D12TranslationLayer::Query> m_StartTimestamp;
+ std::shared_ptr<D3D12TranslationLayer::Query> m_StopTimestamp;
};

class UserEvent : public Task
9 changes: 7 additions & 2 deletions ports/opencl-on-dx12/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ vcpkg_from_github(
REPO microsoft/OpenCLOn12
REF v1.2404.1.0
SHA512 7053cee9db381b55bab74729fa445b485e70f6c71f3358824ffae5aa4dfc6e869825196c029d94582a8b1d88029a508e7e38a24ffe9adafb242725a790f7f3e5
PATCHES
fix-vcpkg.patch
# PATCHES
# fix-cmake.patch
# fix-sources.patch
HEAD_REF master
)
file(REMOVE_RECURSE
${SOURCE_PATH}/include/d3d12translationlayer
${SOURCE_PATH}/src/d3d12translationlayer
)

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
Expand Down

0 comments on commit b373365

Please sign in to comment.