Skip to content

Instantly share code, notes, and snippets.

@lostmsu
Created February 24, 2023 19:50
Show Gist options
  • Save lostmsu/4822365361ca8f1957ceba76cd03c26c to your computer and use it in GitHub Desktop.
Save lostmsu/4822365361ca8f1957ceba76cd03c26c to your computer and use it in GitHub Desktop.
var swapChainDescription = new SwapChainDescription
{
BufferCount = 2,
Flags = SwapChainFlags.None,
IsWindowed = true,
ModeDescription = new ModeDescription(form.ClientSize.Width, form.ClientSize.Height, refreshRate: new Rational(60, 1), Format.B8G8R8A8_UNorm),
OutputHandle = form.Handle,
SampleDescription = new SampleDescription(count: 1, quality: 0),
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput
};
using var factory = new Factory1();
Adapter1 adapter = null;
for (int adapterIndex = 0; adapterIndex < factory.GetAdapterCount1(); adapterIndex++)
{
var potentialAdapter = factory.GetAdapter1(adapterIndex);
if (potentialAdapter.GetOutputCount() == 0)
{
potentialAdapter.Dispose();
continue;
}
if (adapter != null) throw new Exception("Multiple adapters with outputs found");
adapter = potentialAdapter;
}
if (adapter is null) throw new Exception("No adapter with output found");
Device.CreateWithSwapChain(adapter, DeviceCreationFlags.BgraSupport,
new[] { FeatureLevel.Level_11_1 },
swapChainDescription, out var device, out var swapChain);
SetupDevice(device); // some device setup
using var output0 = adapter.GetOutput(0);
using var output1 = output0.QueryInterface<Output1>();
try
{
_duplication = output1.DuplicateOutput(device); // this fails, see catch
} catch (SharpDXException e)
{
MessageBox.Show(e.Message); // <- this happens, prints 0x80070057 E_INVALIDARG
}
device.ImmediateContext.ClearRenderTargetView(renderView, new RawColor4(1.0f, 1.0f, 0.0f, 0.0f));
swapChain1.Present(1, PresentFlags.None, new PresentParameters()).CheckError();
// no issue here, I see yellow screen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment