• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The Dawn Authors
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 
15 #ifndef DAWNNATIVE_METAL_UTILSMETAL_H_
16 #define DAWNNATIVE_METAL_UTILSMETAL_H_
17 
18 #include "dawn_native/dawn_platform.h"
19 #include "dawn_native/metal/DeviceMTL.h"
20 #include "dawn_native/metal/ShaderModuleMTL.h"
21 #include "dawn_native/metal/TextureMTL.h"
22 
23 #import <Metal/Metal.h>
24 
25 namespace dawn_native {
26     struct ProgrammableStage;
27     struct EntryPointMetadata;
28     enum class SingleShaderStage;
29 }
30 
31 namespace dawn_native { namespace metal {
32 
33     MTLCompareFunction ToMetalCompareFunction(wgpu::CompareFunction compareFunction);
34 
35     struct TextureBufferCopySplit {
36         static constexpr uint32_t kMaxTextureBufferCopyRegions = 3;
37 
38         struct CopyInfo {
39             NSUInteger bufferOffset;
40             NSUInteger bytesPerRow;
41             NSUInteger bytesPerImage;
42             Origin3D textureOrigin;
43             Extent3D copyExtent;
44         };
45 
46         uint32_t count = 0;
47         std::array<CopyInfo, kMaxTextureBufferCopyRegions> copies;
48 
beginTextureBufferCopySplit49         auto begin() const {
50             return copies.begin();
51         }
52 
endTextureBufferCopySplit53         auto end() const {
54             return copies.begin() + count;
55         }
56     };
57 
58     TextureBufferCopySplit ComputeTextureBufferCopySplit(const Texture* texture,
59                                                          uint32_t mipLevel,
60                                                          Origin3D origin,
61                                                          Extent3D copyExtent,
62                                                          uint64_t bufferSize,
63                                                          uint64_t bufferOffset,
64                                                          uint32_t bytesPerRow,
65                                                          uint32_t rowsPerImage,
66                                                          Aspect aspect);
67 
68     void EnsureDestinationTextureInitialized(CommandRecordingContext* commandContext,
69                                              Texture* texture,
70                                              const TextureCopy& dst,
71                                              const Extent3D& size);
72 
73     MTLBlitOption ComputeMTLBlitOption(const Format& format, Aspect aspect);
74 
75     // Helper function to create function with constant values wrapped in
76     // if available branch
77     MaybeError CreateMTLFunction(const ProgrammableStage& programmableStage,
78                                  SingleShaderStage singleShaderStage,
79                                  PipelineLayout* pipelineLayout,
80                                  ShaderModule::MetalFunctionData* functionData,
81                                  uint32_t sampleMask = 0xFFFFFFFF,
82                                  const RenderPipeline* renderPipeline = nullptr);
83 
84 }}  // namespace dawn_native::metal
85 
86 #endif  // DAWNNATIVE_METAL_UTILSMETAL_H_
87