blob: b3850bca2545aa7937a649d5b299325b1c33c4b7 [file] [log] [blame]
Corentin Wallez4a9ef4e2018-07-18 11:40:26 +02001// Copyright 2017 The Dawn Authors
Austin Engcfeda4d2017-06-05 17:22:48 -04002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Corentin Wallez30965a72018-07-24 16:42:33 +020015#ifndef DAWNNATIVE_D3D12_SHADERMODULED3D12_H_
16#define DAWNNATIVE_D3D12_SHADERMODULED3D12_H_
Austin Engcfeda4d2017-06-05 17:22:48 -040017
Bryan Bernhart41b3f9c2020-11-20 20:38:37 +000018#include "dawn_native/PersistentCache.h"
Corentin Wallezd37523f2018-07-24 13:53:51 +020019#include "dawn_native/ShaderModule.h"
Austin Engcfeda4d2017-06-05 17:22:48 -040020
Hugo Amiard216c10d2020-05-18 23:56:11 +000021#include "dawn_native/d3d12/d3d12_platform.h"
22
Corentin Wallez49a65d02018-07-24 16:45:45 +020023namespace dawn_native { namespace d3d12 {
Austin Engcfeda4d2017-06-05 17:22:48 -040024
25 class Device;
Stephen White4408b7f2018-11-01 13:59:19 +000026 class PipelineLayout;
Austin Engcfeda4d2017-06-05 17:22:48 -040027
Enrico Galli311a17a2021-01-19 20:29:22 +000028 struct FirstOffsetInfo {
29 bool usesVertexIndex;
30 uint32_t vertexIndexOffset;
31 bool usesInstanceIndex;
32 uint32_t instanceIndexOffset;
33 };
34
35 // Manages a ref to one of the various representations of shader blobs and information used to
36 // emulate vertex/instance index starts
Bryan Bernhart41b3f9c2020-11-20 20:38:37 +000037 struct CompiledShader {
38 ScopedCachedBlob cachedShader;
39 ComPtr<ID3DBlob> compiledFXCShader;
40 ComPtr<IDxcBlob> compiledDXCShader;
41 D3D12_SHADER_BYTECODE GetD3D12ShaderBytecode() const;
Enrico Galli311a17a2021-01-19 20:29:22 +000042
43 FirstOffsetInfo firstOffsetInfo;
Bryan Bernhart41b3f9c2020-11-20 20:38:37 +000044 };
Corentin Wallezb8712c02020-09-09 22:55:17 +000045
Rafael Cintronc64242d2020-04-06 18:20:02 +000046 class ShaderModule final : public ShaderModuleBase {
Corentin Wallez2d62a372017-11-24 14:04:22 -050047 public:
Ryan Harrison58dbfca2019-11-14 16:10:45 +000048 static ResultOrError<ShaderModule*> Create(Device* device,
Austin Eng0d948f72020-12-07 18:12:13 +000049 const ShaderModuleDescriptor* descriptor,
50 ShaderModuleParseResult* parseResult);
Austin Engcfeda4d2017-06-05 17:22:48 -040051
Bryan Bernhart41b3f9c2020-11-20 20:38:37 +000052 ResultOrError<CompiledShader> Compile(const char* entryPointName,
53 SingleShaderStage stage,
54 PipelineLayout* layout,
55 uint32_t compileFlags);
56
57 private:
58 ShaderModule(Device* device, const ShaderModuleDescriptor* descriptor);
59 ~ShaderModule() override = default;
Austin Eng0d948f72020-12-07 18:12:13 +000060 MaybeError Initialize(ShaderModuleParseResult* parseResult);
Bryan Bernhart41b3f9c2020-11-20 20:38:37 +000061
Enrico Galli311a17a2021-01-19 20:29:22 +000062 ResultOrError<std::string> TranslateToHLSLWithTint(const char* entryPointName,
63 SingleShaderStage stage,
64 PipelineLayout* layout,
65 std::string* remappedEntryPointName,
66 FirstOffsetInfo* firstOffsetInfo) const;
Enrico Galli2b6b0f42020-11-05 18:52:49 +000067
68 ResultOrError<std::string> TranslateToHLSLWithSPIRVCross(const char* entryPointName,
69 SingleShaderStage stage,
70 PipelineLayout* layout) const;
Hugo Amiard216c10d2020-05-18 23:56:11 +000071
Bryan Bernhartf6006662021-01-12 18:21:33 +000072 ResultOrError<PersistentCacheKey> CreateHLSLKey(const char* entryPointName,
73 SingleShaderStage stage,
74 const std::string& hlslSource,
75 uint32_t compileFlags) const;
76
77 ResultOrError<uint64_t> GetDXCompilerVersion() const;
78 uint64_t GetD3DCompilerVersion() const;
Austin Eng0d948f72020-12-07 18:12:13 +000079
80#ifdef DAWN_ENABLE_WGSL
Ben Claytone0fecca2021-01-26 12:24:48 +000081 std::unique_ptr<tint::Program> mTintProgram;
Austin Eng0d948f72020-12-07 18:12:13 +000082#endif
Austin Engcfeda4d2017-06-05 17:22:48 -040083 };
84
Corentin Wallez49a65d02018-07-24 16:45:45 +020085}} // namespace dawn_native::d3d12
Austin Engcfeda4d2017-06-05 17:22:48 -040086
Corentin Wallez30965a72018-07-24 16:42:33 +020087#endif // DAWNNATIVE_D3D12_SHADERMODULED3D12_H_