code:
#pragma once

#include "d3d10_multithread.h"

namespace dxvk {

  class D3D11Device;
  class D3D11ImmediateContext;

  class D3D10Device final : public ID3D10Device1 {

  public:

    D3D10Device(
            D3D11Device*                      pDevice,
            D3D11ImmediateContext*            pContext);

    ~D3D10Device();

    HRESULT STDMETHODCALLTYPE QueryInterface(
            REFIID                            riid,
            void**                            ppvObject);

    ULONG STDMETHODCALLTYPE AddRef();

    ULONG STDMETHODCALLTYPE Release();

    HRESULT STDMETHODCALLTYPE GetPrivateData(
            REFGUID                           guid,
            UINT*                             pDataSize,
            void*                             pData);

    HRESULT STDMETHODCALLTYPE SetPrivateData(
            REFGUID                           guid,
            UINT                              DataSize,
      const void*                             pData);

    HRESULT STDMETHODCALLTYPE SetPrivateDataInterface(
            REFGUID                           guid,
      const IUnknown*                         pData);

    HRESULT STDMETHODCALLTYPE GetDeviceRemovedReason();

    HRESULT STDMETHODCALLTYPE SetExceptionMode(
            UINT                              RaiseFlags);

    UINT STDMETHODCALLTYPE GetExceptionMode();

    D3D10_FEATURE_LEVEL1 STDMETHODCALLTYPE GetFeatureLevel();

    void STDMETHODCALLTYPE ClearState();

    void STDMETHODCALLTYPE Flush();

    HRESULT STDMETHODCALLTYPE CreateBuffer(
      const D3D10_BUFFER_DESC*                pDesc,
      const D3D10_SUBRESOURCE_DATA*           pInitialData,
            ID3D10Buffer**                    ppBuffer);

    HRESULT STDMETHODCALLTYPE CreateTexture1D(
      const D3D10_TEXTURE1D_DESC*             pDesc,
      const D3D10_SUBRESOURCE_DATA*           pInitialData,
            ID3D10Texture1D**                 ppTexture1D);

    HRESULT STDMETHODCALLTYPE CreateTexture2D(
      const D3D10_TEXTURE2D_DESC*             pDesc,
      const D3D10_SUBRESOURCE_DATA*           pInitialData,
            ID3D10Texture2D**                 ppTexture2D);

    HRESULT STDMETHODCALLTYPE CreateTexture3D(
      const D3D10_TEXTURE3D_DESC*             pDesc,
      const D3D10_SUBRESOURCE_DATA*           pInitialData,
            ID3D10Texture3D**                 ppTexture3D);

    HRESULT STDMETHODCALLTYPE CreateShaderResourceView(
            ID3D10Resource*                   pResource,
      const D3D10_SHADER_RESOURCE_VIEW_DESC*  pDesc,
            ID3D10ShaderResourceView**        ppSRView);

    HRESULT STDMETHODCALLTYPE CreateShaderResourceView1(
            ID3D10Resource*                   pResource,
      const D3D10_SHADER_RESOURCE_VIEW_DESC1* pDesc,
            ID3D10ShaderResourceView1**       ppSRView);

    HRESULT STDMETHODCALLTYPE CreateRenderTargetView(
            ID3D10Resource*                   pResource,
      const D3D10_RENDER_TARGET_VIEW_DESC*    pDesc,
            ID3D10RenderTargetView**          ppRTView);

    HRESULT STDMETHODCALLTYPE CreateDepthStencilView(
            ID3D10Resource*                   pResource,
      const D3D10_DEPTH_STENCIL_VIEW_DESC*    pDesc,
            ID3D10DepthStencilView**          ppDepthStencilView);

    HRESULT STDMETHODCALLTYPE CreateInputLayout(
      const D3D10_INPUT_ELEMENT_DESC*         pInputElementDescs,
            UINT                              NumElements,
      const void*                             pShaderBytecodeWithInputSignature,
            SIZE_T                            BytecodeLength,
            ID3D10InputLayout**               ppInputLayout);

    HRESULT STDMETHODCALLTYPE CreateVertexShader(
      const void*                             pShaderBytecode,
            SIZE_T                            BytecodeLength,
            ID3D10VertexShader**              ppVertexShader);

    HRESULT STDMETHODCALLTYPE CreateGeometryShader(
      const void*                             pShaderBytecode,
            SIZE_T                            BytecodeLength,
            ID3D10GeometryShader**            ppGeometryShader);

    HRESULT STDMETHODCALLTYPE CreateGeometryShaderWithStreamOutput(
      const void*                             pShaderBytecode,
            SIZE_T                            BytecodeLength,
      const D3D10_SO_DECLARATION_ENTRY*       pSODeclaration,
            UINT                              NumEntries,
            UINT                              OutputStreamStride,
            ID3D10GeometryShader**            ppGeometryShader);

    HRESULT STDMETHODCALLTYPE CreatePixelShader(
      const void*                             pShaderBytecode,
            SIZE_T                            BytecodeLength,
            ID3D10PixelShader**               ppPixelShader);

    HRESULT STDMETHODCALLTYPE CreateBlendState(
      const D3D10_BLEND_DESC*                 pBlendStateDesc,
            ID3D10BlendState**                ppBlendState);

    HRESULT STDMETHODCALLTYPE CreateBlendState1(
      const D3D10_BLEND_DESC1*                pBlendStateDesc,
            ID3D10BlendState1**               ppBlendState);

    HRESULT STDMETHODCALLTYPE CreateDepthStencilState(
      const D3D10_DEPTH_STENCIL_DESC*         pDepthStencilDesc,
            ID3D10DepthStencilState**         ppDepthStencilState);

    HRESULT STDMETHODCALLTYPE CreateRasterizerState(
      const D3D10_RASTERIZER_DESC*            pRasterizerDesc,
            ID3D10RasterizerState**           ppRasterizerState);

    HRESULT STDMETHODCALLTYPE CreateSamplerState(
      const D3D10_SAMPLER_DESC*               pSamplerDesc,
            ID3D10SamplerState**              ppSamplerState);

    HRESULT STDMETHODCALLTYPE CreateQuery(
      const D3D10_QUERY_DESC*                 pQueryDesc,
            ID3D10Query**                     ppQuery);

    HRESULT STDMETHODCALLTYPE CreatePredicate(
      const D3D10_QUERY_DESC*                 pPredicateDesc,
            ID3D10Predicate**                 ppPredicate);

    HRESULT STDMETHODCALLTYPE CreateCounter(
      const D3D10_COUNTER_DESC*               pCounterDesc,
            ID3D10Counter**                   ppCounter);

    HRESULT STDMETHODCALLTYPE CheckFormatSupport(
            DXGI_FORMAT                       Format,
            UINT*                             pFormatSupport);

    HRESULT STDMETHODCALLTYPE CheckMultisampleQualityLevels(
            DXGI_FORMAT                       Format,
            UINT                              SampleCount,
            UINT*                             pNumQualityLevels);

    void STDMETHODCALLTYPE CheckCounterInfo(
            D3D10_COUNTER_INFO*               pCounterInfo);

    HRESULT STDMETHODCALLTYPE CheckCounter(
      const D3D10_COUNTER_DESC*               pDesc,
            D3D10_COUNTER_TYPE*               pType,
            UINT*                             pActiveCounters,
            char*                             name,
            UINT*                             pNameLength,
            char*                             units,
            UINT*                             pUnitsLength,
            char*                             description,
            UINT*                             pDescriptionLength);

    UINT STDMETHODCALLTYPE GetCreationFlags();

    HRESULT STDMETHODCALLTYPE OpenSharedResource(
            HANDLE                            hResource,
            REFIID                            ReturnedInterface,
            void**                            ppResource);

    void STDMETHODCALLTYPE ClearRenderTargetView(
            ID3D10RenderTargetView*           pRenderTargetView,
      const FLOAT                             ColorRGBA[4]);

    void STDMETHODCALLTYPE ClearDepthStencilView(
            ID3D10DepthStencilView*           pDepthStencilView,
            UINT                              ClearFlags,
            FLOAT                             Depth,
            UINT8                             Stencil);

    void STDMETHODCALLTYPE SetPredication(
            ID3D10Predicate*                  pPredicate,
            BOOL                              PredicateValue);

    void STDMETHODCALLTYPE GetPredication(
            ID3D10Predicate**                 ppPredicate,
            BOOL*                             pPredicateValue);

    void STDMETHODCALLTYPE CopySubresourceRegion(
            ID3D10Resource*                   pDstResource,
            UINT                              DstSubresource,
            UINT                              DstX,
            UINT                              DstY,
            UINT                              DstZ,
            ID3D10Resource*                   pSrcResource,
            UINT                              SrcSubresource,
      const D3D10_BOX*                        pSrcBox);

    void STDMETHODCALLTYPE CopyResource(
            ID3D10Resource*                   pDstResource,
            ID3D10Resource*                   pSrcResource);

    void STDMETHODCALLTYPE UpdateSubresource(
            ID3D10Resource*                   pDstResource,
            UINT                              DstSubresource,
      const D3D10_BOX*                        pDstBox,
      const void*                             pSrcData,
            UINT                              SrcRowPitch,
            UINT                              SrcDepthPitch);

    void STDMETHODCALLTYPE GenerateMips(
            ID3D10ShaderResourceView*         pShaderResourceView);

    void STDMETHODCALLTYPE ResolveSubresource(
            ID3D10Resource*                   pDstResource,
            UINT                              DstSubresource,
            ID3D10Resource*                   pSrcResource,
            UINT                              SrcSubresource,
            DXGI_FORMAT                       Format);

    void STDMETHODCALLTYPE Draw(
            UINT                              VertexCount,
            UINT                              StartVertexLocation);

    void STDMETHODCALLTYPE DrawIndexed(
            UINT                              IndexCount,
            UINT                              StartIndexLocation,
            INT                               BaseVertexLocation);

    void STDMETHODCALLTYPE DrawInstanced(
            UINT                              VertexCountPerInstance,
            UINT                              InstanceCount,
            UINT                              StartVertexLocation,
            UINT                              StartInstanceLocation);

    void STDMETHODCALLTYPE DrawIndexedInstanced(
            UINT                              IndexCountPerInstance,
            UINT                              InstanceCount,
            UINT                              StartIndexLocation,
            INT                               BaseVertexLocation,
            UINT                              StartInstanceLocation);

    void STDMETHODCALLTYPE DrawAuto();

    void STDMETHODCALLTYPE IASetInputLayout(
            ID3D10InputLayout*                pInputLayout);

    void STDMETHODCALLTYPE IASetPrimitiveTopology(
            D3D10_PRIMITIVE_TOPOLOGY          Topology);

    void STDMETHODCALLTYPE IASetVertexBuffers(
            UINT                              StartSlot,
            UINT                              NumBuffers,
            ID3D10Buffer* const*              ppVertexBuffers,
      const UINT*                             pStrides,
      const UINT*                             pOffsets);

    void STDMETHODCALLTYPE IASetIndexBuffer(
            ID3D10Buffer*                     pIndexBuffer,
            DXGI_FORMAT                       Format,
            UINT                              Offset);

    void STDMETHODCALLTYPE IAGetInputLayout(
            ID3D10InputLayout**               ppInputLayout);

    void STDMETHODCALLTYPE IAGetPrimitiveTopology(
            D3D10_PRIMITIVE_TOPOLOGY*         pTopology);

    void STDMETHODCALLTYPE IAGetVertexBuffers(
            UINT                              StartSlot,
            UINT                              NumBuffers,
            ID3D10Buffer**                    ppVertexBuffers,
            UINT*                             pStrides,
            UINT*                             pOffsets);

    void STDMETHODCALLTYPE IAGetIndexBuffer(
            ID3D10Buffer**                    pIndexBuffer,
            DXGI_FORMAT*                      Format,
            UINT*                             Offset);

    void STDMETHODCALLTYPE VSSetShader(
            ID3D10VertexShader*               pVertexShader);

    void STDMETHODCALLTYPE VSSetConstantBuffers(
            UINT                              StartSlot,
            UINT                              NumBuffers,
            ID3D10Buffer* const*              ppConstantBuffers);

    void STDMETHODCALLTYPE VSSetShaderResources(
            UINT                              StartSlot,
            UINT                              NumViews,
            ID3D10ShaderResourceView* const*  ppShaderResourceViews);

    void STDMETHODCALLTYPE VSSetSamplers(
            UINT                              StartSlot,
            UINT                              NumSamplers,
            ID3D10SamplerState* const*        ppSamplers);

    void STDMETHODCALLTYPE VSGetShader(
            ID3D10VertexShader**              ppVertexShader);

    void STDMETHODCALLTYPE VSGetConstantBuffers(
            UINT                              StartSlot,
            UINT                              NumBuffers,
            ID3D10Buffer**                    ppConstantBuffers);

    void STDMETHODCALLTYPE VSGetShaderResources(
            UINT                              StartSlot,
            UINT                              NumViews,
            ID3D10ShaderResourceView**        ppShaderResourceViews);

    void STDMETHODCALLTYPE VSGetSamplers(
            UINT                              StartSlot,
            UINT                              NumSamplers,
            ID3D10SamplerState**              ppSamplers);

    void STDMETHODCALLTYPE GSSetShader(
            ID3D10GeometryShader*             pShader);

    void STDMETHODCALLTYPE GSSetConstantBuffers(
            UINT                              StartSlot,
            UINT                              NumBuffers,
            ID3D10Buffer* const*              ppConstantBuffers);

    void STDMETHODCALLTYPE GSSetShaderResources(
            UINT                              StartSlot,
            UINT                              NumViews,
            ID3D10ShaderResourceView* const*  ppShaderResourceViews);

    void STDMETHODCALLTYPE GSSetSamplers(
            UINT                              StartSlot,
            UINT                              NumSamplers,
            ID3D10SamplerState* const*        ppSamplers);

