Merge pull request #6 from DarthAffe/VorticeUpdate

Vortice update
This commit is contained in:
DarthAffe 2023-02-23 00:02:22 +01:00 committed by GitHub
commit ffc52e8f1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 68 additions and 48 deletions

View File

@ -0,0 +1,19 @@
using Vortice.DXGI;
namespace ScreenCapture.NET;
// DarthAffe 22.02.2023: These helper-methods where removed from Vortice and are readded here since they are used.
internal static class DX11CompatibilityExtensions
{
public static IDXGIAdapter1 GetAdapter1(this IDXGIFactory1 factory, int index)
{
factory.EnumAdapters1(index, out IDXGIAdapter1 adapter).CheckError();
return adapter;
}
public static IDXGIOutput GetOutput(this IDXGIAdapter1 adapter, int index)
{
adapter.EnumOutputs(index, out IDXGIOutput output).CheckError();
return output;
}
}

View File

@ -305,18 +305,18 @@ public sealed class DX11ScreenCapture : IScreenCapture
private void InitializeCaptureZone(in CaptureZone captureZone) private void InitializeCaptureZone(in CaptureZone captureZone)
{ {
Texture2DDescription stagingTextureDesc = new() Texture2DDescription stagingTextureDesc = new()
{ {
CpuAccessFlags = CpuAccessFlags.Read, CPUAccessFlags = CpuAccessFlags.Read,
BindFlags = BindFlags.None, BindFlags = BindFlags.None,
Format = Format.B8G8R8A8_UNorm, Format = Format.B8G8R8A8_UNorm,
Width = captureZone.Width, Width = captureZone.Width,
Height = captureZone.Height, Height = captureZone.Height,
OptionFlags = ResourceOptionFlags.None, MiscFlags = ResourceOptionFlags.None,
MipLevels = 1, MipLevels = 1,
ArraySize = 1, ArraySize = 1,
SampleDescription = { Count = 1, Quality = 0 }, SampleDescription = { Count = 1, Quality = 0 },
Usage = ResourceUsage.Staging Usage = ResourceUsage.Staging
}; };
ID3D11Texture2D stagingTexture = _device!.CreateTexture2D(stagingTextureDesc); ID3D11Texture2D stagingTexture = _device!.CreateTexture2D(stagingTextureDesc);
ID3D11Texture2D? scalingTexture = null; ID3D11Texture2D? scalingTexture = null;
@ -324,18 +324,18 @@ public sealed class DX11ScreenCapture : IScreenCapture
if (captureZone.DownscaleLevel > 0) if (captureZone.DownscaleLevel > 0)
{ {
Texture2DDescription scalingTextureDesc = new() Texture2DDescription scalingTextureDesc = new()
{ {
CpuAccessFlags = CpuAccessFlags.None, CPUAccessFlags = CpuAccessFlags.None,
BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
Format = Format.B8G8R8A8_UNorm, Format = Format.B8G8R8A8_UNorm,
Width = captureZone.UnscaledWidth, Width = captureZone.UnscaledWidth,
Height = captureZone.UnscaledHeight, Height = captureZone.UnscaledHeight,
OptionFlags = ResourceOptionFlags.GenerateMips, MiscFlags = ResourceOptionFlags.GenerateMips,
MipLevels = captureZone.DownscaleLevel + 1, MipLevels = captureZone.DownscaleLevel + 1,
ArraySize = 1, ArraySize = 1,
SampleDescription = { Count = 1, Quality = 0 }, SampleDescription = { Count = 1, Quality = 0 },
Usage = ResourceUsage.Default Usage = ResourceUsage.Default
}; };
scalingTexture = _device!.CreateTexture2D(scalingTextureDesc); scalingTexture = _device!.CreateTexture2D(scalingTextureDesc);
scalingTextureView = _device.CreateShaderResourceView(scalingTexture); scalingTextureView = _device.CreateShaderResourceView(scalingTexture);
} }
@ -362,18 +362,18 @@ public sealed class DX11ScreenCapture : IScreenCapture
using IDXGIOutput5 output = _output.QueryInterface<IDXGIOutput5>(); using IDXGIOutput5 output = _output.QueryInterface<IDXGIOutput5>();
Texture2DDescription captureTextureDesc = new() Texture2DDescription captureTextureDesc = new()
{ {
CpuAccessFlags = CpuAccessFlags.None, CPUAccessFlags = CpuAccessFlags.None,
BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
Format = Format.B8G8R8A8_UNorm, Format = Format.B8G8R8A8_UNorm,
Width = Display.Width, Width = Display.Width,
Height = Display.Height, Height = Display.Height,
OptionFlags = ResourceOptionFlags.None, MiscFlags = ResourceOptionFlags.None,
MipLevels = 1, MipLevels = 1,
ArraySize = 1, ArraySize = 1,
SampleDescription = { Count = 1, Quality = 0 }, SampleDescription = { Count = 1, Quality = 0 },
Usage = ResourceUsage.Default Usage = ResourceUsage.Default
}; };
_captureTexture = _device.CreateTexture2D(captureTextureDesc); _captureTexture = _device.CreateTexture2D(captureTextureDesc);
lock (_captureZones) lock (_captureZones)
@ -383,7 +383,7 @@ public sealed class DX11ScreenCapture : IScreenCapture
} }
if (_useNewDuplicationAdapter) if (_useNewDuplicationAdapter)
_duplicatedOutput = output.DuplicateOutput1(_device, Format.B8G8R8A8_UNorm); // DarthAffe 27.02.2021: This prepares for the use of 10bit color depth _duplicatedOutput = output.DuplicateOutput1(_device, new[] { Format.B8G8R8A8_UNorm }); // DarthAffe 27.02.2021: This prepares for the use of 10bit color depth
else else
_duplicatedOutput = output.DuplicateOutput(_device); _duplicatedOutput = output.DuplicateOutput(_device);
} }

