mojoshader_vulkan.c
changeset 1302 974d2cc3558e
parent 1280 d2a0d76469f9
child 1304 d68910d81b6e
equal deleted inserted replaced
1301:79bbc92200dc 1302:974d2cc3558e
    97     MOJOSHADER_vkUniformBuffer *vertUboBuffer;
    97     MOJOSHADER_vkUniformBuffer *vertUboBuffer;
    98     MOJOSHADER_vkUniformBuffer *fragUboBuffer;
    98     MOJOSHADER_vkUniformBuffer *fragUboBuffer;
    99 
    99 
   100     MOJOSHADER_vkProgram *bound_program;
   100     MOJOSHADER_vkProgram *bound_program;
   101     HashTable *linker_cache;
   101     HashTable *linker_cache;
       
   102 
       
   103     // Note that these may not necessarily align with bound_program!
       
   104     // We need to store these so effects can have overlapping shaders.
       
   105     MOJOSHADER_vkShader *bound_vshader;
       
   106     MOJOSHADER_vkShader *bound_pshader;
   102 
   107 
   103     #define VULKAN_INSTANCE_FUNCTION(ret, func, params) \
   108     #define VULKAN_INSTANCE_FUNCTION(ret, func, params) \
   104         vkfntype_MOJOSHADER_##func func;
   109         vkfntype_MOJOSHADER_##func func;
   105     #define VULKAN_DEVICE_FUNCTION(ret, func, params) \
   110     #define VULKAN_DEVICE_FUNCTION(ret, func, params) \
   106         vkfntype_MOJOSHADER_##func func;
   111         vkfntype_MOJOSHADER_##func func;
   633 MOJOSHADER_vkProgram *MOJOSHADER_vkLinkProgram(MOJOSHADER_vkShader *vshader,
   638 MOJOSHADER_vkProgram *MOJOSHADER_vkLinkProgram(MOJOSHADER_vkShader *vshader,
   634                                                MOJOSHADER_vkShader *pshader)
   639                                                MOJOSHADER_vkShader *pshader)
   635 {
   640 {
   636     MOJOSHADER_vkProgram *result;
   641     MOJOSHADER_vkProgram *result;
   637 
   642 
   638     if ((vshader == NULL) && (pshader == NULL))
   643     if ((vshader == NULL) || (pshader == NULL)) // Both shaders MUST exist!
   639         return NULL;
   644         return NULL;
   640 
   645 
   641     result = (MOJOSHADER_vkProgram *) ctx->malloc_fn(sizeof (MOJOSHADER_vkProgram),
   646     result = (MOJOSHADER_vkProgram *) ctx->malloc_fn(sizeof (MOJOSHADER_vkProgram),
   642                                                      ctx->malloc_data);
   647                                                      ctx->malloc_data);
   643     if (result == NULL)
   648     if (result == NULL)
   684 
   689 
   685     MOJOSHADER_vkProgram *program = NULL;
   690     MOJOSHADER_vkProgram *program = NULL;
   686     BoundShaders shaders;
   691     BoundShaders shaders;
   687     shaders.vertex = vshader;
   692     shaders.vertex = vshader;
   688     shaders.fragment = pshader;
   693     shaders.fragment = pshader;
       
   694 
       
   695     ctx->bound_vshader = vshader;
       
   696     ctx->bound_pshader = pshader;
   689 
   697 
   690     const void *val = NULL;
   698     const void *val = NULL;
   691     if (hash_find(ctx->linker_cache, &shaders, &val))
   699     if (hash_find(ctx->linker_cache, &shaders, &val))
   692         program = (MOJOSHADER_vkProgram *) val;
   700         program = (MOJOSHADER_vkProgram *) val;
   693     else
   701     else
   724     if (vshader != NULL)
   732     if (vshader != NULL)
   725     {
   733     {
   726         if (ctx->bound_program != NULL)
   734         if (ctx->bound_program != NULL)
   727             *vshader = ctx->bound_program->vertexShader;
   735             *vshader = ctx->bound_program->vertexShader;
   728         else
   736         else
   729             *vshader = NULL;
   737             *vshader = ctx->bound_vshader; // In case a pshader isn't set yet
   730     } // if
   738     } // if
   731     if (pshader != NULL)
   739     if (pshader != NULL)
   732     {
   740     {
   733         if (ctx->bound_program != NULL)
   741         if (ctx->bound_program != NULL)
   734             *pshader = ctx->bound_program->pixelShader;
   742             *pshader = ctx->bound_program->pixelShader;
   735         else
   743         else
   736             *pshader = NULL;
   744             *pshader = ctx->bound_pshader; // In case a vshader isn't set yet
   737     } // if
   745     } // if
   738 } // MOJOSHADER_vkGetBoundShaders
   746 } // MOJOSHADER_vkGetBoundShaders
   739 
   747 
   740 void MOJOSHADER_vkMapUniformBufferMemory(float **vsf, int **vsi, unsigned char **vsb,
   748 void MOJOSHADER_vkMapUniformBufferMemory(float **vsf, int **vsi, unsigned char **vsb,
   741                                          float **psf, int **psi, unsigned char **psb)
   749                                          float **psf, int **psi, unsigned char **psb)
   748     *psb = ctx->ps_reg_file_b;
   756     *psb = ctx->ps_reg_file_b;
   749 } // MOJOSHADER_vkMapUniformBufferMemory
   757 } // MOJOSHADER_vkMapUniformBufferMemory
   750 
   758 
   751 void MOJOSHADER_vkUnmapUniformBufferMemory()
   759 void MOJOSHADER_vkUnmapUniformBufferMemory()
   752 {
   760 {
   753     /* Why is this function named unmap instead of update?
   761     if (ctx->bound_program == NULL)
   754      * the world may never know...
   762         return; // Ignore buffer updates until we have a real program linked
   755      */
       
   756     assert(ctx->bound_program != NULL);
       
   757     update_uniform_buffer(ctx->bound_program->vertexShader);
   763     update_uniform_buffer(ctx->bound_program->vertexShader);
   758     update_uniform_buffer(ctx->bound_program->pixelShader);
   764     update_uniform_buffer(ctx->bound_program->pixelShader);
   759 } // MOJOSHADER_vkUnmapUniformBufferMemory
   765 } // MOJOSHADER_vkUnmapUniformBufferMemory
   760 
   766 
   761 void MOJOSHADER_vkGetUniformBuffers(VkBuffer *vbuf, unsigned long long *voff, unsigned long long *vsize,
   767 void MOJOSHADER_vkGetUniformBuffers(VkBuffer *vbuf, unsigned long long *voff, unsigned long long *vsize,