    void STDMETHODCALLTYPE GSGetShader(
            ID3D10GeometryShader**            ppGeometryShader);

    void STDMETHODCALLTYPE GSGetConstantBuffers(
            UINT                              StartSlot,
            UINT                              NumBuffers,
            ID3D10Buffer**                    ppConstantBuffers);

    void STDMETHODCALLTYPE GSGetShaderResources(
            UINT                              StartSlot,
            UINT                              NumViews,
            ID3D10ShaderResourceView**        ppShaderResourceViews);

    void STDMETHODCALLTYPE GSGetSamplers(
            UINT                              StartSlot,
            UINT                              NumSamplers,
            ID3D10SamplerState**              ppSamplers);

    void STDMETHODCALLTYPE PSSetShader(
            ID3D10PixelShader*                pPixelShader);

    void STDMETHODCALLTYPE PSSetConstantBuffers(
            UINT                              StartSlot,
            UINT                              NumBuffers,
            ID3D10Buffer* const*              ppConstantBuffers);

    void STDMETHODCALLTYPE PSSetShaderResources(
            UINT                              StartSlot,
            UINT                              NumViews,
            ID3D10ShaderResourceView* const*  ppShaderResourceViews);

    void STDMETHODCALLTYPE PSSetSamplers(
            UINT                              StartSlot,
            UINT                              NumSamplers,
            ID3D10SamplerState* const*        ppSamplers);

    void STDMETHODCALLTYPE PSGetShader(
            ID3D10PixelShader**               ppPixelShader);

    void STDMETHODCALLTYPE PSGetConstantBuffers(
            UINT                              StartSlot,
            UINT                              NumBuffers,
            ID3D10Buffer**                    ppConstantBuffers);

    void STDMETHODCALLTYPE PSGetShaderResources(
            UINT                              StartSlot,
            UINT                              NumViews,
            ID3D10ShaderResourceView**        ppShaderResourceViews);

    void STDMETHODCALLTYPE PSGetSamplers(
            UINT                              StartSlot,
            UINT                              NumSamplers,
            ID3D10SamplerState**              ppSamplers);

    void STDMETHODCALLTYPE OMSetRenderTargets(
            UINT                              NumViews,
            ID3D10RenderTargetView* const*    ppRenderTargetViews,
            ID3D10DepthStencilView*           pDepthStencilView);

    void STDMETHODCALLTYPE OMSetBlendState(
            ID3D10BlendState*                 pBlendState,
      const FLOAT                             BlendFactor[4],
            UINT                              SampleMask);

    void STDMETHODCALLTYPE OMSetDepthStencilState(
            ID3D10DepthStencilState*          pDepthStencilState,
            UINT                              StencilRef);

    void STDMETHODCALLTYPE OMGetRenderTargets(
            UINT                              NumViews,
            ID3D10RenderTargetView**          ppRenderTargetViews,
            ID3D10DepthStencilView**          ppDepthStencilView);

    void STDMETHODCALLTYPE OMGetBlendState(
            ID3D10BlendState**                ppBlendState,
            FLOAT                             BlendFactor[4],
            UINT*                             pSampleMask);

    void STDMETHODCALLTYPE OMGetDepthStencilState(
            ID3D10DepthStencilState**         ppDepthStencilState,
            UINT*                             pStencilRef);

    void STDMETHODCALLTYPE RSSetState(
            ID3D10RasterizerState*            pRasterizerState);

    void STDMETHODCALLTYPE RSSetViewports(
            UINT                              NumViewports,
      const D3D10_VIEWPORT*                   pViewports);

    void STDMETHODCALLTYPE RSSetScissorRects(
            UINT                              NumRects,
      const D3D10_RECT*                       pRects);

    void STDMETHODCALLTYPE RSGetState(
            ID3D10RasterizerState**           ppRasterizerState);

    void STDMETHODCALLTYPE RSGetViewports(
            UINT*                             NumViewports,
            D3D10_VIEWPORT*                   pViewports);

    void STDMETHODCALLTYPE RSGetScissorRects(
            UINT*                             NumRects,
            D3D10_RECT*                       pRects);

    void STDMETHODCALLTYPE SOSetTargets(
            UINT                              NumBuffers,
            ID3D10Buffer* const*              ppSOTargets,
      const UINT*                             pOffsets);

    void STDMETHODCALLTYPE SOGetTargets(
            UINT                              NumBuffers,
            ID3D10Buffer**                    ppSOTargets,
            UINT*                             pOffsets);

    void STDMETHODCALLTYPE SetTextFilterSize(
            UINT                              Width,
            UINT                              Height);

    void STDMETHODCALLTYPE GetTextFilterSize(
            UINT*                             pWidth,
            UINT*                             pHeight);

  private:

    D3D11Device*            m_device;
    D3D11ImmediateContext*  m_context;

  };

}


code:
#pragma once

#include "../dxgi/dxgi_include.h"

#include "../util/sync/sync_spinlock.h"
#include "../util/sync/sync_recursive.h"

#include <d3d10_1.h>
#include <d3d11_1.h>

repo_name: orochi/dxvk


code:
#include "d3d10_input_layout.h"

#include "../d3d11/d3d11_device.h"
#include "../d3d11/d3d11_input_layout.h"

namespace dxvk {

  HRESULT STDMETHODCALLTYPE D3D10InputLayout::QueryInterface(
          REFIID                    riid,
          void**                    ppvObject) {
    return m_d3d11->QueryInterface(riid, ppvObject);
  }

  ULONG STDMETHODCALLTYPE D3D10InputLayout::AddRef() {
    return m_d3d11->AddRef();
  }

  ULONG STDMETHODCALLTYPE D3D10InputLayout::Release() {
    return m_d3d11->Release();
  }

  void STDMETHODCALLTYPE D3D10InputLayout::GetDevice(
          ID3D10Device**            ppDevice) {
    GetD3D10Device(m_d3d11, ppDevice);
  }

  HRESULT STDMETHODCALLTYPE D3D10InputLayout::GetPrivateData(
          REFGUID                   guid,
          UINT*                     pDataSize,
          void*                     pData) {
    return m_d3d11->GetPrivateData(guid, pDataSize, pData);
  }

  HRESULT STDMETHODCALLTYPE D3D10InputLayout::SetPrivateData(
          REFGUID                   guid,
          UINT                      DataSize,
    const void*                     pData) {
    return m_d3d11->SetPrivateData(guid, DataSize, pData);
  }

  HRESULT STDMETHODCALLTYPE D3D10InputLayout::SetPrivateDataInterface(
          REFGUID                   guid,
    const IUnknown*                 pData) {
    return m_d3d11->SetPrivateDataInterface(guid, pData);
  }

}


code:
#pragma once

#include "d3d10_util.h"

namespace dxvk {

  class D3D11Device;
  class D3D11InputLayout;

  class D3D10InputLayout : public ID3D10InputLayout {

  public:

    D3D10InputLayout(D3D11InputLayout* pParent)
    : m_d3d11(pParent) { }

    HRESULT STDMETHODCALLTYPE QueryInterface(
            REFIID                    riid,
            void**                    ppvObject);

    ULONG STDMETHODCALLTYPE AddRef();

    ULONG STDMETHODCALLTYPE Release();

    void STDMETHODCALLTYPE GetDevice(
            ID3D10Device**            ppDevice);

    HRESULT STDMETHODCALLTYPE GetPrivateData(
            REFGUID                   guid,
            UINT*                     pDataSize,
            void*                     pData);

    HRESULT STDMETHODCALLTYPE SetPrivateData(
            REFGUID                   guid,
            UINT                      DataSize,
      const void*                     pData);

    HRESULT STDMETHODCALLTYPE SetPrivateDataInterface(
            REFGUID                   guid,
      const IUnknown*                 pData);

    D3D11InputLayout* GetD3D11Iface() {
      return m_d3d11;
    }

  private:

    D3D11InputLayout* m_d3d11;

  };

}


code:
#pragma once

#include "d3d10_include.h"

#ifdef _MSC_VER
struct __declspec(uuid("0803425a-57f5-4dd6-9465-a87570834a08")) ID3D10StateBlock;
#else
__CRT_UUID_DECL(ID3D10StateBlock, 0x0803425a,0x57f5,0x4dd6,0x94,0x65,0xa8,0x75,0x70,0x83,0x4a,0x08);
#endif


code:
#include <d3dcompiler.h>

#include "d3d10_include.h"
#include "d3d10_reflection.h"

#include "../dxgi/dxgi_adapter.h"

namespace dxvk {
  Logger Logger::s_instance("d3d10.log");
}

