1 /*
2  * Copyright 2015 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 
8 #ifndef GrVkProgramDesc_DEFINED
9 #define GrVkProgramDesc_DEFINED
10 
11 #include "GrColor.h"
12 #include "GrProgramDesc.h"
13 #include "GrGpu.h"
14 #include "GrTypesPriv.h"
15 
16 #include "shaderc/shaderc.h"
17 #include "vulkan/vulkan.h"
18 
19 class GrVkGpu;
20 class GrVkProgramDescBuilder;
21 
22 class GrVkProgramDesc : public GrProgramDesc {
23 private:
24     friend class GrVkProgramDescBuilder;
25 };
26 
27 /**
28  * This class can be used to build a GrProgramDesc.  It also provides helpers for accessing
29  * GL specific info in the header.
30  */
31 class GrVkProgramDescBuilder {
32 public:
33     typedef GrProgramDesc::KeyHeader KeyHeader;
34     // The key, stored in fKey, is composed of five parts(first 2 are defined in the key itself):
35     // 1. uint32_t for total key length.
36     // 2. uint32_t for a checksum.
37     // 3. Header struct defined above.
38     // 4. Backend-specific information including per-processor keys and their key lengths.
39     //    Each processor's key is a variable length array of uint32_t.
40     enum {
41         // Part 3.
42         kHeaderOffset = GrVkProgramDesc::kHeaderOffset,
43         kHeaderSize = SkAlign4(sizeof(KeyHeader)),
44         // Part 4.
45         // This is the offset into the backenend specific part of the key, which includes
46         // per-processor keys.
47         kProcessorKeysOffset = kHeaderOffset + kHeaderSize,
48     };
49 
50     /**
51      * Builds a GL specific program descriptor
52      *
53      * @param GrPrimitiveProcessor The geometry
54      * @param GrPipeline  The optimized drawstate.  The descriptor will represent a program
55      *                        which this optstate can use to draw with.  The optstate contains
56      *                        general draw information, as well as the specific color, geometry,
57      *                        and coverage stages which will be used to generate the GL Program for
58      *                        this optstate.
59      * @param GrVkGpu  A GL Gpu, the caps and Gpu object are used to output processor specific
60      *                 parts of the descriptor.
61      * @param GrProgramDesc  The built and finalized descriptor
62      **/
63     static bool Build(GrProgramDesc*,
64                       const GrPrimitiveProcessor&,
65                       const GrPipeline&,
66                       const GrGLSLCaps&);
67 };
68 
69 #endif
70