~mmach/netext73/mesa-ryzen

« back to all changes in this revision

Viewing changes to src/mesa/main/glspirv.c

  • Committer: mmach
  • Date: 2023-11-02 21:31:35 UTC
  • Revision ID: netbit73@gmail.com-20231102213135-18d4tzh7tj0uz752
2023-11-02 22:11:57

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
   struct gl_spirv_module *module;
75
75
   struct gl_shader_spirv_data *spirv_data;
76
76
 
 
77
   /* From OpenGL 4.6 Core spec, "7.2 Shader Binaries" :
 
78
    *
 
79
    * "An INVALID_VALUE error is generated if the data pointed to by binary
 
80
    *  does not match the specified binaryformat."
 
81
    *
 
82
    * However, the ARB_gl_spirv spec, under issue #16 says:
 
83
    *
 
84
    * "ShaderBinary is expected to form an association between the SPIR-V
 
85
    *  module and likely would not parse the module as would be required to
 
86
    *  detect unsupported capabilities or other validation failures."
 
87
    *
 
88
    * Which specifies little to no validation requirements. Nevertheless, the
 
89
    * two small checks below seem reasonable.
 
90
    */
 
91
   if (!binary || (length % 4) != 0) {
 
92
      _mesa_error(ctx, GL_INVALID_VALUE, "glShaderBinary");
 
93
      return;
 
94
   }
 
95
 
77
96
   module = malloc(sizeof(*module) + length);
78
97
   if (!module) {
79
98
      _mesa_error(ctx, GL_OUT_OF_MEMORY, "glShaderBinary");
329
348
{
330
349
   GET_CURRENT_CONTEXT(ctx);
331
350
   struct gl_shader *sh;
332
 
   bool has_entry_point;
333
351
   struct nir_spirv_specialization *spec_entries = NULL;
334
352
 
335
353
   if (!ctx->Extensions.ARB_gl_spirv) {
384
402
      spec_entries[i].defined_on_module = false;
385
403
   }
386
404
 
387
 
   has_entry_point =
388
 
      gl_spirv_validation((uint32_t *)&spirv_data->SpirVModule->Binary[0],
389
 
                          spirv_data->SpirVModule->Length / 4,
390
 
                          spec_entries, numSpecializationConstants,
391
 
                          sh->Stage, pEntryPoint);
392
 
 
393
 
   /* See previous spec comment */
394
 
   if (!has_entry_point) {
395
 
      _mesa_error(ctx, GL_INVALID_VALUE,
396
 
                  "glSpecializeShaderARB(\"%s\" is not a valid entry point"
397
 
                  " for shader)", pEntryPoint);
398
 
      goto end;
399
 
   }
400
 
 
401
 
   for (unsigned i = 0; i < numSpecializationConstants; ++i) {
402
 
      if (spec_entries[i].defined_on_module == false) {
403
 
         _mesa_error(ctx, GL_INVALID_VALUE,
404
 
                     "glSpecializeShaderARB(constant \"%i\" does not exist "
405
 
                     "in shader)", spec_entries[i].id);
406
 
         goto end;
 
405
   enum spirv_verify_result r = spirv_verify_gl_specialization_constants(
 
406
      (uint32_t *)&spirv_data->SpirVModule->Binary[0],
 
407
      spirv_data->SpirVModule->Length / 4,
 
408
      spec_entries, numSpecializationConstants,
 
409
      sh->Stage, pEntryPoint);
 
410
 
 
411
   switch (r) {
 
412
   case SPIRV_VERIFY_OK:
 
413
      break;
 
414
   case SPIRV_VERIFY_PARSER_ERROR:
 
415
      _mesa_error(ctx, GL_INVALID_VALUE,
 
416
                  "glSpecializeShaderARB(failed to parse entry point \"%s\""
 
417
                  " for shader)", pEntryPoint);
 
418
      goto end;
 
419
   case SPIRV_VERIFY_ENTRY_POINT_NOT_FOUND:
 
420
      _mesa_error(ctx, GL_INVALID_VALUE,
 
421
                  "glSpecializeShaderARB(could not find entry point \"%s\""
 
422
                  " for shader)", pEntryPoint);
 
423
      goto end;
 
424
   case SPIRV_VERIFY_UNKNOWN_SPEC_INDEX:
 
425
      for (unsigned i = 0; i < numSpecializationConstants; ++i) {
 
426
         if (spec_entries[i].defined_on_module == false) {
 
427
            _mesa_error(ctx, GL_INVALID_VALUE,
 
428
                        "glSpecializeShaderARB(constant \"%i\" does not exist "
 
429
                        "in shader)", spec_entries[i].id);
 
430
            break;
 
431
         }
407
432
      }
 
433
      goto end;
408
434
   }
409
435
 
410
436
   spirv_data->SpirVEntryPoint = ralloc_strdup(spirv_data, pEntryPoint);