extern "C" {
  using namespace dxvk;

  HRESULT __stdcall D3D10CoreCreateDevice(
          IDXGIFactory*           pFactory,
          IDXGIAdapter*           pAdapter,
          UINT                    Flags,
          D3D_FEATURE_LEVEL       FeatureLevel,
          ID3D10Device**          ppDevice);

  static HRESULT D3D10InternalCreateDeviceAndSwapChain(
          IDXGIAdapter*           pAdapter,
          D3D10_DRIVER_TYPE       DriverType,
          HMODULE                 Software,
          UINT                    Flags,
          D3D10_FEATURE_LEVEL1    HardwareLevel,
          UINT                    SDKVersion,
          DXGI_SWAP_CHAIN_DESC*   pSwapChainDesc,
          IDXGISwapChain**        ppSwapChain,
          REFIID                  deviceIID,
          void**                  ppDevice) {
    InitReturnPtr(ppDevice);
    InitReturnPtr(ppSwapChain);

    if (ppSwapChain && !pSwapChainDesc)
      return E_INVALIDARG;

    HRESULT hr;

    // Get DXGI factory and adapter. This is mostly
    // copied from the equivalent D3D11 functions.
    Com<IDXGIFactory> dxgiFactory = nullptr;
    Com<IDXGIAdapter> dxgiAdapter = pAdapter;
    Com<ID3D10Device> device      = nullptr;

    if (!pAdapter) {
      if (DriverType != D3D10_DRIVER_TYPE_HARDWARE)
        Logger::warn("D3D10CreateDevice: Unsupported driver type");

      hr = CreateDXGIFactory(__uuidof(IDXGIFactory), reinterpret_cast<void**>(&dxgiFactory));

      if (FAILED(hr)) {
        Logger::err("D3D10CreateDevice: Failed to create a DXGI factory");
        return hr;
      }

      hr = dxgiFactory->EnumAdapters(0, &dxgiAdapter);

      if (FAILED(hr)) {
        Logger::err("D3D10CreateDevice: No default adapter available");
        return hr;
      }
    } else {
      if (FAILED(dxgiAdapter->GetParent(__uuidof(IDXGIFactory), reinterpret_cast<void**>(&dxgiFactory)))) {
        Logger::err("D3D10CreateDevice: Failed to query DXGI factory from DXGI adapter");
        return E_INVALIDARG;
      }

      if (DriverType != D3D10_DRIVER_TYPE_HARDWARE || Software)
        return E_INVALIDARG;
    }

    hr = D3D10CoreCreateDevice(
      dxgiFactory.ptr(), dxgiAdapter.ptr(),
      Flags, D3D_FEATURE_LEVEL(HardwareLevel),
      &device);

    if (FAILED(hr))
      return hr;

    if (ppSwapChain) {
      DXGI_SWAP_CHAIN_DESC desc = *pSwapChainDesc;
      hr = dxgiFactory->CreateSwapChain(device.ptr(), &desc, ppSwapChain);

      if (FAILED(hr)) {
        Logger::err("D3D10CreateDevice: Failed to create swap chain");
        return hr;
      }
    }

    if (ppDevice) {
      // Just assume that this succeeds
      device->QueryInterface(deviceIID, ppDevice);
    }

    if (!ppDevice && !ppSwapChain)
      return S_FALSE;

    return S_OK;
  }

  DLLEXPORT HRESULT __stdcall D3D10CreateDevice(
          IDXGIAdapter*           pAdapter,
          D3D10_DRIVER_TYPE       DriverType,
          HMODULE                 Software,
          UINT                    Flags,
          UINT                    SDKVersion,
          ID3D10Device**          ppDevice) {
    return D3D10InternalCreateDeviceAndSwapChain(
      pAdapter, DriverType, Software, Flags,
      D3D10_FEATURE_LEVEL_10_0, SDKVersion,
      nullptr, nullptr,
      __uuidof(ID3D10Device),
      reinterpret_cast<void**>(ppDevice));
  }

  DLLEXPORT HRESULT __stdcall D3D10CreateDevice1(
          IDXGIAdapter*           pAdapter,
          D3D10_DRIVER_TYPE       DriverType,
          HMODULE                 Software,
          UINT                    Flags,
          D3D10_FEATURE_LEVEL1    HardwareLevel,
          UINT                    SDKVersion,
          ID3D10Device1**         ppDevice) {
    return D3D10InternalCreateDeviceAndSwapChain(
      pAdapter, DriverType, Software, Flags,
      HardwareLevel, SDKVersion,
      nullptr, nullptr,
      __uuidof(ID3D10Device1),
      reinterpret_cast<void**>(ppDevice));
  }

  DLLEXPORT HRESULT __stdcall D3D10CreateDeviceAndSwapChain(
          IDXGIAdapter*           pAdapter,
          D3D10_DRIVER_TYPE       DriverType,
          HMODULE                 Software,
          UINT                    Flags,
          UINT                    SDKVersion,
          DXGI_SWAP_CHAIN_DESC*   pSwapChainDesc,
          IDXGISwapChain**        ppSwapChain,
          ID3D10Device**          ppDevice) {
    return D3D10InternalCreateDeviceAndSwapChain(
      pAdapter, DriverType, Software, Flags,
      D3D10_FEATURE_LEVEL_10_0, SDKVersion,
      pSwapChainDesc, ppSwapChain,
      __uuidof(ID3D10Device),
      reinterpret_cast<void**>(ppDevice));
  }

  DLLEXPORT HRESULT __stdcall D3D10CreateDeviceAndSwapChain1(
          IDXGIAdapter*           pAdapter,
          D3D10_DRIVER_TYPE       DriverType,
          HMODULE                 Software,
          UINT                    Flags,
          D3D10_FEATURE_LEVEL1    HardwareLevel,
          UINT                    SDKVersion,
          DXGI_SWAP_CHAIN_DESC*   pSwapChainDesc,
          IDXGISwapChain**        ppSwapChain,
          ID3D10Device1**         ppDevice) {
    return D3D10InternalCreateDeviceAndSwapChain(
      pAdapter, DriverType, Software, Flags,
      HardwareLevel, SDKVersion,
      pSwapChainDesc, ppSwapChain,
      __uuidof(ID3D10Device1),
      reinterpret_cast<void**>(ppDevice));
  }

  const char* STDMETHODCALLTYPE D3D10GetVertexShaderProfile   (ID3D10Device*) { return "vs_4_1"; }
  const char* STDMETHODCALLTYPE D3D10GetGeometryShaderProfile (ID3D10Device*) { return "gs_4_1"; }
  const char* STDMETHODCALLTYPE D3D10GetPixelShaderProfile    (ID3D10Device*) { return "ps_4_1"; }

  HRESULT STDMETHODCALLTYPE D3D10CreateBlob(SIZE_T size, LPD3D10BLOB* ppBuffer) {
    return D3DCreateBlob(size, ppBuffer);
  }

  HRESULT STDMETHODCALLTYPE D3D10GetInputSignatureBlob(
    const void*                     pShaderBytecode,
          SIZE_T                    BytecodeLength,
          ID3D10Blob**              ppSignatureBlob) {
    return D3DGetInputSignatureBlob(
      pShaderBytecode,
      BytecodeLength,
      ppSignatureBlob);
  }

  HRESULT STDMETHODCALLTYPE D3D10GetOutputSignatureBlob(
    const void*                     pShaderBytecode,
          SIZE_T                    BytecodeLength,
          ID3D10Blob**              ppSignatureBlob) {
    return D3DGetOutputSignatureBlob(
      pShaderBytecode,
      BytecodeLength,
      ppSignatureBlob);
  }

  HRESULT STDMETHODCALLTYPE D3D10ReflectShader(
    const void*                     pShaderBytecode,
          SIZE_T                    BytecodeLength,
          ID3D10ShaderReflection**  ppReflector) {
    static const GUID IID_ID3D11ShaderReflection =
      {0x0a233719,0x3960,0x4578,{0x9d,0x7c,0x20,0x3b,0x8b,0x1d,0x9c,0xc1}};

    InitReturnPtr(ppReflector);

    Com<ID3D11ShaderReflection> d3d11Reflector = nullptr;

    HRESULT hr = D3DReflect(pShaderBytecode,
      BytecodeLength, IID_ID3D11ShaderReflection,
      reinterpret_cast<void**>(&d3d11Reflector));

    if (FAILED(hr)) {
      Logger::err("D3D10ReflectShader: Failed to create ID3D11ShaderReflection");
      return hr;
    }

    *ppReflector = ref(new D3D10ShaderReflection(d3d11Reflector.ptr()));
    return S_OK;
  }

  HRESULT STDMETHODCALLTYPE D3D10CompileShader(
          LPCSTR              pSrcData,
          SIZE_T              SrcDataSize,
          LPCSTR              pFileName,
    const D3D10_SHADER_MACRO* pDefines,
          LPD3D10INCLUDE      pInclude,
          LPCSTR              pFunctionName,
          LPCSTR              pProfile,
          UINT                Flags,
          ID3D10Blob**        ppShader,
          ID3D10Blob**        ppErrorMsgs) {
    return D3DCompile(pSrcData, SrcDataSize, pFileName,
      pDefines, pInclude, pFunctionName, pProfile, Flags,
      0, ppShader, ppErrorMsgs);
  }

  HRESULT STDMETHODCALLTYPE D3D10CreateEffectFromMemory(
          void*               pData,
          SIZE_T              DataSize,
          UINT                EffectFlags,
          ID3D10Device*       pDevice,
          ID3D10EffectPool*   pEffectPool,
          ID3D10Effect**      ppEffect) {
    Logger::warn("D3D10CreateEffectFromMemory: Not implemented");
    return E_NOTIMPL;
  }

  HRESULT STDMETHODCALLTYPE D3D10CreateEffectPoolFromMemory(
          void*               pData,
          SIZE_T              DataSize,
          UINT                EffectFlags,
          ID3D10Device*       pDevice,
          ID3D10EffectPool**  ppEffectPool) {
    Logger::warn("D3D10CreateEffectPoolFromMemory: Not implemented");
    return E_NOTIMPL;
  }

  HRESULT STDMETHODCALLTYPE D3D10CompileEffectFromMemory(
          void*               pData,
          SIZE_T              DataLength,
          LPCSTR              pSrcFileName,
    const D3D10_SHADER_MACRO* pDefines,
          ID3D10Include*      pInclude,
          UINT                ShaderFlags,
          UINT                EffectFlags,
          ID3D10Blob**        ppCompiledEffect,
          ID3D10Blob**        ppErrors) {
    Logger::warn("D3D10CompileEffectFromMemory: Not implemented");
    return E_NOTIMPL;
  }

  HRESULT STDMETHODCALLTYPE D3D10DisassembleEffect(
          ID3D10Effect*       pEffect,
          BOOL                EnableColorCode,
          ID3D10Blob**        ppDisassembly) {
    Logger::warn("D3D10DisassembleEffect: Not implemented");
    return E_NOTIMPL;
  }

  HRESULT STDMETHODCALLTYPE D3D10DisassembleShader(
    const void*               pShader,
          SIZE_T              BytecodeLength,
          BOOL                EnableColorCode,
          LPCSTR              pComments,
          ID3D10Blob**        ppDisassembly) {
    return D3DDisassemble(
      pShader, BytecodeLength,
      0, pComments, ppDisassembly);
  }

  HRESULT STDMETHODCALLTYPE D3D10PreprocessShader(
          LPCSTR              pSrcData,
          SIZE_T              SrcDataSize,
          LPCSTR              pFileName,
    const D3D10_SHADER_MACRO* pDefines,
          LPD3D10INCLUDE      pInclude,
          ID3D10Blob**        ppShaderText,
          ID3D10Blob**        ppErrorMsgs) {
    return D3DPreprocess(
      pSrcData, SrcDataSize,
      pFileName, pDefines,
      pInclude,
      ppShaderText,
      ppErrorMsgs);
  }

  UINT64 STDMETHODCALLTYPE D3D10GetVersion() {
    return 0xa000100041770ull;
  }

  HRESULT STDMETHODCALLTYPE D3D10RegisterLayers() {
    return E_NOTIMPL;
  }

}


code:
#include <utility>

#include "d3d10_device.h"

namespace dxvk {

  D3D10Multithread::D3D10Multithread(
          IUnknown*             pParent,
          BOOL                  Protected)
  : m_parent    (pParent),
    m_protected (Protected) {

  }

  D3D10Multithread::~D3D10Multithread() {

  }

  ULONG STDMETHODCALLTYPE D3D10Multithread::AddRef() {
    return m_parent->AddRef();
  }

  ULONG STDMETHODCALLTYPE D3D10Multithread::Release() {
    return m_parent->Release();
  }

  HRESULT STDMETHODCALLTYPE D3D10Multithread::QueryInterface(
          REFIID                riid,
          void**                ppvObject) {
    return m_parent->QueryInterface(riid, ppvObject);
  }

  void STDMETHODCALLTYPE D3D10Multithread::Enter() {
    if (m_protected)
      m_mutex.lock();
  }

  void STDMETHODCALLTYPE D3D10Multithread::Leave() {
    if (m_protected)
      m_mutex.unlock();
  }

  BOOL STDMETHODCALLTYPE D3D10Multithread::SetMultithreadProtected(
          BOOL                  bMTProtect) {
    return std::exchange(m_protected, bMTProtect);
  }

  BOOL STDMETHODCALLTYPE D3D10Multithread::GetMultithreadProtected() {
    return m_protected;
  }

}


code:
#pragma once

#include "d3d10_include.h"

namespace dxvk {

  /**
   * \brief Device lock
   *
   * Lightweight RAII wrapper that implements
   * a subset of the functionality provided by
   * \c std::unique_lock, with the goal of being
   * cheaper to construct and destroy.
   */
  class D3D10DeviceLock {

  public:

    D3D10DeviceLock()
    : m_mutex(nullptr) { }

    D3D10DeviceLock(sync::RecursiveSpinlock& mutex)
    : m_mutex(&mutex) {
      mutex.lock();
    }

    D3D10DeviceLock(D3D10DeviceLock&& other)
    : m_mutex(other.m_mutex) {
      other.m_mutex = nullptr;
    }

    D3D10DeviceLock& operator = (D3D10DeviceLock&& other) {
      if (m_mutex)
        m_mutex->unlock();

      m_mutex = other.m_mutex;
      other.m_mutex = nullptr;
      return *this;
    }

    ~D3D10DeviceLock() {
      if (unlikely(m_mutex != nullptr))
        m_mutex->unlock();
    }

  private:

    sync::RecursiveSpinlock* m_mutex;

  };

  /**
   * \brief D3D10 device and D3D11 context lock
   *
   * Can be queried from the D3D10 device or from
   * any D3D11 context in order to make individual
   * calls thread-safe. Provides methods to lock
   * the device or context explicitly.
   */
  class D3D10Multithread : public ID3D10Multithread {

  public:

    D3D10Multithread(
            IUnknown*             pParent,
            BOOL                  Protected);

    ~D3D10Multithread();

    ULONG STDMETHODCALLTYPE AddRef() final;

    ULONG STDMETHODCALLTYPE Release() final;

    HRESULT STDMETHODCALLTYPE QueryInterface(
            REFIID                riid,
            void**                ppvObject) final;

    void STDMETHODCALLTYPE Enter() final;

    void STDMETHODCALLTYPE Leave() final;

    BOOL STDMETHODCALLTYPE SetMultithreadProtected(
            BOOL                  bMTProtect) final;

    BOOL STDMETHODCALLTYPE GetMultithreadProtected() final;

    D3D10DeviceLock AcquireLock() {
      return unlikely(m_protected)
        ? D3D10DeviceLock(m_mutex)
        : D3D10DeviceLock();
    }

  private:

    IUnknown* m_parent;
    BOOL      m_protected;

    sync::RecursiveSpinlock m_mutex;

  };

}


code:
#include "d3d10_query.h"
#include "d3d10_device.h"

#include "../d3d11/d3d11_device.h"
#include "../d3d11/d3d11_context.h"
#include "../d3d11/d3d11_query.h"

namespace dxvk {

  HRESULT STDMETHODCALLTYPE D3D10Query::QueryInterface(
          REFIID                    riid,
          void**                    ppvObject) {
    return m_d3d11->QueryInterface(riid, ppvObject);
  }

  ULONG STDMETHODCALLTYPE D3D10Query::AddRef() {
    return m_d3d11->AddRef();
  }

  ULONG STDMETHODCALLTYPE D3D10Query::Release() {
    return m_d3d11->Release();
  }

  void STDMETHODCALLTYPE D3D10Query::GetDevice(
          ID3D10Device**            ppDevice) {
    GetD3D10Device(m_d3d11, ppDevice);
  }

  HRESULT STDMETHODCALLTYPE D3D10Query::GetPrivateData(
          REFGUID                   guid,
          UINT*                     pDataSize,
          void*                     pData) {
    return m_d3d11->GetPrivateData(guid, pDataSize, pData);
  }

  HRESULT STDMETHODCALLTYPE D3D10Query::SetPrivateData(
          REFGUID                   guid,
          UINT                      DataSize,
    const void*                     pData) {
    return m_d3d11->SetPrivateData(guid, DataSize, pData);
  }

  HRESULT STDMETHODCALLTYPE D3D10Query::SetPrivateDataInterface(
          REFGUID                   guid,
    const IUnknown*                 pData) {
    return m_d3d11->SetPrivateDataInterface(guid, pData);
  }

  void STDMETHODCALLTYPE D3D10Query::Begin() {
    Com<ID3D11DeviceContext> ctx;
    GetD3D11Context(m_d3d11, &ctx);

    ctx->Begin(m_d3d11);
  }

  void STDMETHODCALLTYPE D3D10Query::End() {
    Com<ID3D11DeviceContext> ctx;
    GetD3D11Context(m_d3d11, &ctx);

    ctx->End(m_d3d11);
  }

  HRESULT STDMETHODCALLTYPE D3D10Query::GetData(
          void*                     pData,
          UINT                      DataSize,
          UINT                      GetDataFlags) {
    Com<ID3D11DeviceContext> ctx;
    GetD3D11Context(m_d3d11, &ctx);

    return ctx->GetData(m_d3d11,
      pData, DataSize, GetDataFlags);
  }

  UINT STDMETHODCALLTYPE D3D10Query::GetDataSize() {
    return m_d3d11->GetDataSize();
  }

  void STDMETHODCALLTYPE D3D10Query::GetDesc(
          D3D10_QUERY_DESC*         pDesc) {
    D3D11_QUERY_DESC d3d11Desc;
    m_d3d11->GetDesc(&d3d11Desc);

    pDesc->Query      = D3D10_QUERY(d3d11Desc.Query);
    pDesc->MiscFlags  = d3d11Desc.MiscFlags;
  }

}


code:
#pragma once

#include "d3d10_util.h"

namespace dxvk {

  class D3D10Device;
  class D3D11Device;
  class D3D11DeviceContext;
  class D3D11Query;

  class D3D10Query : public ID3D10Predicate {

  public:

    D3D10Query(D3D11Query* pParent)
    : m_d3d11(pParent) { }

    HRESULT STDMETHODCALLTYPE QueryInterface(
            REFIID                    riid,
            void**                    ppvObject);

    ULONG STDMETHODCALLTYPE AddRef();

