d3d11: implement ComputePipeline

Bug: dawn:1705
Change-Id: I915000a747cc913ed52a423940d20e169b829315
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/126664
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Peng Huang <penghuang@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Peng Huang 2023-04-12 00:02:30 +00:00 committed by Dawn LUCI CQ
parent 04d61c85cd
commit c3cc75067e
8 changed files with 150 additions and 11 deletions

View File

@ -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",

View File

@ -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"

View File

@ -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 <memory>
#include <utility>
#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> 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<ComputePipelineBase> computePipeline,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata) {
std::unique_ptr<CreateComputePipelineAsyncTask> asyncTask =
std::make_unique<CreateComputePipelineAsyncTask>(std::move(computePipeline), callback,
userdata);
CreateComputePipelineAsyncTask::RunAsync(std::move(asyncTask));
}
} // namespace dawn::native::d3d11

View File

@ -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<ComputePipeline> CreateUninitialized(Device* device,
const ComputePipelineDescriptor* descriptor);
static void InitializeAsync(Ref<ComputePipelineBase> computePipeline,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata);
void ApplyNow(CommandRecordingContext* commandContext);
MaybeError Initialize() override;
private:
using ComputePipelineBase::ComputePipelineBase;
~ComputePipeline() override;
void DestroyImpl() override;
ComPtr<ID3D11ComputeShader> mComputeShader;
};
} // namespace dawn::native::d3d11
#endif // SRC_DAWN_NATIVE_D3D11_COMPUTEPIPELINEGL_H_

View File

@ -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<Ref<CommandBufferBase>> Device::CreateCommandBuffer(
Ref<ComputePipelineBase> Device::CreateUninitializedComputePipelineImpl(
const ComputePipelineDescriptor* descriptor) {
return nullptr;
return ComputePipeline::CreateUninitialized(this, descriptor);
}
ResultOrError<Ref<PipelineLayoutBase>> Device::CreatePipelineLayoutImpl(
@ -307,7 +308,9 @@ ResultOrError<Ref<TextureViewBase>> Device::CreateTextureViewImpl(
void Device::InitializeComputePipelineAsyncImpl(Ref<ComputePipelineBase> computePipeline,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata) {}
void* userdata) {
ComputePipeline::InitializeAsync(std::move(computePipeline), callback, userdata);
}
void Device::InitializeRenderPipelineAsyncImpl(Ref<RenderPipelineBase> renderPipeline,
WGPUCreateRenderPipelineAsyncCallback callback,

View File

@ -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;

View File

@ -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

View File

@ -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