xref: /aosp_15_r20/external/angle/src/libANGLE/renderer/metal/ProvokingVertexHelper.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2021 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // ProvokingVertexHelper.h:
7 //    Manages re-writing index buffers when provoking vertex support is needed.
8 //    Handles points, lines, triangles, line strips, and triangle strips.
9 //    Line loops, and triangle fans should be pre-processed.
10 //
11 #ifndef LIBANGLE_RENDERER_METAL_PROVOKINGVERTEXHELPER_H
12 #define LIBANGLE_RENDERER_METAL_PROVOKINGVERTEXHELPER_H
13 
14 #include "libANGLE/Context.h"
15 #include "libANGLE/renderer/ContextImpl.h"
16 #include "libANGLE/renderer/metal/DisplayMtl.h"
17 #include "libANGLE/renderer/metal/mtl_buffer_pool.h"
18 #include "libANGLE/renderer/metal/mtl_command_buffer.h"
19 #include "libANGLE/renderer/metal/mtl_context_device.h"
20 #include "libANGLE/renderer/metal/mtl_state_cache.h"
21 namespace rx
22 {
23 class ContextMtl;
24 
25 class ProvokingVertexHelper : angle::NonCopyable
26 {
27   public:
28     ProvokingVertexHelper(ContextMtl *context);
29     angle::Result preconditionIndexBuffer(ContextMtl *context,
30                                           mtl::BufferRef indexBuffer,
31                                           size_t indexCount,
32                                           size_t indexOffset,
33                                           bool primitiveRestartEnabled,
34                                           gl::PrimitiveMode primitiveMode,
35                                           gl::DrawElementsType elementsType,
36                                           size_t &outIndexCount,
37                                           size_t &outIndexOffset,
38                                           gl::PrimitiveMode &outPrimitiveMode,
39                                           mtl::BufferRef &outNewBuffer);
40 
41     angle::Result generateIndexBuffer(ContextMtl *context,
42                                       size_t first,
43                                       size_t indexCount,
44                                       gl::PrimitiveMode primitiveMode,
45                                       gl::DrawElementsType elementsType,
46                                       size_t &outIndexCount,
47                                       size_t &outIndexOffset,
48                                       gl::PrimitiveMode &outPrimitiveMode,
49                                       mtl::BufferRef &outNewBuffer);
50 
51     void releaseInFlightBuffers(ContextMtl *contextMtl);
52     void ensureCommandBufferReady();
53     void onDestroy(ContextMtl *context);
54     mtl::ComputeCommandEncoder *getComputeCommandEncoder();
55 
56   private:
57     angle::Result getComputePipleineState(
58         ContextMtl *context,
59         const mtl::ProvokingVertexComputePipelineDesc &desc,
60         mtl::AutoObjCPtr<id<MTLComputePipelineState>> *outComputePipeline);
61 
62     angle::Result prepareCommandEncoderForDescriptor(ContextMtl *context,
63                                                      mtl::ComputeCommandEncoder *encoder,
64                                                      mtl::ProvokingVertexComputePipelineDesc desc);
65 
66     mtl::BufferPool mIndexBuffers;
67 
68     std::unordered_map<mtl::ProvokingVertexComputePipelineDesc, mtl::AutoObjCPtr<id<MTLFunction>>>
69         mComputeFunctions;
70 };
71 }  // namespace rx
72 #endif /* LIBANGLE_RENDERER_METAL_PROVOKINGVERTEXHELPER_H */
73