Skip to content

Commit

Permalink
Upstream RavEngine changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravbug committed Jun 30, 2024
1 parent 975e2d0 commit d5f8353
Show file tree
Hide file tree
Showing 162 changed files with 81,261 additions and 70 deletions.
22 changes: 17 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,14 @@ if (RGL_ENABLE_RGLC)
target_compile_features(rglc PRIVATE cxx_std_20)
target_link_libraries(rglc PRIVATE librglc)
target_include_directories(rglc PRIVATE "deps/cxxopts/include")
if(MSVC)
set(rglc_ext ".exe")
endif()
set(rglc_path "${CMAKE_BINARY_DIR}/$<CONFIGURATION>/rglc${rglc_ext}" CACHE INTERNAL "rglc compiler path")
set(rglc_path "rglc" CACHE INTERNAL "rglc compiler path")
set(rglc_exe "rglc")
set_target_properties(rglc
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/rglc"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/rglc"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/rglc"
)
endif()

find_package(Vulkan)
Expand Down Expand Up @@ -134,6 +137,15 @@ if(MSVC AND NOT RGL_DISABLE_DX)
FOLDER "${RGL_IDE_ROOT}/Libraries"
)
target_include_directories(${PROJECT_NAME} PUBLIC "deps/DirectXTK12/Inc")

# PIX stuff

add_subdirectory(deps/PixEvents-cmake)
set(PIXLIB $<$<NOT:$<CONFIG:release>>:WinPixEventRuntime>)

set_target_properties("WinPixEventRuntime" "WinPixEventRuntime_ETW" "PixDecoder" PROPERTIES
FOLDER "${RGL_IDE_ROOT}/Libraries/"
)
else()
target_compile_definitions(${PROJECT_NAME} PUBLIC RGL_DX12_AVAILABLE=0)
set(RGL_DX12_AVAILABLE OFF CACHE INTERNAL "RGL DX12")
Expand Down Expand Up @@ -165,6 +177,7 @@ target_link_libraries(${PROJECT_NAME} PRIVATE
${QZC_LIB}
${X11_LIBRARIES}
${RGL_RUNTIME_COMPILER_LIB}
${PIXLIB}
SPIRV-Reflect
)

Expand Down Expand Up @@ -215,7 +228,6 @@ set_target_properties("GenericCodeGen" "glslang" "MachineIndependent" "OGLCompil
FOLDER "${RGL_IDE_ROOT}/Libraries/glslang"
)