    ULONG STDMETHODCALLTYPE Release();

    void STDMETHODCALLTYPE GetDevice(
            ID3D10Device**            ppDevice);

    HRESULT STDMETHODCALLTYPE GetPrivateData(
            REFGUID                   guid,
            UINT*                     pDataSize,
            void*                     pData);

    HRESULT STDMETHODCALLTYPE SetPrivateData(
            REFGUID                   guid,
            UINT                      DataSize,
      const void*                     pData);

    HRESULT STDMETHODCALLTYPE SetPrivateDataInterface(
            REFGUID                   guid,
      const IUnknown*                 pData);

    void STDMETHODCALLTYPE Begin();

    void STDMETHODCALLTYPE End();

    HRESULT STDMETHODCALLTYPE GetData(
            void*                     pData,
            UINT                      DataSize,
            UINT                      GetDataFlags);

    UINT STDMETHODCALLTYPE GetDataSize();

    void STDMETHODCALLTYPE GetDesc(
            D3D10_QUERY_DESC*         pDesc);

    D3D11Query* GetD3D11Iface() {
      return m_d3d11;
    }

  private:

    D3D11Query*  m_d3d11;

  };

}


code:
#include "d3d10_rasterizer.h"

#include "../d3d11/d3d11_device.h"
#include "../d3d11/d3d11_rasterizer.h"

namespace dxvk {

  HRESULT STDMETHODCALLTYPE D3D10RasterizerState::QueryInterface(
          REFIID                    riid,
          void**                    ppvObject) {
    return m_d3d11->QueryInterface(riid, ppvObject);
  }

  ULONG STDMETHODCALLTYPE D3D10RasterizerState::AddRef() {
    return m_d3d11->AddRef();
  }

  ULONG STDMETHODCALLTYPE D3D10RasterizerState::Release() {
    return m_d3d11->Release();
  }

  void STDMETHODCALLTYPE D3D10RasterizerState::GetDevice(
          ID3D10Device**            ppDevice) {
    GetD3D10Device(m_d3d11, ppDevice);
  }

  HRESULT STDMETHODCALLTYPE D3D10RasterizerState::GetPrivateData(
          REFGUID                   guid,
          UINT*                     pDataSize,
          void*                     pData) {
    return m_d3d11->GetPrivateData(guid, pDataSize, pData);
  }

  HRESULT STDMETHODCALLTYPE D3D10RasterizerState::SetPrivateData(
          REFGUID                   guid,
          UINT                      DataSize,
    const void*                     pData) {
    return m_d3d11->SetPrivateData(guid, DataSize, pData);
  }

  HRESULT STDMETHODCALLTYPE D3D10RasterizerState::SetPrivateDataInterface(
          REFGUID                   guid,
    const IUnknown*                 pData) {
    return m_d3d11->SetPrivateDataInterface(guid, pData);
  }

  void STDMETHODCALLTYPE D3D10RasterizerState::GetDesc(
          D3D10_RASTERIZER_DESC*    pDesc) {
    static_assert(sizeof(D3D10_RASTERIZER_DESC) == sizeof(D3D11_RASTERIZER_DESC));
    m_d3d11->GetDesc(reinterpret_cast<D3D11_RASTERIZER_DESC*>(pDesc));
  }

}


code:
#pragma once

#include "d3d10_util.h"

namespace dxvk {

  class D3D11RasterizerState;
  class D3D11Device;

  class D3D10RasterizerState : public ID3D10RasterizerState {

  public:

    D3D10RasterizerState(D3D11RasterizerState* pParent)
    : m_d3d11(pParent) { }

    HRESULT STDMETHODCALLTYPE QueryInterface(
            REFIID                    riid,
            void**                    ppvObject);

    ULONG STDMETHODCALLTYPE AddRef();

    ULONG STDMETHODCALLTYPE Release();

    void STDMETHODCALLTYPE GetDevice(
            ID3D10Device**            ppDevice);

    HRESULT STDMETHODCALLTYPE GetPrivateData(
            REFGUID                   guid,
            UINT*                     pDataSize,
            void*                     pData);

    HRESULT STDMETHODCALLTYPE SetPrivateData(
            REFGUID                   guid,
            UINT                      DataSize,
      const void*                     pData);

    HRESULT STDMETHODCALLTYPE SetPrivateDataInterface(
            REFGUID                   guid,
      const IUnknown*                 pData);

    void STDMETHODCALLTYPE GetDesc(
            D3D10_RASTERIZER_DESC*    pDesc);

    D3D11RasterizerState* GetD3D11Iface() {
      return m_d3d11;
    }

  private:

    D3D11RasterizerState* m_d3d11;

  };

}


code:
#include "d3d10_reflection.h"

namespace dxvk {

  D3D10ShaderReflectionType::D3D10ShaderReflectionType(
          ID3D11ShaderReflectionType*     d3d11)
  : m_d3d11(d3d11) {

  }

  D3D10ShaderReflectionType::~D3D10ShaderReflectionType() {

  }

  HRESULT STDMETHODCALLTYPE D3D10ShaderReflectionType::GetDesc(
          D3D10_SHADER_TYPE_DESC*         pDesc) {
    D3D11_SHADER_TYPE_DESC d3d11Desc;
    HRESULT hr = m_d3d11->GetDesc(&d3d11Desc);

    if (FAILED(hr))
      return hr;

    pDesc->Class    = D3D10_SHADER_VARIABLE_CLASS(d3d11Desc.Class);
    pDesc->Type     = D3D10_SHADER_VARIABLE_TYPE (d3d11Desc.Type);
    pDesc->Rows     = d3d11Desc.Rows;
    pDesc->Columns  = d3d11Desc.Columns;
    pDesc->Elements = d3d11Desc.Elements;
    pDesc->Members  = d3d11Desc.Members;
    pDesc->Offset   = d3d11Desc.Offset;
    return S_OK;
  }

  ID3D10ShaderReflectionType* STDMETHODCALLTYPE D3D10ShaderReflectionType::GetMemberTypeByIndex(
          UINT                            Index) {
    return FindMemberType(m_d3d11->GetMemberTypeByIndex(Index));
  }

  ID3D10ShaderReflectionType* STDMETHODCALLTYPE D3D10ShaderReflectionType::GetMemberTypeByName(
    const char*                           Name) {
    return FindMemberType(m_d3d11->GetMemberTypeByName(Name));
  }

  const char* STDMETHODCALLTYPE D3D10ShaderReflectionType::GetMemberTypeName(
          UINT                            Index) {
    return m_d3d11->GetMemberTypeName(Index);
  }

  ID3D10ShaderReflectionType* D3D10ShaderReflectionType::FindMemberType(
          ID3D11ShaderReflectionType*     pMemberType) {
    if (!pMemberType)
      return nullptr;

    auto entry = m_members.find(pMemberType);

    if (entry == m_members.end()) {
      entry = m_members.insert({ pMemberType,
        std::make_unique<D3D10ShaderReflectionType>(pMemberType) }).first;
    }

    return entry->second.get();
  }

  D3D10ShaderReflectionVariable::D3D10ShaderReflectionVariable(ID3D11ShaderReflectionVariable* d3d11)
  : m_d3d11(d3d11), m_type(m_d3d11->GetType()) {

  }

  D3D10ShaderReflectionVariable::~D3D10ShaderReflectionVariable() {

  }

  HRESULT STDMETHODCALLTYPE D3D10ShaderReflectionVariable::GetDesc(
          D3D10_SHADER_VARIABLE_DESC*     pDesc) {
    D3D11_SHADER_VARIABLE_DESC d3d11Desc;
    HRESULT hr = m_d3d11->GetDesc(&d3d11Desc);

    if (FAILED(hr))
      return hr;

    pDesc->Name         = d3d11Desc.Name;
    pDesc->StartOffset  = d3d11Desc.StartOffset;
    pDesc->Size         = d3d11Desc.Size;
    pDesc->uFlags       = d3d11Desc.uFlags;
    pDesc->DefaultValue = d3d11Desc.DefaultValue;
    return S_OK;
  }

  ID3D10ShaderReflectionType* STDMETHODCALLTYPE D3D10ShaderReflectionVariable::GetType() {
    return &m_type;
  }

  D3D10ShaderReflectionConstantBuffer::D3D10ShaderReflectionConstantBuffer(
          ID3D11ShaderReflectionConstantBuffer* d3d11)
  : m_d3d11(d3d11) {

  }

  D3D10ShaderReflectionConstantBuffer::~D3D10ShaderReflectionConstantBuffer() {

  }

  HRESULT STDMETHODCALLTYPE D3D10ShaderReflectionConstantBuffer::GetDesc(
          D3D10_SHADER_BUFFER_DESC*       pDesc) {
    D3D11_SHADER_BUFFER_DESC d3d11Desc;
    HRESULT hr = m_d3d11->GetDesc(&d3d11Desc);

    if (FAILED(hr))
      return hr;

    pDesc->Name       = d3d11Desc.Name;
    pDesc->Type       = D3D10_CBUFFER_TYPE(d3d11Desc.Type);
    pDesc->Variables  = d3d11Desc.Variables;
    pDesc->Size       = d3d11Desc.Size;
    pDesc->uFlags     = d3d11Desc.uFlags;
    return S_OK;
  }

  ID3D10ShaderReflectionVariable* STDMETHODCALLTYPE D3D10ShaderReflectionConstantBuffer::GetVariableByIndex(
          UINT                            Index) {
    return FindVariable(m_d3d11->GetVariableByIndex(Index));
  }

  ID3D10ShaderReflectionVariable* STDMETHODCALLTYPE D3D10ShaderReflectionConstantBuffer::GetVariableByName(
          LPCSTR                          Name) {
    return FindVariable(m_d3d11->GetVariableByName(Name));
  }

  ID3D10ShaderReflectionVariable* D3D10ShaderReflectionConstantBuffer::FindVariable(
          ID3D11ShaderReflectionVariable* pVariable) {
    if (!pVariable)
      return nullptr;

    auto entry = m_variables.find(pVariable);

    if (entry == m_variables.end()) {
      entry = m_variables.emplace(
        std::piecewise_construct,
        std::forward_as_tuple(pVariable),
        std::forward_as_tuple(pVariable)).first;
    }

    return &entry->second;
  }

  D3D10ShaderReflection::D3D10ShaderReflection(ID3D11ShaderReflection* d3d11)
  : m_d3d11(d3d11) {

  }

  D3D10ShaderReflection::~D3D10ShaderReflection() {

  }

  HRESULT STDMETHODCALLTYPE D3D10ShaderReflection::QueryInterface(
          REFIID              riid,
          void**              ppvObject) {
    if (ppvObject == nullptr)
      return E_POINTER;

    static const GUID IID_ID3D10ShaderReflection
      = {0xd40e20b6,0xf8f7,0x42ad,{0xab,0x20,0x4b,0xaf,0x8f,0x15,0xdf,0xaa}};

    if (riid == __uuidof(IUnknown)
     || riid == IID_ID3D10ShaderReflection) {
      *ppvObject = ref(this);
      return S_OK;
    }

    return E_NOINTERFACE;
  }

  HRESULT STDMETHODCALLTYPE D3D10ShaderReflection::GetDesc(
          D3D10_SHADER_DESC*              pDesc) {
    D3D11_SHADER_DESC d3d11Desc;
    HRESULT hr = m_d3d11->GetDesc(&d3d11Desc);

    if (FAILED(hr))
      return hr;

    pDesc->Version                     = d3d11Desc.Version;
    pDesc->Creator                     = d3d11Desc.Creator;
    pDesc->Flags                       = d3d11Desc.Flags;
    pDesc->ConstantBuffers             = d3d11Desc.ConstantBuffers;
    pDesc->BoundResources              = d3d11Desc.BoundResources;
    pDesc->InputParameters             = d3d11Desc.InputParameters;
    pDesc->OutputParameters            = d3d11Desc.OutputParameters;
    pDesc->InstructionCount            = d3d11Desc.InstructionCount;
    pDesc->TempRegisterCount           = d3d11Desc.TempRegisterCount;
    pDesc->TempArrayCount              = d3d11Desc.TempArrayCount;
    pDesc->DefCount                    = d3d11Desc.DefCount;
    pDesc->DclCount                    = d3d11Desc.DclCount;
    pDesc->TextureNormalInstructions   = d3d11Desc.TextureNormalInstructions;
    pDesc->TextureLoadInstructions     = d3d11Desc.TextureLoadInstructions;
    pDesc->TextureCompInstructions     = d3d11Desc.TextureCompInstructions;
    pDesc->TextureBiasInstructions     = d3d11Desc.TextureBiasInstructions;
    pDesc->TextureGradientInstructions = d3d11Desc.TextureGradientInstructions;
    pDesc->FloatInstructionCount       = d3d11Desc.FloatInstructionCount;
    pDesc->IntInstructionCount         = d3d11Desc.IntInstructionCount;
    pDesc->UintInstructionCount        = d3d11Desc.UintInstructionCount;
    pDesc->StaticFlowControlCount      = d3d11Desc.StaticFlowControlCount;
    pDesc->DynamicFlowControlCount     = d3d11Desc.DynamicFlowControlCount;
    pDesc->MacroInstructionCount       = d3d11Desc.MacroInstructionCount;
    pDesc->ArrayInstructionCount       = d3d11Desc.ArrayInstructionCount;
    pDesc->CutInstructionCount         = d3d11Desc.CutInstructionCount;
    pDesc->EmitInstructionCount        = d3d11Desc.EmitInstructionCount;
    pDesc->GSOutputTopology            = D3D10_PRIMITIVE_TOPOLOGY(d3d11Desc.GSOutputTopology);
    pDesc->GSMaxOutputVertexCount      = d3d11Desc.GSMaxOutputVertexCount;
    return S_OK;
  }

  ID3D10ShaderReflectionConstantBuffer* STDMETHODCALLTYPE
  D3D10ShaderReflection::GetConstantBufferByIndex(
          UINT                            Index) {
    return FindConstantBuffer(m_d3d11->GetConstantBufferByIndex(Index));
  }

