Compare commits

...

5 Commits

Author SHA1 Message Date
Mike Griese
e2ff838ec3 yes this is actually right 2024-02-22 10:25:28 -06:00
Mike Griese
aa3df882a9 Merge remote-tracking branch 'origin/main' into pull/14073 2024-02-22 09:51:15 -06:00
mrange
ee9cc96c9e Added support for loading pixes shader texture to Atlas.
Loaded using DirectX ToolKit which in turn relies on WIC.

Should enable new classes of pixel shader backgrounds
as texture can be logos but also noise like perlin noise
which is very useful in many shader scenarios.
2022-10-30 08:48:19 +01:00
mrange
052d11242e Adding git submodule to DirectX ToolKit 2022-10-30 08:48:19 +01:00
mrange
5c831b4deb Fixing spelling complaints 2022-10-30 08:48:14 +01:00
25 changed files with 193 additions and 4 deletions

View File

@@ -42,11 +42,13 @@ ftp
fvar
gantt
gcc
Geddy
geeksforgeeks
ghe
github
gje
godbolt
hardcode
hostname
hostnames
https
@@ -84,6 +86,7 @@ overlined
perlw
pipeline
postmodern
Premultiplied
Powerline
powerline
ptys
@@ -131,6 +134,7 @@ westus
wildcards
workarounds
XBox
XTK
YBox
yeru
zhe

View File

@@ -1,3 +1,4 @@
ABORTIFHUNG
ACCEPTFILES
ACCESSDENIED
acl
@@ -7,6 +8,7 @@ alignof
allocconsolewithoptions
APPLYTOSUBMENUS
appxrecipe
Bgra
bitfield
bitfields
BUILDBRANCH
@@ -23,7 +25,9 @@ colspan
COMDLG
commandlinetoargv
comparand
cosf
cstdint
CUsers
CXICON
CYICON
Dacl
@@ -44,8 +48,10 @@ enumset
environstrings
EXPCMDFLAGS
EXPCMDSTATE
fenv
filetime
FILTERSPEC
FMA
FORCEFILESYSTEM
FORCEMINIMIZE
frac
@@ -53,9 +59,11 @@ fullkbd
futex
GETDESKWALLPAPER
GETHIGHCONTRAST
GETKEYSTATE
GETMOUSEHOVERTIME
GETTEXTLENGTH
Hashtable
hicon
HIGHCONTRASTON
HIGHCONTRASTW
hinternet
@@ -83,6 +91,7 @@ Idn
IExplorer
IFACEMETHOD
IFile
IFolder
IGraphics
IInheritable
IMap
@@ -91,8 +100,13 @@ IObject
iosfwd
IPackage
IPeasant
<<<<<<< HEAD
IService
=======
isa
>>>>>>> origin/main
ISetup
ISoftware
isspace
IStorage
istream
@@ -102,25 +116,34 @@ ITaskbar
itow
IUri
IVirtual
IWIC
KEYSELECT
LCID
llabs
llu
localtime
lround
lroundf
Lsa
lsass
LSHIFT
LTGRAY
MAINWINDOW
<<<<<<< HEAD
MAPVIRTUALKEY
=======
MAXIMIZEBOX
>>>>>>> origin/main
memchr
memicmp
MENUCOMMAND
MENUDATA
MENUINFO
MENUITEMINFOW
<<<<<<< HEAD
=======
MINIMIZEBOX
>>>>>>> origin/main
mmeapi
MOUSELEAVE
mov
@@ -143,6 +166,7 @@ NOREPEAT
NOTIFYBYPOS
NOTIFYICON
NOTIFYICONDATA
NOTIMEOUTIFNOTHUNG
ntprivapi
oaidl
ocidl
@@ -168,7 +192,10 @@ rcx
REGCLS
RETURNCMD
rfind
<<<<<<< HEAD
=======
RLO
>>>>>>> origin/main
ROOTOWNER
roundf
RSHIFT
@@ -178,6 +205,7 @@ SEH
semver
serializer
SETVERSION
SFolder
SHELLEXECUTEINFOW
shobjidl
SHOWHIDE
@@ -226,6 +254,16 @@ UPDATEINIFILE
urlmon
userenv
USEROBJECTFLAGS
<<<<<<< HEAD
versionf
Viewbox
VKKEYSCAN
wcsstr
wcstoui
wic
WIC
wincodec
=======
Vcpp
Viewbox
virtualalloc
@@ -236,6 +274,7 @@ wcstoui
WDJ
winhttp
wininet
>>>>>>> origin/main
winmain
winsta
winstamin

