Skip to content

Enabling Hardware Acceleration on RDP #7684

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

Merged
merged 2 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,21 @@ public static bool EnableDynamicDirtyRectangles

#endregion

#region EnableHardwareAccelerationInRdp

internal const string EnableHardwareAccelerationInRdpSwitchName = "Switch.System.Windows.Media.EnableHardwareAccelerationInRdp";
private static int _enableHardwareAccelerationInRdp;
public static bool EnableHardwareAccelerationInRdp
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return LocalAppContext.GetCachedSwitchValue(EnableHardwareAccelerationInRdpSwitchName, ref _enableHardwareAccelerationInRdp);
}
}

#endregion

}
#pragma warning restore 436
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ private static void InitializeNetFxSwitchDefaultsForNetCoreRuntime()
LocalAppContext.DefineSwitchDefault(CoreAppContextSwitches.ShouldNotRenderInNonInteractiveWindowStationSwitchName, false);
LocalAppContext.DefineSwitchDefault(CoreAppContextSwitches.DoNotUsePresentationDpiCapabilityTier3OrGreaterSwitchName, false);
LocalAppContext.DefineSwitchDefault(CoreAppContextSwitches.AllowExternalProcessToBlockAccessToTemporaryFilesSwitchName, false);
LocalAppContext.DefineSwitchDefault(CoreAppContextSwitches.EnableHardwareAccelerationInRdpSwitchName, false);
}
}
#pragma warning restore 436
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public static bool Startup(MediaContext mc)
}
s_refCount++;
}

// Setting renderOption for Hardware acceleration in RDP as per appcontext switch.
UnsafeNativeMethods.RenderOptions_EnableHardwareAccelerationInRdp(CoreAppContextSwitches.EnableHardwareAccelerationInRdp);

// Consider making MediaSystem.ConnectTransport return the state of transport connectedness so
// that we can initialize the media system to a disconnected state.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,10 @@ internal unsafe static extern void RenderOptions_ForceSoftwareRenderingModeForPr
bool fForce);

[DllImport(DllImport.MilCore, EntryPoint = "RenderOptions_IsSoftwareRenderingForcedForProcess")]
internal unsafe static extern bool RenderOptions_IsSoftwareRenderingForcedForProcess();
internal unsafe static extern bool RenderOptions_IsSoftwareRenderingForcedForProcess();

[DllImport(DllImport.MilCore, EntryPoint = "RenderOptions_EnableHardwareAccelerationInRdp")]
internal unsafe static extern void RenderOptions_EnableHardwareAccelerationInRdp(bool value);

[DllImport(DllImport.MilCore, EntryPoint = "MilResource_CreateCWICWrapperBitmap")]
internal unsafe static extern int /* HRESULT */ CreateCWICWrapperBitmap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,11 @@ GetMinimalTextureDesc(
}

// If format is ok, restore HR from width/height check
if (hr == S_OK)
if(SUCCEEDED(hr))
{
hr = hrWH;
}

}

#if DBG
Expand Down Expand Up @@ -315,8 +316,3 @@ GetSuperiorSurfaceFormat(

return D3DFMT_UNKNOWN;
}





Original file line number Diff line number Diff line change
Expand Up @@ -2125,7 +2125,7 @@ CDisplaySet::GetGraphicsAccelerationCaps(
*pulDisplayUniqueness = m_ulDisplayUniquenessLoader;
}

if (m_rgpDisplays.GetCount() == 0 || m_fNonLocalDevicePresent)
if (m_rgpDisplays.GetCount() == 0 || (!RenderOptions::IsHardwareAccelerationInRdpEnabled() && m_fNonLocalDevicePresent))
{
//
// No display - no acceleration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@ RenderOptions_IsSoftwareRenderingForcedForProcess()
return RenderOptions::IsSoftwareRenderingForcedForProcess();
}

void WINAPI
RenderOptions_EnableHardwareAccelerationInRdp(BOOL fEnable)
{
RenderOptions::EnableHardwareAccelerationInRdp(fEnable);
}

// m_cs must be entered before accessing m_fForceSoftware because multiple
// managed threads plus the render thread could try to access it
static CCriticalSection m_cs;
static bool m_fForceSoftware;
static bool m_fHwAccelerationInRdpEnabled;

//+---------------------------------------------------------------------------------
//
Expand All @@ -41,6 +48,7 @@ HRESULT
RenderOptions::Init()
{
m_fForceSoftware = false;
m_fHwAccelerationInRdpEnabled = false;
RRETURN(m_cs.Init());
}

Expand Down Expand Up @@ -94,4 +102,30 @@ RenderOptions::IsSoftwareRenderingForcedForProcess()
return m_fForceSoftware;
}

//+---------------------------------------------------------------------------------
//
// RenderOptions::EnableGraphicHWAccelerationInRdp
//
// Synopsis: Sets whether or not Hardware Acceleration should be enabled for RDP.
//
//----------------------------------------------------------------------------------
void
RenderOptions::EnableHardwareAccelerationInRdp(BOOL fEnable)
{
CGuard<CCriticalSection> guard(m_cs);
m_fHwAccelerationInRdpEnabled = !!fEnable;
}

//+---------------------------------------------------------------------------------
//
// RenderOptions::IsHardwareAccelerationInRdpEnabled
//
// Synopsis: return whether or not Hardware Acceleration for RDP is enabled.
//
//----------------------------------------------------------------------------------
BOOL
RenderOptions::IsHardwareAccelerationInRdpEnabled()
{
return m_fHwAccelerationInRdpEnabled;
}

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ namespace RenderOptions
void ForceSoftwareRenderingForProcess(BOOL fForce);

BOOL IsSoftwareRenderingForcedForProcess();

void EnableHardwareAccelerationInRdp(BOOL fEnable);

BOOL IsHardwareAccelerationInRdpEnabled();
};


1 change: 1 addition & 0 deletions src/Microsoft.DotNet.Wpf/src/WpfGfx/core/dll/wpfgfx.def
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,5 @@ EXPORTS

RenderOptions_ForceSoftwareRenderingModeForProcess
RenderOptions_IsSoftwareRenderingForcedForProcess
RenderOptions_EnableHardwareAccelerationInRdp

Original file line number Diff line number Diff line change
Expand Up @@ -1421,16 +1421,17 @@ CHwBitmapColorSource::ComputeRealizationParameters(
&uLevels
);

Assert(pDevice->GetMinimalTextureDesc(
&d3dsdRequired,
TRUE,
(GMTD_CHECK_ALL |
(TextureAddressingAllowsConditionalNonPower2Usage(
oRealizationParams.dlU.d3dta,
oRealizationParams.dlV.d3dta) ?
GMTD_NONPOW2CONDITIONAL_OK : 0)
)
) == S_OK);
Assert(SUCCEEDED(pDevice->GetMinimalTextureDesc(
&d3dsdRequired,
TRUE,
(GMTD_CHECK_ALL |
(TextureAddressingAllowsConditionalNonPower2Usage(
oRealizationParams.dlU.d3dta,
oRealizationParams.dlV.d3dta) ?
GMTD_NONPOW2CONDITIONAL_OK : 0)
)
)));

}
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ HRESULT CDesktopRenderTarget::Create(
// check whether any adapters don't support Hw acceleration or D3D is not
// available.
//
if ( pDisplaySet->IsNonLocalDisplayPresent()
if ( (!(RenderOptions::IsHardwareAccelerationInRdpEnabled()) && pDisplaySet->IsNonLocalDisplayPresent())
|| !pDisplaySet->D3DObject())
{
// If possible, just revert to Sw. This simply prevents trying Hw and
Expand Down