diff options
| author | j-p <jp.bruyere@live.be> | 2018-04-14 06:26:08 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-04-14 06:26:08 +0200 |
| commit | d37f97b2e866ccb94606f19e239bf15ad2201556 (patch) | |
| tree | bb359f660514d5b2b1a3101577d8c09e6f6d29e0 /src | |
| parent | e9f311def74bf9f4e124ca0d73a70e40bdbd3cfb (diff) | |
| parent | 2ac48aa6ee1fd888bf739e0f245bc4d6d13e6a8e (diff) | |
Merge pull request #5 from jpbruyere/devel2
Devel2
Diffstat (limited to 'src')
| -rw-r--r-- | src/vkvg_context.c | 14 | ||||
| -rw-r--r-- | src/vkvg_context_internal.c | 31 | ||||
| -rw-r--r-- | src/vkvg_context_internal.h | 1 | ||||
| -rw-r--r-- | src/vkvg_device_internal.c | 37 | ||||
| -rw-r--r-- | src/vkvg_surface.c | 5 |
5 files changed, 67 insertions, 21 deletions
diff --git a/src/vkvg_context.c b/src/vkvg_context.c index 9569b73..7bb9cdd 100644 --- a/src/vkvg_context.c +++ b/src/vkvg_context.c @@ -23,7 +23,7 @@ VkvgContext vkvg_create(VkvgSurface surf) push_constants pc = { {}, {2.0f/(float)ctx->pSurf->width,2.0f/(float)ctx->pSurf->height}, - {-1.f,-1.f}, + {0.f,0.f}, VKVG_SRC_SOLID }; ctx->pushConsts = pc; @@ -50,6 +50,8 @@ VkvgContext vkvg_create(VkvgSurface surf) _init_cmd_buff (ctx); _clear_path (ctx); + + return ctx; } void vkvg_flush (VkvgContext ctx){ @@ -425,10 +427,17 @@ void _vkvg_fill_rectangle (VkvgContext ctx, float x, float y, float width, float } void vkvg_paint (VkvgContext ctx){ _vkvg_fill_rectangle (ctx, 0, 0, ctx->pSurf->width, ctx->pSurf->height); + _record_draw_cmd (ctx); } void vkvg_set_rgba (VkvgContext ctx, float r, float g, float b, float a) { + if (ctx->pushConsts.srcType == VKVG_SRC_PATTERN){ + _flush_cmd_buff (ctx); + _reset_src_descriptor_set (ctx); + _init_cmd_buff (ctx); + } + vec4 c = {r,g,b,a}; ctx->pushConsts.source = c; ctx->pushConsts.srcType = VKVG_SRC_SOLID; @@ -464,7 +473,8 @@ void vkvg_set_source_surface(VkvgContext ctx, VkvgSurface surf, float x, float y ctx->source = surf->img; - vkh_image_create_sampler(ctx->source,VK_FILTER_NEAREST, VK_FILTER_NEAREST, + if (vkh_image_get_sampler(ctx->source) == VK_NULL_HANDLE) + vkh_image_create_sampler(ctx->source,VK_FILTER_NEAREST, VK_FILTER_NEAREST, VK_SAMPLER_MIPMAP_MODE_NEAREST,VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER); if (vkh_image_get_layout (ctx->source) != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL){ diff --git a/src/vkvg_context_internal.c b/src/vkvg_context_internal.c index 97a14b1..3d7f317 100644 --- a/src/vkvg_context_internal.c +++ b/src/vkvg_context_internal.c @@ -89,6 +89,13 @@ void _record_draw_cmd (VkvgContext ctx){ if (ctx->indCount == ctx->curIndStart) return; vkCmdDrawIndexed(ctx->cmd, ctx->indCount - ctx->curIndStart, 1, ctx->curIndStart, 0, 1); + + //DEBUG + /*vkCmdBindPipeline(ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->pSurf->dev->pipelineWired); + vkCmdDrawIndexed(ctx->cmd, ctx->indCount - ctx->curIndStart, 1, ctx->curIndStart, 0, 1); + vkCmdBindPipeline(ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->pSurf->dev->pipeline);*/ + ////////// + ctx->curIndStart = ctx->indCount; } @@ -152,7 +159,7 @@ void _init_cmd_buff (VkvgContext ctx){ //clearValues[0].color = { { 0.0f, 0.0f, 0.0f, 1.0f } }; //clearValues[1].depthStencil = { 1.0f, 0 }; VkClearValue clearValues[4] = { - { 0.0f, 0.0f, 0.0f, 1.0f }, + { 0.0f, 1.0f, 0.0f, 1.0f }, { 0.0f, 0.0f, 0.0f, 1.0f }, { 1.0f, 0 }, { 1.0f, 0 } @@ -161,9 +168,9 @@ void _init_cmd_buff (VkvgContext ctx){ .renderPass = ctx->pSurf->dev->renderPass, .framebuffer = ctx->pSurf->fb, .renderArea.extent = {ctx->pSurf->width,ctx->pSurf->height}, - }; - //.clearValueCount = 4, - //.pClearValues = clearValues}; + .clearValueCount = 4, + .pClearValues = clearValues}; + vkh_cmd_begin (ctx->cmd,VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT); vkCmdBeginRenderPass (ctx->cmd, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE); VkViewport viewport = {0,0,ctx->pSurf->width,ctx->pSurf->height,0,1}; @@ -224,6 +231,22 @@ void _update_descriptor_set (VkvgContext ctx, VkhImage img, VkDescriptorSet ds){ }; vkUpdateDescriptorSets(ctx->pSurf->dev->vkDev, 1, &writeDescriptorSet, 0, NULL); } + +/* + * Reset currently bound descriptor which image could be destroyed + */ +void _reset_src_descriptor_set (VkvgContext ctx){ + VkvgDevice dev = ctx->pSurf->dev; + //VkDescriptorSet dss[] = {ctx->dsSrc}; + vkFreeDescriptorSets (dev->vkDev, ctx->descriptorPool, 1, &ctx->dsSrc); + + VkDescriptorSetAllocateInfo descriptorSetAllocateInfo = { .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, + .descriptorPool = ctx->descriptorPool, + .descriptorSetCount = 1, + .pSetLayouts = &dev->dslSrc }; + VK_CHECK_RESULT(vkAllocateDescriptorSets(dev->vkDev, &descriptorSetAllocateInfo, &ctx->dsSrc)); +} + void _createDescriptorPool (VkvgContext ctx) { VkvgDevice dev = ctx->pSurf->dev; VkDescriptorPoolSize descriptorPoolSize = {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 2 }; diff --git a/src/vkvg_context_internal.h b/src/vkvg_context_internal.h index 5399dfc..fd20637 100644 --- a/src/vkvg_context_internal.h +++ b/src/vkvg_context_internal.h @@ -140,6 +140,7 @@ uint32_t _get_last_point_of_closed_path (VkvgContext ctx, uint32_t ptrPath); void _createDescriptorPool (VkvgContext ctx); void _init_descriptor_sets (VkvgContext ctx); void _update_descriptor_set (VkvgContext ctx, VkhImage img, VkDescriptorSet ds); +void _reset_src_descriptor_set(VkvgContext ctx); void _free_ctx_save (vkvg_context_save_t* sav); static inline float vec2_zcross (vec2 v1, vec2 v2){ diff --git a/src/vkvg_device_internal.c b/src/vkvg_device_internal.c index 61e6a94..360d1de 100644 --- a/src/vkvg_device_internal.c +++ b/src/vkvg_device_internal.c @@ -27,9 +27,9 @@ void _setupRenderPass(VkvgDevice dev) .format = FB_COLOR_FORMAT, .samples = VKVG_SAMPLES, .loadOp = VK_ATTACHMENT_LOAD_OP_LOAD, - .storeOp = VK_ATTACHMENT_STORE_OP_STORE, - .stencilLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD, - .stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE, + .storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE, + .stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE, + .stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE, .finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL }; VkAttachmentDescription attColorResolve = { .format = FB_COLOR_FORMAT, @@ -43,10 +43,10 @@ void _setupRenderPass(VkvgDevice dev) VkAttachmentDescription attDS = { .format = VK_FORMAT_S8_UINT, .samples = VKVG_SAMPLES, - .loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR, + .loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE, .storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE, - .stencilLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD, - .stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE, + .stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE, + .stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE, .finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL }; /* VkAttachmentDescription attDSResolve = { .format = VK_FORMAT_S8_UINT, @@ -164,8 +164,8 @@ void _setupPipelines(VkvgDevice dev) if (VKVG_SAMPLES != VK_SAMPLE_COUNT_1_BIT){ multisampleState.sampleShadingEnable = VK_TRUE; multisampleState.minSampleShading = 0.25f; - multisampleState.alphaToCoverageEnable = VK_FALSE; - multisampleState.alphaToOneEnable = VK_FALSE; + //multisampleState.alphaToCoverageEnable = VK_FALSE; + //multisampleState.alphaToOneEnable = VK_FALSE; } VkVertexInputBindingDescription vertexInputBinding = { .binding = 0, .stride = sizeof(Vertex), @@ -182,7 +182,7 @@ void _setupPipelines(VkvgDevice dev) .vertexAttributeDescriptionCount = 2, .pVertexAttributeDescriptions = vertexInputAttributs }; - VkShaderModule modVert, modFrag; + VkShaderModule modVert, modFrag, modFragWired; VkShaderModuleCreateInfo createInfo = { .sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO, .pCode = triangle_vert_spv, .codeSize = triangle_vert_spv_len }; @@ -190,6 +190,9 @@ void _setupPipelines(VkvgDevice dev) createInfo.pCode = triangle_frag_spv; createInfo.codeSize = triangle_frag_spv_len; VK_CHECK_RESULT(vkCreateShaderModule(dev->vkDev, &createInfo, NULL, &modFrag)); + createInfo.pCode = wired_frag_spv; + createInfo.codeSize = wired_frag_spv_len; + VK_CHECK_RESULT(vkCreateShaderModule(dev->vkDev, &createInfo, NULL, &modFragWired)); VkPipelineShaderStageCreateInfo vertStage = { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_VERTEX_BIT, @@ -238,16 +241,20 @@ void _setupPipelines(VkvgDevice dev) blendAttachmentState.alphaBlendOp = blendAttachmentState.colorBlendOp = VK_BLEND_OP_SUBTRACT; VK_CHECK_RESULT(vkCreateGraphicsPipelines(dev->vkDev, dev->pipelineCache, 1, &pipelineCreateInfo, NULL, &dev->pipeline_OP_SUB)); - inputAssemblyState.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; - rasterizationState.polygonMode = VK_POLYGON_MODE_LINE; - VK_CHECK_RESULT(vkCreateGraphicsPipelines(dev->vkDev, dev->pipelineCache, 1, &pipelineCreateInfo, NULL, &dev->pipelineWired)); - rasterizationState.polygonMode = VK_POLYGON_MODE_FILL; inputAssemblyState.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST; VK_CHECK_RESULT(vkCreateGraphicsPipelines(dev->vkDev, dev->pipelineCache, 1, &pipelineCreateInfo, NULL, &dev->pipelineLineList)); - vkDestroyShaderModule(dev->vkDev, shaderStages[0].module, NULL); - vkDestroyShaderModule(dev->vkDev, shaderStages[1].module, NULL); + shaderStages[1].module = modFragWired; + //pipelineCreateInfo.pStages = shaderStages; + + inputAssemblyState.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + rasterizationState.polygonMode = VK_POLYGON_MODE_LINE; + VK_CHECK_RESULT(vkCreateGraphicsPipelines(dev->vkDev, dev->pipelineCache, 1, &pipelineCreateInfo, NULL, &dev->pipelineWired)); + + vkDestroyShaderModule(dev->vkDev, modVert, NULL); + vkDestroyShaderModule(dev->vkDev, modFrag, NULL); + vkDestroyShaderModule(dev->vkDev, modFragWired, NULL); } void _createDescriptorSetLayout (VkvgDevice dev) { diff --git a/src/vkvg_surface.c b/src/vkvg_surface.c index 2fe0a9a..0e8955c 100644 --- a/src/vkvg_surface.c +++ b/src/vkvg_surface.c @@ -146,6 +146,11 @@ VkvgSurface vkvg_surface_create_from_image (VkvgDevice dev, const char* filePath //create tmp context with rendering pipeline to create the multisample img VkvgContext ctx = vkvg_create (surf); + + VkClearAttachment ca = {VK_IMAGE_ASPECT_COLOR_BIT,0, { 0.0f, 0.0f, 0.0f, 0.0f }}; + VkClearRect cr = {{{0,0},{surf->width,surf->height}},0,1}; + vkCmdClearAttachments(ctx->cmd, 1, &ca, 1, &cr); + vec4 srcRect = {0,0,surf->width,surf->height}; ctx->pushConsts.source = srcRect; ctx->pushConsts.srcType = VKVG_SRC_PATTERN; |