Skip to content

Commit 40b9fcd

Browse files
committed
Minor fixes and updates after rebase on 'master'
1 parent 2718ab5 commit 40b9fcd

File tree

8 files changed

+1020
-402
lines changed

8 files changed

+1020
-402
lines changed

sources/core/Stride.Core/Unsafe/StringMarshal.cs

Lines changed: 208 additions & 197 deletions
Large diffs are not rendered by default.

sources/engine/Stride.Games/GameWindowRenderer.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ public class GameWindowRenderer : GameSystemBase
4040
private PixelFormat preferredBackBufferFormat;
4141
private int preferredBackBufferHeight;
4242
private int preferredBackBufferWidth;
43-
private PixelFormat preferredDepthStencilFormat;
44-
private ColorSpaceType preferredOutputColorSpace;
43+
private ColorSpaceType preferredOutputColorSpace = ColorSpaceType.Rgb_Full_G22_None_P709;
4544

4645
private GraphicsPresenter savedPresenter;
4746

@@ -59,7 +58,6 @@ public class GameWindowRenderer : GameSystemBase
5958
public GameWindowRenderer(IServiceRegistry registry, GameContext gameContext) : base(registry)
6059
{
6160
GameContext = gameContext;
62-
preferredOutputColorSpace = ColorSpaceType.RgbFullG22NoneP709;
6361
}
6462

6563

@@ -95,17 +93,21 @@ public PixelFormat PreferredBackBufferFormat
9593
}
9694

