X-Git-Url: http://git.mutantstargoat.com?a=blobdiff_plain;f=src%2Fvulkan%2Fshader-vk.cc;h=51c472269d9d2f3e555dcd237e119bfd6e338cdf;hb=f6ceb163227d00d7f97df1fc2dfbdd419c56277e;hp=1fa9fb3a6e2f6e8fed2f25fe2287cd4eb6adb720;hpb=05d269a194496bcef85da78652b947f5bf1c9bcf;p=demo diff --git a/src/vulkan/shader-vk.cc b/src/vulkan/shader-vk.cc index 1fa9fb3..51c4722 100644 --- a/src/vulkan/shader-vk.cc +++ b/src/vulkan/shader-vk.cc @@ -11,7 +11,7 @@ ShaderVK::~ShaderVK() destroy(); } -bool ShaderVK::load(const char *fname, SType type) +bool ShaderVK::load(const char *fname, ShaderType type) { char *vk_fname = new char[strlen(fname) + strlen(".spirv") + 1]; strcpy(vk_fname, fname); @@ -41,7 +41,7 @@ bool ShaderVK::create(char *buf, unsigned int bsz, const char *fname) sminf.codeSize = bsz; sminf.pCode = (uint32_t *)buf; - if(vkCreateShaderModule(vk_device, &sminf, 0, &sm) != VK_SUCCESS) { + if(vkCreateShaderModule(vk_device, &sminf, 0, &sdr) != VK_SUCCESS) { delete [] buf; fprintf(stderr, "Failed to create vertex shader module.\n"); @@ -54,7 +54,7 @@ bool ShaderVK::create(char *buf, unsigned int bsz, const char *fname) void ShaderVK::destroy() { - vkDestroyShaderModule(vk_device, sm, 0); + vkDestroyShaderModule(vk_device, sdr, 0); } ShaderProgramVK::ShaderProgramVK() @@ -63,48 +63,11 @@ ShaderProgramVK::ShaderProgramVK() ShaderProgramVK::~ShaderProgramVK() { + destroy(); } bool ShaderProgramVK::create() { - /* pipeline cache */ - VkPipelineCacheCreateInfo pcinf; - memset(&pcinf, 0, sizeof pcinf); - pcinf.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; - - VkPipelineCache pcache; - if(!vkCreatePipelineCache(vk_device, &pcinf, 0, &pcache) != VK_SUCCESS) { - fprintf(stderr, "Failed to create pipeline cache.\n"); - return false; - } - - /* pipeline */ - VkGraphicsPipelineCreateInfo gpinf; - memset(&gpinf, 0, sizeof gpinf); - gpinf.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; - gpinf.stageCount = 2; - - VkPipelineShaderStageCreateInfo ssinf[2]; - for(int i=0; i<2; i++) { - memset(&ssinf[i], 0, sizeof ssinf[i]); - ssinf[i].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; - - switch(shaders[i]->get_type()) { - case SDR_VERTEX: - ssinf[i].stage = VK_SHADER_STAGE_VERTEX_BIT; - break; - case SDR_FRAGMENT: - ssinf[i].stage = VK_SHADER_STAGE_FRAGMENT_BIT; - break; - default: - fprintf(stderr, "Failed to create graphics pipeline: Invalid shader type.\n"); - return false; - } - ssinf[i].module = ((ShaderVK *)shaders[i])->sm; - } - - gpinf.pStages = ssinf; - return true; } @@ -120,6 +83,12 @@ bool ShaderProgramVK::use() const void ShaderProgramVK::destroy() { + int len = sizeof shaders / sizeof *shaders; + + for(int i=0; i