VkFramebuffer vkobj;
};
+struct pipeline {
+ int used;
+ int vport[4], scissor[4];
+ VkShaderModule sdr[VKSDR_MAX];
+ VkPrimitiveTopology prim;
+ VkPolygonMode polymode;
+ VkCullModeFlags cull;
+ VkFrontFace frontface;
+ VkColorComponentFlags colorwr;
+ int zbuf, depthwr;
+ int stencil, stencilwr;
+ VkStencilOp sfail, szfail, szpass;
+ VkCompareOp sop;
+ unsigned int sref, smask;
+ int blend;
+ VkBlendFactor srcblend, dstblend, srcblend_a, dstblend_a;
+
+ int vkobj_valid;
+ VkPipeline vkobj;
+};
+
static struct rpass *rpasses;
static struct framebuf *framebufs;
+static struct pipeline *pipelines;
static int create_instance(void);
}
+int vk_create_pipeln(void)
+{
+ int i;
+ struct pipeline pipeln = {0}, *pp = &pipeln;
+
+ if(!pipelines) {
+ pipelines = darr_alloc(0, sizeof *pipelines);
+ darr_push(pipelines, &pipeln); /* add dummy pipeline */
+ }
+
+ for(i=1; i<darr_size(pipelines); i++) {
+ if(!pipelines[i].used) {
+ pp = pipelines + i;
+ }
+ }
+
+ /* init pipeline defaults */
+ memset(pp, 0, sizeof *pp);
+ pp->used = 1;
+ pp->vport[2] = pp->scissor[2] = 640;
+ pp->vport[3] = pp->scissor[3] = 480;
+ pp->prim = VKPRIM_TRIANGLES;
+ pp->polymode = VK_POLYGON_MODE_FILL;
+ pp->cull = VK_CULL_MODE_BACK_BIT;
+ pp->frontface = VK_FRONT_FACE_COUNTER_CLOCKWISE;
+ pp->colorwr = 0xf; /* RGBA */
+ pp->zbuf = 1;
+ pp->depthwr = 1;
+ pp->stencil = 0;
+ pp->stencilwr = 1;
+ pp->sop = VK_COMPARE_OP_ALWAYS;
+ pp->smask = 0xffffffff;
+ pp->blend = 0;
+ pp->srcblend = pp->srcblend_a = VK_BLEND_FACTOR_ONE;
+ pp->dstblend = pp->dstblend_a = VK_BLEND_FACTOR_ZERO;
+
+ if(pp == &pipeln) {
+ darr_push(pipelines, pp);
+ return darr_size(pipelines) - 1;
+ }
+ return pp - pipelines;
+}
+
+void vk_free_pipeln(int pp)
+{
+ if(!pipelines || pp < 1 || pp >= darr_size(pipelines)) {
+ return;
+ }
+
+ if(pipelines[pp].used && pipelines[pp].vkobj) {
+ vkDestroyPipeline(vkdev, pipelines[pp].vkobj, 0);
+ }
+ pipelines[pp].used = 0;
+}
+
+void vk_viewport(int pp, int x, int y, int width, int height)
+{
+ struct pipeline *p = pipelines + pp;
+ p->vport[0] = x;
+ p->vport[1] = y;
+ p->vport[2] = width;
+ p->vport[3] = height;
+ p->vkobj_valid = 0;
+}
+
+void vk_scissor(int pp, int x, int y, int width, int height)
+{
+ struct pipeline *p = pipelines + pp;
+ p->scissor[0] = x;
+ p->scissor[1] = y;
+ p->scissor[2] = width;
+ p->scissor[3] = height;
+ p->vkobj_valid = 0;
+}
+
+void vk_pipeln_shader(int pp, int type, VkShaderModule sdr)
+{
+ struct pipeline *p = pipelines + pp;
+ p->sdr[type] = sdr;
+ p->vkobj_valid = 0;
+}
+
+/* TODO: vertex input */
+void vk_pipeln_prim(int pp, int prim)
+{
+ struct pipeline *p = pipelines + pp;
+ p->prim = prim;
+ p->vkobj_valid = 0;
+}
+
+void vk_pipeln_polymode(int pp, int mode)
+{
+ struct pipeline *p = pipelines + pp;
+ p->polymode = mode;
+ p->vkobj_valid = 0;
+}
+
+void vk_pipeln_cull(int pp, int cull)
+{
+ struct pipeline *p = pipelines + pp;
+ p->cull = cull;
+ p->vkobj_valid = 0;
+}
+
+void vk_pipeln_frontface(int pp, int ff)
+{
+ struct pipeline *p = pipelines + pp;
+ p->frontface = ff;
+ p->vkobj_valid = 0;
+}
+
+void vk_pipeln_multisample(int pp, int nsamples)
+{
+ /* TODO */
+}
+
+void vk_pipeln_colormask(int pp, int r, int g, int b, int a)
+{
+ struct pipeline *p = pipelines + pp;
+ p->colorwr = 0;
+ if(r) p->colorwr |= VK_COLOR_COMPONENT_R_BIT;
+ if(g) p->colorwr |= VK_COLOR_COMPONENT_G_BIT;
+ if(b) p->colorwr |= VK_COLOR_COMPONENT_B_BIT;
+ if(a) p->colorwr |= VK_COLOR_COMPONENT_A_BIT;
+ p->vkobj_valid = 0;
+}
+
+void vk_pipeln_depthmask(int pp, int z)
+{
+ struct pipeline *p = pipelines + pp;
+ p->depthwr = z;
+ p->vkobj_valid = 0;
+}
+
+void vk_pipeln_stencilmask(int pp, int s)
+{
+ struct pipeline *p = pipelines + pp;
+ p->stencilwr = s;
+ p->vkobj_valid = 0;
+}
+
+void vk_pipeln_zbuffer(int pp, int enable)
+{
+ struct pipeline *p = pipelines + pp;
+ p->zbuf = enable;
+ p->vkobj_valid = 0;
+}
+
+void vk_pipeln_stencil(int pp, int enable)
+{
+ struct pipeline *p = pipelines + pp;
+ p->stencil = enable;
+ p->vkobj_valid = 0;
+}
+
+void vk_pipeln_stencil_op(int pp, int sfail, int zfail, int zpass)
+{
+ struct pipeline *p = pipelines + pp;
+ p->sfail = sfail;
+ p->szfail = zfail;
+ p->szpass = zpass;
+ p->vkobj_valid = 0;
+}
+
+void vk_pipeln_stencil_func(int pp, int op, unsigned int ref, unsigned int mask)
+{
+ struct pipeline *p = pipelines + pp;
+ p->sop = op;
+ p->sref = ref;
+ p->smask = mask;
+ p->vkobj_valid = 0;
+}
+
+void vk_pipeln_blend(int pp, int enable)
+{
+ struct pipeline *p = pipelines + pp;
+ p->blend = enable;
+ p->vkobj_valid = 0;
+}
+
+void vk_pipeln_blendfunc(int pp, int src, int dst)
+{
+ struct pipeline *p = pipelines + pp;
+ p->srcblend = src;
+ p->dstblend = dst;
+ p->vkobj_valid = 0;
+}
+
+VkPipeline vk_pipeln(int pp)
+{
+ struct pipeline *p = pipelines + pp;
+
+ if(p->vkobj_valid) {
+ return p->vkobj;
+ }
+ /* TODO */
+}
+
+
#define ARRSZ(arr) (sizeof arr / sizeof *arr)
static const char *known_layer_list[] = {
"VK_LAYER_GOOGLE_threading",
VKQ_XFER = 8
};
-/* shader types */
+/* shader types
+ * arranged so that: (1 << VKSDR_FOO) == VK_SHADER_STAGE_FOO_BIT
+ */
enum {
- VKSDR_VERTEX,
- VKSDR_PIXEL,
- VKSDR_TESS_CTL,
- VKSDR_TESS_EVAL,
- VKSDR_GEOM
+ VKSDR_VERTEX = 0,
+ VKSDR_TESS_CTL = 1,
+ VKSDR_TESS_EVAL = 2,
+ VKSDR_GEOM = 3,
+ VKSDR_PIXEL = 4,
+ VKSDR_COMPUTE = 5,
+
+ VKSDR_TASK = 6,
+ VKSDR_MESH = 7,
+
+ VKSDR_RAYGEN = 8,
+ VKSDR_ANYHIT = 9,
+ VKSDR_CLOSESTHIT = 10,
+ VKSDR_MISS = 11,
+ VKSDR_ISECT = 12,
+
+ VKSDR_MAX
};
/* primitives */
enum {
- VKPRIM_POINTS,
- VKPRIM_LINES,
- VKPRIM_TRIANGLES
+ VKPRIM_POINTS = VK_PRIMITIVE_TOPOLOGY_POINT_LIST,
+ VKPRIM_LINES = VK_PRIMITIVE_TOPOLOGY_LINE_LIST,
+ VKPRIM_TRIANGLES = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST
};
void vk_init_xwin(Display *dpy, Window win);
void vk_pipeln_polymode(int pp, int mode);
void vk_pipeln_cull(int pp, int cull);
void vk_pipeln_frontface(int pp, int ff);
-void vk_pipeln_linewidth(int pp, float w);
void vk_pipeln_multisample(int pp, int nsamples);
-void vk_pipeln_colormask(int pp, int r, int g, int b);
+void vk_pipeln_colormask(int pp, int r, int g, int b, int a);
void vk_pipeln_depthmask(int pp, int z);
void vk_pipeln_stencilmask(int pp, int s);
void vk_pipeln_zbuffer(int pp, int enable);
void vk_pipeln_stencil_func(int pp, int op, unsigned int ref, unsigned int mask);
void vk_pipeln_blend(int pp, int enable);
void vk_pipeln_blendfunc(int pp, int src, int dst);
+VkPipeline vk_pipeln(int pp);
#endif /* VK_H_ */