# Copyright 2020 The ANGLE Project Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# This file houses the build configuration for the ANGLE D3D back-ends.

import("../../../../gni/angle.gni")

assert(angle_enable_d3d11 || angle_enable_d3d9)

_d3d_shared_sources = [
  "BufferD3D.cpp",
  "BufferD3D.h",
  "CompilerD3D.cpp",
  "CompilerD3D.h",
  "ContextD3D.h",
  "DeviceD3D.cpp",
  "DeviceD3D.h",
  "DisplayD3D.cpp",
  "DisplayD3D.h",
  "DynamicHLSL.cpp",
  "DynamicHLSL.h",
  "DynamicImage2DHLSL.cpp",
  "DynamicImage2DHLSL.h",
  "EGLImageD3D.cpp",
  "EGLImageD3D.h",
  "FramebufferD3D.cpp",
  "FramebufferD3D.h",
  "HLSLCompiler.cpp",
  "HLSLCompiler.h",
  "ImageD3D.cpp",
  "ImageD3D.h",
  "IndexBuffer.cpp",
  "IndexBuffer.h",
  "IndexDataManager.cpp",
  "IndexDataManager.h",
  "NativeWindowD3D.cpp",
  "NativeWindowD3D.h",
  "ProgramD3D.cpp",
  "ProgramD3D.h",
  "RenderTargetD3D.cpp",
  "RenderTargetD3D.h",
  "RenderbufferD3D.cpp",
  "RenderbufferD3D.h",
  "RendererD3D.cpp",
  "RendererD3D.h",
  "SamplerD3D.h",
  "ShaderD3D.cpp",
  "ShaderD3D.h",
  "ShaderExecutableD3D.cpp",
  "ShaderExecutableD3D.h",
  "SurfaceD3D.cpp",
  "SurfaceD3D.h",
  "SwapChainD3D.cpp",
  "SwapChainD3D.h",
  "TextureD3D.cpp",
  "TextureD3D.h",
  "TextureStorage.h",
  "VertexBuffer.cpp",
  "VertexBuffer.h",
  "VertexDataManager.cpp",
  "VertexDataManager.h",
  "formatutilsD3D.h",
]

if (!angle_is_winuwp) {
  _d3d_shared_sources += [
    "../../../third_party/systeminfo/SystemInfo.cpp",
    "../../../third_party/systeminfo/SystemInfo.h",
  ]
}

if (angle_enable_d3d9) {
  _d3d9_backend_sources = [
    "d3d9/Blit9.cpp",
    "d3d9/Blit9.h",
    "d3d9/Buffer9.cpp",
    "d3d9/Buffer9.h",
    "d3d9/Context9.cpp",
    "d3d9/Context9.h",
    "d3d9/DebugAnnotator9.cpp",
    "d3d9/DebugAnnotator9.h",
    "d3d9/Fence9.cpp",
    "d3d9/Fence9.h",
    "d3d9/Framebuffer9.cpp",
    "d3d9/Framebuffer9.h",
    "d3d9/Image9.cpp",
    "d3d9/Image9.h",
    "d3d9/IndexBuffer9.cpp",
    "d3d9/IndexBuffer9.h",
    "d3d9/NativeWindow9.cpp",
    "d3d9/NativeWindow9.h",
    "d3d9/Query9.cpp",
    "d3d9/Query9.h",
    "d3d9/RenderTarget9.cpp",
    "d3d9/RenderTarget9.h",
    "d3d9/Renderer9.cpp",
    "d3d9/Renderer9.h",
    "d3d9/ShaderCache.h",
    "d3d9/ShaderExecutable9.cpp",
    "d3d9/ShaderExecutable9.h",
    "d3d9/StateManager9.cpp",
    "d3d9/StateManager9.h",
    "d3d9/SwapChain9.cpp",
    "d3d9/SwapChain9.h",
    "d3d9/TextureStorage9.cpp",
    "d3d9/TextureStorage9.h",
    "d3d9/VertexArray9.h",
    "d3d9/VertexBuffer9.cpp",
    "d3d9/VertexBuffer9.h",
    "d3d9/VertexDeclarationCache.cpp",
    "d3d9/VertexDeclarationCache.h",
    "d3d9/formatutils9.cpp",
    "d3d9/formatutils9.h",
    "d3d9/renderer9_utils.cpp",
    "d3d9/renderer9_utils.h",
    "d3d9/shaders/compiled/componentmaskpremultps.h",
    "d3d9/shaders/compiled/componentmaskps.h",
    "d3d9/shaders/compiled/componentmaskunmultps.h",
    "d3d9/shaders/compiled/luminancepremultps.h",
    "d3d9/shaders/compiled/luminanceps.h",
    "d3d9/shaders/compiled/luminanceunmultps.h",
    "d3d9/shaders/compiled/passthroughps.h",
    "d3d9/shaders/compiled/standardvs.h",
    "d3d9/vertexconversion.h",
  ]
}

