| Corentin Wallez | 4a9ef4e | 2018-07-18 11:40:26 +0200 | [diff] [blame] | 1 | // Copyright 2017 The Dawn Authors |
| Austin Eng | cfeda4d | 2017-06-05 17:22:48 -0400 | [diff] [blame] | 2 | // |
| 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 Wallez | 30965a7 | 2018-07-24 16:42:33 +0200 | [diff] [blame] | 15 | #ifndef DAWNNATIVE_D3D12_SHADERMODULED3D12_H_ |
| 16 | #define DAWNNATIVE_D3D12_SHADERMODULED3D12_H_ |
| Austin Eng | cfeda4d | 2017-06-05 17:22:48 -0400 | [diff] [blame] | 17 | |
| Bryan Bernhart | 41b3f9c | 2020-11-20 20:38:37 +0000 | [diff] [blame] | 18 | #include "dawn_native/PersistentCache.h" |
| Corentin Wallez | d37523f | 2018-07-24 13:53:51 +0200 | [diff] [blame] | 19 | #include "dawn_native/ShaderModule.h" |
| Austin Eng | cfeda4d | 2017-06-05 17:22:48 -0400 | [diff] [blame] | 20 | |
| Hugo Amiard | 216c10d | 2020-05-18 23:56:11 +0000 | [diff] [blame] | 21 | #include "dawn_native/d3d12/d3d12_platform.h" |
| 22 | |
| Corentin Wallez | 49a65d0 | 2018-07-24 16:45:45 +0200 | [diff] [blame] | 23 | namespace dawn_native { namespace d3d12 { |
| Austin Eng | cfeda4d | 2017-06-05 17:22:48 -0400 | [diff] [blame] | 24 | |
| 25 | class Device; |
| Stephen White | 4408b7f | 2018-11-01 13:59:19 +0000 | [diff] [blame] | 26 | class PipelineLayout; |
| Austin Eng | cfeda4d | 2017-06-05 17:22:48 -0400 | [diff] [blame] | 27 | |
| Enrico Galli | 311a17a | 2021-01-19 20:29:22 +0000 | [diff] [blame] | 28 | 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 Bernhart | 41b3f9c | 2020-11-20 20:38:37 +0000 | [diff] [blame] | 37 | struct CompiledShader { |
| 38 | ScopedCachedBlob cachedShader; |
| 39 | ComPtr<ID3DBlob> compiledFXCShader; |
| 40 | ComPtr<IDxcBlob> compiledDXCShader; |
| 41 | D3D12_SHADER_BYTECODE GetD3D12ShaderBytecode() const; |
| Enrico Galli | 311a17a | 2021-01-19 20:29:22 +0000 | [diff] [blame] | 42 | |
| 43 | FirstOffsetInfo firstOffsetInfo; |
| Bryan Bernhart | 41b3f9c | 2020-11-20 20:38:37 +0000 | [diff] [blame] | 44 | }; |
| Corentin Wallez | b8712c0 | 2020-09-09 22:55:17 +0000 | [diff] [blame] | 45 | |
| Rafael Cintron | c64242d | 2020-04-06 18:20:02 +0000 | [diff] [blame] | 46 | class ShaderModule final : public ShaderModuleBase { |
| Corentin Wallez | 2d62a37 | 2017-11-24 14:04:22 -0500 | [diff] [blame] | 47 | public: |
| Ryan Harrison | 58dbfca | 2019-11-14 16:10:45 +0000 | [diff] [blame] | 48 | static ResultOrError<ShaderModule*> Create(Device* device, |
| Austin Eng | 0d948f7 | 2020-12-07 18:12:13 +0000 | [diff] [blame] | 49 | const ShaderModuleDescriptor* descriptor, |
| 50 | ShaderModuleParseResult* parseResult); |
| Austin Eng | cfeda4d | 2017-06-05 17:22:48 -0400 | [diff] [blame] | 51 | |
| Bryan Bernhart | 41b3f9c | 2020-11-20 20:38:37 +0000 | [diff] [blame] | 52 | 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 Eng | 0d948f7 | 2020-12-07 18:12:13 +0000 | [diff] [blame] | 60 | MaybeError Initialize(ShaderModuleParseResult* parseResult); |
| Bryan Bernhart | 41b3f9c | 2020-11-20 20:38:37 +0000 | [diff] [blame] | 61 | |
| Enrico Galli | 311a17a | 2021-01-19 20:29:22 +0000 | [diff] [blame] | 62 | ResultOrError<std::string> TranslateToHLSLWithTint(const char* entryPointName, |
| 63 | SingleShaderStage stage, |
| 64 | PipelineLayout* layout, |
| 65 | std::string* remappedEntryPointName, |
| 66 | FirstOffsetInfo* firstOffsetInfo) const; |
| Enrico Galli | 2b6b0f4 | 2020-11-05 18:52:49 +0000 | [diff] [blame] | 67 | |
| 68 | ResultOrError<std::string> TranslateToHLSLWithSPIRVCross(const char* entryPointName, |
| 69 | SingleShaderStage stage, |
| 70 | PipelineLayout* layout) const; |
| Hugo Amiard | 216c10d | 2020-05-18 23:56:11 +0000 | [diff] [blame] | 71 | |
| Bryan Bernhart | f600666 | 2021-01-12 18:21:33 +0000 | [diff] [blame] | 72 | 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 Eng | 0d948f7 | 2020-12-07 18:12:13 +0000 | [diff] [blame] | 79 | |
| 80 | #ifdef DAWN_ENABLE_WGSL |
| Ben Clayton | e0fecca | 2021-01-26 12:24:48 +0000 | [diff] [blame] | 81 | std::unique_ptr<tint::Program> mTintProgram; |
| Austin Eng | 0d948f7 | 2020-12-07 18:12:13 +0000 | [diff] [blame] | 82 | #endif |
| Austin Eng | cfeda4d | 2017-06-05 17:22:48 -0400 | [diff] [blame] | 83 | }; |
| 84 | |
| Corentin Wallez | 49a65d0 | 2018-07-24 16:45:45 +0200 | [diff] [blame] | 85 | }} // namespace dawn_native::d3d12 |
| Austin Eng | cfeda4d | 2017-06-05 17:22:48 -0400 | [diff] [blame] | 86 | |
| Corentin Wallez | 30965a7 | 2018-07-24 16:42:33 +0200 | [diff] [blame] | 87 | #endif // DAWNNATIVE_D3D12_SHADERMODULED3D12_H_ |