2018-07-18 09:40:26 +00:00
|
|
|
// Copyright 2017 The Dawn Authors
|
2017-07-15 05:28:31 +00:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2018-07-24 11:53:51 +00:00
|
|
|
#include "dawn_native/d3d12/ComputePipelineD3D12.h"
|
2017-07-15 05:28:31 +00:00
|
|
|
|
|
|
|
#include "common/Assert.h"
|
2018-07-24 11:53:51 +00:00
|
|
|
#include "dawn_native/d3d12/DeviceD3D12.h"
|
|
|
|
#include "dawn_native/d3d12/PipelineLayoutD3D12.h"
|
2018-08-30 12:20:28 +00:00
|
|
|
#include "dawn_native/d3d12/PlatformFunctions.h"
|
2018-07-24 11:53:51 +00:00
|
|
|
#include "dawn_native/d3d12/ShaderModuleD3D12.h"
|
2017-07-15 05:28:31 +00:00
|
|
|
|
2018-07-24 14:45:45 +00:00
|
|
|
namespace dawn_native { namespace d3d12 {
|
2017-07-15 05:28:31 +00:00
|
|
|
|
2018-08-27 21:12:56 +00:00
|
|
|
ComputePipeline::ComputePipeline(Device* device, const ComputePipelineDescriptor* descriptor)
|
|
|
|
: ComputePipelineBase(device, descriptor) {
|
2017-07-15 05:28:31 +00:00
|
|
|
uint32_t compileFlags = 0;
|
|
|
|
#if defined(_DEBUG)
|
|
|
|
// Enable better shader debugging with the graphics debugging tools.
|
|
|
|
compileFlags |= D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION;
|
|
|
|
#endif
|
|
|
|
// SPRIV-cross does matrix multiplication expecting row major matrices
|
|
|
|
compileFlags |= D3DCOMPILE_PACK_MATRIX_ROW_MAJOR;
|
|
|
|
|
2019-09-05 09:41:17 +00:00
|
|
|
const ShaderModule* module = ToBackend(descriptor->computeStage.module);
|
2018-11-01 13:59:19 +00:00
|
|
|
const std::string& hlslSource = module->GetHLSLSource(ToBackend(GetLayout()));
|
2017-07-15 05:28:31 +00:00
|
|
|
|
|
|
|
ComPtr<ID3DBlob> compiledShader;
|
|
|
|
ComPtr<ID3DBlob> errors;
|
|
|
|
|
2018-08-27 21:12:56 +00:00
|
|
|
const PlatformFunctions* functions = device->GetFunctions();
|
2018-08-30 12:20:28 +00:00
|
|
|
if (FAILED(functions->d3dCompile(hlslSource.c_str(), hlslSource.length(), nullptr, nullptr,
|
2019-09-05 09:41:17 +00:00
|
|
|
nullptr, descriptor->computeStage.entryPoint, "cs_5_1",
|
2019-04-09 15:17:30 +00:00
|
|
|
compileFlags, 0, &compiledShader, &errors))) {
|
2017-07-15 05:28:31 +00:00
|
|
|
printf("%s\n", reinterpret_cast<char*>(errors->GetBufferPointer()));
|
|
|
|
ASSERT(false);
|
|
|
|
}
|
|
|
|
|
2018-08-27 21:12:56 +00:00
|
|
|
D3D12_COMPUTE_PIPELINE_STATE_DESC d3dDesc = {};
|
|
|
|
d3dDesc.pRootSignature = ToBackend(GetLayout())->GetRootSignature().Get();
|
|
|
|
d3dDesc.CS.pShaderBytecode = compiledShader->GetBufferPointer();
|
|
|
|
d3dDesc.CS.BytecodeLength = compiledShader->GetBufferSize();
|
2017-07-15 05:28:31 +00:00
|
|
|
|
2018-08-27 21:12:56 +00:00
|
|
|
device->GetD3D12Device()->CreateComputePipelineState(&d3dDesc,
|
2017-11-24 19:04:22 +00:00
|
|
|
IID_PPV_ARGS(&mPipelineState));
|
2017-07-15 05:28:31 +00:00
|
|
|
}
|
|
|
|
|
2018-03-02 16:07:07 +00:00
|
|
|
ComputePipeline::~ComputePipeline() {
|
2018-08-27 21:12:56 +00:00
|
|
|
ToBackend(GetDevice())->ReferenceUntilUnused(mPipelineState);
|
2018-03-02 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2017-07-15 05:28:31 +00:00
|
|
|
ComPtr<ID3D12PipelineState> ComputePipeline::GetPipelineState() {
|
2017-11-23 19:14:03 +00:00
|
|
|
return mPipelineState;
|
2017-07-15 05:28:31 +00:00
|
|
|
}
|
|
|
|
|
2018-07-24 14:45:45 +00:00
|
|
|
}} // namespace dawn_native::d3d12
|