-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AtlasEngine: Make shader hot-reloads possible in Windows Terminal #12227
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,6 @@ | |
|
||
#include "../../interactivity/win32/CustomWindowMessages.h" | ||
|
||
#define SHADER_SOURCE_DIRECTORY LR"(..\..\renderer\atlas\)" | ||
|
||
// #### NOTE #### | ||
// This file should only contain methods that are only accessed by the caller of Present() (the "Renderer" class). | ||
// Basically this file poses the "synchronization" point between the concurrently running | ||
|
@@ -192,16 +190,17 @@ AtlasEngine::AtlasEngine() | |
_sr.isWindows10OrGreater = IsWindows10OrGreater(); | ||
|
||
#ifndef NDEBUG | ||
// If you run the Host.EXE project inside Visual Studio it'll have a working directory of | ||
// $(SolutionDir)\src\host\exe. This relative path will thus end up in this source directory. | ||
_sr.sourceCodeWatcher = wil::make_folder_change_reader_nothrow(SHADER_SOURCE_DIRECTORY, false, wil::FolderChangeEvents::FileName | wil::FolderChangeEvents::LastWriteTime, [this](wil::FolderChangeEvent, PCWSTR path) { | ||
if (til::ends_with(path, L".hlsl")) | ||
{ | ||
auto expected = INT64_MAX; | ||
const auto invalidationTime = std::chrono::steady_clock::now() + std::chrono::milliseconds(100); | ||
_sr.sourceCodeInvalidationTime.compare_exchange_strong(expected, invalidationTime.time_since_epoch().count(), std::memory_order_relaxed); | ||
} | ||
}); | ||
{ | ||
_sr.sourceDirectory = std::filesystem::path{ __FILE__ }.parent_path(); | ||
_sr.sourceCodeWatcher = wil::make_folder_change_reader_nothrow(_sr.sourceDirectory.c_str(), false, wil::FolderChangeEvents::FileName | wil::FolderChangeEvents::LastWriteTime, [this](wil::FolderChangeEvent, PCWSTR path) { | ||
if (til::ends_with(path, L".hlsl")) | ||
{ | ||
auto expected = INT64_MAX; | ||
const auto invalidationTime = std::chrono::steady_clock::now() + std::chrono::milliseconds(100); | ||
_sr.sourceCodeInvalidationTime.compare_exchange_strong(expected, invalidationTime.time_since_epoch().count(), std::memory_order_relaxed); | ||
} | ||
}); | ||
} | ||
#endif | ||
} | ||
|
||
|
@@ -265,8 +264,8 @@ try | |
|
||
try | ||
{ | ||
static const auto compile = [](const wchar_t* path, const char* target) { | ||
const wil::unique_hfile fileHandle{ CreateFileW(path, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr) }; | ||
static const auto compile = [](const std::filesystem::path& path, const char* target) { | ||
const wil::unique_hfile fileHandle{ CreateFileW(path.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr) }; | ||
THROW_LAST_ERROR_IF(!fileHandle); | ||
|
||
const auto fileSize = GetFileSize(fileHandle.get(), nullptr); | ||
|
@@ -303,8 +302,8 @@ try | |
return blob; | ||
}; | ||
|
||
const auto vs = compile(SHADER_SOURCE_DIRECTORY "shader_vs.hlsl", "vs_4_1"); | ||
const auto ps = compile(SHADER_SOURCE_DIRECTORY "shader_ps.hlsl", "ps_4_1"); | ||
const auto vs = compile(_sr.sourceDirectory / L"shader_vs.hlsl", "vs_4_1"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we're only setting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This section of code is also guarded by a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah okay I clearly missed that |
||
const auto ps = compile(_sr.sourceDirectory / L"shader_ps.hlsl", "ps_4_1"); | ||
|
||
THROW_IF_FAILED(_r.device->CreateVertexShader(vs->GetBufferPointer(), vs->GetBufferSize(), nullptr, _r.vertexShader.put())); | ||
THROW_IF_FAILED(_r.device->CreatePixelShader(ps->GetBufferPointer(), ps->GetBufferSize(), nullptr, _r.pixelShader.put())); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How the devil does this work when the app is packaged and deployed? Does it just look for the hlsl's in the package?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
__FILE__
usually expands to the absolute path of the current source file (AtlasEngine.cpp). Sometimes with some compilers or toolchain setups this isn't the case, but it works for us at least. If I take the parent path of AtlasEngine.cpp I can get the absolute path to the /atlas/ source directory.