1 //
2 // Copyright 2020 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 //    names, trademarks, service marks, or product names of the Licensor
11 //    and its affiliates, except as required to comply with Section 4(c) of
12 //    the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 //     http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_IMAGING_HGI_METAL_BLIT_CMDS_H
25 #define PXR_IMAGING_HGI_METAL_BLIT_CMDS_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hgiMetal/api.h"
29 #include "pxr/imaging/hgi/blitCmds.h"
30 
31 PXR_NAMESPACE_OPEN_SCOPE
32 
33 class HgiMetal;
34 
35 
36 /// \class HgiMetalBlitCmds
37 ///
38 /// Metal implementation of HgiBlitCmds.
39 ///
40 class HgiMetalBlitCmds final : public HgiBlitCmds
41 {
42 public:
43     HGIMETAL_API
44     ~HgiMetalBlitCmds() override;
45 
46     HGIMETAL_API
47     void PushDebugGroup(const char* label) override;
48 
49     HGIMETAL_API
50     void PopDebugGroup() override;
51 
52     HGIMETAL_API
53     void CopyTextureGpuToCpu(HgiTextureGpuToCpuOp const& copyOp) override;
54 
55     HGIMETAL_API
56     void CopyTextureCpuToGpu(HgiTextureCpuToGpuOp const& copyOp) override;
57 
58     HGIMETAL_API
59     void CopyBufferGpuToGpu(HgiBufferGpuToGpuOp const& copyOp) override;
60 
61     HGIMETAL_API
62     void CopyBufferCpuToGpu(HgiBufferCpuToGpuOp const& copyOp) override;
63 
64     HGIMETAL_API
65     void CopyBufferGpuToCpu(HgiBufferGpuToCpuOp const& copyOp) override;
66 
67     HGIMETAL_API
68     void CopyTextureToBuffer(HgiTextureToBufferOp const& copyOp) override;
69 
70     HGIMETAL_API
71     void CopyBufferToTexture(HgiBufferToTextureOp const& copyOp) override;
72 
73     HGIMETAL_API
74     void GenerateMipMaps(HgiTextureHandle const& texture) override;
75 
76     HGIMETAL_API
77     void MemoryBarrier(HgiMemoryBarrier barrier) override;
78 
79 protected:
80     friend class HgiMetal;
81 
82     HGIMETAL_API
83     HgiMetalBlitCmds(HgiMetal* hgi);
84 
85     HGIMETAL_API
86     bool _Submit(Hgi* hgi, HgiSubmitWaitType wait) override;
87 
88 private:
89     HgiMetalBlitCmds() = delete;
90     HgiMetalBlitCmds & operator=(const HgiMetalBlitCmds&) = delete;
91     HgiMetalBlitCmds(const HgiMetalBlitCmds&) = delete;
92 
93     void _CreateEncoder();
94 
95     HgiMetal* _hgi;
96     id<MTLCommandBuffer> _commandBuffer;
97     id<MTLBlitCommandEncoder> _blitEncoder;
98     NSString* _label;
99     bool _secondaryCommandBuffer;
100 
101     // BlitCmds is used only one frame so storing multi-frame state on BlitCmds
102     // will not survive.
103 };
104 
105 PXR_NAMESPACE_CLOSE_SCOPE
106 
107 #endif
108