nuclear@8: #include nuclear@8: #include nuclear@8: #include nuclear@8: #include nuclear@8: #include "vksdr.h" nuclear@8: #include "vku.h" nuclear@8: nuclear@8: VkShaderModule vku_load_shader(const char *fname) nuclear@8: { nuclear@8: int size; nuclear@8: VkShaderModuleCreateInfo inf; nuclear@8: VkShaderModule sdr; nuclear@8: FILE *fp; nuclear@9: void *buf = 0; nuclear@8: nuclear@8: if(!(fp = fopen(fname, "rb"))) { nuclear@8: fprintf(stderr, "vku_load_shader: failed to load %s: %s\n", fname, strerror(errno)); nuclear@8: return 0; nuclear@8: } nuclear@8: fseek(fp, 0, SEEK_END); nuclear@8: size = ftell(fp); nuclear@8: rewind(fp); nuclear@8: nuclear@8: if(!(buf = malloc(size + 1))) { nuclear@8: fprintf(stderr, "vku_load_shader: failed to allocate buffer\n"); nuclear@8: goto err; nuclear@8: } nuclear@8: if(fread(buf, 1, size, fp) < size) { nuclear@8: fprintf(stderr, "vku_load_shader: unexpected end of file while reading: %s\n", fname); nuclear@8: goto err; nuclear@8: } nuclear@8: nuclear@8: memset(&inf, 0, sizeof inf); nuclear@8: inf.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; nuclear@8: inf.codeSize = size; nuclear@9: inf.pCode = buf; nuclear@8: nuclear@8: if(vkCreateShaderModule(vkdev, &inf, 0, &sdr) != 0) { nuclear@8: fprintf(stderr, "vku_load_shader: failed to create shader: %s\n", fname); nuclear@8: goto err; nuclear@8: } nuclear@8: return sdr; nuclear@8: nuclear@8: err: nuclear@8: fclose(fp); nuclear@8: free(buf); nuclear@8: return 0; nuclear@8: } nuclear@8: nuclear@8: void vku_destroy_shader(VkShaderModule sdr) nuclear@8: { nuclear@8: vkDestroyShaderModule(vkdev, sdr, 0); nuclear@8: }