9795
/// <summary>
98-
/// Gets or sets the preferred presenter output color space. Can be used to render to HDR monitors. Currently only supported by the DirectX backend.
99-
/// See: https://learn.microsoft.com/en-us/windows/win32/direct3darticles/high-dynamic-range
96+
/// Gets or sets the preferred output color space the <see cref="Presenter"/> should use.
10097
/// </summary>
101-
/// <value>The preferred presenter output color space.</value>
98+
/// <remarks>
99+
/// <para>
100+
/// The output color space can be used to render to HDR monitors.
101+
/// </para>
102+
/// <para>
103+
/// Note that this is currently only supported in Stride when using the Direct3D Graphics API.
104+
/// For more information about High Dynamic Range (HDR) rendering, see
105+
/// <see href="https://learn.microsoft.com/en-us/windows/win32/direct3darticles/high-dynamic-range"/>.
106+
/// </para>
107+
/// </remarks>
102108
public ColorSpaceType PreferredOutputColorSpace
103109
{
104-
get
105-
{
106-
return preferredOutputColorSpace;
107-
}
108-
110+
get => preferredOutputColorSpace;
109111
set
110112
{
111113
if (preferredOutputColorSpace != value)

sources/engine/Stride.Graphics/Direct3D/SwapChainGraphicsPresenter.Direct3D.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -692,17 +692,16 @@ static ISwapChainPanelNative GetNativePanelFromHandle(WindowHandle windowHandle)
692692
result.Throw();
693693

694694
// We need a IDXGISwapChain3 to enable output color space setting to support HDR outputs
695-
IDXGISwapChain3* swapChain3;
696-
result = newSwapChain->QueryInterface(SilkMarshal.GuidPtrOf<IDXGISwapChain3>(), (void**) &swapChain3);
695+
result = newSwapChain.QueryInterface(out ComPtr<IDXGISwapChain3> swapChain3);
697696

698697
if (result.IsSuccess)
699698
{
700-
swapChain3->SetColorSpace1((Silk.NET.DXGI.ColorSpaceType) Description.OutputColorSpace);
701-
swapChain3->Release();
699+
swapChain3.SetColorSpace1((Silk.NET.DXGI.ColorSpaceType) Description.OutputColorSpace);
700+
swapChain3.Release();
702701
}
703702

704-
// Prevent switching between windowed and full screen modes by pressing Alt+ENTER
705-
GraphicsAdapterFactory.NativeFactory.MakeWindowAssociation(handle, DxgiConstants.WindowAssociation_NoAltEnter);
703+
// Prevent switching between windowed and fullscreen modes by pressing Alt+ENTER
704+
nativeFactory.MakeWindowAssociation(handle, DxgiConstants.WindowAssociation_NoAltEnter);
706705

707706
if (Description.IsFullScreen)
708707
{

sources/engine/Stride.Graphics/GraphicsPresenter.cs

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ public virtual void EndDraw(CommandList commandList, bool present)
193193
/// The new preferred pixel format for the Back-Buffer. The specified format may be overriden
194194
/// depending on Graphics Device features and configuration (for example, to use sRGB when appropriate).
195195
/// </param>
196+
/// <exception cref="System.NotSupportedException">
197+
/// The specified pixel <paramref name="format"/> or size is not supported by the Graphics Device.
198+
/// </exception>
196199
public void Resize(int width, int height, PixelFormat format)
197200
{
198201
GraphicsDevice.Begin();
@@ -202,31 +205,66 @@ public void Resize(int width, int height, PixelFormat format)
202205
Description.BackBufferFormat = NormalizeBackBufferFormat(format);
203206

204207
ResizeBackBuffer(width, height, format);
205-
ResizeDepthStencilBuffer(width, height, format);
208+
ResizeDepthStencilBuffer(width, height, DepthStencilBuffer.ViewFormat);
206209

207210
GraphicsDevice.End();
208211
}
209212

210213
/// <summary>
211-
/// Sets the output color space of the presenter and the format for the backbuffer. Currently only supported by the DirectX backend.
212-
/// Use the following combinations: <br />
213-
/// Render to SDR Display with gamma 2.2: <see cref="ColorSpaceType.RgbFullG22NoneP709"/> with <see cref="PixelFormat.R8G8B8A8_UNorm"/>, <see cref="PixelFormat.R8G8B8A8_UNorm_SRgb"/>, <see cref="PixelFormat.B8G8R8A8_UNorm"/>, <see cref="PixelFormat.B8G8R8A8_UNorm"/>. <br />
214-
/// Render to HDR Display in scRGB (standard linear), windows DWM will do the color conversion: <see cref="ColorSpaceType.RgbFullG10NoneP709"/> with <see cref="PixelFormat.R16G16B16A16_Float"/> <br />
215-
/// Render to HDR Display in HDR10/BT.2100, no windows DWM conversion, rendering needs to be in the Display color space: <see cref="ColorSpaceType.RgbFullG2084NoneP2020"/> with <see cref="PixelFormat.R10G10B10A2_UNorm"/> <br />
214+
/// Sets the output color space of the Graphics Presenter and the pixel format to use for the Back-Buffer.
216215
/// </summary>
217-
/// <param name="colorSpace"></param>
218-
/// <param name="format"></param>
216+
/// <param name="colorSpace">The output color space the Graphics Presenter should use.</param>
217+
/// <param name="format">The pixel format to use for the Back-Buffer.</param>
218+
/// <remarks>
219+
/// <para>
220+
/// The output color space can be used to render to HDR monitors.
221+
/// </para>
222+
/// <para>
223+
/// Use the following combinations:
224+
/// <list type="table">
225+
/// <item>
226+
/// <term>For rendering to a SDR display with gamma 2.2</term>
227+
/// <description>
228+
/// Set a color space of <see cref="ColorSpaceType.RgbFullG22NoneP709"/> with a Back-Buffer format <see cref="PixelFormat.R8G8B8A8_UNorm"/>,
229+
/// <see cref="PixelFormat.R8G8B8A8_UNorm_SRgb"/>, <see cref="PixelFormat.B8G8R8A8_UNorm"/>, or <see cref="PixelFormat.B8G8R8A8_UNorm"/>.
230+
/// </description>
231+
/// </item>
232+
/// <item>
233+
/// <term>For rendering to a HDR display in scRGB (standard linear), and letting the Windows DWM do the color conversion</term>
234+
/// <description>
235+
/// Set a color space of <see cref="ColorSpaceType.RgbFullG10NoneP709"/> with a Back-Buffer format <see cref="PixelFormat.R16G16B16A16_Float"/>.
236+
/// </description>
237+
/// </item>
238+
/// <item>
239+
/// <term>
240+
/// For rendering to a HDR display in HDR10 / BT.2100, with no color conversion by the Windows DWM, rendering needs to happen in the
241+
/// same color space as the display.
242+
/// </term>
243+
/// <description>
244+
/// Set a color space of <see cref="ColorSpaceType.RgbFullG2084NoneP2020"/> with a Back-Buffer format <see cref="PixelFormat.R10G10B10A2_UNorm"/>.
245+
/// </description>
246+
/// </item>
247+
/// </list>
248+
/// </para>
249+
/// <para>
250+
/// Note that this is currently only supported in Stride when using the Direct3D Graphics API.
251+
/// For more information about High Dynamic Range (HDR) rendering, see
252+
/// <see href="https://learn.microsoft.com/en-us/windows/win32/direct3darticles/high-dynamic-range"/>.
253+
/// </para>
254+
/// </remarks>
255+
/// <exception cref="System.NotSupportedException">
256+
/// The specified pixel <paramref name="format"/> or size is not supported by the Graphics Device.
257+
/// </exception>
219258
public void SetOutputColorSpace(ColorSpaceType colorSpace, PixelFormat format)
220259
{
221260
GraphicsDevice.Begin();
222261

223262
Description.BackBufferFormat = NormalizeBackBufferFormat(format);
224263

225-
// new resources
226264
ResizeBackBuffer(Description.BackBufferWidth, Description.BackBufferHeight, format);
227-
ResizeDepthStencilBuffer(Description.BackBufferWidth, Description.BackBufferHeight, depthStencilBuffer.ViewFormat);
265+
ResizeDepthStencilBuffer(Description.BackBufferWidth, Description.BackBufferHeight, DepthStencilBuffer.ViewFormat);
228266

229-
// recreate swapchain
267+
// We need to recreate the Swap Chain
230268
OnDestroyed();
231269
Description.OutputColorSpace = colorSpace;
232270
OnRecreated();

sources/engine/Stride.Graphics/PresentationParameters.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public sealed class PresentationParameters : IEquatable<PresentationParameters>
2121
private const bool DefaultIsFullScreen = false;
2222
private const int DefaultRefreshRate = 60; // Hz
2323
private const ColorSpace DefaultColorSpace = ColorSpace.Linear;
24+
private const ColorSpaceType DefaultOutputColorSpace = ColorSpaceType.Rgb_Full_G22_None_P709; // Default RGB output for monitors with a standard gamma of 2.2
2425

2526
#endregion
2627

@@ -193,6 +194,22 @@ public sealed class PresentationParameters : IEquatable<PresentationParameters>
193194
/// </remarks>
194195
public ColorSpace ColorSpace;
195196

197+
/// <summary>
198+
/// The color space type used for the Graphics Presenter output.
199+
/// </summary>
200+
/// <remarks>
201+
/// <para>
202+
/// The output color space can be used to render to HDR monitors.
203+
/// Consult the documentation of the <see cref="ColorSpaceType"/> enum for more details.
204+
/// </para>
205+
/// <para>
206+
/// Note that this is currently only supported in Stride when using the Direct3D Graphics API.
207+
/// For more information about High Dynamic Range (HDR) rendering, see
208+
/// <see href="https://learn.microsoft.com/en-us/windows/win32/direct3darticles/high-dynamic-range"/>.
209+
/// </para>
210+
/// </remarks>
211+
public ColorSpaceType OutputColorSpace;
212+
196213

197214
/// <summary>
198215
/// Initializes a new instance of the <see cref="PresentationParameters"/> class with default values.
@@ -209,7 +226,11 @@ public sealed class PresentationParameters : IEquatable<PresentationParameters>
209226
/// (<see cref="PixelFormat.D24_UNorm_S8_UInt"/>).
210227
/// </item>
211228
/// <item>No multi-sampling.</item>
212-
/// <item>Assuming a linear color space (<see cref="ColorSpace.Linear"/>).</item>
229+
/// <item>
230+
/// Assuming a linear color space (<see cref="ColorSpace.Linear"/>) and an output color space
231+
/// <see cref="ColorSpaceType.RgbFullG22NoneP709"/>, which is the default RGB output for monitors
232+
/// with a standard gamma of 2.2.
233+
/// </item>
213234
/// <item>
214235
/// A windowed presentation at 60 Hz with no V-Sync (<see cref="PresentInterval.Immediate"/>).
215236
/// </item>
@@ -226,6 +247,7 @@ public PresentationParameters()
226247
IsFullScreen = DefaultIsFullScreen;
227248
RefreshRate = DefaultRefreshRate;
228249
ColorSpace = DefaultColorSpace;
250+
OutputColorSpace = DefaultOutputColorSpace;
229251
}
230252

231253
/// <summary>

sources/engine/Stride.Video/VideoSystem.Direct3D.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public override unsafe void Initialize()
2222
var graphicsDevice = Services.GetService<IGame>().GraphicsDevice;
2323

2424
var d3d11Device = graphicsDevice.NativeDevice;
25-
var d3d11DeviceSharpDX = new SharpDX.ComObject((IntPtr) d3d11Device);
25+
var d3d11DeviceSharpDX = new SharpDX.ComObject((IntPtr) d3d11Device.Handle);
2626

2727
DxgiDeviceManager = new DXGIDeviceManager();
2828
DxgiDeviceManager.ResetDevice(d3d11DeviceSharpDX);

sources/engine/Stride/Graphics/ColorSpace.cs

Lines changed: 0 additions & 175 deletions
Original file line numberDiff line numberDiff line change
@@ -36,178 +36,3 @@ public enum ColorSpace
3636
/// </remarks>
3737
Gamma
3838
}
39-
40-
/// <summary>
41-
/// Specifies the type of color space a Graphics Presenter has to output.
42-
/// </summary>
43-
/// <remarks>
44-
/// <para>
45-
/// This enum is used within a Graphics Presenter when configuring a Swap Chain to check
46-
/// the color space support of the Graphics Adapter and the Graphics Output, set a
47-
/// specific color space as output of the Swap Chain. It is also referenced in D3D11 video methods
48-
/// </para>
49-
/// <para>
50-
/// It is also used for defining the output color space of video decoding.
51-
/// </para>
52-
/// </remarks>
53-
public enum ColorSpaceType
54-
{
55-
/// <summary>
56-
/// ColorspaceRGB Range0-255 Gamma2.2 SitingImage PrimariesBT.709. Use with backbuffer of 8 bit colors, such as PixelFormat.B8G8R8A8_UNorm.
57-
/// This is the standard definition for sRGB. Note that this is often implemented
58-
/// with a linear segment, but in that case, the exponent is corrected to stay aligned
59-
/// with a gamma 2.2 curve. This is usually used with 8-bit and 10-bit color channels.
60-
/// </summary>
61-
RgbFullG22NoneP709 = 0,
62-
63-
/// <summary>
64-
/// ColorspaceRGB Range0-255 Gamma1.0 SitingImage PrimariesBT.709. Use with backbuffer of 16 bit colors, PixelFormat.R16G16B16A16_Float.
65-
/// This is the standard definition for scRGB, and is usually used with 16-bit integer,
66-
/// 16-bit floating point, and 32-bit floating point channels.
67-
/// </summary>
68-
RgbFullG10NoneP709 = 1,
69-
70-
/// <summary>
71-
/// ColorspaceRGB Range16-235 Gamma2.2 SitingImage PrimariesBT.709.
72-
/// This is the standard definition for ITU-R Recommendation BT.709. Note that
73-
/// due to the inclusion of a linear segment, the transfer curve looks similar to
74-
/// a pure exponential gamma of 1.9. This is usually used with 8-bit and 10-bit color
75-
/// channels.
76-
/// </summary>
77-
RgbStudioG22NoneP709 = 2,
78-
79-
/// <summary>
80-
/// ColorspaceRGB Range16-235 Gamma2.2 SitingImage PrimariesBT.2020.
81-
/// This is usually used with 10, 12, or 16-bit color channels.
82-
/// </summary>
83-
RgbStudioG22NoneP2020 = 3,
84-
85-
/// <summary>
86-
/// Reserved.
87-
/// </summary>
88-
Reserved = 4,
89-
90-
/// <summary>
91-
/// ColorspaceYCbCr Range0-255 Gamma2.2 SitingImage PrimariesBT.709 TransferBT.601.
92-
/// This definition is commonly used for JPG, and is usually used with 8, 10, 12,
93-
/// or 16-bit color channels.
94-
/// </summary>
95-
YcbcrFullG22NoneP709X601 = 5,
96-
97-
/// <summary>
98-
/// ColorspaceYCbCr Range16-235 Gamma2.2 SitingVideo PrimariesBT.601.
99-
/// This definition is commonly used for MPEG2, and is usually used with 8, 10, 12,
100-
/// or 16-bit color channels.
101-
/// </summary>
102-
YcbcrStudioG22LeftP601 = 6,
103-
104-
/// <summary>
105-
/// ColorspaceYCbCr Range0-255 Gamma2.2 SitingVideo PrimariesBT.601.
106-
/// This is sometimes used for H.264 camera capture, and is usually used with 8, 10,
107-
/// 12, or 16-bit color channels.
108-
/// </summary>
109-
YcbcrFullG22LeftP601 = 7,
110-
111-
/// <summary>
112-
/// ColorspaceYCbCr Range16-235 Gamma2.2 SitingVideo PrimariesBT.709.
113-
/// This definition is commonly used for H.264 and HEVC, and is usually used with
114-
/// 8, 10, 12, or 16-bit color channels.
115-
/// </summary>
116-
YcbcrStudioG22LeftP709 = 8,
117-
118-
/// <summary>
119-
/// ColorspaceYCbCr Range0-255 Gamma2.2 SitingVideo PrimariesBT.709.
120-
/// This is sometimes used for H.264 camera capture, and is usually used with 8, 10,
121-
/// 12, or 16-bit color channels.
122-
/// </summary>
123-
YcbcrFullG22LeftP709 = 9,
124-
125-
/// <summary>
126-
/// ColorspaceYCbCr Range16-235 Gamma2.2 SitingVideo PrimariesBT.2020.
127-
/// This definition may be used by HEVC, and is usually used with 10, 12, or 16-bit
128-
/// color channels.
129-
/// </summary>
130-
YcbcrStudioG22LeftP2020 = 10,
131-
132-
/// <summary>
133-
/// ColorspaceYCbCr Range0-255 Gamma2.2 SitingVideo PrimariesBT.2020.
134-
/// This is usually used with 10, 12, or 16-bit color channels.
135-
/// </summary>
136-
YcbcrFullG22LeftP2020 = 11,
137-
138-
/// <summary>
139-
/// ColorspaceRGB Range0-255 Gamma2084 SitingImage PrimariesBT.2020. Use with backbuffer of 10 bit colors, PixelFormat.R10G10B10A2_UNorm.
140-
/// This is usually used with 10, 12, or 16-bit color channels.
141-
/// </summary>
142-
RgbFullG2084NoneP2020 = 12,
143-
144-
/// <summary>
145-
/// ColorspaceYCbCr Range16-235 Gamma2084 SitingVideo PrimariesBT.2020.
146-
/// This is usually used with 10, 12, or 16-bit color channels.
147-
/// </summary>
148-
YcbcrStudioG2084LeftP2020 = 13,
149-
150-
/// <summary>
151-
/// ColorspaceRGB Range16-235 Gamma2084 SitingImage PrimariesBT.2020.
152-
/// This is usually used with 10, 12, or 16-bit color channels.
153-
/// </summary>
154-
RgbStudioG2084NoneP2020 = 14,
155-
156-
/// <summary>
157-
/// ColorspaceYCbCr Range16-235 Gamma2.2 SitingVideo PrimariesBT.2020.
158-
/// This is usually used with 10, 12, or 16-bit color channels.
159-
/// </summary>
160-
YcbcrStudioG22TopleftP2020 = 15,
161-
162-
/// <summary>
163-
/// ColorspaceYCbCr Range16-235 Gamma2084 SitingVideo PrimariesBT.2020.
164-
/// This is usually used with 10, 12, or 16-bit color channels.
165-
/// </summary>
166-
YcbcrStudioG2084TopleftP2020 = 16,
167-
168-
/// <summary>
169-
/// ColorspaceRGB Range0-255 Gamma2.2 SitingImage PrimariesBT.2020.
170-
/// This is usually used with 10, 12, or 16-bit color channels.
171-
/// </summary>
172-
RgbFullG22NoneP2020 = 17,
173-
174-
/// <summary>
175-
/// A custom color definition is used.
176-
/// </summary>
177-
YcbcrStudioGhlgTopleftP2020 = 18,
178-
179-
/// <summary>
180-
/// No documentation.
181-
/// </summary>
182-
YcbcrFullGhlgTopleftP2020 = 19,
183-
184-
/// <summary>
185-
/// No documentation.
186-
/// </summary>
187-
RgbStudioG24NoneP709 = 20,
188-
189-
/// <summary>
190-
/// No documentation.
191-
/// </summary>
192-
RgbStudioG24NoneP2020 = 21,
193-
194-
/// <summary>
195-
/// No documentation.
196-
/// </summary>
197-
YcbcrStudioG24LeftP709 = 22,
198-
199-
/// <summary>
200-
/// No documentation.
201-
/// </summary>
202-
YcbcrStudioG24LeftP2020 = 23,
203-
204-
/// <summary>
205-
/// No documentation.
206-
/// </summary>
207-
YcbcrStudioG24TopleftP2020 = 24,
208-
209-
/// <summary>
210-
/// A custom color definition is used.
211-
/// </summary>
212-
Custom = -1
213-
}

0 commit comments

Comments
 (0)