1 module gfx.graal.pipeline; 2 3 import gfx.core.rc; 4 import gfx.core.typecons; 5 import gfx.core.types; 6 import gfx.graal.format; 7 import gfx.graal.renderpass; 8 9 import std.typecons : Flag; 10 11 interface ShaderModule : AtomicRefCounted 12 { 13 @property string entryPoint(); 14 } 15 16 interface PipelineLayout : AtomicRefCounted 17 {} 18 19 interface Pipeline : AtomicRefCounted 20 {} 21 22 23 struct PipelineInfo { 24 GraphicsShaderSet shaders; 25 VertexInputBinding[] inputBindings; 26 VertexInputAttrib[] inputAttribs; 27 InputAssembly assembly; 28 Rasterizer rasterizer; 29 /// Viewport configuration of the pipeline. 30 /// For dynamic viewport, leave this array empty 31 ViewportConfig[] viewports; 32 33 // TODO: tesselation, multisample, depth-stencil 34 ColorBlendInfo blendInfo; 35 36 DynamicState[] dynamicStates; 37 38 PipelineLayout layout; 39 40 RenderPass renderPass; 41 uint subpassIndex; 42 } 43 44 enum ShaderLanguage { 45 spirV = 0x01, 46 glsl = 0x02, // TODO: glsl versions 47 } 48 49 enum ShaderStage { 50 vertex = 0x01, 51 tessellationControl = 0x02, 52 tessellationEvaluation = 0x04, 53 geometry = 0x08, 54 fragment = 0x10, 55 compute = 0x20, 56 57 allGraphics = 0x1f, 58 all = allGraphics | compute, 59 } 60 61 struct GraphicsShaderSet { 62 ShaderModule vertex; 63 ShaderModule tessControl; 64 ShaderModule tessEval; 65 ShaderModule geometry; 66 ShaderModule fragment; 67 } 68 69 70 /// Describes the binding of a buffer to the pipeline 71 struct VertexInputBinding { 72 uint binding; 73 size_t stride; 74 Flag!"instanced" instanced; 75 } 76 77 /// Describes a vertex attribute 78 struct VertexInputAttrib { 79 uint location; 80 uint binding; 81 Format format; 82 size_t offset; 83 } 84 85 86 enum Primitive { 87 pointList, lineList, lineStrip, 88 triangleList, triangleStrip, triangleFan, 89 lineListAdjacency, lineStripAdjacency, 90 triangleListAdjacency, triangleStripAdjacency, 91 patchList, 92 } 93 94 struct InputAssembly { 95 Primitive primitive; 96 Flag!"primitiveRestart" primitiveRestart; 97 } 98 99 enum FrontFace { 100 ccw, cw, 101 } 102 103 enum Cull { 104 none = 0x00, 105 front = 0x01, 106 back = 0x02, 107 frontAndBack = front | back, 108 } 109 110 enum PolygonMode { 111 fill, line, point, 112 } 113 114 struct DepthBias 115 { 116 float constantFactor; 117 float clamp; 118 float slopeFactor; 119 } 120 121 struct Rasterizer { 122 PolygonMode mode; 123 Cull cull; 124 FrontFace front; 125 Flag!"depthClamp" depthClamp; 126 Option!DepthBias depthBias; 127 float lineWidth=1f; 128 } 129 130 struct ViewportConfig { 131 Viewport viewport; 132 Rect scissors; 133 } 134 135 enum CompareOp 136 { 137 never, less, equal, lessOrEqual, greater, notEqual, greaterOrEqual, always, 138 } 139 140 enum BlendFactor 141 { 142 zero = 0, 143 one = 1, 144 srcColor = 2, 145 oneMinusSrcColor = 3, 146 dstColor = 4, 147 oneMinusDstColor = 5, 148 srcAlpha = 6, 149 oneMinusSrcAlpha = 7, 150 dstAlpha = 8, 151 oneMinusDstAlpha = 9, 152 constantColor = 10, 153 oneMinusConstantColor = 11, 154 constantAlpha = 12, 155 oneMinusConstantAlpha = 13, 156 srcAlphaSaturate = 14, 157 src1Color = 15, 158 oneMinusSrc1Color = 16, 159 src1Alpha = 17, 160 oneMinusSrc1Alpha = 18, 161 } 162 163 enum BlendOp { 164 add, 165 subtract, 166 reverseSubtract, 167 min, 168 max, 169 } 170 171 struct BlendState { 172 Trans!BlendFactor factor; 173 BlendOp op; 174 } 175 176 enum ColorMask { 177 r = 0x01, 178 g = 0x02, 179 b = 0x04, 180 a = 0x08, 181 182 all = r | g | b | a, 183 } 184 185 struct ColorBlendAttachment { 186 Flag!"enabled" enabled; 187 BlendState colorBlend; 188 BlendState alphaBlend; 189 ColorMask colorMask; 190 } 191 192 enum LogicOp { 193 clear, 194 and, 195 andReverse, 196 copy, 197 andInverted, 198 noop, 199 xor, 200 or, 201 nor, 202 equivalent, 203 invert, 204 orReverse, 205 copyInverted, 206 orInverted, 207 nand, 208 set, 209 } 210 211 struct ColorBlendInfo 212 { 213 Option!LogicOp logicOp; 214 ColorBlendAttachment[] attachments; 215 float[4] blendConstants; 216 } 217 218 enum DynamicState { 219 viewport, 220 scissor, 221 lineWidth, 222 depthBias, 223 blendConstants, 224 depthBounds, 225 stencilCmpMask, 226 stencilWriteMask, 227 stencilRef, 228 }