Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrD3DPipelineStateBuilder.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2020 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8//#include <d3dcompiler.h>
9
11
31
32#include <d3dcompiler.h>
33
34using namespace skia_private;
35
36std::unique_ptr<GrD3DPipelineState> GrD3DPipelineStateBuilder::MakePipelineState(
37 GrD3DGpu* gpu,
38 GrD3DRenderTarget* renderTarget,
39 const GrProgramDesc& desc,
40 const GrProgramInfo& programInfo) {
41 // ensure that we use "." as a decimal separator when creating SkSL code
42 GrAutoLocaleSetter als("C");
43
44 // create a builder. This will be handed off to effects so they can use it to add
45 // uniforms, varyings, textures, etc
46 GrD3DPipelineStateBuilder builder(gpu, renderTarget, desc, programInfo);
47
48 if (!builder.emitAndInstallProcs()) {
49 return nullptr;
50 }
51
52 return builder.finalize();
53}
54
55GrD3DPipelineStateBuilder::GrD3DPipelineStateBuilder(GrD3DGpu* gpu,
56 GrD3DRenderTarget* renderTarget,
57 const GrProgramDesc& desc,
58 const GrProgramInfo& programInfo)
59 : INHERITED(desc, programInfo)
60 , fGpu(gpu)
61 , fVaryingHandler(this)
62 , fUniformHandler(this)
63 , fRenderTarget(renderTarget) {}
64
66 return fGpu->caps();
67}
68
70 outputColor.addLayoutQualifier("location = 0, index = 1");
71}
72
74 const std::string& hlsl,
75 SkSL::ProgramKind kind) {
76 TRACE_EVENT0("skia.shaders", "driver_compile_shader");
77 const char* compileTarget = nullptr;
78 switch (kind) {
80 compileTarget = "vs_5_1";
81 break;
83 compileTarget = "ps_5_1";
84 break;
85 default:
87 }
88
89 uint32_t compileFlags = 0;
90#ifdef SK_DEBUG
91 // Enable better shader debugging with the graphics debugging tools.
92 compileFlags |= D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION;
93#endif
94 // SPRIV-cross does matrix multiplication expecting row major matrices
95 compileFlags |= D3DCOMPILE_PACK_MATRIX_ROW_MAJOR;
96
97 gr_cp<ID3DBlob> shader;
98 gr_cp<ID3DBlob> errors;
99 HRESULT hr = D3DCompile(hlsl.c_str(), hlsl.length(), nullptr, nullptr, nullptr, "main",
100 compileTarget, compileFlags, 0, &shader, &errors);
101 if (!SUCCEEDED(hr)) {
103 hlsl.c_str(), reinterpret_cast<char*>(errors->GetBufferPointer()));
104 }
105 return shader;
106}
107
108bool GrD3DPipelineStateBuilder::loadHLSLFromCache(SkReadBuffer* reader, gr_cp<ID3DBlob> shaders[]) {
109
110 std::string hlsl[kGrShaderTypeCount];
112
114 return false;
115 }
116
117 auto compile = [&](SkSL::ProgramKind kind, GrShaderType shaderType) {
118 if (intfs[shaderType].fRTFlipUniform != SkSL::Program::Interface::kRTFlip_None) {
120 }
121 shaders[shaderType] = GrCompileHLSLShader(fGpu, hlsl[shaderType], kind);
122 return shaders[shaderType].get();
123 };
124
127}
128
129gr_cp<ID3DBlob> GrD3DPipelineStateBuilder::compileD3DProgram(SkSL::ProgramKind kind,
130 const std::string& sksl,
131 const SkSL::ProgramSettings& settings,
132 SkSL::Program::Interface* outInterface,
133 std::string* outHLSL) {
134 if (!skgpu::SkSLToHLSL(this->caps()->shaderCaps(),
135 sksl,
136 kind,
137 settings,
138 outHLSL,
139 outInterface,
140 fGpu->getContext()->priv().getShaderErrorHandler())) {
141 return gr_cp<ID3DBlob>();
142 }
143
146 }
147
148 return GrCompileHLSLShader(fGpu, *outHLSL, kind);
149}
150
152 switch (type) {
154 return DXGI_FORMAT_R32_FLOAT;
156 return DXGI_FORMAT_R32G32_FLOAT;
158 return DXGI_FORMAT_R32G32B32_FLOAT;
160 return DXGI_FORMAT_R32G32B32A32_FLOAT;
162 return DXGI_FORMAT_R16_FLOAT;
164 return DXGI_FORMAT_R16G16_FLOAT;
166 return DXGI_FORMAT_R16G16B16A16_FLOAT;
168 return DXGI_FORMAT_R32G32_SINT;
170 return DXGI_FORMAT_R32G32B32_SINT;
172 return DXGI_FORMAT_R32G32B32A32_SINT;
174 return DXGI_FORMAT_R8_SINT;
176 return DXGI_FORMAT_R8G8_SINT;
178 return DXGI_FORMAT_R8G8B8A8_SINT;
180 return DXGI_FORMAT_R8_UINT;
182 return DXGI_FORMAT_R8G8_UINT;
184 return DXGI_FORMAT_R8G8B8A8_UINT;
186 return DXGI_FORMAT_R8_UNORM;
188 return DXGI_FORMAT_R8G8B8A8_UNORM;
190 return DXGI_FORMAT_R16G16_SINT;
192 return DXGI_FORMAT_R16G16B16A16_SINT;
194 return DXGI_FORMAT_R16G16_UINT;
196 return DXGI_FORMAT_R16G16_UNORM;
198 return DXGI_FORMAT_R32_SINT;
200 return DXGI_FORMAT_R32_UINT;
202 return DXGI_FORMAT_R16_UNORM;
204 return DXGI_FORMAT_R16G16B16A16_UNORM;
205 }
206 SK_ABORT("Unknown vertex attrib type");
207}
208
210 D3D12_INPUT_ELEMENT_DESC* inputElements) {
211 unsigned int slotNumber = 0;
212 unsigned int vertexSlot = 0;
213 unsigned int instanceSlot = 0;
214 if (geomProc.hasVertexAttributes()) {
215 vertexSlot = slotNumber++;
216 }
217 if (geomProc.hasInstanceAttributes()) {
218 instanceSlot = slotNumber++;
219 }
220
221 unsigned int currentAttrib = 0;
222
223 for (auto attrib : geomProc.vertexAttributes()) {
224 // When using SPIRV-Cross it converts the location modifier in SPIRV to be
225 // TEXCOORD<N> where N is the location value for eveery vertext attribute
226 inputElements[currentAttrib] = { "TEXCOORD", currentAttrib,
227 attrib_type_to_format(attrib.cpuType()),
228 vertexSlot, SkToU32(*attrib.offset()),
229 D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 };
230 currentAttrib++;
231 }
232
233 for (auto attrib : geomProc.instanceAttributes()) {
234 // When using SPIRV-Cross it converts the location modifier in SPIRV to be
235 // TEXCOORD<N> where N is the location value for eveery vertext attribute
236 inputElements[currentAttrib] = { "TEXCOORD", currentAttrib,
237 attrib_type_to_format(attrib.cpuType()),
238 instanceSlot, SkToU32(*attrib.offset()),
239 D3D12_INPUT_CLASSIFICATION_PER_INSTANCE_DATA, 1 };
240 currentAttrib++;
241 }
242}
243
245 switch (coeff) {
247 return D3D12_BLEND_ZERO;
249 return D3D12_BLEND_ONE;
251 return D3D12_BLEND_SRC_COLOR;
253 return D3D12_BLEND_INV_SRC_COLOR;
255 return D3D12_BLEND_DEST_COLOR;
257 return D3D12_BLEND_INV_DEST_COLOR;
259 return D3D12_BLEND_SRC_ALPHA;
261 return D3D12_BLEND_INV_SRC_ALPHA;
263 return D3D12_BLEND_DEST_ALPHA;
265 return D3D12_BLEND_INV_DEST_ALPHA;
267 return D3D12_BLEND_BLEND_FACTOR;
269 return D3D12_BLEND_INV_BLEND_FACTOR;
271 return D3D12_BLEND_SRC1_COLOR;
273 return D3D12_BLEND_INV_SRC1_COLOR;
275 return D3D12_BLEND_SRC1_ALPHA;
277 return D3D12_BLEND_INV_SRC1_ALPHA;
279 return D3D12_BLEND_ZERO;
280 }
282}
283
285 switch (coeff) {
286 // Force all srcColor used in alpha slot to alpha version.
288 return D3D12_BLEND_SRC_ALPHA;
290 return D3D12_BLEND_INV_SRC_ALPHA;
292 return D3D12_BLEND_DEST_ALPHA;
294 return D3D12_BLEND_INV_DEST_ALPHA;
296 return D3D12_BLEND_SRC1_ALPHA;
298 return D3D12_BLEND_INV_SRC1_ALPHA;
299
300 default:
301 return blend_coeff_to_d3d_blend(coeff);
302 }
303}
304
305
306static D3D12_BLEND_OP blend_equation_to_d3d_op(skgpu::BlendEquation equation) {
307 switch (equation) {
309 return D3D12_BLEND_OP_ADD;
311 return D3D12_BLEND_OP_SUBTRACT;
313 return D3D12_BLEND_OP_REV_SUBTRACT;
314 default:
316 }
317}
318
319static void fill_in_blend_state(const GrPipeline& pipeline, D3D12_BLEND_DESC* blendDesc) {
320 blendDesc->AlphaToCoverageEnable = false;
321 blendDesc->IndependentBlendEnable = false;
322
323 const skgpu::BlendInfo& blendInfo = pipeline.getXferProcessor().getBlendInfo();
324
325 skgpu::BlendEquation equation = blendInfo.fEquation;
326 skgpu::BlendCoeff srcCoeff = blendInfo.fSrcBlend;
327 skgpu::BlendCoeff dstCoeff = blendInfo.fDstBlend;
328 bool blendOff = skgpu::BlendShouldDisable(equation, srcCoeff, dstCoeff);
329
330 auto& rtBlend = blendDesc->RenderTarget[0];
331 rtBlend.BlendEnable = !blendOff;
332 if (!blendOff) {
333 rtBlend.SrcBlend = blend_coeff_to_d3d_blend(srcCoeff);
334 rtBlend.DestBlend = blend_coeff_to_d3d_blend(dstCoeff);
335 rtBlend.BlendOp = blend_equation_to_d3d_op(equation);
336 rtBlend.SrcBlendAlpha = blend_coeff_to_d3d_blend_for_alpha(srcCoeff);
337 rtBlend.DestBlendAlpha = blend_coeff_to_d3d_blend_for_alpha(dstCoeff);
338 rtBlend.BlendOpAlpha = blend_equation_to_d3d_op(equation);
339 }
340
341 if (!blendInfo.fWritesColor) {
342 rtBlend.RenderTargetWriteMask = 0;
343 } else {
344 rtBlend.RenderTargetWriteMask = D3D12_COLOR_WRITE_ENABLE_ALL;
345 }
346}
347
348static void fill_in_rasterizer_state(const GrPipeline& pipeline,
349 bool multisampleEnable,
350 const GrCaps* caps,
351 D3D12_RASTERIZER_DESC* rasterizer) {
352 rasterizer->FillMode = (caps->wireframeMode() || pipeline.isWireframe()) ?
353 D3D12_FILL_MODE_WIREFRAME : D3D12_FILL_MODE_SOLID;
354 rasterizer->CullMode = D3D12_CULL_MODE_NONE;
355 rasterizer->FrontCounterClockwise = true;
356 rasterizer->DepthBias = 0;
357 rasterizer->DepthBiasClamp = 0.0f;
358 rasterizer->SlopeScaledDepthBias = 0.0f;
359 rasterizer->DepthClipEnable = false;
360 rasterizer->MultisampleEnable = multisampleEnable;
361 rasterizer->AntialiasedLineEnable = false;
362 rasterizer->ForcedSampleCount = 0;
363 rasterizer->ConservativeRaster = D3D12_CONSERVATIVE_RASTERIZATION_MODE_OFF;
364}
365
366static D3D12_STENCIL_OP stencil_op_to_d3d_op(GrStencilOp op) {
367 switch (op) {
369 return D3D12_STENCIL_OP_KEEP;
371 return D3D12_STENCIL_OP_ZERO;
373 return D3D12_STENCIL_OP_REPLACE;
375 return D3D12_STENCIL_OP_INVERT;
377 return D3D12_STENCIL_OP_INCR;
379 return D3D12_STENCIL_OP_DECR;
381 return D3D12_STENCIL_OP_INCR_SAT;
383 return D3D12_STENCIL_OP_DECR_SAT;
384 }
386}
387
388static D3D12_COMPARISON_FUNC stencil_test_to_d3d_func(GrStencilTest test) {
389 switch (test) {
391 return D3D12_COMPARISON_FUNC_ALWAYS;
393 return D3D12_COMPARISON_FUNC_NEVER;
395 return D3D12_COMPARISON_FUNC_GREATER;
397 return D3D12_COMPARISON_FUNC_GREATER_EQUAL;
399 return D3D12_COMPARISON_FUNC_LESS;
401 return D3D12_COMPARISON_FUNC_LESS_EQUAL;
403 return D3D12_COMPARISON_FUNC_EQUAL;
405 return D3D12_COMPARISON_FUNC_NOT_EQUAL;
406 }
408}
409
410static void setup_stencilop_desc(D3D12_DEPTH_STENCILOP_DESC* desc,
411 const GrStencilSettings::Face& stencilFace) {
412 desc->StencilFailOp = stencil_op_to_d3d_op(stencilFace.fFailOp);
413 desc->StencilDepthFailOp = desc->StencilFailOp;
414 desc->StencilPassOp = stencil_op_to_d3d_op(stencilFace.fPassOp);
415 desc->StencilFunc = stencil_test_to_d3d_func(stencilFace.fTest);
416}
417
418static void fill_in_depth_stencil_state(const GrProgramInfo& programInfo,
419 D3D12_DEPTH_STENCIL_DESC* dsDesc) {
420 GrStencilSettings stencilSettings = programInfo.nonGLStencilSettings();
421 GrSurfaceOrigin origin = programInfo.origin();
422
423 dsDesc->DepthEnable = false;
424 dsDesc->DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ZERO;
425 dsDesc->DepthFunc = D3D12_COMPARISON_FUNC_NEVER;
426 dsDesc->StencilEnable = !stencilSettings.isDisabled();
427 if (!stencilSettings.isDisabled()) {
428 if (stencilSettings.isTwoSided()) {
429 const auto& frontFace = stencilSettings.postOriginCCWFace(origin);
430 const auto& backFace = stencilSettings.postOriginCWFace(origin);
431
432 SkASSERT(frontFace.fTestMask == backFace.fTestMask);
433 SkASSERT(frontFace.fWriteMask == backFace.fWriteMask);
434 dsDesc->StencilReadMask = frontFace.fTestMask;
435 dsDesc->StencilWriteMask = frontFace.fWriteMask;
436
437 setup_stencilop_desc(&dsDesc->FrontFace, frontFace);
438 setup_stencilop_desc(&dsDesc->BackFace, backFace);
439 } else {
440 dsDesc->StencilReadMask = stencilSettings.singleSidedFace().fTestMask;
441 dsDesc->StencilWriteMask = stencilSettings.singleSidedFace().fWriteMask;
442 setup_stencilop_desc(&dsDesc->FrontFace, stencilSettings.singleSidedFace());
443 dsDesc->BackFace = dsDesc->FrontFace;
444 }
445 }
446}
447
448static D3D12_PRIMITIVE_TOPOLOGY_TYPE gr_primitive_type_to_d3d(GrPrimitiveType primitiveType) {
449 switch (primitiveType) {
451 case GrPrimitiveType::kTriangleStrip: //fall through
452 return D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
454 return D3D12_PRIMITIVE_TOPOLOGY_TYPE_POINT;
455 case GrPrimitiveType::kLines: // fall through
457 return D3D12_PRIMITIVE_TOPOLOGY_TYPE_LINE;
458 default:
460 }
461}
462
464 GrD3DGpu* gpu, const GrProgramInfo& programInfo, const sk_sp<GrD3DRootSignature>& rootSig,
465 gr_cp<ID3DBlob> vertexShader, gr_cp<ID3DBlob> pixelShader,
466 DXGI_FORMAT renderTargetFormat, DXGI_FORMAT depthStencilFormat,
467 unsigned int sampleQualityPattern) {
468 D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {};
469
470 psoDesc.pRootSignature = rootSig->rootSignature();
471
472 psoDesc.VS = { reinterpret_cast<UINT8*>(vertexShader->GetBufferPointer()),
473 vertexShader->GetBufferSize() };
474 psoDesc.PS = { reinterpret_cast<UINT8*>(pixelShader->GetBufferPointer()),
475 pixelShader->GetBufferSize() };
476
477 psoDesc.StreamOutput = { nullptr, 0, nullptr, 0, 0 };
478
479 fill_in_blend_state(programInfo.pipeline(), &psoDesc.BlendState);
480 psoDesc.SampleMask = UINT_MAX;
481
482 fill_in_rasterizer_state(programInfo.pipeline(), programInfo.numSamples() > 1, gpu->caps(),
483 &psoDesc.RasterizerState);
484
485 fill_in_depth_stencil_state(programInfo, &psoDesc.DepthStencilState);
486
487 unsigned int totalAttributeCnt = programInfo.geomProc().numVertexAttributes() +
488 programInfo.geomProc().numInstanceAttributes();
489 AutoSTArray<4, D3D12_INPUT_ELEMENT_DESC> inputElements(totalAttributeCnt);
490 setup_vertex_input_layout(programInfo.geomProc(), inputElements.get());
491
492 psoDesc.InputLayout = { inputElements.get(), totalAttributeCnt };
493
494 psoDesc.IBStripCutValue = D3D12_INDEX_BUFFER_STRIP_CUT_VALUE_DISABLED;
495
496 // This is for geometry or hull shader primitives
497 psoDesc.PrimitiveTopologyType = gr_primitive_type_to_d3d(programInfo.primitiveType());
498
499 psoDesc.NumRenderTargets = 1;
500
501 psoDesc.RTVFormats[0] = renderTargetFormat;
502
503 psoDesc.DSVFormat = depthStencilFormat;
504
505 unsigned int numSamples = programInfo.numSamples();
506 psoDesc.SampleDesc = { numSamples, sampleQualityPattern };
507
508 // Only used for multi-adapter systems.
509 psoDesc.NodeMask = 0;
510
511 psoDesc.CachedPSO = { nullptr, 0 };
512 psoDesc.Flags = D3D12_PIPELINE_STATE_FLAG_NONE;
513
514 gr_cp<ID3D12PipelineState> pipelineState;
515 {
516 TRACE_EVENT0("skia.shaders", "CreateGraphicsPipelineState");
518 gpu->device()->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&pipelineState)));
519 }
520
521 return pipelineState;
522}
523
524static constexpr SkFourByteTag kHLSL_Tag = SkSetFourByteTag('H', 'L', 'S', 'L');
525static constexpr SkFourByteTag kSKSL_Tag = SkSetFourByteTag('S', 'K', 'S', 'L');
526
527std::unique_ptr<GrD3DPipelineState> GrD3DPipelineStateBuilder::finalize() {
528 TRACE_EVENT0("skia.shaders", TRACE_FUNC);
529
530 this->finalizeShaders();
531
532 SkSL::ProgramSettings settings;
533 settings.fSharpenTextures = true;
534 settings.fRTFlipOffset = fUniformHandler.getRTFlipOffset();
535 settings.fRTFlipBinding = 0;
536 settings.fRTFlipSet = 0;
537
538 sk_sp<SkData> cached;
539 SkReadBuffer reader;
540 SkFourByteTag shaderType = 0;
541 auto persistentCache = fGpu->getContext()->priv().getPersistentCache();
542 if (persistentCache) {
543 // Shear off the D3D-specific portion of the Desc to get the persistent key. We only cache
544 // shader code, not entire pipelines.
546 SkData::MakeWithoutCopy(this->desc().asKey(), this->desc().initialKeyLength());
547 cached = persistentCache->load(*key);
548 if (cached) {
549 reader.setMemory(cached->data(), cached->size());
550 shaderType = GrPersistentCacheUtils::GetType(&reader);
551 }
552 }
553
554 const GrGeometryProcessor& geomProc = this->geometryProcessor();
556
557 if (kHLSL_Tag == shaderType && this->loadHLSLFromCache(&reader, shaders)) {
558 // We successfully loaded and compiled HLSL
559 } else {
561 std::string* sksl[kGrShaderTypeCount] = {
564 };
565 std::string cached_sksl[kGrShaderTypeCount];
566 std::string hlsl[kGrShaderTypeCount];
567
568 if (kSKSL_Tag == shaderType) {
569 if (GrPersistentCacheUtils::UnpackCachedShaders(&reader, cached_sksl, intfs,
571 for (int i = 0; i < kGrShaderTypeCount; ++i) {
572 sksl[i] = &cached_sksl[i];
573 }
574 }
575 }
576
577 auto compile = [&](SkSL::ProgramKind kind, GrShaderType shaderType) {
578 shaders[shaderType] = this->compileD3DProgram(
579 kind, *sksl[shaderType], settings, &intfs[shaderType], &hlsl[shaderType]);
580 return shaders[shaderType].get();
581 };
582
585 return nullptr;
586 }
587
588 if (persistentCache && !cached) {
589 const bool cacheSkSL = fGpu->getContext()->priv().options().fShaderCacheStrategy ==
591 if (cacheSkSL) {
592 // Replace the HLSL with formatted SkSL to be cached. This looks odd, but this is
593 // the last time we're going to use these strings, so it's safe.
594 for (int i = 0; i < kGrShaderTypeCount; ++i) {
595 hlsl[i] = SkShaderUtils::PrettyPrint(*sksl[i]);
596 }
597 }
599 SkData::MakeWithoutCopy(this->desc().asKey(), this->desc().initialKeyLength());
600 SkString description = GrProgramDesc::Describe(fProgramInfo, *this->caps());
602 cacheSkSL ? kSKSL_Tag : kHLSL_Tag, hlsl, intfs, kGrShaderTypeCount);
603 persistentCache->store(*key, *data, description);
604 }
605 }
606
608 fGpu->resourceProvider().findOrCreateRootSignature(fUniformHandler.fSamplers.count());
609 if (!rootSig) {
610 return nullptr;
611 }
612
613 const GrD3DRenderTarget* rt = static_cast<const GrD3DRenderTarget*>(fRenderTarget);
615 fGpu, fProgramInfo, rootSig, std::move(shaders[kVertex_GrShaderType]),
616 std::move(shaders[kFragment_GrShaderType]),
618 sk_sp<GrD3DPipeline> pipeline = GrD3DPipeline::Make(std::move(pipelineState));
619 if (!pipeline) {
620 return nullptr;
621 }
622
623 return std::unique_ptr<GrD3DPipelineState>(
624 new GrD3DPipelineState(std::move(pipeline),
625 std::move(rootSig),
627 fUniformHandler.fUniforms,
628 fUniformHandler.fCurrentUBOOffset,
629 fUniformHandler.fSamplers.count(),
630 std::move(fGPImpl),
631 std::move(fXPImpl),
632 std::move(fFPImpls),
633 geomProc.vertexStride(),
634 geomProc.instanceStride()));
635}
636
637
639 GrD3DRootSignature* rootSig,
640 const char* shader) {
641 D3D12_COMPUTE_PIPELINE_STATE_DESC psoDesc = {};
642 psoDesc.pRootSignature = rootSig->rootSignature();
643
644 // compile shader
645 gr_cp<ID3DBlob> shaderBlob;
646 {
647 TRACE_EVENT0("skia.shaders", "driver_compile_shader");
648 uint32_t compileFlags = 0;
649#ifdef SK_DEBUG
650 // Enable better shader debugging with the graphics debugging tools.
651 compileFlags |= D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION;
652#endif
653
654 gr_cp<ID3DBlob> errors;
655 HRESULT hr = D3DCompile(shader, strlen(shader), nullptr, nullptr, nullptr, "main",
656 "cs_5_1", compileFlags, 0, &shaderBlob, &errors);
657 if (!SUCCEEDED(hr)) {
659 shader, reinterpret_cast<char*>(errors->GetBufferPointer()));
660 return nullptr;
661 }
662 psoDesc.CS = { reinterpret_cast<UINT8*>(shaderBlob->GetBufferPointer()),
663 shaderBlob->GetBufferSize() };
664 }
665
666 // Only used for multi-adapter systems.
667 psoDesc.NodeMask = 0;
668
669 psoDesc.CachedPSO = { nullptr, 0 };
670 psoDesc.Flags = D3D12_PIPELINE_STATE_FLAG_NONE;
671
672 gr_cp<ID3D12PipelineState> pipelineState;
673 {
674 TRACE_EVENT0("skia.shaders", "CreateComputePipelineState");
676 gpu->device()->CreateComputePipelineState(&psoDesc, IID_PPV_ARGS(&pipelineState)));
677 }
678
679 return GrD3DPipeline::Make(std::move(pipelineState));
680}
static DXGI_FORMAT attrib_type_to_format(GrVertexAttribType type)
static void setup_vertex_input_layout(const GrGeometryProcessor &geomProc, D3D12_INPUT_ELEMENT_DESC *inputElements)
gr_cp< ID3D12PipelineState > create_pipeline_state(GrD3DGpu *gpu, const GrProgramInfo &programInfo, const sk_sp< GrD3DRootSignature > &rootSig, gr_cp< ID3DBlob > vertexShader, gr_cp< ID3DBlob > pixelShader, DXGI_FORMAT renderTargetFormat, DXGI_FORMAT depthStencilFormat, unsigned int sampleQualityPattern)
static gr_cp< ID3DBlob > GrCompileHLSLShader(GrD3DGpu *gpu, const std::string &hlsl, SkSL::ProgramKind kind)
static constexpr SkFourByteTag kHLSL_Tag
static D3D12_STENCIL_OP stencil_op_to_d3d_op(GrStencilOp op)
static void fill_in_depth_stencil_state(const GrProgramInfo &programInfo, D3D12_DEPTH_STENCIL_DESC *dsDesc)
static D3D12_BLEND blend_coeff_to_d3d_blend_for_alpha(skgpu::BlendCoeff coeff)
static D3D12_BLEND blend_coeff_to_d3d_blend(skgpu::BlendCoeff coeff)
static void fill_in_rasterizer_state(const GrPipeline &pipeline, bool multisampleEnable, const GrCaps *caps, D3D12_RASTERIZER_DESC *rasterizer)
static D3D12_PRIMITIVE_TOPOLOGY_TYPE gr_primitive_type_to_d3d(GrPrimitiveType primitiveType)
static D3D12_COMPARISON_FUNC stencil_test_to_d3d_func(GrStencilTest test)
static void setup_stencilop_desc(D3D12_DEPTH_STENCILOP_DESC *desc, const GrStencilSettings::Face &stencilFace)
static void fill_in_blend_state(const GrPipeline &pipeline, D3D12_BLEND_DESC *blendDesc)
static D3D12_BLEND_OP blend_equation_to_d3d_op(skgpu::BlendEquation equation)
static constexpr SkFourByteTag kSKSL_Tag
#define GR_D3D_CALL_ERRCHECK(X)
Definition GrD3DUtil.h:16
GrStencilTest
GrStencilOp
GrPrimitiveType
Definition GrTypesPriv.h:42
GrShaderType
@ kFragment_GrShaderType
@ kVertex_GrShaderType
GrVertexAttribType
@ kUShort_norm_GrVertexAttribType
@ kFloat2_GrVertexAttribType
@ kUShort2_GrVertexAttribType
@ kUInt_GrVertexAttribType
@ kUByte4_norm_GrVertexAttribType
@ kUByte_GrVertexAttribType
@ kShort2_GrVertexAttribType
@ kUShort4_norm_GrVertexAttribType
@ kInt_GrVertexAttribType
@ kByte_GrVertexAttribType
@ kByte4_GrVertexAttribType
@ kFloat3_GrVertexAttribType
@ kFloat_GrVertexAttribType
@ kByte2_GrVertexAttribType
@ kFloat4_GrVertexAttribType
@ kShort4_GrVertexAttribType
@ kUShort2_norm_GrVertexAttribType
@ kInt3_GrVertexAttribType
@ kHalf2_GrVertexAttribType
@ kHalf4_GrVertexAttribType
@ kUByte4_GrVertexAttribType
@ kUByte2_GrVertexAttribType
@ kInt4_GrVertexAttribType
@ kUByte_norm_GrVertexAttribType
@ kInt2_GrVertexAttribType
@ kHalf_GrVertexAttribType
static const int kGrShaderTypeCount
GrSurfaceOrigin
Definition GrTypes.h:147
#define SkUNREACHABLE
Definition SkAssert.h:135
#define SK_ABORT(message,...)
Definition SkAssert.h:70
#define SkASSERT(cond)
Definition SkAssert.h:116
#define INHERITED(method,...)
#define SKSL_RTFLIP_NAME
Definition SkSLProgram.h:19
constexpr uint32_t SkToU32(S x)
Definition SkTo.h:26
#define TRACE_FUNC
uint32_t SkFourByteTag
Definition SkTypes.h:166
static constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d)
Definition SkTypes.h:167
const GrContextOptions & options() const
GrContextOptions::ShaderErrorHandler * getShaderErrorHandler() const
bool wireframeMode() const
Definition GrCaps.h:399
GrD3DResourceProvider & resourceProvider()
Definition GrD3DGpu.h:38
ID3D12Device * device() const
Definition GrD3DGpu.h:43
static sk_sp< GrD3DPipeline > MakeComputePipeline(GrD3DGpu *, GrD3DRootSignature *, const char *shader)
const GrCaps * caps() const override
void finalizeFragmentSecondaryColor(GrShaderVar &outputColor) override
static std::unique_ptr< GrD3DPipelineState > MakePipelineState(GrD3DGpu *, GrD3DRenderTarget *, const GrProgramDesc &, const GrProgramInfo &)
static sk_sp< GrD3DPipeline > Make(gr_cp< ID3D12PipelineState > pipelineState)
DXGI_FORMAT stencilDxgiFormat() const
sk_sp< GrD3DRootSignature > findOrCreateRootSignature(int numTextureSamplers, int numUAVs=0)
ID3D12RootSignature * rootSignature() const
DXGI_FORMAT dxgiFormat() const
unsigned int sampleQualityPattern() const
GrContextOptions::PersistentCache * getPersistentCache()
GrDirectContextPriv priv()
const GrProgramDesc & desc() const
std::vector< std::unique_ptr< GrFragmentProcessor::ProgramImpl > > fFPImpls
std::unique_ptr< GrGeometryProcessor::ProgramImpl > fGPImpl
const GrShaderCaps * shaderCaps() const
GrGLSLVertexBuilder fVS
const GrGeometryProcessor & geometryProcessor() const
std::unique_ptr< GrXferProcessor::ProgramImpl > fXPImpl
GrGLSLBuiltinUniformHandles fUniformHandles
const GrProgramInfo & fProgramInfo
GrGLSLFragmentShaderBuilder fFS
void addRTFlipUniform(const char *name)
const GrPipeline & pipeline() const
bool hasInstanceAttributes() const
const AttributeSet & vertexAttributes() const
const AttributeSet & instanceAttributes() const
size_t instanceStride() const
const GrCaps * caps() const
Definition GrGpu.h:73
GrDirectContext * getContext()
Definition GrGpu.h:67
bool isWireframe() const
Definition GrPipeline.h:170
const GrXferProcessor & getXferProcessor() const
Definition GrPipeline.h:116
static SkString Describe(const GrProgramInfo &, const GrCaps &)
int numSamples() const
GrSurfaceOrigin origin() const
GrPrimitiveType primitiveType() const
const GrPipeline & pipeline() const
const GrGeometryProcessor & geomProc() const
GrStencilSettings nonGLStencilSettings() const
void addLayoutQualifier(const char *layoutQualifier)
bool isTwoSided() const
const Face & postOriginCCWFace(GrSurfaceOrigin origin) const
bool isDisabled() const
const Face & singleSidedFace() const
const Face & postOriginCWFace(GrSurfaceOrigin origin) const
skgpu::BlendInfo getBlendInfo() const
static sk_sp< SkData > MakeWithoutCopy(const void *data, size_t length)
Definition SkData.h:116
void setMemory(const void *, size_t)
int count() const
T * get() const
Definition GrD3DTypes.h:108
virtual void compileError(const char *shader, const char *errors)
sk_sp< SkData > PackCachedShaders(SkFourByteTag shaderType, const std::string shaders[], const SkSL::Program::Interface interfaces[], int numInterfaces, const ShaderMetadata *meta)
bool UnpackCachedShaders(SkReadBuffer *reader, std::string shaders[], SkSL::Program::Interface interfaces[], int numInterfaces, ShaderMetadata *meta)
SkFourByteTag GetType(SkReadBuffer *reader)
std::string PrettyPrint(const std::string &string)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41
static constexpr bool BlendShouldDisable(BlendEquation equation, BlendCoeff srcCoeff, BlendCoeff dstCoeff)
Definition Blend.h:145
BlendEquation
Definition Blend.h:26
BlendCoeff
Definition Blend.h:60
ShaderCacheStrategy fShaderCacheStrategy
skgpu::BlendCoeff fDstBlend
Definition Blend.h:96
bool fWritesColor
Definition Blend.h:98
skgpu::BlendCoeff fSrcBlend
Definition Blend.h:95
#define TRACE_EVENT0(category_group, name)
#define SUCCEEDED(hr)