View File

@@ -89,6 +89,7 @@ Wellons
Westerman
Wirt
Wojciech
XTK
zadjii
Zamor
zamora

3
.gitmodules vendored
View File

@@ -1,3 +1,6 @@
[submodule "dep/gsl"]
path = dep/gsl
url = https://github.com/microsoft/gsl
[submodule "dep/DirectXTK"]
path = dep/DirectXTK
url = https://github.com/microsoft/DirectXTK.git

1
dep/DirectXTK Submodule

Submodule dep/DirectXTK added at d1d5e73189

View File

@@ -0,0 +1,26 @@
// Demo shader to show passing in an image using
// experimental.pixelShaderImagePath. This shader simply displays the Terminal
// contents on top of the given image.
//
// The image loaded by the terminal will be placed into the `image` texture.
SamplerState samplerState;
Texture2D shaderTexture : register(t0);
Texture2D image : register(t1);
cbuffer PixelShaderSettings {
float Time;
float Scale;
float2 Resolution;
float4 Background;
};
float4 main(float4 pos : SV_POSITION, float2 tex : TEXCOORD) : SV_TARGET
{
float4 terminalColor = shaderTexture.Sample(samplerState, tex);
float4 imageColor = image.Sample(samplerState, tex);
float4 color = lerp(imageColor, terminalColor, terminalColor.a);
return color;
}

View File

@@ -387,6 +387,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
_renderEngine->SetRetroTerminalEffect(_settings->RetroTerminalEffect());
_renderEngine->SetPixelShaderPath(_settings->PixelShaderPath());
_renderEngine->SetPixelShaderImagePath(_settings->PixelShaderImagePath());
_renderEngine->SetForceFullRepaintRendering(_settings->ForceFullRepaintRendering());
_renderEngine->SetSoftwareRendering(_settings->SoftwareRendering());
@@ -914,6 +915,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
_renderEngine->SetRetroTerminalEffect(newAppearance->RetroTerminalEffect());
_renderEngine->SetPixelShaderPath(newAppearance->PixelShaderPath());
_renderEngine->SetPixelShaderImagePath(newAppearance->PixelShaderImagePath());
// Incase EnableUnfocusedAcrylic is disabled and Focused Acrylic is set to true,
// the terminal should ignore the unfocused opacity from settings.
// The Focused Opacity from settings should be ignored if overridden at runtime.

View File

@@ -18,5 +18,6 @@ namespace Microsoft.Terminal.Control
// Experimental settings
Boolean RetroTerminalEffect { get; };
String PixelShaderPath { get; };
String PixelShaderImagePath { get; };
};
}

View File

@@ -333,7 +333,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// (The window has a min. size that ensures that there's always a scrollbar thumb.)
if (drawableRange < 0)
{
assert(false);
// assert(false);
return;
}

View File

