GrMtlPipelineStateBuilder.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright 2018 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #ifndef GrMtlPipelineStateBuilder_DEFINED
  8. #define GrMtlPipelineStateBuilder_DEFINED
  9. #include "src/gpu/GrPipeline.h"
  10. #include "src/gpu/GrProgramDesc.h"
  11. #include "src/gpu/glsl/GrGLSLProgramBuilder.h"
  12. #include "src/gpu/mtl/GrMtlUniformHandler.h"
  13. #include "src/gpu/mtl/GrMtlVaryingHandler.h"
  14. #include "src/sksl/SkSLCompiler.h"
  15. #import <Metal/Metal.h>
  16. class GrMtlGpu;
  17. class GrMtlPipelineState;
  18. class GrMtlPipelineStateBuilder : public GrGLSLProgramBuilder {
  19. public:
  20. /**
  21. * For Metal we want to cache the entire pipeline for reuse of draws. The Desc here holds all
  22. * the information needed to differentiate one pipeline from another.
  23. *
  24. * The GrProgramDesc contains all the information need to create the actual shaders for the
  25. * pipeline.
  26. *
  27. * For Metal we need to add to the GrProgramDesc to include the rest of the state on the
  28. * pipeline. This includes blending information and primitive type. The pipeline is immutable
  29. * so any remaining dynamic state is set via the MtlRenderCmdEncoder.
  30. */
  31. class Desc : public GrProgramDesc {
  32. public:
  33. static bool Build(Desc*,
  34. GrRenderTarget*,
  35. const GrPrimitiveProcessor&,
  36. const GrPipeline&,
  37. GrPrimitiveType,
  38. GrMtlGpu* gpu);
  39. size_t shaderKeyLength() const { return fShaderKeyLength; }
  40. private:
  41. size_t fShaderKeyLength;
  42. typedef GrProgramDesc INHERITED;
  43. };
  44. /** Generates a pipeline state.
  45. *
  46. * The GrMtlPipelineState implements what is specified in the GrPipeline and
  47. * GrPrimitiveProcessor as input. After successful generation, the builder result objects are
  48. * available to be used. This function may modify the program key by setting the surface origin
  49. * key to 0 (unspecified) if it turns out the program does not care about the surface origin.
  50. * @return true if generation was successful.
  51. */
  52. static GrMtlPipelineState* CreatePipelineState(GrMtlGpu*,
  53. GrRenderTarget*, GrSurfaceOrigin,
  54. const GrPrimitiveProcessor&,
  55. const GrTextureProxy* const primProcProxies[],
  56. const GrPipeline&,
  57. Desc*);
  58. private:
  59. GrMtlPipelineStateBuilder(GrMtlGpu*, GrRenderTarget*, GrSurfaceOrigin,
  60. const GrPipeline&,
  61. const GrPrimitiveProcessor&,
  62. const GrTextureProxy* const primProcProxies[],
  63. GrProgramDesc*);
  64. GrMtlPipelineState* finalize(GrRenderTarget* renderTarget,
  65. const GrPrimitiveProcessor& primProc,
  66. const GrPipeline& pipeline,
  67. Desc*);
  68. const GrCaps* caps() const override;
  69. void finalizeFragmentOutputColor(GrShaderVar& outputColor) override;
  70. void finalizeFragmentSecondaryColor(GrShaderVar& outputColor) override;
  71. id<MTLLibrary> createMtlShaderLibrary(const GrGLSLShaderBuilder& builder,
  72. SkSL::Program::Kind kind,
  73. const SkSL::Program::Settings& settings,
  74. GrProgramDesc* desc);
  75. GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; }
  76. const GrGLSLUniformHandler* uniformHandler() const override { return &fUniformHandler; }
  77. GrGLSLVaryingHandler* varyingHandler() override { return &fVaryingHandler; }
  78. GrMtlGpu* fGpu;
  79. GrMtlUniformHandler fUniformHandler;
  80. GrMtlVaryingHandler fVaryingHandler;
  81. typedef GrGLSLProgramBuilder INHERITED;
  82. };
  83. #endif