mojoshader.c
changeset 1224 21cd84f1aa0a
parent 1223 32ab7e4fbdc6
child 1225 50b8dd7e0b1a
equal deleted inserted replaced
1223:32ab7e4fbdc6 1224:21cd84f1aa0a
   261 #define AT_LEAST_ONE_PROFILE 1
   261 #define AT_LEAST_ONE_PROFILE 1
   262 #define PROFILE_EMITTER_ARB1(op) emit_ARB1_##op,
   262 #define PROFILE_EMITTER_ARB1(op) emit_ARB1_##op,
   263 PREDECLARE_PROFILE(ARB1)
   263 PREDECLARE_PROFILE(ARB1)
   264 #endif
   264 #endif
   265 
   265 
       
   266 #if !SUPPORT_PROFILE_SPIRV
       
   267 #define PROFILE_EMITTER_SPIRV(op)
       
   268 #else
       
   269 #undef AT_LEAST_ONE_PROFILE
       
   270 #define AT_LEAST_ONE_PROFILE 1
       
   271 #define PROFILE_EMITTER_SPIRV(op) emit_SPIRV_##op,
       
   272 PREDECLARE_PROFILE(SPIRV)
       
   273 #endif
       
   274 
   266 #if !AT_LEAST_ONE_PROFILE
   275 #if !AT_LEAST_ONE_PROFILE
   267 #error No profiles are supported. Fix your build.
   276 #error No profiles are supported. Fix your build.
   268 #endif
   277 #endif
   269 
   278 
   270 #define DEFINE_PROFILE(prof) { \
   279 #define DEFINE_PROFILE(prof) { \
   298     DEFINE_PROFILE(ARB1)
   307     DEFINE_PROFILE(ARB1)
   299 #endif
   308 #endif
   300 #if SUPPORT_PROFILE_METAL
   309 #if SUPPORT_PROFILE_METAL
   301     DEFINE_PROFILE(METAL)
   310     DEFINE_PROFILE(METAL)
   302 #endif
   311 #endif
       
   312 #if SUPPORT_PROFILE_SPIRV
       
   313     DEFINE_PROFILE(SPIRV)
       
   314 #endif
   303 };
   315 };
   304 
   316 
   305 #undef DEFINE_PROFILE
   317 #undef DEFINE_PROFILE
   306 
   318 
   307 // This is for profiles that extend other profiles...
   319 // This is for profiles that extend other profiles...
   319      PROFILE_EMITTER_D3D(op) \
   331      PROFILE_EMITTER_D3D(op) \
   320      PROFILE_EMITTER_BYTECODE(op) \
   332      PROFILE_EMITTER_BYTECODE(op) \
   321      PROFILE_EMITTER_GLSL(op) \
   333      PROFILE_EMITTER_GLSL(op) \
   322      PROFILE_EMITTER_ARB1(op) \
   334      PROFILE_EMITTER_ARB1(op) \
   323      PROFILE_EMITTER_METAL(op) \
   335      PROFILE_EMITTER_METAL(op) \
       
   336      PROFILE_EMITTER_SPIRV(op) \
   324 }
   337 }
   325 
   338 
   326 static int parse_destination_token(Context *ctx, DestArgInfo *info)
   339 static int parse_destination_token(Context *ctx, DestArgInfo *info)
   327 {
   340 {
   328     // !!! FIXME: recheck against the spec for ranges (like RASTOUT values, etc).
   341     // !!! FIXME: recheck against the spec for ranges (like RASTOUT values, etc).
  3443         retval->symbol_count = ctx->ctab.symbol_count;
  3456         retval->symbol_count = ctx->ctab.symbol_count;
  3444         retval->symbols = ctx->ctab.symbols;
  3457         retval->symbols = ctx->ctab.symbols;
  3445         retval->preshader = ctx->preshader;
  3458         retval->preshader = ctx->preshader;
  3446         retval->mainfn = ctx->mainfn;
  3459         retval->mainfn = ctx->mainfn;
  3447 
  3460 
       
  3461 #if SUPPORT_PROFILE_SPIRV
       
  3462         if (strcmp(retval->profile, "spirv") == 0)
       
  3463         {
       
  3464             size_t i, max;
       
  3465             int binary_size = retval->output_len - sizeof(SpirvPatchTable);
       
  3466             uint32 *binary = (uint32 *) retval->output;
       
  3467             SpirvPatchTable *table = (SpirvPatchTable *) &retval->output[binary_size];
       
  3468 
       
  3469             if (table->vpflip.offset)      binary[table->vpflip.offset]      = table->vpflip.location;
       
  3470             if (table->array_vec4.offset)  binary[table->array_vec4.offset]  = table->array_vec4.location;
       
  3471             if (table->array_ivec4.offset) binary[table->array_ivec4.offset] = table->array_ivec4.location;
       
  3472             if (table->array_bool.offset)  binary[table->array_bool.offset]  = table->array_bool.location;
       
  3473 
       
  3474             for (i = 0, max = STATICARRAYLEN(table->samplers); i < max; i++)
       
  3475             {
       
  3476                 SpirvPatchEntry entry = table->samplers[i];
       
  3477                 if (entry.offset)
       
  3478                     binary[entry.offset] = entry.location;
       
  3479             } // for
       
  3480         } // if
       
  3481 #endif
       
  3482 
  3448         // we don't own these now, retval does.
  3483         // we don't own these now, retval does.
  3449         ctx->ctab.symbols = NULL;
  3484         ctx->ctab.symbols = NULL;
  3450         ctx->preshader = NULL;
  3485         ctx->preshader = NULL;
  3451         ctx->ctab.symbol_count = 0;
  3486         ctx->ctab.symbol_count = 0;
  3452         ctx->mainfn = NULL;
  3487         ctx->mainfn = NULL;
  3826     PROFILE_SHADER_MODEL(MOJOSHADER_PROFILE_ARB1, 2);
  3861     PROFILE_SHADER_MODEL(MOJOSHADER_PROFILE_ARB1, 2);
  3827     PROFILE_SHADER_MODEL(MOJOSHADER_PROFILE_NV2, 2);
  3862     PROFILE_SHADER_MODEL(MOJOSHADER_PROFILE_NV2, 2);
  3828     PROFILE_SHADER_MODEL(MOJOSHADER_PROFILE_NV3, 2);
  3863     PROFILE_SHADER_MODEL(MOJOSHADER_PROFILE_NV3, 2);
  3829     PROFILE_SHADER_MODEL(MOJOSHADER_PROFILE_NV4, 3);
  3864     PROFILE_SHADER_MODEL(MOJOSHADER_PROFILE_NV4, 3);
  3830     PROFILE_SHADER_MODEL(MOJOSHADER_PROFILE_METAL, 3);
  3865     PROFILE_SHADER_MODEL(MOJOSHADER_PROFILE_METAL, 3);
       
  3866     PROFILE_SHADER_MODEL(MOJOSHADER_PROFILE_SPIRV, 3);
  3831     #undef PROFILE_SHADER_MODEL
  3867     #undef PROFILE_SHADER_MODEL
  3832     return -1;  // unknown profile?
  3868     return -1;  // unknown profile?
  3833 } // MOJOSHADER_maxShaderModel
  3869 } // MOJOSHADER_maxShaderModel
  3834 
  3870 
  3835 
  3871