@@ -1602,7 +1602,7 @@ til::point Terminal::GetViewportRelativeCursorPosition() const noexcept
// These functions are used by TerminalInput, which must build in conhost
// against OneCore compatible signatures. See the definitions in
// VtApiRedirection.hpp (which we cannot include cross-project.)
// Since we do nto run on OneCore, we can dispense with the compatibility
// Since we don't run on OneCore, we can dispense with the compatibility
// shims.
extern "C" UINT OneCoreSafeMapVirtualKeyW(_In_ UINT uCode, _In_ UINT uMapType)
{

View File

@@ -51,6 +51,7 @@ namespace Microsoft.Terminal.Settings.Model
INHERITABLE_APPEARANCE_SETTING(Boolean, RetroTerminalEffect);
INHERITABLE_APPEARANCE_SETTING(String, PixelShaderPath);
INHERITABLE_APPEARANCE_SETTING(String, PixelShaderImagePath);
INHERITABLE_APPEARANCE_SETTING(IntenseStyle, IntenseTextStyle);
INHERITABLE_APPEARANCE_SETTING(Microsoft.Terminal.Core.AdjustTextMode, AdjustIndistinguishableColors);
INHERITABLE_APPEARANCE_SETTING(Double, Opacity);

View File

@@ -124,6 +124,7 @@ Author(s):
X(winrt::Windows::UI::Xaml::Media::Stretch, BackgroundImageStretchMode, "backgroundImageStretchMode", winrt::Windows::UI::Xaml::Media::Stretch::UniformToFill) \
X(bool, RetroTerminalEffect, "experimental.retroTerminalEffect", false) \
X(hstring, PixelShaderPath, "experimental.pixelShaderPath") \
X(hstring, PixelShaderImagePath, "experimental.pixelShaderImagePath") \
X(ConvergedAlignment, BackgroundImageAlignment, "backgroundImageAlignment", ConvergedAlignment::Horizontal_Center | ConvergedAlignment::Vertical_Center) \
X(hstring, BackgroundImagePath, "backgroundImage") \
X(Model::IntenseStyle, IntenseTextStyle, "intenseTextStyle", Model::IntenseStyle::Bright) \

View File

@@ -256,6 +256,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
_RetroTerminalEffect = appearance.RetroTerminalEffect();
_PixelShaderPath = winrt::hstring{ wil::ExpandEnvironmentStringsW<std::wstring>(appearance.PixelShaderPath().c_str()) };
_PixelShaderImagePath = winrt::hstring{ wil::ExpandEnvironmentStringsW<std::wstring>(appearance.PixelShaderImagePath().c_str()) };
_IntenseIsBold = WI_IsFlagSet(appearance.IntenseTextStyle(), Microsoft::Terminal::Settings::Model::IntenseStyle::Bold);
_IntenseIsBright = WI_IsFlagSet(appearance.IntenseTextStyle(), Microsoft::Terminal::Settings::Model::IntenseStyle::Bright);

View File

@@ -159,6 +159,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
INHERITABLE_SETTING(Model::TerminalSettings, bool, ForceVTInput, false);
INHERITABLE_SETTING(Model::TerminalSettings, hstring, PixelShaderPath);
INHERITABLE_SETTING(Model::TerminalSettings, hstring, PixelShaderImagePath);
INHERITABLE_SETTING(Model::TerminalSettings, bool, Elevate, false);

View File

@@ -27,7 +27,8 @@
X(winrt::Windows::UI::Xaml::HorizontalAlignment, BackgroundImageHorizontalAlignment, winrt::Windows::UI::Xaml::HorizontalAlignment::Center) \
X(winrt::Windows::UI::Xaml::VerticalAlignment, BackgroundImageVerticalAlignment, winrt::Windows::UI::Xaml::VerticalAlignment::Center) \
X(bool, RetroTerminalEffect, false) \
X(winrt::hstring, PixelShaderPath)
X(winrt::hstring, PixelShaderPath) \
X(winrt::hstring, PixelShaderImagePath)
// --------------------------- Core Settings ---------------------------
// All of these settings are defined in ICoreSettings.

View File

@@ -328,6 +328,11 @@ HRESULT AtlasEngine::Enable() noexcept
return _api.s->misc->customPixelShaderPath;
}
[[nodiscard]] std::wstring_view AtlasEngine::GetPixelShaderImagePath() noexcept
{
return _api.s->misc->customPixelShaderImagePath;
}
[[nodiscard]] bool AtlasEngine::GetRetroTerminalEffect() const noexcept
{
return _api.s->misc->useRetroTerminalEffect;
@@ -400,6 +405,15 @@ try
}
CATCH_LOG()
void AtlasEngine::SetPixelShaderImagePath(std::wstring_view value) noexcept
{
if (_api.s->misc->customPixelShaderImagePath != value)
{
_api.s.write()->misc.write()->customPixelShaderImagePath = value;
_resolveTransparencySettings();
}
}
void AtlasEngine::SetRetroTerminalEffect(bool enable) noexcept
{
if (_api.s->misc->useRetroTerminalEffect != enable)

View File

@@ -61,6 +61,7 @@ namespace Microsoft::Console::Render::Atlas
// DxRenderer - getter
HRESULT Enable() noexcept override;
[[nodiscard]] std::wstring_view GetPixelShaderPath() noexcept override;
[[nodiscard]] std::wstring_view GetPixelShaderImagePath() noexcept override;
[[nodiscard]] bool GetRetroTerminalEffect() const noexcept override;
[[nodiscard]] float GetScaling() const noexcept override;
[[nodiscard]] Types::Viewport GetViewportInCharacters(const Types::Viewport& viewInPixels) const noexcept override;
@@ -72,6 +73,7 @@ namespace Microsoft::Console::Render::Atlas
void SetForceFullRepaintRendering(bool enable) noexcept override;
[[nodiscard]] HRESULT SetHwnd(HWND hwnd) noexcept override;
void SetPixelShaderPath(std::wstring_view value) noexcept override;
void SetPixelShaderImagePath(std::wstring_view value) noexcept override;
void SetRetroTerminalEffect(bool enable) noexcept override;
void SetSelectionBackground(COLORREF color, float alpha = 0.5f) noexcept override;
void SetSoftwareRendering(bool enable) noexcept override;
@@ -165,6 +167,7 @@ namespace Microsoft::Console::Render::Atlas
u16r invalidatedCursorArea = invalidatedAreaNone;
range<u16> invalidatedRows = invalidatedRowsNone; // x is treated as "top" and y as "bottom"
i16 scrollOffset = 0;
} _api;
};
}