View File

@ -102,6 +102,7 @@ public sealed class CaptureZone
/// <param name="y">The y-location of the region on the screen.</param> /// <param name="y">The y-location of the region on the screen.</param>
/// <param name="width">The width of the region on the screen.</param> /// <param name="width">The width of the region on the screen.</param>
/// <param name="height">The height of the region on the screen.</param> /// <param name="height">The height of the region on the screen.</param>
/// <param name="bytesPerPixel">The number of bytes per pixel.</param>
/// <param name="downscaleLevel">The level of downscaling applied to the image of this region before copying to local memory.</param> /// <param name="downscaleLevel">The level of downscaling applied to the image of this region before copying to local memory.</param>
/// <param name="unscaledWidth">The original width of the region.</param> /// <param name="unscaledWidth">The original width of the region.</param>
/// <param name="unscaledHeight">The original height of the region</param> /// <param name="unscaledHeight">The original height of the region</param>
@ -141,7 +142,7 @@ public sealed class CaptureZone
IsUpdateRequested = false; IsUpdateRequested = false;
BlackBars.InvalidateCache(); BlackBars.InvalidateCache();
Updated?.Invoke(this, new EventArgs()); Updated?.Invoke(this, EventArgs.Empty);
} }
/// <summary> /// <summary>

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net6.0;net5.0</TargetFrameworks> <TargetFrameworks>net7.0;net6.0</TargetFrameworks>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
@ -16,8 +16,8 @@
<RootNamespace>ScreenCapture.NET</RootNamespace> <RootNamespace>ScreenCapture.NET</RootNamespace>
<Description>Vortice based Screen-Capturing</Description> <Description>Vortice based Screen-Capturing</Description>
<Summary>Vortice based Screen-Capturing using Desktop Duplication</Summary> <Summary>Vortice based Screen-Capturing using Desktop Duplication</Summary>
<Copyright>Copyright © Darth Affe 2022</Copyright> <Copyright>Copyright © Darth Affe 2023</Copyright>
<PackageCopyright>Copyright © Darth Affe 2022</PackageCopyright> <PackageCopyright>Copyright © Darth Affe 2023</PackageCopyright>
<PackageIcon>icon.png</PackageIcon> <PackageIcon>icon.png</PackageIcon>
<PackageProjectUrl>https://github.com/DarthAffe/ScreenCapture.NET</PackageProjectUrl> <PackageProjectUrl>https://github.com/DarthAffe/ScreenCapture.NET</PackageProjectUrl>
<PackageLicenseExpression>LGPL-2.1-only</PackageLicenseExpression> <PackageLicenseExpression>LGPL-2.1-only</PackageLicenseExpression>
@ -26,14 +26,14 @@
<GeneratePackageOnBuild>True</GeneratePackageOnBuild> <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageReleaseNotes> <PackageReleaseNotes>
- Added IScreenCapture.UpdateCaptureZone to modify existing CaptureZones without having to remove and add them again. - Updated Vortice
(This has performance benefits when only X and/or Y is changed, changes to width, height and downscale are internally still reinitializing the zone.) - Added .NET 7 Target
- Fixed ambiguous equals in Display - Removed unsupported .NET 5 Target
</PackageReleaseNotes> </PackageReleaseNotes>
<Version>1.2.0</Version> <Version>1.2.1</Version>
<AssemblyVersion>1.2.0</AssemblyVersion> <AssemblyVersion>1.2.1</AssemblyVersion>
<FileVersion>1.2.0</FileVersion> <FileVersion>1.2.1</FileVersion>
<OutputPath>..\bin\</OutputPath> <OutputPath>..\bin\</OutputPath>
<GenerateDocumentationFile>true</GenerateDocumentationFile> <GenerateDocumentationFile>true</GenerateDocumentationFile>
@ -64,7 +64,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Vortice.Direct3D11" Version="1.9.143" /> <PackageReference Include="Vortice.Direct3D11" Version="2.3.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>