  ID3D10ShaderReflectionConstantBuffer* STDMETHODCALLTYPE
  D3D10ShaderReflection::GetConstantBufferByName(
          LPCSTR                          Name) {
    return FindConstantBuffer(m_d3d11->GetConstantBufferByName(Name));
  }

  HRESULT STDMETHODCALLTYPE D3D10ShaderReflection::GetInputParameterDesc(
          UINT                            ParameterIndex,
          D3D10_SIGNATURE_PARAMETER_DESC* pDesc) {
    D3D11_SIGNATURE_PARAMETER_DESC d3d11Desc;
    HRESULT hr = m_d3d11->GetInputParameterDesc(ParameterIndex, &d3d11Desc);

    if (FAILED(hr))
      return hr;

    ConvertSignatureParameterDesc(&d3d11Desc, pDesc);
    return S_OK;
  }

  HRESULT STDMETHODCALLTYPE D3D10ShaderReflection::GetOutputParameterDesc(
          UINT                            ParameterIndex,
          D3D10_SIGNATURE_PARAMETER_DESC* pDesc) {
    D3D11_SIGNATURE_PARAMETER_DESC d3d11Desc;
    HRESULT hr = m_d3d11->GetOutputParameterDesc(ParameterIndex, &d3d11Desc);

    if (FAILED(hr))
      return hr;

    ConvertSignatureParameterDesc(&d3d11Desc, pDesc);
    return S_OK;
  }

  HRESULT STDMETHODCALLTYPE D3D10ShaderReflection::GetResourceBindingDesc(
          UINT                            ResourceIndex,
          D3D10_SHADER_INPUT_BIND_DESC*   pDesc) {
    D3D11_SHADER_INPUT_BIND_DESC d3d11Desc;
    HRESULT hr = m_d3d11->GetResourceBindingDesc(
      ResourceIndex, &d3d11Desc);

    if (FAILED(hr))
      return hr;

    pDesc->Name         = d3d11Desc.Name;
    pDesc->Type         = D3D10_SHADER_INPUT_TYPE(d3d11Desc.Type);
    pDesc->BindPoint    = d3d11Desc.BindPoint;
    pDesc->BindCount    = d3d11Desc.BindCount;
    pDesc->uFlags       = d3d11Desc.uFlags;
    pDesc->ReturnType   = D3D10_RESOURCE_RETURN_TYPE(d3d11Desc.ReturnType);
    pDesc->Dimension    = D3D10_SRV_DIMENSION       (d3d11Desc.Dimension);
    pDesc->NumSamples   = d3d11Desc.NumSamples;
    return S_OK;
  }

  ID3D10ShaderReflectionConstantBuffer* D3D10ShaderReflection::FindConstantBuffer(
          ID3D11ShaderReflectionConstantBuffer* pConstantBuffer) {
    if (!pConstantBuffer)
      return nullptr;

    auto entry = m_constantBuffers.find(pConstantBuffer);

    if (entry == m_constantBuffers.end()) {
      entry = m_constantBuffers.emplace(
        std::piecewise_construct,
        std::forward_as_tuple(pConstantBuffer),
        std::forward_as_tuple(pConstantBuffer)).first;
    }

    return &entry->second;
  }

  void D3D10ShaderReflection::ConvertSignatureParameterDesc(
    const D3D11_SIGNATURE_PARAMETER_DESC* pSrcDesc,
          D3D10_SIGNATURE_PARAMETER_DESC* pDstDesc) {
    pDstDesc->SemanticName        = pSrcDesc->SemanticName;
    pDstDesc->SemanticIndex       = pSrcDesc->SemanticIndex;
    pDstDesc->Register            = pSrcDesc->Register;
    pDstDesc->SystemValueType     = D3D10_NAME(pSrcDesc->SystemValueType);
    pDstDesc->ComponentType       = D3D10_REGISTER_COMPONENT_TYPE(pSrcDesc->ComponentType);
    pDstDesc->Mask                = pSrcDesc->Mask;
    pDstDesc->ReadWriteMask       = pSrcDesc->ReadWriteMask;
  }

}


code:
#pragma once

#include <unordered_map>
#include <vector>

#include "d3d10_include.h"

#include <d3d10shader.h>
#include <d3d11shader.h>

namespace dxvk {

  class D3D10ShaderReflectionType : public ID3D10ShaderReflectionType {

  public:

    D3D10ShaderReflectionType(
            ID3D11ShaderReflectionType*     d3d11);

    ~D3D10ShaderReflectionType();

    HRESULT STDMETHODCALLTYPE GetDesc(
            D3D10_SHADER_TYPE_DESC*         pDesc);

    ID3D10ShaderReflectionType* STDMETHODCALLTYPE GetMemberTypeByIndex(
            UINT                            Index);

    ID3D10ShaderReflectionType* STDMETHODCALLTYPE GetMemberTypeByName(
      const char*                           Name);

    const char* STDMETHODCALLTYPE GetMemberTypeName(
            UINT                            Index);

    ID3D11ShaderReflectionType* GetD3D11Iface() {
      return m_d3d11;
    }

  private:

    ID3D11ShaderReflectionType* m_d3d11;

    std::unordered_map<
      ID3D11ShaderReflectionType*,
      std::unique_ptr<D3D10ShaderReflectionType>> m_members;

    ID3D10ShaderReflectionType* FindMemberType(
            ID3D11ShaderReflectionType*     pMemberType);

  };

  class D3D10ShaderReflectionVariable : public ID3D10ShaderReflectionVariable {

  public:

    D3D10ShaderReflectionVariable(
            ID3D11ShaderReflectionVariable* d3d11);

    ~D3D10ShaderReflectionVariable();

    HRESULT STDMETHODCALLTYPE GetDesc(
            D3D10_SHADER_VARIABLE_DESC*     pDesc);

    ID3D10ShaderReflectionType* STDMETHODCALLTYPE GetType();

    ID3D11ShaderReflectionVariable* STDMETHODCALLTYPE GetD3D11Iface() {
      return m_d3d11;
    }

  private:

    ID3D11ShaderReflectionVariable* m_d3d11;
    D3D10ShaderReflectionType       m_type;

  };

  class D3D10ShaderReflectionConstantBuffer : public ID3D10ShaderReflectionConstantBuffer {

  public:

    D3D10ShaderReflectionConstantBuffer(
            ID3D11ShaderReflectionConstantBuffer* d3d11);

    ~D3D10ShaderReflectionConstantBuffer();

    HRESULT STDMETHODCALLTYPE GetDesc(
            D3D10_SHADER_BUFFER_DESC*       pDesc);

    ID3D10ShaderReflectionVariable* STDMETHODCALLTYPE GetVariableByIndex(
            UINT                            Index);

    ID3D10ShaderReflectionVariable* STDMETHODCALLTYPE GetVariableByName(
            LPCSTR                          Name);

    ID3D11ShaderReflectionConstantBuffer* STDMETHODCALLTYPE GetD3D11Iface() {
      return m_d3d11;
    }

  private:

    ID3D11ShaderReflectionConstantBuffer* m_d3d11;

    std::unordered_map<
      ID3D11ShaderReflectionVariable*,
      D3D10ShaderReflectionVariable> m_variables;

    ID3D10ShaderReflectionVariable* FindVariable(
            ID3D11ShaderReflectionVariable* pVariable);

  };

  class D3D10ShaderReflection : public ComObject<ID3D10ShaderReflection> {

  public:

    D3D10ShaderReflection(ID3D11ShaderReflection* d3d11);
    ~D3D10ShaderReflection();

    HRESULT STDMETHODCALLTYPE QueryInterface(
            REFIID                          riid,
            void**                          ppvObject);

    HRESULT STDMETHODCALLTYPE GetDesc(
            D3D10_SHADER_DESC*              pDesc);

    ID3D10ShaderReflectionConstantBuffer* STDMETHODCALLTYPE GetConstantBufferByIndex(
            UINT                            Index);

    ID3D10ShaderReflectionConstantBuffer* STDMETHODCALLTYPE GetConstantBufferByName(
            LPCSTR                          Name);

    HRESULT STDMETHODCALLTYPE GetInputParameterDesc(
            UINT                            ParameterIndex,
            D3D10_SIGNATURE_PARAMETER_DESC* pDesc);

    HRESULT STDMETHODCALLTYPE GetOutputParameterDesc(
            UINT                            ParameterIndex,
            D3D10_SIGNATURE_PARAMETER_DESC* pDesc);

    HRESULT STDMETHODCALLTYPE GetResourceBindingDesc(
            UINT                            ResourceIndex,
            D3D10_SHADER_INPUT_BIND_DESC*   pDesc);

  private:

    Com<ID3D11ShaderReflection> m_d3d11;

    std::unordered_map<
      ID3D11ShaderReflectionConstantBuffer*,
      D3D10ShaderReflectionConstantBuffer> m_constantBuffers;

    ID3D10ShaderReflectionConstantBuffer* FindConstantBuffer(
            ID3D11ShaderReflectionConstantBuffer* pConstantBuffer);

    void ConvertSignatureParameterDesc(
      const D3D11_SIGNATURE_PARAMETER_DESC* pSrcDesc,
            D3D10_SIGNATURE_PARAMETER_DESC* pDstDesc);

  };

}


code:
#include "d3d10_sampler.h"

#include "../d3d11/d3d11_device.h"
#include "../d3d11/d3d11_sampler.h"

namespace dxvk {

  HRESULT STDMETHODCALLTYPE D3D10SamplerState::QueryInterface(
          REFIID                    riid,
          void**                    ppvObject) {
    return m_d3d11->QueryInterface(riid, ppvObject);
  }

  ULONG STDMETHODCALLTYPE D3D10SamplerState::AddRef() {
    return m_d3d11->AddRef();
  }

  ULONG STDMETHODCALLTYPE D3D10SamplerState::Release() {
    return m_d3d11->Release();
  }

  void STDMETHODCALLTYPE D3D10SamplerState::GetDevice(
          ID3D10Device**            ppDevice) {
    GetD3D10Device(m_d3d11, ppDevice);
  }

  HRESULT STDMETHODCALLTYPE D3D10SamplerState::GetPrivateData(
          REFGUID                   guid,
          UINT*                     pDataSize,
          void*                     pData) {
    return m_d3d11->GetPrivateData(guid, pDataSize, pData);
  }

  HRESULT STDMETHODCALLTYPE D3D10SamplerState::SetPrivateData(
          REFGUID                   guid,
          UINT                      DataSize,
    const void*                     pData) {
    return m_d3d11->SetPrivateData(guid, DataSize, pData);
  }

  HRESULT STDMETHODCALLTYPE D3D10SamplerState::SetPrivateDataInterface(
          REFGUID                   guid,
    const IUnknown*                 pData) {
    return m_d3d11->SetPrivateDataInterface(guid, pData);
  }

  void STDMETHODCALLTYPE D3D10SamplerState::GetDesc(
          D3D10_SAMPLER_DESC*       pDesc) {
    D3D11_SAMPLER_DESC d3d11Desc;
    m_d3d11->GetDesc(&d3d11Desc);

    pDesc->Filter            = D3D10_FILTER(d3d11Desc.Filter);
    pDesc->AddressU          = D3D10_TEXTURE_ADDRESS_MODE(d3d11Desc.AddressU);
    pDesc->AddressV          = D3D10_TEXTURE_ADDRESS_MODE(d3d11Desc.AddressV);
    pDesc->AddressW          = D3D10_TEXTURE_ADDRESS_MODE(d3d11Desc.AddressW);
    pDesc->MipLODBias        = d3d11Desc.MipLODBias;
    pDesc->MaxAnisotropy     = d3d11Desc.MaxAnisotropy;
    pDesc->ComparisonFunc    = D3D10_COMPARISON_FUNC(d3d11Desc.ComparisonFunc);
    pDesc->MinLOD            = d3d11Desc.MinLOD;
    pDesc->MaxLOD            = d3d11Desc.MaxLOD;

    for (uint32_t i = 0; i < 4; i++)
      pDesc->BorderColor[i] = d3d11Desc.BorderColor[i];
  }

}


code:
#pragma once

#include "d3d10_util.h"

namespace dxvk {

  class D3D11Device;
  class D3D11SamplerState;

  class D3D10SamplerState : public ID3D10SamplerState {

  public:

    D3D10SamplerState(D3D11SamplerState* pParent)
    : m_d3d11(pParent) { }

    HRESULT STDMETHODCALLTYPE QueryInterface(
            REFIID                    riid,
            void**                    ppvObject);

    ULONG STDMETHODCALLTYPE AddRef();

    ULONG STDMETHODCALLTYPE Release();

    void STDMETHODCALLTYPE GetDevice(
            ID3D10Device**            ppDevice);

    HRESULT STDMETHODCALLTYPE GetPrivateData(
            REFGUID                   guid,
            UINT*                     pDataSize,
            void*                     pData);

    HRESULT STDMETHODCALLTYPE SetPrivateData(
            REFGUID                   guid,
            UINT                      DataSize,
      const void*                     pData);

    HRESULT STDMETHODCALLTYPE SetPrivateDataInterface(
            REFGUID                   guid,
      const IUnknown*                 pData);

    void STDMETHODCALLTYPE GetDesc(
            D3D10_SAMPLER_DESC*       pDesc);

    D3D11SamplerState* GetD3D11Iface() {
      return m_d3d11;
    }

  private:

    D3D11SamplerState* m_d3d11;

  };

}


code:
#pragma once

#include "d3d10_util.h"

namespace dxvk {

  template<typename D3D11Interface, typename D3D10Interface>
  class D3D11Shader;

  template<typename D3D10Interface, typename D3D11Interface>
  class D3D10Shader : public D3D10Interface {
    using D3D11ShaderClass = D3D11Shader<D3D11Interface, D3D10Interface>;
  public:

    D3D10Shader(D3D11Shader<D3D11Interface, D3D10Interface>* pParent)
    : m_d3d11(pParent) { }

    HRESULT STDMETHODCALLTYPE QueryInterface(
            REFIID                    riid,
            void**                    ppvObject) {
      return m_d3d11->QueryInterface(riid, ppvObject);
    }

    ULONG STDMETHODCALLTYPE AddRef() {
      return m_d3d11->AddRef();
    }

    ULONG STDMETHODCALLTYPE Release() {
      return m_d3d11->Release();
    }

    void STDMETHODCALLTYPE GetDevice(
            ID3D10Device**            ppDevice) {
      GetD3D10Device(m_d3d11, ppDevice);
    }

    HRESULT STDMETHODCALLTYPE GetPrivateData(
            REFGUID                   guid,
            UINT*                     pDataSize,
            void*                     pData) {
      return m_d3d11->GetPrivateData(guid, pDataSize, pData);
    }

    HRESULT STDMETHODCALLTYPE SetPrivateData(
            REFGUID                   guid,
            UINT                      DataSize,
      const void*                     pData) {
      return m_d3d11->SetPrivateData(guid, DataSize, pData);
    }

    HRESULT STDMETHODCALLTYPE SetPrivateDataInterface(
            REFGUID                   guid,
      const IUnknown*                 pData) {
      return m_d3d11->SetPrivateDataInterface(guid, pData);
    }

    D3D11ShaderClass* GetD3D11Iface() {
      return m_d3d11;
    }

  private:

    D3D11ShaderClass* m_d3d11;

  };

  using D3D10VertexShader   = D3D10Shader<ID3D10VertexShader,   ID3D11VertexShader>;
  using D3D10GeometryShader = D3D10Shader<ID3D10GeometryShader, ID3D11GeometryShader>;
  using D3D10PixelShader    = D3D10Shader<ID3D10PixelShader,    ID3D11PixelShader>;

}


code:
#include "d3d10_state_block.h"

#define MAKE_STATE_TYPE(field, count) { offsetof(D3D10_STATE_BLOCK_MASK, field), count }

namespace dxvk {

  static const std::array<std::pair<size_t, size_t>, 24> g_stateTypes = {{
    MAKE_STATE_TYPE(SOBuffers,                1),
    MAKE_STATE_TYPE(OMRenderTargets,          1),
    MAKE_STATE_TYPE(OMDepthStencilState,      1),
    MAKE_STATE_TYPE(OMBlendState,             1),
    MAKE_STATE_TYPE(VS,                       1),
    MAKE_STATE_TYPE(VSSamplers,               D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT),
    MAKE_STATE_TYPE(VSShaderResources,        D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT),
    MAKE_STATE_TYPE(VSConstantBuffers,        D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT),
    MAKE_STATE_TYPE(GS,                       1),
    MAKE_STATE_TYPE(GSSamplers,               D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT),
    MAKE_STATE_TYPE(GSShaderResources,        D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT),
    MAKE_STATE_TYPE(GSConstantBuffers,        D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT),
    MAKE_STATE_TYPE(PS,                       1),
    MAKE_STATE_TYPE(PSSamplers,               D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT),
    MAKE_STATE_TYPE(PSShaderResources,        D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT),
    MAKE_STATE_TYPE(PSConstantBuffers,        D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT),
    MAKE_STATE_TYPE(IAVertexBuffers,          D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT),
    MAKE_STATE_TYPE(IAIndexBuffer,            1),
    MAKE_STATE_TYPE(IAInputLayout,            1),
    MAKE_STATE_TYPE(IAPrimitiveTopology,      1),
    MAKE_STATE_TYPE(RSViewports,              1),
    MAKE_STATE_TYPE(RSScissorRects,           1),
    MAKE_STATE_TYPE(RSRasterizerState,        1),
    MAKE_STATE_TYPE(Predication,              1),
  }};

  D3D10StateBlock::D3D10StateBlock(
          ID3D10Device*             pDevice,
    const D3D10_STATE_BLOCK_MASK*   pMask)
  : m_device(pDevice), m_mask(*pMask) {

  }

  D3D10StateBlock::~D3D10StateBlock() {

  }

  HRESULT STDMETHODCALLTYPE D3D10StateBlock::QueryInterface(
          REFIID                    riid,
          void**                    ppvObject) {
    if (ppvObject == nullptr)
      return E_POINTER;

    *ppvObject = nullptr;

    if (riid == __uuidof(IUnknown)
     || riid == __uuidof(ID3D10StateBlock)) {
      *ppvObject = ref(this);
      return S_OK;
    }

    Logger::warn("D3D10StateBlock::QueryInterface: Unknown interface query");
    Logger::warn(str::format(riid));
    return E_NOINTERFACE;
  }

  HRESULT STDMETHODCALLTYPE D3D10StateBlock::Capture() {
    m_state = D3D10_STATE_BLOCK_STATE();

    if (TestBit(&m_mask.VS, 0)) m_device->VSGetShader(&m_state.vs);
    if (TestBit(&m_mask.GS, 0)) m_device->GSGetShader(&m_state.gs);
    if (TestBit(&m_mask.PS, 0)) m_device->PSGetShader(&m_state.ps);

    for (uint32_t i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; i++) {
      if (TestBit(m_mask.VSSamplers, i)) m_device->VSGetSamplers(i, 1, &m_state.vsSso[i]);
      if (TestBit(m_mask.GSSamplers, i)) m_device->GSGetSamplers(i, 1, &m_state.gsSso[i]);
      if (TestBit(m_mask.PSSamplers, i)) m_device->PSGetSamplers(i, 1, &m_state.psSso[i]);
    }

    for (uint32_t i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; i++) {
      if (TestBit(m_mask.VSShaderResources, i)) m_device->VSGetShaderResources(i, 1, &m_state.vsSrv[i]);
      if (TestBit(m_mask.GSShaderResources, i)) m_device->GSGetShaderResources(i, 1, &m_state.gsSrv[i]);
      if (TestBit(m_mask.PSShaderResources, i)) m_device->PSGetShaderResources(i, 1, &m_state.psSrv[i]);
    }

    for (uint32_t i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; i++) {
      if (TestBit(m_mask.VSConstantBuffers, i)) m_device->VSGetConstantBuffers(i, 1, &m_state.vsCbo[i]);
      if (TestBit(m_mask.GSConstantBuffers, i)) m_device->GSGetConstantBuffers(i, 1, &m_state.gsCbo[i]);
      if (TestBit(m_mask.PSConstantBuffers, i)) m_device->PSGetConstantBuffers(i, 1, &m_state.psCbo[i]);
    }

    for (uint32_t i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; i++) {
      if (TestBit(m_mask.IAVertexBuffers, i)) {
        m_device->IAGetVertexBuffers(i, 1,
          &m_state.iaVertexBuffers[i],
          &m_state.iaVertexOffsets[i],
          &m_state.iaVertexStrides[i]);
      }
    }

    if (TestBit(&m_mask.IAIndexBuffer, 0)) {
      m_device->IAGetIndexBuffer(
        &m_state.iaIndexBuffer,
        &m_state.iaIndexFormat,
        &m_state.iaIndexOffset);
    }

    if (TestBit(&m_mask.IAInputLayout, 0))
      m_device->IAGetInputLayout(&m_state.iaInputLayout);

    if (TestBit(&m_mask.IAPrimitiveTopology, 0))
      m_device->IAGetPrimitiveTopology(&m_state.iaTopology);

    if (TestBit(&m_mask.OMRenderTargets, 0)) {
      m_device->OMGetRenderTargets(
        D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT,
        &m_state.omRtv[0], &m_state.omDsv);
    }

    if (TestBit(&m_mask.OMDepthStencilState, 0)) {
      m_device->OMGetDepthStencilState(
        &m_state.omDepthStencilState,
        &m_state.omStencilRef);
    }

    if (TestBit(&m_mask.OMBlendState, 0)) {
      m_device->OMGetBlendState(
        &m_state.omBlendState,
         m_state.omBlendFactor,
        &m_state.omSampleMask);
    }

    if (TestBit(&m_mask.RSViewports, 0)) {
      m_device->RSGetViewports(&m_state.rsViewportCount, nullptr);
      m_device->RSGetViewports(&m_state.rsViewportCount, m_state.rsViewports);
    }

    if (TestBit(&m_mask.RSScissorRects, 0)) {
      m_device->RSGetScissorRects(&m_state.rsScissorCount, nullptr);
      m_device->RSGetScissorRects(&m_state.rsScissorCount, m_state.rsScissors);
    }

    if (TestBit(&m_mask.RSRasterizerState, 0))
      m_device->RSGetState(&m_state.rsState);

    if (TestBit(&m_mask.SOBuffers, 0)) {
      m_device->SOGetTargets(
        D3D10_SO_BUFFER_SLOT_COUNT,
        &m_state.soBuffers[0],
        &m_state.soOffsets[0]);
    }

    if (TestBit(&m_mask.Predication, 0))
      m_device->GetPredication(&m_state.predicate, &m_state.predicateInvert);

    return S_OK;
  }

  HRESULT STDMETHODCALLTYPE D3D10StateBlock::Apply() {
    if (TestBit(&m_mask.VS, 0)) m_device->VSSetShader(m_state.vs.ptr());
    if (TestBit(&m_mask.GS, 0)) m_device->GSSetShader(m_state.gs.ptr());
    if (TestBit(&m_mask.PS, 0)) m_device->PSSetShader(m_state.ps.ptr());

    for (uint32_t i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; i++) {
      if (TestBit(m_mask.VSSamplers, i)) m_device->VSSetSamplers(i, 1, &m_state.vsSso[i]);
      if (TestBit(m_mask.GSSamplers, i)) m_device->GSSetSamplers(i, 1, &m_state.gsSso[i]);
      if (TestBit(m_mask.PSSamplers, i)) m_device->PSSetSamplers(i, 1, &m_state.psSso[i]);
    }

    for (uint32_t i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; i++) {
      if (TestBit(m_mask.VSShaderResources, i)) m_device->VSSetShaderResources(i, 1, &m_state.vsSrv[i]);
      if (TestBit(m_mask.GSShaderResources, i)) m_device->GSSetShaderResources(i, 1, &m_state.gsSrv[i]);
      if (TestBit(m_mask.PSShaderResources, i)) m_device->PSSetShaderResources(i, 1, &m_state.psSrv[i]);
    }

    for (uint32_t i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; i++) {
      if (TestBit(m_mask.VSConstantBuffers, i)) m_device->VSSetConstantBuffers(i, 1, &m_state.vsCbo[i]);
      if (TestBit(m_mask.GSConstantBuffers, i)) m_device->GSSetConstantBuffers(i, 1, &m_state.gsCbo[i]);
      if (TestBit(m_mask.PSConstantBuffers, i)) m_device->PSSetConstantBuffers(i, 1, &m_state.psCbo[i]);
    }

    for (uint32_t i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; i++) {
      if (TestBit(m_mask.IAVertexBuffers, i)) {
        m_device->IASetVertexBuffers(i, 1,
          &m_state.iaVertexBuffers[i],
          &m_state.iaVertexOffsets[i],
          &m_state.iaVertexStrides[i]);
      }
    }

    if (TestBit(&m_mask.IAIndexBuffer, 0)) {
      m_device->IASetIndexBuffer(
        m_state.iaIndexBuffer.ptr(),
        m_state.iaIndexFormat,
        m_state.iaIndexOffset);
    }

    if (TestBit(&m_mask.IAInputLayout, 0))
      m_device->IASetInputLayout(m_state.iaInputLayout.ptr());

    if (TestBit(&m_mask.IAPrimitiveTopology, 0))
      m_device->IASetPrimitiveTopology(m_state.iaTopology);

    if (TestBit(&m_mask.OMRenderTargets, 0)) {
      m_device->OMSetRenderTargets(
        D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT,
        &m_state.omRtv[0], m_state.omDsv.ptr());
    }

    if (TestBit(&m_mask.OMDepthStencilState, 0)) {
      m_device->OMSetDepthStencilState(
        m_state.omDepthStencilState.ptr(),
        m_state.omStencilRef);
    }

    if (TestBit(&m_mask.OMBlendState, 0)) {
      m_device->OMSetBlendState(
        m_state.omBlendState.ptr(),
        m_state.omBlendFactor,
        m_state.omSampleMask);
    }

    if (TestBit(&m_mask.RSViewports, 0))
      m_device->RSSetViewports(m_state.rsViewportCount, m_state.rsViewports);

    if (TestBit(&m_mask.RSScissorRects, 0))
      m_device->RSSetScissorRects(m_state.rsScissorCount, m_state.rsScissors);

    if (TestBit(&m_mask.RSRasterizerState, 0))
      m_device->RSSetState(m_state.rsState.ptr());

    if (TestBit(&m_mask.SOBuffers, 0)) {
      m_device->SOSetTargets(
        D3D10_SO_BUFFER_SLOT_COUNT,
        &m_state.soBuffers[0],
        &m_state.soOffsets[0]);
    }

    if (TestBit(&m_mask.Predication, 0))
      m_device->SetPredication(m_state.predicate.ptr(), m_state.predicateInvert);

    return S_OK;
  }

  HRESULT STDMETHODCALLTYPE D3D10StateBlock::GetDevice(
          ID3D10Device**            ppDevice) {
    Logger::err("D3D10StateBlock::GetDevice: Stub");
    return E_NOTIMPL;
  }

  HRESULT STDMETHODCALLTYPE D3D10StateBlock::ReleaseAllDeviceObjects() {
    // Not entirely sure if this is correct?
    m_state = D3D10_STATE_BLOCK_STATE();
    return S_OK;
  }

  BOOL D3D10StateBlock::TestBit(
    const BYTE*                     pMask,
          UINT                      Idx) {
    uint32_t byte = Idx / 8;
    uint32_t bit  = Idx % 8;
    return (pMask[byte] & (1 << bit)) != 0;
  }

}