if (angle_enable_d3d11) {
  _d3d11_backend_sources = [
    "d3d11/Blit11.cpp",
    "d3d11/Blit11.h",
    "d3d11/Blit11Helper_autogen.inc",
    "d3d11/Buffer11.cpp",
    "d3d11/Buffer11.h",
    "d3d11/Clear11.cpp",
    "d3d11/Clear11.h",
    "d3d11/Context11.cpp",
    "d3d11/Context11.h",
    "d3d11/DebugAnnotator11.cpp",
    "d3d11/DebugAnnotator11.h",
    "d3d11/ExternalImageSiblingImpl11.cpp",
    "d3d11/ExternalImageSiblingImpl11.h",
    "d3d11/Fence11.cpp",
    "d3d11/Fence11.h",
    "d3d11/Framebuffer11.cpp",
    "d3d11/Framebuffer11.h",
    "d3d11/Image11.cpp",
    "d3d11/Image11.h",
    "d3d11/IndexBuffer11.cpp",
    "d3d11/IndexBuffer11.h",
    "d3d11/InputLayoutCache.cpp",
    "d3d11/InputLayoutCache.h",
    "d3d11/MappedSubresourceVerifier11.cpp",
    "d3d11/MappedSubresourceVerifier11.h",
    "d3d11/NativeWindow11.h",
    "d3d11/PixelTransfer11.cpp",
    "d3d11/PixelTransfer11.h",
    "d3d11/Program11.cpp",
    "d3d11/Program11.h",
    "d3d11/ProgramPipeline11.cpp",
    "d3d11/ProgramPipeline11.h",
    "d3d11/Query11.cpp",
    "d3d11/Query11.h",
    "d3d11/RenderStateCache.cpp",
    "d3d11/RenderStateCache.h",
    "d3d11/RenderTarget11.cpp",
    "d3d11/RenderTarget11.h",
    "d3d11/Renderer11.cpp",
    "d3d11/Renderer11.h",
    "d3d11/ResourceManager11.cpp",
    "d3d11/ResourceManager11.h",
    "d3d11/ShaderExecutable11.cpp",
    "d3d11/ShaderExecutable11.h",
    "d3d11/StateManager11.cpp",
    "d3d11/StateManager11.h",
    "d3d11/StreamProducerD3DTexture.cpp",
    "d3d11/StreamProducerD3DTexture.h",
    "d3d11/SwapChain11.cpp",
    "d3d11/SwapChain11.h",
    "d3d11/TextureStorage11.cpp",
    "d3d11/TextureStorage11.h",
    "d3d11/TransformFeedback11.cpp",
    "d3d11/TransformFeedback11.h",
    "d3d11/Trim11.cpp",
    "d3d11/Trim11.h",
    "d3d11/VertexArray11.cpp",
    "d3d11/VertexArray11.h",
    "d3d11/VertexBuffer11.cpp",
    "d3d11/VertexBuffer11.h",
    "d3d11/formatutils11.cpp",
    "d3d11/formatutils11.h",
    "d3d11/renderer11_utils.cpp",
    "d3d11/renderer11_utils.h",
    "d3d11/shaders/compiled/buffertotexture11_gs.h",
    "d3d11/shaders/compiled/buffertotexture11_ps_4f.h",
    "d3d11/shaders/compiled/buffertotexture11_ps_4i.h",
    "d3d11/shaders/compiled/buffertotexture11_ps_4ui.h",
    "d3d11/shaders/compiled/buffertotexture11_vs.h",
    "d3d11/shaders/compiled/clear11_fl9vs.h",
    "d3d11/shaders/compiled/clear11multiviewgs.h",
    "d3d11/shaders/compiled/clear11multiviewvs.h",
    "d3d11/shaders/compiled/clear11vs.h",
    "d3d11/shaders/compiled/cleardepth11ps.h",
    "d3d11/shaders/compiled/clearfloat11_fl9ps.h",
    "d3d11/shaders/compiled/clearfloat11ps1.h",
    "d3d11/shaders/compiled/clearfloat11ps2.h",
    "d3d11/shaders/compiled/clearfloat11ps3.h",
    "d3d11/shaders/compiled/clearfloat11ps4.h",
    "d3d11/shaders/compiled/clearfloat11ps5.h",
    "d3d11/shaders/compiled/clearfloat11ps6.h",
    "d3d11/shaders/compiled/clearfloat11ps7.h",
    "d3d11/shaders/compiled/clearfloat11ps8.h",
    "d3d11/shaders/compiled/clearsint11ps1.h",
    "d3d11/shaders/compiled/clearsint11ps2.h",
    "d3d11/shaders/compiled/clearsint11ps3.h",
    "d3d11/shaders/compiled/clearsint11ps4.h",
    "d3d11/shaders/compiled/clearsint11ps5.h",
    "d3d11/shaders/compiled/clearsint11ps6.h",
    "d3d11/shaders/compiled/clearsint11ps7.h",
    "d3d11/shaders/compiled/clearsint11ps8.h",
    "d3d11/shaders/compiled/clearuint11ps1.h",
    "d3d11/shaders/compiled/clearuint11ps2.h",
    "d3d11/shaders/compiled/clearuint11ps3.h",
    "d3d11/shaders/compiled/clearuint11ps4.h",
    "d3d11/shaders/compiled/clearuint11ps5.h",
    "d3d11/shaders/compiled/clearuint11ps6.h",
    "d3d11/shaders/compiled/clearuint11ps7.h",
    "d3d11/shaders/compiled/clearuint11ps8.h",
    "d3d11/shaders/compiled/passthrough2d11vs.h",
    "d3d11/shaders/compiled/passthrough3d11gs.h",
    "d3d11/shaders/compiled/passthrough3d11vs.h",
    "d3d11/shaders/compiled/passthroughdepth2d11ps.h",
    "d3d11/shaders/compiled/passthroughrgba2dms11ps.h",
    "d3d11/shaders/compiled/resolvecolor2dps.h",
    "d3d11/shaders/compiled/resolvedepth11_ps.h",
    "d3d11/shaders/compiled/resolvedepthstencil11_ps.h",
    "d3d11/shaders/compiled/resolvedepthstencil11_vs.h",
    "d3d11/shaders/compiled/resolvestencil11_ps.h",
    "d3d11/shaders/compiled/swizzlef2darrayps.h",
    "d3d11/shaders/compiled/swizzlef2dps.h",
    "d3d11/shaders/compiled/swizzlef3dps.h",
    "d3d11/shaders/compiled/swizzlei2darrayps.h",
    "d3d11/shaders/compiled/swizzlei2dps.h",
    "d3d11/shaders/compiled/swizzlei3dps.h",
    "d3d11/shaders/compiled/swizzleui2darrayps.h",
    "d3d11/shaders/compiled/swizzleui2dps.h",
    "d3d11/shaders/compiled/swizzleui3dps.h",
    "d3d11/texture_format_table.cpp",
    "d3d11/texture_format_table.h",
    "d3d11/texture_format_table_autogen.cpp",
    "d3d11/texture_format_table_utils.h",
  ]

  if (angle_is_winuwp) {
    _d3d11_backend_sources += [
      "d3d11/winrt/CoreWindowNativeWindow.cpp",
      "d3d11/winrt/CoreWindowNativeWindow.h",
      "d3d11/winrt/InspectableNativeWindow.cpp",
      "d3d11/winrt/InspectableNativeWindow.h",
      "d3d11/winrt/NativeWindow11WinRT.cpp",
      "d3d11/winrt/NativeWindow11WinRT.h",
      "d3d11/winrt/SwapChainPanelNativeWindow.cpp",
      "d3d11/winrt/SwapChainPanelNativeWindow.h",
    ]
  } else {
    _d3d11_backend_sources += [
      "d3d11/converged/CompositorNativeWindow11.cpp",
      "d3d11/converged/CompositorNativeWindow11.h",
      "d3d11/win32/NativeWindow11Win32.cpp",
      "d3d11/win32/NativeWindow11Win32.h",
    ]
  }

  import("d3d11/d3d11_blit_shaders_autogen.gni")
  _d3d11_backend_sources += libangle_d3d11_blit_shaders
}

