Corentin Wallez | 4a9ef4e | 2018-07-18 11:40:26 +0200 | [diff] [blame] | 1 | // Copyright 2017 The Dawn Authors |
Corentin Wallez | 0ba5550 | 2017-06-14 15:46:59 -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_METAL_SHADERMODULEMTL_H_ |
| 16 | #define DAWNNATIVE_METAL_SHADERMODULEMTL_H_ |
Corentin Wallez | 0ba5550 | 2017-06-14 15:46:59 -0400 | [diff] [blame] | 17 | |
Corentin Wallez | d37523f | 2018-07-24 13:53:51 +0200 | [diff] [blame] | 18 | #include "dawn_native/ShaderModule.h" |
Corentin Wallez | 0ba5550 | 2017-06-14 15:46:59 -0400 | [diff] [blame] | 19 | |
Corentin Wallez | 0055d95 | 2020-11-16 23:07:56 +0000 | [diff] [blame] | 20 | #include "common/NSRef.h" |
Ryan Harrison | 58dbfca | 2019-11-14 16:10:45 +0000 | [diff] [blame] | 21 | #include "dawn_native/Error.h" |
| 22 | |
Corentin Wallez | 0055d95 | 2020-11-16 23:07:56 +0000 | [diff] [blame] | 23 | #import <Metal/Metal.h> |
| 24 | |
Corentin Wallez | ec9cf2a | 2022-01-12 09:17:35 +0000 | [diff] [blame^] | 25 | namespace dawn::native::metal { |
Corentin Wallez | 0ba5550 | 2017-06-14 15:46:59 -0400 | [diff] [blame] | 26 | |
Corentin Wallez | df67103 | 2018-08-20 17:01:20 +0200 | [diff] [blame] | 27 | class Device; |
Corentin Wallez | 30beb65 | 2017-07-26 12:35:35 -0400 | [diff] [blame] | 28 | class PipelineLayout; |
Idan Raiter | d315022 | 2020-08-13 23:53:59 +0000 | [diff] [blame] | 29 | class RenderPipeline; |
Corentin Wallez | 30beb65 | 2017-07-26 12:35:35 -0400 | [diff] [blame] | 30 | |
Rafael Cintron | c64242d | 2020-04-06 18:20:02 +0000 | [diff] [blame] | 31 | class ShaderModule final : public ShaderModuleBase { |
Corentin Wallez | f58d84d | 2017-11-24 14:12:44 -0500 | [diff] [blame] | 32 | public: |
Corentin Wallez | 50f9958 | 2021-03-31 18:36:32 +0000 | [diff] [blame] | 33 | static ResultOrError<Ref<ShaderModule>> Create(Device* device, |
| 34 | const ShaderModuleDescriptor* descriptor, |
| 35 | ShaderModuleParseResult* parseResult); |
Corentin Wallez | 0ba5550 | 2017-06-14 15:46:59 -0400 | [diff] [blame] | 36 | |
Corentin Wallez | f58d84d | 2017-11-24 14:12:44 -0500 | [diff] [blame] | 37 | struct MetalFunctionData { |
Corentin Wallez | 0055d95 | 2020-11-16 23:07:56 +0000 | [diff] [blame] | 38 | NSPRef<id<MTLFunction>> function; |
Corentin Wallez | bfc9cee | 2019-08-02 18:15:08 +0000 | [diff] [blame] | 39 | bool needsStorageBufferLength; |
Austin Eng | 5528d0e | 2021-09-15 18:16:50 +0000 | [diff] [blame] | 40 | std::vector<uint32_t> workgroupAllocations; |
Corentin Wallez | f58d84d | 2017-11-24 14:12:44 -0500 | [diff] [blame] | 41 | }; |
Shrek Shao | b0a5ed4 | 2021-11-04 18:43:10 +0000 | [diff] [blame] | 42 | |
| 43 | // MTLFunctionConstantValues needs @available tag to compile |
| 44 | // Use id (like void*) in function signature as workaround and do static cast inside |
Corentin Wallez | 676e8f3 | 2020-09-09 22:47:07 +0000 | [diff] [blame] | 45 | MaybeError CreateFunction(const char* entryPointName, |
| 46 | SingleShaderStage stage, |
| 47 | const PipelineLayout* layout, |
| 48 | MetalFunctionData* out, |
Shrek Shao | b0a5ed4 | 2021-11-04 18:43:10 +0000 | [diff] [blame] | 49 | id constantValues = nil, |
Corentin Wallez | 676e8f3 | 2020-09-09 22:47:07 +0000 | [diff] [blame] | 50 | uint32_t sampleMask = 0xFFFFFFFF, |
Jiawei Shao | 24cad6e | 2021-09-15 01:28:23 +0000 | [diff] [blame] | 51 | const RenderPipeline* renderPipeline = nullptr); |
Corentin Wallez | 0ba5550 | 2017-06-14 15:46:59 -0400 | [diff] [blame] | 52 | |
Corentin Wallez | f58d84d | 2017-11-24 14:12:44 -0500 | [diff] [blame] | 53 | private: |
Stephen White | c0f20fb | 2021-09-02 16:50:58 +0000 | [diff] [blame] | 54 | ResultOrError<std::string> TranslateToMSL(const char* entryPointName, |
| 55 | SingleShaderStage stage, |
| 56 | const PipelineLayout* layout, |
| 57 | uint32_t sampleMask, |
| 58 | const RenderPipeline* renderPipeline, |
Stephen White | c0f20fb | 2021-09-02 16:50:58 +0000 | [diff] [blame] | 59 | std::string* remappedEntryPointName, |
| 60 | bool* needsStorageBufferLength, |
Austin Eng | 5528d0e | 2021-09-15 18:16:50 +0000 | [diff] [blame] | 61 | bool* hasInvariantAttribute, |
| 62 | std::vector<uint32_t>* workgroupAllocations); |
Ryan Harrison | 58dbfca | 2019-11-14 16:10:45 +0000 | [diff] [blame] | 63 | ShaderModule(Device* device, const ShaderModuleDescriptor* descriptor); |
Rafael Cintron | c64242d | 2020-04-06 18:20:02 +0000 | [diff] [blame] | 64 | ~ShaderModule() override = default; |
Austin Eng | 0d948f7 | 2020-12-07 18:12:13 +0000 | [diff] [blame] | 65 | MaybeError Initialize(ShaderModuleParseResult* parseResult); |
Corentin Wallez | 0ba5550 | 2017-06-14 15:46:59 -0400 | [diff] [blame] | 66 | }; |
| 67 | |
Corentin Wallez | ec9cf2a | 2022-01-12 09:17:35 +0000 | [diff] [blame^] | 68 | } // namespace dawn::native::metal |
Corentin Wallez | 0ba5550 | 2017-06-14 15:46:59 -0400 | [diff] [blame] | 69 | |
Corentin Wallez | 30965a7 | 2018-07-24 16:42:33 +0200 | [diff] [blame] | 70 | #endif // DAWNNATIVE_METAL_SHADERMODULEMTL_H_ |