• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 : public mtl::ProvokingVertexCacheSpecializeShaderFactory
26 {
27   public:
28     ProvokingVertexHelper(ContextMtl *context,
29                           mtl::CommandQueue *commandQueue,
30                           DisplayMtl *display);
31     mtl::BufferRef preconditionIndexBuffer(ContextMtl *context,
32                                            mtl::BufferRef indexBuffer,
33                                            size_t indexCount,
34                                            size_t indexOffset,
35                                            bool primitiveRestartEnabled,
36                                            gl::PrimitiveMode primitiveMode,
37                                            gl::DrawElementsType elementsType,
38                                            size_t &outIndexCount,
39                                            size_t &outIndexOffset,
40                                            gl::PrimitiveMode &outPrimitiveMode);
41 
42     mtl::BufferRef generateIndexBuffer(ContextMtl *context,
43                                        size_t first,
44                                        size_t indexCount,
45                                        gl::PrimitiveMode primitiveMode,
46                                        gl::DrawElementsType elementsType,
47                                        size_t &outIndexCount,
48                                        size_t &outIndexOffset,
49                                        gl::PrimitiveMode &outPrimitiveMode);
50 
51     void commitPreconditionCommandBuffer(ContextMtl *context);
52     void ensureCommandBufferReady();
53     void onDestroy(ContextMtl *context);
54     mtl::ComputeCommandEncoder *getComputeCommandEncoder();
55 
56   private:
57     id<MTLLibrary> mProvokingVertexLibrary;
58     mtl::CommandBuffer mCommandBuffer;
59     mtl::BufferPool mIndexBuffers;
60     mtl::ProvokingVertexComputePipelineCache mPipelineCache;
61     mtl::ProvokingVertexComputePipelineDesc mCachedDesc;
62     mtl::ComputeCommandEncoder mCurrentEncoder;
63 
64     // Program cache
65     virtual angle::Result getSpecializedShader(
66         rx::mtl::Context *context,
67         gl::ShaderType shaderType,
68         const mtl::ProvokingVertexComputePipelineDesc &renderPipelineDesc,
69         id<MTLFunction> *shaderOut) override;
70     // Private command buffer
71     virtual bool hasSpecializedShader(
72         gl::ShaderType shaderType,
73         const mtl::ProvokingVertexComputePipelineDesc &renderPipelineDesc) override;
74 
75     void prepareCommandEncoderForDescriptor(ContextMtl *context,
76                                             mtl::ComputeCommandEncoder *encoder,
77                                             mtl::ProvokingVertexComputePipelineDesc desc);
78 };
79 }  // namespace rx
80 #endif /* LIBANGLE_RENDERER_METAL_PROVOKINGVERTEXHELPER_H */
81