set_target_properties(
"SPIRV-Tools-opt" "SPIRV-Tools-reduce" "SPIRV-Tools-static" "SPIRV-Tools-shared" "SPIRV-Tools-lint" "SPIRV-Tools-diff" "SPIRV-Tools-link"
"spirv-tools-shared-pkg-config" "spirv-tools-pkg-config"
Expand Down
46 changes: 46 additions & 0 deletions deps/PixEvents-cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

project(PixEvents)

file(GLOB_RECURSE DECODER_SRC "PixEvents/decoder/*.cpp" "PixEvents/decoder/*.h")
add_library(PixDecoder ${DECODER_SRC})
target_compile_features(PixDecoder PUBLIC cxx_std_17)
target_include_directories(PixDecoder PUBLIC
"${CMAKE_CURRENT_LIST_DIR}/PixEvents/include"
"${CMAKE_CURRENT_LIST_DIR}/PixEvents/"
"${CMAKE_CURRENT_LIST_DIR}/PixEvents/decoder/include/"
)
target_compile_definitions(PixDecoder PRIVATE NOMINMAX)

set(WIL_BUILD_TESTS OFF)
set(WIL_BUILD_PACKAGING OFF)
add_subdirectory(PixEvents/third_party/wil)

# PIXETW is generated by mc.exe. We need to manually account for this.
# This command generates an identical PIXETW as the official visual studio solution.
set(ETW_PATH "${CMAKE_CURRENT_BINARY_DIR}/PIXETW.h")
set(ETW_INPUT "${CMAKE_CURRENT_LIST_DIR}/PixEvents/runtime/lib/PIXETW.man")
add_custom_command(
PRE_BUILD
OUTPUT "${ETW_PATH}"
DEPENDS "${ETW_INPUT}"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
COMMAND "mc.exe" -um "${ETW_INPUT}"
)
add_custom_target(WinPixEventRuntime_ETW DEPENDS "${ETW_PATH}")

file(GLOB_RECURSE RUNTIME_SRC "PixEvents/runtime/lib/*.cpp" "PixEvents/runtime/dll/*.cpp" "PixEvents/runtime/lib/*.h")
add_library(WinPixEventRuntime SHARED)
target_sources(WinPixEventRuntime PRIVATE ${RUNTIME_SRC})
target_compile_features(WinPixEventRuntime PUBLIC cxx_std_17)
target_include_directories(WinPixEventRuntime PUBLIC
"${CMAKE_CURRENT_LIST_DIR}/PixEvents/include"
"${CMAKE_CURRENT_LIST_DIR}/PixEvents/"
"${CMAKE_CURRENT_LIST_DIR}/PixEvents/runtime/include/"
"${CMAKE_CURRENT_LIST_DIR}/PixEvents/runtime/"
"${CMAKE_CURRENT_BINARY_DIR}"
)
target_precompile_headers(WinPixEventRuntime PRIVATE "PixEvents/runtime/lib/pch.h") # without this, it doesn't compile
target_compile_definitions(WinPixEventRuntime PRIVATE DBG) # this is on all the time??
add_dependencies(WinPixEventRuntime WinPixEventRuntime_ETW)
target_link_libraries(WinPixEventRuntime PUBLIC PixDecoder WIL)
set_target_properties(WinPixEventRuntime PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
33 changes: 33 additions & 0 deletions deps/PixEvents-cmake/PixEvents/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

#Ignore thumbnails created by Windows
Thumbs.db
#Ignore files built by Visual Studio
*.obj
*.exe
*.pdb
*.user
*.aps
*.pch
*.vspscc
*_i.c
*_p.c
*.ncb
*.suo
*.tlb
*.tlh
*.bak
*.cache
*.ilk
*.log
[Bb]in
[Dd]ebug*/
*.lib
*.sbr
obj/
[Rr]elease*/
[Ii]ntermediates*/
_ReSharper*/
[Tt]est[Rr]esult*
.vs/
#Nuget packages folder
packages/
9 changes: 9 additions & 0 deletions deps/PixEvents-cmake/PixEvents/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Microsoft Open Source Code of Conduct

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).

Resources:

- [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/)
- [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
- Contact [[email protected]](mailto:[email protected]) with questions or concerns
14 changes: 14 additions & 0 deletions deps/PixEvents-cmake/PixEvents/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Contributing

This project welcomes contributions and suggestions. Most contributions require you to
agree to a Contributor License Agreement (CLA) declaring that you have the right to,
and actually do, grant us the rights to use your contribution. For details, visit
https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need
to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the
instructions provided by the bot. You will only need to do this once across all repositories using our CLA.

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
or contact [[email protected]](mailto:[email protected]) with any additional questions or comments.
21 changes: 21 additions & 0 deletions deps/PixEvents-cmake/PixEvents/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Copyright (c) Microsoft Corporation.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
111 changes: 111 additions & 0 deletions deps/PixEvents-cmake/PixEvents/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
- [PixEvents](#pixevents)
- [Usage](#usage)
- [Recommendations for game/application developers](#recommendations-for-gameapplication-developers)
- [Recommendations for developer tool authors](#recommendations-for-developer-tool-authors)
- [Why use PIX events?](#why-use-pix-events)
- [How do PIX events work?](#how-do-pix-events-work)
- [Building and Running](#building-and-running)
- [Contributing](#contributing)
- [Component Overview](#component-overview)
- [Microsoft Open Source Code of Conduct](#microsoft-open-source-code-of-conduct)
- [Trademarks](#trademarks)

# PixEvents
PIX events can be used by developers to instrument their game or application, labeling regions of work or important occurrences in the application's CPU or GPU workloads. Adding this instrumentation during development can make it far easier to use developer tools like [PIX](https://devblogs.microsoft.com/pix/).

This repository contains:
- The PIX event headers (pix3.h and friends) that define the PIX event APIs.
- The source code for WinPixEventRuntime.dll, which contains key PIX event functionality.
- The code necessary to decode PIX event blobs into strings and colors.
- Miscellaneous associated code, such as unit tests.

<br>

## Usage
Installation, usage instructions, and an API reference can be found at the [WinPixEventRuntime devblog](https://devblogs.microsoft.com/pix/winpixeventruntime/).

### Recommendations for game/application developers
There are two good options:
1. Use the [WinPixEventRuntime NuGet package](https://www.nuget.org/packages/WinPixEventRuntime). This conveniently combines the PIX event headers and prebuilt WinPixEventRuntime.dll binaries into one package. Note that the .nupkg file can be renamed to a .zip file, allowing you to easily extract its contents. Also note that, as of March 2024, the NuGet package is distributed under the MIT license.
2. Build WinPixEventRuntime.dll yourself. This may be more convenient for some users. If you do this, then we strongly recommend that you build and use WinPixEventRuntime.dll instead of statically linking the full WinPixEventRuntime.lib (and all of its functionality) into each of your binaries. This will avoid ETW problems that may occur if separate binaries within your process each emit PIX events.

### Recommendations for developer tool authors
If you would like to decode PIX events in your tool, then we strongly recommend that you use the PIX events decoder in this repository instead of creating your own decoder. This will give you a reliable decoder that supports all versions of the PIX event blob format. See the [How do PIX events work?](#how-do-pix-events-work) section below for more info about the PIX event blob format.

<br>

## Why use PIX events?
PIX events offer several significant advantages over simpler solutions, such as the similar (but deprecated) APIs in the old pix.h. For example:

1) **Performance:** PIX events are designed to be as efficient as possible, offering helpful developer annotations while minimizing impact on the application's performance. For example:
* We do not sprintf strings inside the game/application process. The sprintf parameters are encoded into the PIX event blob, and the sprintf'ing is done by the analysis tool like PIX.
* We have micro-optimized the PIX event APIs to make the blob encoding as fast as possible on a wide range of hardware.
* When emitting PIX events via ETW, we batch the events into blocks to reduce the ETW overhead.
2. **CPU and GPU annotations**: the PIX event APIs such as `PIXBeginEvent(...)` have multiple overloads that allow you to annotate work on both your CPU and GPU timelines. The GPU timeline overloads take a GPU context (e.g. an `ID3D12GraphicsCommandList*`) while the CPU timeline overloads do not.
3. **ETW support**: GPU PIX events can be interpreted by API-level tools, including API capture/replay tools like PIX's GPU Captures or tools such as Microsoft's [DRED](https://learn.microsoft.com/en-us/windows/win32/direct3d12/use-dred). CPU and GPU PIX events can be interpreted by tools that process ETW events, such as PIX's Timing Captures.
4. **Timestamps**: PIX events include CPU timestamps (via `QueryPerformanceCounter())`). This allows performance tools to show helpful information, such as correlating when a PIX event is recorded on the CPU with its GPU execution time.

<br>

## How do PIX events work?

*The implementation of `void PIXBeginEvent(CONTEXT* context, UINT64 color, STR formatString, ARGS... args)` in [`include/PIXEvents.h`](include/PIXEvents.h) will be a helpful reference in this section.*

When the application calls `PIXBeginEvent()` with a GPU context (e.g. an `ID3D12GraphicsCommandList*`), the following happens:
1. The implementation checks to see if a tool (e.g. PIX Timing Captures) has turned on the PIX events ETW provider. If yes, then the PIX event runtime will encode the incoming PIX event information into the current "block" of PIX events that are due to be emitted by ETW. If the block is full, then the block will be emitted via ETW.
2. After that, the implementation will pass the encoded PIX event blob into `ID3D12GraphicsCommandList::BeginEvent()` (or equivalent API). This means that API tools such as PIX's GPU Captures can intercept the blob and save it into the capture file. It also means that D3D features like DRED can access the event blobs.

The exact behavior depends on whether `PIX_USE_GPU_MARKERS_V2` was defined before the application included `pix3.h`. In 2023, the PIX team changed the format of the PIX event blob *(for the first time in 10 years!)* to enable future functionality. Step 1 above will always use the new blob format. If `PIX_USE_GPU_MARKERS_V2` is set, then Step 2 will use the new blob format too. However, if `PIX_USE_GPU_MARKERS_V2` isn't set, then Step 2 will use the old legacy blob format. This preserves compatibility with older tools that aren't aware of the new blob format. By default, `PIX_USE_GPU_MARKERS_V2` is not currently defined, but the PIX team will change this default in the future. If third party products use the PIX event decoder available in this repository, then they will automatically support both the old and the new PIX event blob layout.

When the application calls `PIXBeginEvent()` without a GPU context parameter, Step 1 above still happens but Step 2 does not.

<br>

# Building and Running

**Requirements:**
- Visual Studio 2022 with v143 build tools *(optional: v143 arm64 tools)*

**Instructions:**
- Open `/pixEvents.sln` in VS2022 and build.
- The projects under the `test/` directory are the unit tests built on Google Test. These can be run through the Visual Studio Test Explorer window or as a standalone .exe.

<br>

# Contributing

This project is open to contributions! We are particularly interested in bug fixes, performance optimizations, and contributions that add or simplify the ability to use PIX events in languages other than C++.

We are certainly open to other contributions too, such as new PIX event-style APIs or even PIX event overloads for other graphics APIs. These kinds of contributions would require careful collaboration with with Microsoft before they could be accepted though. If you are interested in making a contribution like this then please reach out to us.

This project doesn't follow any particular style guide. However, if you are submitting changes then please match the style of the surrounding code.

<br>

# Component Overview

| Directory | Description |
| ----------- | ----------- |
| `decoder/` | Contains code tht can decode a PIX event blob. We expect `TryDecodePIXBeginEventOrPIXSetMarkerBlob(...)` in [`/decoder/include/PixEventDecoder.h`](/decoder/include/PixEventDecoder.h) to be the most commonly used function for tools other than PIX. |
| `include/` | Contains pix3.h and associated headers that define APIs such as PIXBeginEvent(). These are the headers that are distributed with the WinPixEventRuntime nuget package. |
| `pipelines/` | Contains `.yml` files used by Microsoft to build PixEvents in Azure DevOps. |
| `runtime/dll/` | Creates the various .dll files that are shipped in the WinPixEventRuntime. |
| `runtime/lib/` | Creates a static lib that contains WinPixEventRuntime functionality, which is linked into the DLLs in the `runtime/dll/` directory. We recommend using the .DLLs in your own project and not the static lib. See [](#recommended-usage) above for details. |
| `shared/` | Contains a header file that is shared across various components. |
| `test/` | Contains unit tests for most PixEvents functionality. |
| `third_party/` | Contains third party code used in this repo, e.g. Google Test and Windows Implementation Library (WIL). |

<br>

# Microsoft Open Source Code of Conduct

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). Resources:

- [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/)
- [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
- Contact [[email protected]](mailto:[email protected]) with questions or concerns

<br/>

# Trademarks
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft’s Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party’s policies.
41 changes: 41 additions & 0 deletions deps/PixEvents-cmake/PixEvents/SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!-- BEGIN MICROSOFT SECURITY.MD V0.0.9 BLOCK -->

## Security

Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet) and [Xamarin](https://github.com/xamarin).

If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/security.md/definition), please report it to us as described below.

## Reporting Security Issues

**Please do not report security vulnerabilities through public GitHub issues.**

Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/security.md/msrc/create-report).

If you prefer to submit without logging in, send email to [[email protected]](mailto:[email protected]). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/security.md/msrc/pgp).

You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc).

Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:

* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
* Full paths of source file(s) related to the manifestation of the issue
* The location of the affected source code (tag/branch/commit or direct URL)
* Any special configuration required to reproduce the issue
* Step-by-step instructions to reproduce the issue
* Proof-of-concept or exploit code (if possible)
* Impact of the issue, including how an attacker might exploit the issue

This information will help us triage your report more quickly.

If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/security.md/msrc/bounty) page for more details about our active programs.

## Preferred Languages

We prefer all communications to be in English.

## Policy

Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/security.md/cvd).

<!-- END MICROSOFT SECURITY.MD BLOCK -->
23 changes: 23 additions & 0 deletions deps/PixEvents-cmake/PixEvents/cgmanifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"Registrations": [
{
"component": {
"type": "git",
"git": {
"repositoryUrl": "https://github.com/google/googletest",
"commitHash": "703bd9caab50b139428cea1aaff9974ebee5742e"
}
}
},
{
"component": {
"type": "git",
"git": {
"repositoryUrl": "https://github.com/microsoft/wil/",
"commitHash": "9db6276dce851dc2b6807fc81bffbec2e27acd0b"
}
}
},
],
"Version": 1
}
Loading

0 comments on commit d5f8353

Please sign in to comment.