extern "C" {
  using namespace dxvk;

  HRESULT STDMETHODCALLTYPE D3D10CreateStateBlock(
          ID3D10Device*             pDevice,
          D3D10_STATE_BLOCK_MASK*   pStateBlockMask,
          ID3D10StateBlock**        ppStateBlock) {
    InitReturnPtr(ppStateBlock);

    if (!pDevice || !pStateBlockMask || !ppStateBlock)
      return E_INVALIDARG;

    *ppStateBlock = ref(new D3D10StateBlock(pDevice, pStateBlockMask));
    return S_OK;
  }

  HRESULT STDMETHODCALLTYPE D3D10StateBlockMaskEnableCapture(
          D3D10_STATE_BLOCK_MASK*   pMask,
          D3D10_DEVICE_STATE_TYPES  StateType,
          UINT                      StartIdx,
          UINT                      Count) {
    if (!pMask || !StateType || StateType > g_stateTypes.size())
      return E_INVALIDARG;

    auto pair = g_stateTypes[uint32_t(StateType) - 1];
    auto mask = reinterpret_cast<BYTE*>(pMask) + pair.first;

    if (StartIdx + Count > pair.second)
      return E_INVALIDARG;

    for (uint32_t i = StartIdx; i < StartIdx + Count; i++) {
      uint32_t byte = i / 8;
      uint32_t bit  = i % 8;
      mask[byte] |= 1 << bit;
    }

    return S_OK;
  }

  HRESULT STDMETHODCALLTYPE D3D10StateBlockMaskDisableCapture(
          D3D10_STATE_BLOCK_MASK*   pMask,
          D3D10_DEVICE_STATE_TYPES  StateType,
          UINT                      StartIdx,
          UINT                      Count) {
    if (!pMask || !StateType || StateType > g_stateTypes.size())
      return E_INVALIDARG;

    auto pair = g_stateTypes[uint32_t(StateType) - 1];
    auto mask = reinterpret_cast<BYTE*>(pMask) + pair.first;

    if (StartIdx + Count > pair.second)
      return E_INVALIDARG;

    for (uint32_t i = StartIdx; i < StartIdx + Count; i++) {
      uint32_t byte = i / 8;
      uint32_t bit  = i % 8;
      mask[byte] &= ~(1 << bit);
    }

    return S_OK;
  }

  HRESULT STDMETHODCALLTYPE D3D10StateBlockMaskEnableAll(
          D3D10_STATE_BLOCK_MASK*   pMask) {
    if (!pMask)
      return E_INVALIDARG;

    *pMask = D3D10_STATE_BLOCK_MASK();
    for (size_t i = 0; i < g_stateTypes.size(); i++) {
      D3D10StateBlockMaskEnableCapture(pMask,
        D3D10_DEVICE_STATE_TYPES(i + 1),
        0, g_stateTypes[i].second);
    }

    return S_OK;
  }

  HRESULT STDMETHODCALLTYPE D3D10StateBlockMaskDisableAll(
          D3D10_STATE_BLOCK_MASK* pMask) {
    if (!pMask)
      return E_INVALIDARG;

    *pMask = D3D10_STATE_BLOCK_MASK();
    return S_OK;
  }

  BOOL STDMETHODCALLTYPE D3D10StateBlockMaskGetSetting(
          D3D10_STATE_BLOCK_MASK*   pMask,
          D3D10_DEVICE_STATE_TYPES  StateType,
          UINT                      Idx) {
    if (!pMask || !StateType || StateType > g_stateTypes.size())
      return FALSE;

    auto pair = g_stateTypes[uint32_t(StateType) - 1];
    auto mask = reinterpret_cast<BYTE*>(pMask) + pair.first;

    if (Idx >= pair.second)
      return FALSE;

    uint32_t byte = Idx / 8;
    uint32_t bit  = Idx % 8;
    return (mask[byte] & (1 << bit)) != 0;
  }

  HRESULT STDMETHODCALLTYPE D3D10StateBlockMaskDifference(
          D3D10_STATE_BLOCK_MASK* pA,
          D3D10_STATE_BLOCK_MASK* pB,
          D3D10_STATE_BLOCK_MASK* pResult) {
    if (!pA || !pB || !pResult)
      return E_INVALIDARG;

    auto a = reinterpret_cast<const BYTE*>(pA);
    auto b = reinterpret_cast<const BYTE*>(pB);
    auto r = reinterpret_cast<BYTE*>(pResult);

    for (size_t i = 0; i < sizeof(D3D10_STATE_BLOCK_MASK); i++)
      r[i] = a[i] ^ b[i];
    return S_OK;
  }

  HRESULT STDMETHODCALLTYPE D3D10StateBlockMaskIntersect(
          D3D10_STATE_BLOCK_MASK*   pA,
          D3D10_STATE_BLOCK_MASK*   pB,
          D3D10_STATE_BLOCK_MASK*   pResult) {
    if (!pA || !pB || !pResult)
      return E_INVALIDARG;

    auto a = reinterpret_cast<const BYTE*>(pA);
    auto b = reinterpret_cast<const BYTE*>(pB);
    auto r = reinterpret_cast<BYTE*>(pResult);

    for (size_t i = 0; i < sizeof(D3D10_STATE_BLOCK_MASK); i++)
      r[i] = a[i] & b[i];
    return S_OK;
  }

  HRESULT STDMETHODCALLTYPE D3D10StateBlockMaskUnion(
          D3D10_STATE_BLOCK_MASK*   pA,
          D3D10_STATE_BLOCK_MASK*   pB,
          D3D10_STATE_BLOCK_MASK*   pResult) {
    if (!pA || !pB || !pResult)
      return E_INVALIDARG;

    auto a = reinterpret_cast<const BYTE*>(pA);
    auto b = reinterpret_cast<const BYTE*>(pB);
    auto r = reinterpret_cast<BYTE*>(pResult);

    for (size_t i = 0; i < sizeof(D3D10_STATE_BLOCK_MASK); i++)
      r[i] = a[i] | b[i];
    return S_OK;
  }

}


code:
#pragma once

#include "d3d10_include.h"
#include "d3d10_interfaces.h"

namespace dxvk {

  struct D3D10_STATE_BLOCK_STATE {
    Com<ID3D10VertexShader>       vs                  = { };
    Com<ID3D10SamplerState>       vsSso[D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT]              = { };
    Com<ID3D10ShaderResourceView> vsSrv[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT]       = { };
    Com<ID3D10Buffer>             vsCbo[D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT]  = { };
    Com<ID3D10GeometryShader>     gs                  = { };
    Com<ID3D10SamplerState>       gsSso[D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT]              = { };
    Com<ID3D10ShaderResourceView> gsSrv[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT]       = { };
    Com<ID3D10Buffer>             gsCbo[D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT]  = { };
    Com<ID3D10PixelShader>        ps                  = { };
    Com<ID3D10SamplerState>       psSso[D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT]              = { };
    Com<ID3D10ShaderResourceView> psSrv[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT]       = { };
    Com<ID3D10Buffer>             psCbo[D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT]  = { };
    Com<ID3D10Buffer>             iaVertexBuffers[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT] = { };
    UINT                          iaVertexOffsets[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT] = { };
    UINT                          iaVertexStrides[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT] = { };
    Com<ID3D10Buffer>             iaIndexBuffer       = { };
    DXGI_FORMAT                   iaIndexFormat       = DXGI_FORMAT_UNKNOWN;
    UINT                          iaIndexOffset       = 0;
    Com<ID3D10InputLayout>        iaInputLayout       = nullptr;
    D3D10_PRIMITIVE_TOPOLOGY      iaTopology          = D3D10_PRIMITIVE_TOPOLOGY_UNDEFINED;
    Com<ID3D10RenderTargetView>   omRtv[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT] = { };
    Com<ID3D10DepthStencilView>   omDsv               = { };
    Com<ID3D10DepthStencilState>  omDepthStencilState = { };
    UINT                          omStencilRef        = 0;
    Com<ID3D10BlendState>         omBlendState        = { };
    FLOAT                         omBlendFactor[4]    = { };
    UINT                          omSampleMask        = 0;
    UINT                          rsViewportCount     = 0;
    D3D10_VIEWPORT                rsViewports[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE] = { };
    UINT                          rsScissorCount      = 0;
    RECT                          rsScissors [D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE] = { };
    Com<ID3D10RasterizerState>    rsState             = { };
    Com<ID3D10Buffer>             soBuffers[D3D10_SO_BUFFER_SLOT_COUNT] = { };
    UINT                          soOffsets[D3D10_SO_BUFFER_SLOT_COUNT] = { };
    Com<ID3D10Predicate>          predicate           = { };
    BOOL                          predicateInvert     = FALSE;
  };

  class D3D10StateBlock : public ComObject<ID3D10StateBlock> {

  public:
    D3D10StateBlock(
            ID3D10Device*             pDevice,
      const D3D10_STATE_BLOCK_MASK*   pMask);

    ~D3D10StateBlock();

    HRESULT STDMETHODCALLTYPE QueryInterface(
            REFIID                    riid,
            void**                    ppvObject);

    HRESULT STDMETHODCALLTYPE Capture();

    HRESULT STDMETHODCALLTYPE Apply();

    HRESULT STDMETHODCALLTYPE GetDevice(
            ID3D10Device**            ppDevice);

    HRESULT STDMETHODCALLTYPE ReleaseAllDeviceObjects();

  private:

    Com<ID3D10Device>       m_device;
    D3D10_STATE_BLOCK_MASK  m_mask;
    D3D10_STATE_BLOCK_STATE m_state;

    static BOOL TestBit(
      const BYTE*                     pMask,
            UINT                      Idx);

  };

}


code:
#include "d3d10_texture.h"
#include "d3d10_device.h"

#include "../d3d11/d3d11_device.h"
#include "../d3d11/d3d11_context.h"
#include "../d3d11/d3d11_texture.h"

namespace dxvk {

  HRESULT STDMETHODCALLTYPE D3D10Texture1D::QueryInterface(
          REFIID                    riid,
          void**                    ppvObject) {
    return m_d3d11->QueryInterface(riid, ppvObject);
  }

  ULONG STDMETHODCALLTYPE D3D10Texture1D::AddRef() {
    return m_d3d11->AddRef();
  }

  ULONG STDMETHODCALLTYPE D3D10Texture1D::Release() {
    return m_d3d11->Release();
  }

  void STDMETHODCALLTYPE D3D10Texture1D::GetDevice(
          ID3D10Device**            ppDevice) {
    GetD3D10Device(m_d3d11, ppDevice);
  }

  HRESULT STDMETHODCALLTYPE D3D10Texture1D::GetPrivateData(
          REFGUID                   guid,
          UINT*                     pDataSize,
          void*                     pData) {
    return m_d3d11->GetPrivateData(guid, pDataSize, pData);
  }

  HRESULT STDMETHODCALLTYPE D3D10Texture1D::SetPrivateData(
          REFGUID                   guid,
          UINT                      DataSize,
    const void*                     pData) {
    return m_d3d11->SetPrivateData(guid, DataSize, pData);
  }

  HRESULT STDMETHODCALLTYPE D3D10Texture1D::SetPrivateDataInterface(
          REFGUID                   guid,
    const IUnknown*                 pData) {
    return m_d3d11->SetPrivateDataInterface(guid, pData);
  }

  void STDMETHODCALLTYPE D3D10Texture1D::GetType(
          D3D10_RESOURCE_DIMENSION* rType) {
    *rType = D3D10_RESOURCE_DIMENSION_TEXTURE1D;
  }

  void STDMETHODCALLTYPE D3D10Texture1D::SetEvictionPriority(
          UINT                      EvictionPriority) {
    m_d3d11->SetEvictionPriority(EvictionPriority);
  }

  UINT STDMETHODCALLTYPE D3D10Texture1D::GetEvictionPriority() {
    return m_d3d11->GetEvictionPriority();
  }

  HRESULT STDMETHODCALLTYPE D3D10Texture1D::Map(
          UINT                      Subresource,
          D3D10_MAP                 MapType,
          UINT                      MapFlags,
          void**                    ppData) {
    Com<ID3D11DeviceContext> ctx;
    GetD3D11Context(m_d3d11, &ctx);

    D3D11_MAPPED_SUBRESOURCE sr;
    HRESULT hr = ctx->Map(m_d3d11, Subresource,
      D3D11_MAP(MapType), MapFlags, &sr);

    if (FAILED(hr))
      return hr;

    if (ppData != nullptr) {
      *ppData = sr.pData;
      return S_OK;
    } return S_FALSE;
  }

  void STDMETHODCALLTYPE D3D10Texture1D::Unmap(
          UINT                      Subresource) {
    Com<ID3D11DeviceContext> ctx;
    GetD3D11Context(m_d3d11, &ctx);

    ctx->Unmap(m_d3d11, Subresource);
  }

  void STDMETHODCALLTYPE D3D10Texture1D::GetDesc(
          D3D10_TEXTURE1D_DESC*     pDesc) {
    D3D11_TEXTURE1D_DESC d3d11Desc;
    m_d3d11->GetDesc(&d3d11Desc);

    pDesc->Width           = d3d11Desc.Width;
    pDesc->MipLevels       = d3d11Desc.MipLevels;
    pDesc->ArraySize       = d3d11Desc.ArraySize;
    pDesc->Format          = d3d11Desc.Format;
    pDesc->Usage           = D3D10_USAGE(d3d11Desc.Usage);
    pDesc->BindFlags       = d3d11Desc.BindFlags;
    pDesc->CPUAccessFlags  = d3d11Desc.CPUAccessFlags;
    pDesc->MiscFlags       = ConvertD3D11ResourceFlags(d3d11Desc.MiscFlags);
  }

  HRESULT STDMETHODCALLTYPE D3D10Texture2D::QueryInterface(
          REFIID                    riid,
          void**                    ppvObject) {
    return m_d3d11->QueryInterface(riid, ppvObject);
  }

