blob: ceb30b974e1c5014681eacf49b9d4d464e0c7515 [file] [log] [blame]
// Copyright 2023 The Dawn & Tint Authors
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// D3D12Backend.cpp: contains the definition of symbols exported by D3D12Backend.h so that they
// can be compiled twice: once export (shared library), once not exported (static library)
#include "dawn/native/D3DBackend.h"
#include <memory>
#include <utility>
#include "dawn/common/Log.h"
#include "dawn/native/Adapter.h"
#include "dawn/native/d3d/DeviceD3D.h"
#include "dawn/native/d3d/ExternalImageDXGIImpl.h"
#include "dawn/native/d3d/Forward.h"
#include "dawn/native/d3d/PhysicalDeviceD3D.h"
namespace dawn::native::d3d {
RequestAdapterOptionsLUID::RequestAdapterOptionsLUID() {
sType = wgpu::SType::RequestAdapterOptionsLUID;
}
Microsoft::WRL::ComPtr<IDXGIAdapter> GetDXGIAdapter(WGPUAdapter adapter) {
return ToBackend(FromAPI(adapter)->GetPhysicalDevice())->GetHardwareAdapter();
}
ExternalImageDescriptorDXGISharedHandle::ExternalImageDescriptorDXGISharedHandle()
: ExternalImageDescriptor(ExternalImageType::DXGISharedHandle) {}
ExternalImageDescriptorD3D11Texture::ExternalImageDescriptorD3D11Texture()
: ExternalImageDescriptor(ExternalImageType::D3D11Texture) {}
ExternalImageDXGI::ExternalImageDXGI(std::unique_ptr<ExternalImageDXGIImpl> impl)
: mImpl(std::move(impl)) {
DAWN_ASSERT(mImpl != nullptr);
}
ExternalImageDXGI::~ExternalImageDXGI() {
auto deviceLock = mImpl->GetScopedDeviceLock();
mImpl = nullptr;
}
bool ExternalImageDXGI::IsValid() const {
auto deviceLock = mImpl->GetScopedDeviceLock();
return mImpl->IsValid();
}
WGPUTexture ExternalImageDXGI::BeginAccess(
const ExternalImageDXGIBeginAccessDescriptor* descriptor) {
auto deviceLock = mImpl->GetScopedDeviceLock();
return mImpl->BeginAccess(descriptor);
}
void ExternalImageDXGI::EndAccess(WGPUTexture texture,
ExternalImageDXGIFenceDescriptor* signalFence) {
auto deviceLock = mImpl->GetScopedDeviceLock();
mImpl->EndAccess(texture, signalFence);
}
// static
std::unique_ptr<ExternalImageDXGI> ExternalImageDXGI::Create(
WGPUDevice device,
const ExternalImageDescriptor* descriptor) {
Device* backendDevice = ToBackend(FromAPI(device));
auto deviceLock = backendDevice->GetScopedLock();
std::unique_ptr<ExternalImageDXGIImpl> impl =
backendDevice->CreateExternalImageDXGIImpl(descriptor);
if (!impl) {
dawn::ErrorLog() << "Failed to create DXGI external image";
return nullptr;
}
return std::unique_ptr<ExternalImageDXGI>(new ExternalImageDXGI(std::move(impl)));
}
} // namespace dawn::native::d3d