X-Git-Url: http://git.mutantstargoat.com?a=blobdiff_plain;f=src%2Fvulkan%2Fshader-vk.cc;h=1fa9fb3a6e2f6e8fed2f25fe2287cd4eb6adb720;hb=05d269a194496bcef85da78652b947f5bf1c9bcf;hp=eb22b97b1764fc193764d3af4fc61a3408afe947;hpb=72995482b98ff2a014ddd737131a0935ead89977;p=demo diff --git a/src/vulkan/shader-vk.cc b/src/vulkan/shader-vk.cc index eb22b97..1fa9fb3 100644 --- a/src/vulkan/shader-vk.cc +++ b/src/vulkan/shader-vk.cc @@ -2,8 +2,6 @@ #include "shader-vk.h" /* static variables */ -static vku_buffer ubo; - ShaderVK::ShaderVK() { } @@ -13,18 +11,50 @@ ShaderVK::~ShaderVK() destroy(); } -bool ShaderVK::create(char *buf, unsigned int bsz, const char *fname) +bool ShaderVK::load(const char *fname, SType type) { - return true; + char *vk_fname = new char[strlen(fname) + strlen(".spirv") + 1]; + strcpy(vk_fname, fname); + + char *suffix = strrchr(vk_fname, '.'); + + if(suffix) { + *suffix = 0; + } + + strcat(vk_fname, ".spirv"); + + bool res = Shader::load(vk_fname, type); + delete [] vk_fname; + + return res; } -bool ShaderVK::load(const char *fname, SType type) +bool ShaderVK::create(char *buf, unsigned int bsz, const char *fname) { + name = std::string(fname); + + VkShaderModuleCreateInfo sminf; + memset(&sminf, 0, sizeof sminf); + sminf.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; + + sminf.codeSize = bsz; + sminf.pCode = (uint32_t *)buf; + + if(vkCreateShaderModule(vk_device, &sminf, 0, &sm) != VK_SUCCESS) { + delete [] buf; + + fprintf(stderr, "Failed to create vertex shader module.\n"); + return false; + } + + delete [] buf; return true; } void ShaderVK::destroy() { + vkDestroyShaderModule(vk_device, sm, 0); } ShaderProgramVK::ShaderProgramVK() @@ -37,6 +67,44 @@ ShaderProgramVK::~ShaderProgramVK() 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; } @@ -57,45 +125,3 @@ void ShaderProgramVK::destroy() void ShaderProgramVK::attach_shader(Shader *shader) { } - -int ShaderProgramVK::get_uniform_location(const char *name) const -{ - return 0; -} - -void ShaderProgramVK::set_uniformi(int location, int value) -{ -} - -void ShaderProgramVK::set_uniformi(int location, int x, int y) -{ -} - -void ShaderProgramVK::set_uniformi(int location, int x, int y, int z) -{ -} - -void ShaderProgramVK::set_uniformi(int location, int x, int y, int z, int w) -{ -} - - -void ShaderProgramVK::set_uniformf(int location, float value) -{ -} - -void ShaderProgramVK::set_uniformf(int location, float x, float y) -{ -} - -void ShaderProgramVK::set_uniformf(int location, float x, float y, float z) -{ -} - -void ShaderProgramVK::set_uniformf(int location, float x, float y, float z, float w) -{ -} - -void ShaderProgramVK::set_uniform_matrix(int location, const Mat4 &mat) -{ -} \ No newline at end of file