Giter Club home page Giter Club logo

Comments (4)

AArnott avatar AArnott commented on July 21, 2024

I suspect this change is a fallout of improving support in other areas where we discovered certain interop rules had to be honored, and this was an area where we weren't fully following the rules, causing failures in at least some cases.

I'll leave this active till we have a chance to confirm.

from cswin32.

iraqigeek avatar iraqigeek commented on July 21, 2024

having the same issue with D3D11 after updating from 0.3.49-beta to 0.3.106

from cswin32.

smourier avatar smourier commented on July 21, 2024

Same for me. It's actually a showstopper for upgrading nuget packages.

from cswin32.

AffluentOwl avatar AffluentOwl commented on July 21, 2024

It wasn't that hard to work around this issue. Just had to spend the month learning x64 ASM and how to reverse engineer Windows binaries. Then produced the following elegant and idiomatic C# code which is required to both retain managed and unmanaged copies of the same COM objects, and properly handle both of their lifetimes. My new favorite part of coding in C# with projections is all the time one gets to spend reading and writing assembly.

  [Guid("94D99BDB-F1F8-4AB0-B236-7DA0170EDAB1"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), ComImport()]
  internal interface IDXGISwapChain3Extra : IDXGISwapChain3
  {
    void _VtblGap_6();
  
    unsafe void GetBufferRaw(uint Buffer, Guid* riid, void** ppSurface);
  }

  List<ID3D12Resource> gSurfaces = new List<ID3D12Resource>();
  List<nint> gSurfacesRaw = new List<nint>();

  // ...

  guid = typeof(ID3D12Resource).GUID;
  void* ppSurface;
  gSwapChain.GetBufferRaw(i, &guid, &ppSurface);
  gSurfacesRaw.Add((nint)ppSurface);
  gSurfaces.Add((ID3D12Resource)Marshal.GetObjectForIUnknown((nint)ppSurface));
  
  gDevice.CreateRenderTargetView(gSurfaces.Last(), null, rtvHandle);
  
  // ...
  
  ID3D12Resource_unmanaged* p = (ID3D12Resource_unmanaged*)gSurfacesRaw[(int)gFrameIndex];
  D3D12_RESOURCE_BARRIER[] b = [
    new() {
      Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE,
      Anonymous = new()
      {
        Transition = new()
        {
          pResource = p,
          Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES,
          StateBefore = D3D12_RESOURCE_STATE_PRESENT,
          StateAfter = D3D12_RESOURCE_STATE_RENDER_TARGET,
        }
      }
    }
  ];
  gCommandList.ResourceBarrier(1, b);
  
  // ...

  void ResizeBuffers(nint lParam)
  {
    if (gSwapChain != null && gFence != null && gSurfaces.Count > 0)
    {
      WaitForPreviousFrame();

      for (int i = 0; i < 2; i++)
      {
        Marshal.ReleaseComObject(gSurfaces[i]);
        ((ID3D12Resource_unmanaged*)gSurfacesRaw[(int)i])->Release();
      }
      gSurfaces.Clear();
      gSurfacesRaw.Clear();

      // ...
      
      Guid guid = typeof(ID3D12Resource).GUID;
      void* ppSurface;
      gSwapChain!.GetBufferRaw(i, &guid, &ppSurface);
      gSurfacesRaw.Add((nint)ppSurface);
      gSurfaces.Add((ID3D12Resource)Marshal.GetObjectForIUnknown((nint)ppSurface));

      gDevice.CreateRenderTargetView(gSurfaces.Last(), null, rtvHandle);

from cswin32.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.