config("angle_d3d_shared_config") {
  defines = [ "ANGLE_PRELOADED_D3DCOMPILER_MODULE_NAMES={ " + "\"d3dcompiler_47.dll\", \"d3dcompiler_46.dll\", \"d3dcompiler_43.dll\" }" ]
}

angle_source_set("angle_d3d_shared") {
  sources = _d3d_shared_sources
  public_deps = [
    "$angle_root:angle_d3d_format_tables",
    "$angle_root:angle_gpu_info_util",
    "$angle_root:angle_image_util",
    "$angle_root:libANGLE_headers",
  ]
  public_configs = [ ":angle_d3d_shared_config" ]
}

if (angle_enable_d3d9) {
  config("angle_d3d9_backend_config") {
    defines = [ "ANGLE_ENABLE_D3D9" ]
    ldflags = [ "/DELAYLOAD:d3d9.dll" ]
  }

  angle_source_set("angle_d3d9_backend") {
    sources = _d3d9_backend_sources
    libs = [
      "d3d9.lib",
      "delayimp.lib",
    ]
    public_deps = [ ":angle_d3d_shared" ]
    public_configs = [ ":angle_d3d9_backend_config" ]
  }
}

if (angle_enable_d3d11) {
  config("angle_d3d11_backend_config") {
    defines = [ "ANGLE_ENABLE_D3D11" ]
  }

  angle_source_set("angle_d3d11_backend") {
    sources = _d3d11_backend_sources

    libs = [ "dxguid.lib" ]

    public_deps = [ ":angle_d3d_shared" ]
    public_configs = [ ":angle_d3d11_backend_config" ]
  }
}
