diff --git a/src/dawn/native/BUILD.gn b/src/dawn/native/BUILD.gn index a9c3ae698a..2beee921be 100644 --- a/src/dawn/native/BUILD.gn +++ b/src/dawn/native/BUILD.gn @@ -433,6 +433,8 @@ source_set("sources") { "d3d11/BindGroupLayoutD3D11.h", "d3d11/CommandRecordingContextD3D11.cpp", "d3d11/CommandRecordingContextD3D11.h", + "d3d11/ComputePipelineD3D11.cpp", + "d3d11/ComputePipelineD3D11.h", "d3d11/D3D11Backend.cpp", "d3d11/DeviceD3D11.cpp", "d3d11/DeviceD3D11.h", diff --git a/src/dawn/native/CMakeLists.txt b/src/dawn/native/CMakeLists.txt index 533d63da4d..6e5a6a0c75 100644 --- a/src/dawn/native/CMakeLists.txt +++ b/src/dawn/native/CMakeLists.txt @@ -290,6 +290,8 @@ if (DAWN_ENABLE_D3D11) "d3d11/BindGroupLayoutD3D11.h" "d3d11/CommandRecordingContextD3D11.cpp" "d3d11/CommandRecordingContextD3D11.h" + "d3d11/ComputePipelineD3D11.cpp" + "d3d11/ComputePipelineD3D11.h" "d3d11/D3D11Backend.cpp" "d3d11/DeviceD3D11.cpp" "d3d11/DeviceD3D11.h" diff --git a/src/dawn/native/d3d11/ComputePipelineD3D11.cpp b/src/dawn/native/d3d11/ComputePipelineD3D11.cpp new file mode 100644 index 0000000000..8744a0f662 --- /dev/null +++ b/src/dawn/native/d3d11/ComputePipelineD3D11.cpp @@ -0,0 +1,88 @@ +// Copyright 2023 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "dawn/native/d3d11/ComputePipelineD3D11.h" + +#include +#include + +#include "dawn/native/CreatePipelineAsyncTask.h" +#include "dawn/native/d3d/D3DError.h" +#include "dawn/native/d3d11/DeviceD3D11.h" +#include "dawn/native/d3d11/ShaderModuleD3D11.h" + +namespace dawn::native::d3d11 { + +// static +Ref ComputePipeline::CreateUninitialized( + Device* device, + const ComputePipelineDescriptor* descriptor) { + return AcquireRef(new ComputePipeline(device, descriptor)); +} + +ComputePipeline::~ComputePipeline() = default; + +void ComputePipeline::DestroyImpl() { + ComputePipelineBase::DestroyImpl(); +} + +MaybeError ComputePipeline::Initialize() { + Device* device = ToBackend(GetDevice()); + uint32_t compileFlags = 0; + + if (!device->IsToggleEnabled(Toggle::UseDXC) && + !device->IsToggleEnabled(Toggle::FxcOptimizations)) { + compileFlags |= D3DCOMPILE_OPTIMIZATION_LEVEL0; + } + + if (device->IsToggleEnabled(Toggle::EmitHLSLDebugSymbols)) { + compileFlags |= D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION; + } + + // Tint does matrix multiplication expecting row major matrices + compileFlags |= D3DCOMPILE_PACK_MATRIX_ROW_MAJOR; + + // FXC can miscompile code that depends on special float values (NaN, INF, etc) when IEEE + // strictness is not enabled. See crbug.com/tint/976. + compileFlags |= D3DCOMPILE_IEEE_STRICTNESS; + + const ProgrammableStage& programmableStage = GetStage(SingleShaderStage::Compute); + + d3d::CompiledShader compiledShader; + DAWN_TRY_ASSIGN(compiledShader, ToBackend(programmableStage.module) + ->Compile(programmableStage, SingleShaderStage::Compute, + ToBackend(GetLayout()), compileFlags)); + DAWN_TRY(CheckHRESULT(device->GetD3D11Device()->CreateComputeShader( + compiledShader.shaderBlob.Data(), compiledShader.shaderBlob.Size(), + nullptr, &mComputeShader), + "D3D11 create compute shader")); + + return {}; +} + +void ComputePipeline::ApplyNow(CommandRecordingContext* commandContext) { + ID3D11DeviceContext1* d3dDeviceContext1 = commandContext->GetD3D11DeviceContext1(); + d3dDeviceContext1->CSSetShader(mComputeShader.Get(), nullptr, 0); +} + +void ComputePipeline::InitializeAsync(Ref computePipeline, + WGPUCreateComputePipelineAsyncCallback callback, + void* userdata) { + std::unique_ptr asyncTask = + std::make_unique(std::move(computePipeline), callback, + userdata); + CreateComputePipelineAsyncTask::RunAsync(std::move(asyncTask)); +} + +} // namespace dawn::native::d3d11 diff --git a/src/dawn/native/d3d11/ComputePipelineD3D11.h b/src/dawn/native/d3d11/ComputePipelineD3D11.h new file mode 100644 index 0000000000..7da11e8ae7 --- /dev/null +++ b/src/dawn/native/d3d11/ComputePipelineD3D11.h @@ -0,0 +1,49 @@ +// Copyright 2023 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef SRC_DAWN_NATIVE_D3D11_COMPUTEPIPELINEGL_H_ +#define SRC_DAWN_NATIVE_D3D11_COMPUTEPIPELINEGL_H_ + +#include "dawn/native/ComputePipeline.h" + +#include "dawn/native/d3d/d3d_platform.h" + +namespace dawn::native::d3d11 { + +class CommandRecordingContext; +class Device; + +class ComputePipeline final : public ComputePipelineBase { + public: + static Ref CreateUninitialized(Device* device, + const ComputePipelineDescriptor* descriptor); + static void InitializeAsync(Ref computePipeline, + WGPUCreateComputePipelineAsyncCallback callback, + void* userdata); + + void ApplyNow(CommandRecordingContext* commandContext); + + MaybeError Initialize() override; + + private: + using ComputePipelineBase::ComputePipelineBase; + ~ComputePipeline() override; + void DestroyImpl() override; + + ComPtr mComputeShader; +}; + +} // namespace dawn::native::d3d11 + +#endif // SRC_DAWN_NATIVE_D3D11_COMPUTEPIPELINEGL_H_ diff --git a/src/dawn/native/d3d11/DeviceD3D11.cpp b/src/dawn/native/d3d11/DeviceD3D11.cpp index d24902b6c3..1c3a9ec402 100644 --- a/src/dawn/native/d3d11/DeviceD3D11.cpp +++ b/src/dawn/native/d3d11/DeviceD3D11.cpp @@ -32,6 +32,7 @@ #include "dawn/native/d3d11/BackendD3D11.h" #include "dawn/native/d3d11/BindGroupD3D11.h" #include "dawn/native/d3d11/BindGroupLayoutD3D11.h" +#include "dawn/native/d3d11/ComputePipelineD3D11.h" #include "dawn/native/d3d11/PipelineLayoutD3D11.h" #include "dawn/native/d3d11/PlatformFunctionsD3D11.h" #include "dawn/native/d3d11/QueueD3D11.h" @@ -255,7 +256,7 @@ ResultOrError> Device::CreateCommandBuffer( Ref Device::CreateUninitializedComputePipelineImpl( const ComputePipelineDescriptor* descriptor) { - return nullptr; + return ComputePipeline::CreateUninitialized(this, descriptor); } ResultOrError> Device::CreatePipelineLayoutImpl( @@ -307,7 +308,9 @@ ResultOrError> Device::CreateTextureViewImpl( void Device::InitializeComputePipelineAsyncImpl(Ref computePipeline, WGPUCreateComputePipelineAsyncCallback callback, - void* userdata) {} + void* userdata) { + ComputePipeline::InitializeAsync(std::move(computePipeline), callback, userdata); +} void Device::InitializeRenderPipelineAsyncImpl(Ref renderPipeline, WGPUCreateRenderPipelineAsyncCallback callback, diff --git a/src/dawn/native/d3d11/TextureD3D11.h b/src/dawn/native/d3d11/TextureD3D11.h index 2476fe052f..725e9b5c66 100644 --- a/src/dawn/native/d3d11/TextureD3D11.h +++ b/src/dawn/native/d3d11/TextureD3D11.h @@ -40,13 +40,8 @@ class Texture final : public TextureBase { DXGI_FORMAT GetD3D11CopyableSubresourceFormat(Aspect aspect) const; D3D11_RENDER_TARGET_VIEW_DESC GetRTVDescriptor(const Format& format, - uint32_t mipLevel, - uint32_t baseSlice, - uint32_t sliceCount) const; - D3D11_DEPTH_STENCIL_VIEW_DESC GetDSVDescriptor(uint32_t mipLevel, - uint32_t baseArrayLayer, - uint32_t layerCount, - Aspect aspects, + const SubresourceRange& range) const; + D3D11_DEPTH_STENCIL_VIEW_DESC GetDSVDescriptor(const SubresourceRange& range, bool depthReadOnly, bool stencilReadOnly) const; diff --git a/src/dawn/native/d3d12/ComputePipelineD3D12.cpp b/src/dawn/native/d3d12/ComputePipelineD3D12.cpp index 9c6845ab5e..db3de1bd36 100644 --- a/src/dawn/native/d3d12/ComputePipelineD3D12.cpp +++ b/src/dawn/native/d3d12/ComputePipelineD3D12.cpp @@ -47,7 +47,7 @@ MaybeError ComputePipeline::Initialize() { compileFlags |= D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION; } - // SPRIV-cross does matrix multiplication expecting row major matrices + // Tint does matrix multiplication expecting row major matrices compileFlags |= D3DCOMPILE_PACK_MATRIX_ROW_MAJOR; // FXC can miscompile code that depends on special float values (NaN, INF, etc) when IEEE diff --git a/src/dawn/native/d3d12/RenderPipelineD3D12.cpp b/src/dawn/native/d3d12/RenderPipelineD3D12.cpp index ab9cbb1126..c25bc024cc 100644 --- a/src/dawn/native/d3d12/RenderPipelineD3D12.cpp +++ b/src/dawn/native/d3d12/RenderPipelineD3D12.cpp @@ -367,7 +367,7 @@ MaybeError RenderPipeline::Initialize() { compileFlags |= D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION; } - // SPRIV-cross does matrix multiplication expecting row major matrices + // Tint does matrix multiplication expecting row major matrices compileFlags |= D3DCOMPILE_PACK_MATRIX_ROW_MAJOR; // FXC can miscompile code that depends on special float values (NaN, INF, etc) when IEEE