• 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_state_cache.h"
20 namespace rx
21 {
22 class ContextMtl;
23 
24 class ProvokingVertexHelper : public mtl::ProvokingVertexCacheSpecializeShaderFactory
25 {
26   public:
27     ProvokingVertexHelper(ContextMtl *context,
28                           mtl::CommandQueue *commandQueue,
29                           DisplayMtl *display);
30     mtl::BufferRef preconditionIndexBuffer(ContextMtl *context,
31                                            mtl::BufferRef indexBuffer,
32                                            size_t indexCount,
33                                            size_t indexOffset,
34                                            bool primitiveRestartEnabled,
35                                            gl::PrimitiveMode primitiveMode,
36                                            gl::DrawElementsType elementsType,
37                                            size_t &outIndexcount,
38                                            gl::PrimitiveMode &outPrimitiveMode);
39     void commitPreconditionCommandBuffer(ContextMtl *context);
40     void ensureCommandBufferReady();
41     void onDestroy(ContextMtl *context);
42     mtl::ComputeCommandEncoder *getComputeCommandEncoder();
43 
44   private:
45     id<MTLLibrary> mProvokingVertexLibrary;
46     mtl::CommandBuffer mCommandBuffer;
47     mtl::BufferPool mIndexBuffers;
48     mtl::ProvokingVertexComputePipelineCache mPipelineCache;
49     mtl::ProvokingVertexComputePipelineDesc mCachedDesc;
50     mtl::ComputeCommandEncoder mCurrentEncoder;
51 
52     // Program cache
53     virtual angle::Result getSpecializedShader(
54         rx::mtl::Context *context,
55         gl::ShaderType shaderType,
56         const mtl::ProvokingVertexComputePipelineDesc &renderPipelineDesc,
57         id<MTLFunction> *shaderOut) override;
58     // Private command buffer
59     virtual bool hasSpecializedShader(
60         gl::ShaderType shaderType,
61         const mtl::ProvokingVertexComputePipelineDesc &renderPipelineDesc) override;
62 
63     void prepareCommandEncoderForDescriptor(ContextMtl *context,
64                                             mtl::ComputeCommandEncoder *encoder,
65                                             mtl::ProvokingVertexComputePipelineDesc desc);
66 };
67 }  // namespace rx
68 #endif /* LIBANGLE_RENDERER_METAL_PROVOKINGVERTEXHELPER_H */
69