View File

@@ -9,6 +9,8 @@
#include <shader_ps.h>
#include <shader_vs.h>
#include <wincodec.h>
#include "dwrite.h"
#include "../../types/inc/ColorFix.hpp"
@@ -379,6 +381,13 @@ void BackendD3D::_recreateCustomShader(const RenderingPayload& p)
_customShaderSamplerState.reset();
_requiresContinuousRedraw = false;
if (!p.s->misc->customPixelShaderImagePath.empty())
{
_customShaderTexture = LoadShaderTextureFromFile(
p.device.get(),
p.s->misc->customPixelShaderImagePath);
}
if (!p.s->misc->customPixelShaderPath.empty())
{
const char* target = nullptr;
@@ -2222,7 +2231,14 @@ void BackendD3D::_executeCustomShader(RenderingPayload& p)
// PS: Pixel Shader
p.deviceContext->PSSetShader(_customPixelShader.get(), nullptr, 0);
p.deviceContext->PSSetConstantBuffers(0, 1, _customShaderConstantBuffer.addressof());
p.deviceContext->PSSetShaderResources(0, 1, _customOffscreenTextureView.addressof());
ID3D11ShaderResourceView* const resourceViews[]{
_customOffscreenTextureView.get(), // The temrinal contents
_customShaderTexture.TextureView.get(), // the experimental.pixelShaderImagePath, if there is one
};
// Checking if customer shader texture is set
const UINT numViews = resourceViews[1] ? 2 : 1;
p.deviceContext->PSSetShaderResources(0, numViews, &resourceViews[0]);
p.deviceContext->PSSetSamplers(0, 1, _customShaderSamplerState.addressof());
// OM: Output Merger

View File

@@ -9,6 +9,8 @@
#include "Backend.h"
#include "TextureLoader.h"
namespace Microsoft::Console::Render::Atlas
{
struct BackendD3D : IBackend
@@ -250,6 +252,7 @@ namespace Microsoft::Console::Render::Atlas
wil::com_ptr<ID3D11PixelShader> _customPixelShader;
wil::com_ptr<ID3D11Buffer> _customShaderConstantBuffer;
wil::com_ptr<ID3D11SamplerState> _customShaderSamplerState;
ShaderTexture _customShaderTexture;
std::chrono::steady_clock::time_point _customShaderStartTime;
wil::com_ptr<ID3D11Texture2D> _backgroundBitmap;

View File

@@ -0,0 +1,40 @@
#include "pch.h"
#include "TextureLoader.h"
#include "WICTextureLoader.h"
namespace Microsoft::Console::Render
{
Microsoft::Console::Render::ShaderTexture LoadShaderTextureFromFile(
ID3D11Device* d3dDevice,
const std::wstring& fileName)
{
Microsoft::Console::Render::ShaderTexture result;
const auto hr = DirectX::CreateWICTextureFromFileEx(
d3dDevice,
fileName.c_str(),
0,
D3D11_USAGE_DEFAULT,
D3D11_BIND_SHADER_RESOURCE,
0,
0,
DirectX::WIC_LOADER_DEFAULT
// TODO: Should we ignore SRGB conversion?
// If we use the default settings the texture is converted
// from SRGB into linear RGB which do make a lot of sense but
// can also be a somewhat surprising to devs not used to it.
| DirectX::WIC_LOADER_IGNORE_SRGB,
result.Texture.addressof(),
result.TextureView.addressof());
if (FAILED(hr))
{
LOG_HR(hr);
return Microsoft::Console::Render::ShaderTexture();
}
return result;
}
}

View File

@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#pragma once
namespace Microsoft::Console::Render
{
struct ShaderTexture
{
wil::com_ptr<ID3D11Resource> Texture;
wil::com_ptr<ID3D11ShaderResourceView> TextureView;
};
Microsoft::Console::Render::ShaderTexture LoadShaderTextureFromFile(
ID3D11Device* d3dDevice,
const std::wstring& fileName);
}

View File

@@ -7,10 +7,12 @@
<ProjectName>RendererAtlas</ProjectName>
<TargetName>ConRenderAtlas</TargetName>
<ConfigurationType>StaticLibrary</ConfigurationType>
<IncludePath>$(SolutionDir)\dep\DirectXTK\Inc;$(IncludePath)</IncludePath>
</PropertyGroup>
<Import Project="$(SolutionDir)src\common.build.pre.props" />
<Import Project="$(SolutionDir)src\common.nugetversions.props" />
<ItemGroup>
<ClCompile Include="$(SolutionDir)\dep\DirectXTK\Src\WICTextureLoader.cpp" />
<ClCompile Include="AtlasEngine.api.cpp" />
<ClCompile Include="AtlasEngine.r.cpp" />
<ClCompile Include="Backend.cpp" />
@@ -22,6 +24,7 @@
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="AtlasEngine.cpp" />
<ClCompile Include="TextureLoader.cpp" />
<ClCompile Include="stb_rect_pack.cpp" />
</ItemGroup>
<ItemGroup>
@@ -34,7 +37,9 @@
<ClInclude Include="DWriteTextAnalysis.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="AtlasEngine.h" />
<ClInclude Include="TextureLoader.h" />
<ClInclude Include="wic.h" />
</ItemGroup>
<ItemGroup>
<FxCompile Include="custom_shader_ps.hlsl">

View File

@@ -379,6 +379,7 @@ namespace Microsoft::Console::Render::Atlas
u32 backgroundColor = 0;
u32 selectionColor = 0x7fffffff;
std::wstring customPixelShaderPath;
std::wstring customPixelShaderImagePath;
bool useRetroTerminalEffect = false;
};

View File

@@ -27,6 +27,9 @@
#include <dxgidebug.h>
#include <VersionHelpers.h>
#include <wrl/client.h>
#include <wincodec.h>
#include <gsl/gsl_util>
#include <gsl/pointers>
#include <wil/com.h>

View File

@@ -96,11 +96,14 @@ namespace Microsoft::Console::Render
// DxRenderer - getter
virtual HRESULT Enable() noexcept { return S_OK; }
[[nodiscard]] virtual std::wstring_view GetPixelShaderPath() noexcept { return {}; }
[[nodiscard]] virtual std::wstring_view GetPixelShaderImagePath() noexcept { return {}; }
[[nodiscard]] virtual bool GetRetroTerminalEffect() const noexcept { return false; }
[[nodiscard]] virtual float GetScaling() const noexcept { return 1; }
[[nodiscard]] virtual Types::Viewport GetViewportInCharacters(const Types::Viewport& viewInPixels) const noexcept { return Types::Viewport::Empty(); }
[[nodiscard]] virtual Types::Viewport GetViewportInPixels(const Types::Viewport& viewInCharacters) const noexcept { return Types::Viewport::Empty(); }
// DxRenderer - setter
virtual void SetAntialiasingMode(const D2D1_TEXT_ANTIALIAS_MODE antialiasingMode) noexcept {}
virtual void SetCallback(std::function<void(HANDLE)> pfn) noexcept {}
@@ -108,6 +111,7 @@ namespace Microsoft::Console::Render
virtual void SetForceFullRepaintRendering(bool enable) noexcept {}
[[nodiscard]] virtual HRESULT SetHwnd(const HWND hwnd) noexcept { return E_NOTIMPL; }
virtual void SetPixelShaderPath(std::wstring_view value) noexcept {}
virtual void SetPixelShaderImagePath(std::wstring_view value) noexcept {}
virtual void SetRetroTerminalEffect(bool enable) noexcept {}
virtual void SetSelectionBackground(const COLORREF color, const float alpha = 0.5f) noexcept {}
virtual void SetSoftwareRendering(bool enable) noexcept {}