  ULONG STDMETHODCALLTYPE D3D10Texture2D::AddRef() {
    return m_d3d11->AddRef();
  }

  ULONG STDMETHODCALLTYPE D3D10Texture2D::Release() {
    return m_d3d11->Release();
  }

  void STDMETHODCALLTYPE D3D10Texture2D::GetDevice(
          ID3D10Device**            ppDevice) {
    GetD3D10Device(m_d3d11, ppDevice);
  }

  HRESULT STDMETHODCALLTYPE D3D10Texture2D::GetPrivateData(
          REFGUID                   guid,
          UINT*                     pDataSize,
          void*                     pData) {
    return m_d3d11->GetPrivateData(guid, pDataSize, pData);
  }

  HRESULT STDMETHODCALLTYPE D3D10Texture2D::SetPrivateData(
          REFGUID                   guid,
          UINT                      DataSize,
    const void*                     pData) {
    return m_d3d11->SetPrivateData(guid, DataSize, pData);
  }

  HRESULT STDMETHODCALLTYPE D3D10Texture2D::SetPrivateDataInterface(
          REFGUID                   guid,
    const IUnknown*                 pData) {
    return m_d3d11->SetPrivateDataInterface(guid, pData);
  }

  void STDMETHODCALLTYPE D3D10Texture2D::GetType(
          D3D10_RESOURCE_DIMENSION* rType) {
    *rType = D3D10_RESOURCE_DIMENSION_TEXTURE2D;
  }

  void STDMETHODCALLTYPE D3D10Texture2D::SetEvictionPriority(
          UINT                      EvictionPriority) {
    m_d3d11->SetEvictionPriority(EvictionPriority);
  }

  UINT STDMETHODCALLTYPE D3D10Texture2D::GetEvictionPriority() {
    return m_d3d11->GetEvictionPriority();
  }

  HRESULT STDMETHODCALLTYPE D3D10Texture2D::Map(
          UINT                      Subresource,
          D3D10_MAP                 MapType,
          UINT                      MapFlags,
          D3D10_MAPPED_TEXTURE2D*   pMappedTex2D) {
    Com<ID3D11DeviceContext> ctx;
    GetD3D11Context(m_d3d11, &ctx);

    D3D11_MAPPED_SUBRESOURCE sr;
    HRESULT hr = ctx->Map(m_d3d11, Subresource,
      D3D11_MAP(MapType), MapFlags, &sr);

    if (FAILED(hr))
      return hr;

    if (pMappedTex2D != nullptr) {
      pMappedTex2D->pData    = sr.pData;
      pMappedTex2D->RowPitch = sr.RowPitch;
      return S_OK;
    } return S_FALSE;
  }

  void STDMETHODCALLTYPE D3D10Texture2D::Unmap(
          UINT                      Subresource) {
    Com<ID3D11DeviceContext> ctx;
    GetD3D11Context(m_d3d11, &ctx);

    ctx->Unmap(m_d3d11, Subresource);
  }

  void STDMETHODCALLTYPE D3D10Texture2D::GetDesc(
          D3D10_TEXTURE2D_DESC*     pDesc) {
    D3D11_TEXTURE2D_DESC d3d11Desc;
    m_d3d11->GetDesc(&d3d11Desc);

    pDesc->Width           = d3d11Desc.Width;
    pDesc->Height          = d3d11Desc.Height;
    pDesc->MipLevels       = d3d11Desc.MipLevels;
    pDesc->ArraySize       = d3d11Desc.ArraySize;
    pDesc->Format          = d3d11Desc.Format;
    pDesc->SampleDesc      = d3d11Desc.SampleDesc;
    pDesc->Usage           = D3D10_USAGE(d3d11Desc.Usage);
    pDesc->BindFlags       = d3d11Desc.BindFlags;
    pDesc->CPUAccessFlags  = d3d11Desc.CPUAccessFlags;
    pDesc->MiscFlags       = ConvertD3D11ResourceFlags(d3d11Desc.MiscFlags);
  }

  HRESULT STDMETHODCALLTYPE D3D10Texture3D::QueryInterface(
          REFIID                    riid,
          void**                    ppvObject) {
    return m_d3d11->QueryInterface(riid, ppvObject);
  }

  ULONG STDMETHODCALLTYPE D3D10Texture3D::AddRef() {
    return m_d3d11->AddRef();
  }

  ULONG STDMETHODCALLTYPE D3D10Texture3D::Release() {
    return m_d3d11->Release();
  }

  void STDMETHODCALLTYPE D3D10Texture3D::GetDevice(
          ID3D10Device**            ppDevice) {
    GetD3D10Device(m_d3d11, ppDevice);
  }

  HRESULT STDMETHODCALLTYPE D3D10Texture3D::GetPrivateData(
          REFGUID                   guid,
          UINT*                     pDataSize,
          void*                     pData) {
    return m_d3d11->GetPrivateData(guid, pDataSize, pData);
  }

  HRESULT STDMETHODCALLTYPE D3D10Texture3D::SetPrivateData(
          REFGUID                   guid,
          UINT                      DataSize,
    const void*                     pData) {
    return m_d3d11->SetPrivateData(guid, DataSize, pData);
  }

  HRESULT STDMETHODCALLTYPE D3D10Texture3D::SetPrivateDataInterface(
          REFGUID                   guid,
    const IUnknown*                 pData) {
    return m_d3d11->SetPrivateDataInterface(guid, pData);
  }

  void STDMETHODCALLTYPE D3D10Texture3D::GetType(
          D3D10_RESOURCE_DIMENSION* rType) {
    *rType = D3D10_RESOURCE_DIMENSION_TEXTURE3D;
  }

  void STDMETHODCALLTYPE D3D10Texture3D::SetEvictionPriority(
          UINT                      EvictionPriority) {
    m_d3d11->SetEvictionPriority(EvictionPriority);
  }

  UINT STDMETHODCALLTYPE D3D10Texture3D::GetEvictionPriority() {
    return m_d3d11->GetEvictionPriority();
  }

  HRESULT STDMETHODCALLTYPE D3D10Texture3D::Map(
          UINT                      Subresource,
          D3D10_MAP                 MapType,
          UINT                      MapFlags,
          D3D10_MAPPED_TEXTURE3D*   pMappedTex3D) {
    Com<ID3D11DeviceContext> ctx;
    GetD3D11Context(m_d3d11, &ctx);

    D3D11_MAPPED_SUBRESOURCE sr;
    HRESULT hr = ctx->Map(m_d3d11, Subresource,
      D3D11_MAP(MapType), MapFlags, &sr);

    if (FAILED(hr))
      return hr;

    if (pMappedTex3D != nullptr) {
      pMappedTex3D->pData      = sr.pData;
      pMappedTex3D->RowPitch   = sr.RowPitch;
      pMappedTex3D->DepthPitch = sr.DepthPitch;
      return S_OK;
    } return S_FALSE;
  }

  void STDMETHODCALLTYPE D3D10Texture3D::Unmap(
          UINT                      Subresource) {
    Com<ID3D11DeviceContext> ctx;
    GetD3D11Context(m_d3d11, &ctx);

    ctx->Unmap(m_d3d11, Subresource);
  }

  void STDMETHODCALLTYPE D3D10Texture3D::GetDesc(
          D3D10_TEXTURE3D_DESC*     pDesc) {
    D3D11_TEXTURE3D_DESC d3d11Desc;
    m_d3d11->GetDesc(&d3d11Desc);

    pDesc->Width           = d3d11Desc.Width;
    pDesc->Height          = d3d11Desc.Height;
    pDesc->Depth           = d3d11Desc.Depth;
    pDesc->MipLevels       = d3d11Desc.MipLevels;
    pDesc->Format          = d3d11Desc.Format;
    pDesc->Usage           = D3D10_USAGE(d3d11Desc.Usage);
    pDesc->BindFlags       = d3d11Desc.BindFlags;
    pDesc->CPUAccessFlags  = d3d11Desc.CPUAccessFlags;
    pDesc->MiscFlags       = ConvertD3D11ResourceFlags(d3d11Desc.MiscFlags);
  }

}


code:
#pragma once

#include "d3d10_util.h"

namespace dxvk {

  class D3D10Device;
  class D3D11Device;
  class D3D11Texture1D;
  class D3D11Texture2D;
  class D3D11Texture3D;

  ///////////////////////////////////////////
  //      D 3 D 1 0 T E X T U R E 1 D
  class D3D10Texture1D : public ID3D10Texture1D {

  public:

    D3D10Texture1D(D3D11Texture1D* pParent)
    : m_d3d11(pParent) { }

    HRESULT STDMETHODCALLTYPE QueryInterface(
            REFIID                    riid,
            void**                    ppvObject);

    ULONG STDMETHODCALLTYPE AddRef();

    ULONG STDMETHODCALLTYPE Release();

    void STDMETHODCALLTYPE GetDevice(
            ID3D10Device**            ppDevice);

    HRESULT STDMETHODCALLTYPE GetPrivateData(
            REFGUID                   guid,
            UINT*                     pDataSize,
            void*                     pData);

    HRESULT STDMETHODCALLTYPE SetPrivateData(
            REFGUID                   guid,
            UINT                      DataSize,
      const void*                     pData);

    HRESULT STDMETHODCALLTYPE SetPrivateDataInterface(
            REFGUID                   guid,
      const IUnknown*                 pData);

    void STDMETHODCALLTYPE GetType(
            D3D10_RESOURCE_DIMENSION* rType);

    void STDMETHODCALLTYPE SetEvictionPriority(
            UINT                      EvictionPriority);

    UINT STDMETHODCALLTYPE GetEvictionPriority();

    HRESULT STDMETHODCALLTYPE Map(
            UINT                      Subresource,
            D3D10_MAP                 MapType,
            UINT                      MapFlags,
            void**                    ppData);

    void STDMETHODCALLTYPE Unmap(
            UINT                      Subresource);

    void STDMETHODCALLTYPE GetDesc(
            D3D10_TEXTURE1D_DESC*     pDesc);

    D3D11Texture1D* GetD3D11Iface() {
      return m_d3d11;
    }

  private:

    D3D11Texture1D* m_d3d11;

  };

  ///////////////////////////////////////////
  //      D 3 D 1 0 T E X T U R E 2 D
  class D3D10Texture2D : public ID3D10Texture2D {

  public:

    D3D10Texture2D(D3D11Texture2D* pParent)
    :  m_d3d11(pParent) { }

    HRESULT STDMETHODCALLTYPE QueryInterface(
            REFIID                    riid,
            void**                    ppvObject);

    ULONG STDMETHODCALLTYPE AddRef();

    ULONG STDMETHODCALLTYPE Release();

    void STDMETHODCALLTYPE GetDevice(
            ID3D10Device**            ppDevice);

    HRESULT STDMETHODCALLTYPE GetPrivateData(
            REFGUID                   guid,
            UINT*                     pDataSize,
            void*                     pData);

    HRESULT STDMETHODCALLTYPE SetPrivateData(
            REFGUID                   guid,
            UINT                      DataSize,
      const void*                     pData);

    HRESULT STDMETHODCALLTYPE SetPrivateDataInterface(
            REFGUID                   guid,
      const IUnknown*                 pData);

    void STDMETHODCALLTYPE GetType(
            D3D10_RESOURCE_DIMENSION* rType);

    void STDMETHODCALLTYPE SetEvictionPriority(
            UINT                      EvictionPriority);

    UINT STDMETHODCALLTYPE GetEvictionPriority();

    HRESULT STDMETHODCALLTYPE Map(
            UINT                      Subresource,
            D3D10_MAP                 MapType,
            UINT                      MapFlags,
            D3D10_MAPPED_TEXTURE2D*   pMappedTex2D);

    void STDMETHODCALLTYPE Unmap(
            UINT                      Subresource);

    void STDMETHODCALLTYPE GetDesc(
            D3D10_TEXTURE2D_DESC*     pDesc);

    D3D11Texture2D* GetD3D11Iface() {
      return m_d3d11;
    }

  private:

    D3D11Texture2D* m_d3d11;

  };

  ///////////////////////////////////////////
  //      D 3 D 1 0 T E X T U R E 3 D
  class D3D10Texture3D : public ID3D10Texture3D {

  public:

    D3D10Texture3D(D3D11Texture3D* pParent)
    : m_d3d11(pParent) { }

    HRESULT STDMETHODCALLTYPE QueryInterface(
            REFIID                    riid,
            void**                    ppvObject);

    ULONG STDMETHODCALLTYPE AddRef();

    ULONG STDMETHODCALLTYPE Release();

    void STDMETHODCALLTYPE GetDevice(
            ID3D10Device**            ppDevice);

    HRESULT STDMETHODCALLTYPE GetPrivateData(
            REFGUID                   guid,
            UINT*                     pDataSize,
            void*                     pData);

    HRESULT STDMETHODCALLTYPE SetPrivateData(
            REFGUID                   guid,
            UINT                      DataSize,
      const void*                     pData);

    HRESULT STDMETHODCALLTYPE SetPrivateDataInterface(
            REFGUID                   guid,
      const IUnknown*                 pData);

    void STDMETHODCALLTYPE GetType(
            D3D10_RESOURCE_DIMENSION* rType);

    void STDMETHODCALLTYPE SetEvictionPriority(
            UINT                      EvictionPriority);

    UINT STDMETHODCALLTYPE GetEvictionPriority();

    HRESULT STDMETHODCALLTYPE Map(
            UINT                      Subresource,
            D3D10_MAP                 MapType,
            UINT                      MapFlags,
            D3D10_MAPPED_TEXTURE3D*   pMappedTex3D);

    void STDMETHODCALLTYPE Unmap(
            UINT                      Subresource);

    void STDMETHODCALLTYPE GetDesc(
            D3D10_TEXTURE3D_DESC*     pDesc);

    D3D11Texture3D* GetD3D11Iface() {
      return m_d3d11;
    }

  private:

    D3D11Texture3D* m_d3d11;

  };

}