~mmach/netext73/mesa-ryzen

« back to all changes in this revision

Viewing changes to src/gallium/drivers/etnaviv/etnaviv_shader.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:
34
34
#include "etnaviv_screen.h"
35
35
#include "etnaviv_util.h"
36
36
 
37
 
#include "tgsi/tgsi_parse.h"
38
37
#include "nir/tgsi_to_nir.h"
39
38
#include "util/u_atomic.h"
40
39
#include "util/u_cpu_detect.h"
58
57
   return true;
59
58
}
60
59
 
61
 
extern const char *tgsi_swizzle_names[];
62
60
void
63
61
etna_dump_shader(const struct etna_shader_variant *shader)
64
62
{
73
71
   printf("num temps: %i\n", shader->num_temps);
74
72
   printf("immediates:\n");
75
73
   for (int idx = 0; idx < shader->uniforms.count; ++idx) {
76
 
      printf(" [%i].%s = %f (0x%08x) (%d)\n",
 
74
      printf(" [%i].%c = %f (0x%08x) (%d)\n",
77
75
             idx / 4,
78
 
             tgsi_swizzle_names[idx % 4],
 
76
             "xyzw"[idx % 4],
79
77
             *((float *)&shader->uniforms.data[idx]),
80
78
             shader->uniforms.data[idx],
81
79
             shader->uniforms.contents[idx]);
121
119
                  struct etna_shader_variant *vs, struct etna_shader_variant *fs)
122
120
{
123
121
   struct etna_shader_link_info link = { };
124
 
   bool failed;
125
122
 
126
123
   assert(vs->stage == MESA_SHADER_VERTEX);
127
124
   assert(fs->stage == MESA_SHADER_FRAGMENT);
128
125
 
129
 
#ifdef DEBUG
130
 
   if (DBG_ENABLED(ETNA_DBG_DUMP_SHADERS)) {
131
 
      etna_dump_shader(vs);
132
 
      etna_dump_shader(fs);
133
 
   }
134
 
#endif
135
 
 
136
 
   failed = etna_link_shader(&link, vs, fs);
137
 
 
138
 
   if (failed) {
139
 
      /* linking failed: some fs inputs do not have corresponding
140
 
       * vs outputs */
141
 
      assert(0);
142
 
 
143
 
      return false;
144
 
   }
 
126
   etna_link_shader(&link, vs, fs);
145
127
 
146
128
   if (DBG_ENABLED(ETNA_DBG_LINKER_MSGS)) {
147
129
      debug_printf("link result:\n");
365
347
}
366
348
 
367
349
static inline const char *
368
 
etna_shader_stage(struct etna_shader_variant *shader)
 
350
etna_shader_stage(struct etna_shader *shader)
369
351
{
370
 
   switch (shader->stage) {
 
352
   switch (shader->nir->info.stage) {
371
353
   case MESA_SHADER_VERTEX:     return "VERT";
372
354
   case MESA_SHADER_FRAGMENT:   return "FRAG";
373
355
   case MESA_SHADER_COMPUTE:    return "CL";
380
362
static void
381
363
dump_shader_info(struct etna_shader_variant *v, struct util_debug_callback *debug)
382
364
{
383
 
   if (!unlikely(etna_mesa_debug & ETNA_DBG_SHADERDB))
 
365
   if (!DBG_ENABLED(ETNA_DBG_SHADERDB))
384
366
      return;
385
367
 
386
368
   util_debug_message(debug, SHADER_INFO,
387
369
         "%s shader: %u instructions, %u temps, "
388
370
         "%u immediates, %u loops",
389
 
         etna_shader_stage(v),
390
 
         v->code_size,
 
371
         etna_shader_stage(v->shader),
 
372
         v->code_size / 4,
391
373
         v->num_temps,
392
374
         v->uniforms.count,
393
375
         v->num_loops);
425
407
 
426
408
   etna_disk_cache_store(shader->compiler, v);
427
409
 
 
410
#ifdef DEBUG
 
411
   if (DBG_ENABLED(ETNA_DBG_DUMP_SHADERS))
 
412
      etna_dump_shader(v);
 
413
#endif
 
414
 
428
415
   return v;
429
416
 
430
417
fail:
435
422
struct etna_shader_variant *
436
423
etna_shader_variant(struct etna_shader *shader,
437
424
                    const struct etna_shader_key* const key,
438
 
                    struct util_debug_callback *debug)
 
425
                    struct util_debug_callback *debug,
 
426
                    bool called_from_draw)
439
427
{
440
428
   struct etna_shader_variant *v;
441
429
 
453
441
      dump_shader_info(v, debug);
454
442
   }
455
443
 
 
444
   if (called_from_draw) {
 
445
      perf_debug_message(debug, SHADER_INFO,
 
446
                         "%s shader: recompiling at draw time: global "
 
447
                         "0x%08x\n",
 
448
                         etna_shader_stage(shader), key->global);
 
449
   }
 
450
 
456
451
   return v;
457
452
}
458
453
 
467
462
static inline bool
468
463
initial_variants_synchronous(struct etna_context *ctx)
469
464
{
470
 
   return unlikely(ctx->base.debug.debug_message) || (etna_mesa_debug & ETNA_DBG_SHADERDB);
 
465
   return unlikely(ctx->base.debug.debug_message) || DBG_ENABLED(ETNA_DBG_SHADERDB);
471
466
}
472
467
 
473
468
static void
477
472
   struct util_debug_callback debug = {};
478
473
   static struct etna_shader_key key;
479
474
 
480
 
   etna_shader_variant(shader, &key, &debug);
 
475
   etna_shader_variant(shader, &key, &debug, false);
481
476
}
482
477
 
483
478
static void *
504
499
 
505
500
   if (initial_variants_synchronous(ctx)) {
506
501
      struct etna_shader_key key = {};
507
 
      etna_shader_variant(shader, &key, &ctx->base.debug);
 
502
      etna_shader_variant(shader, &key, &ctx->base.debug, false);
508
503
   } else {
509
504
      struct etna_screen *screen = ctx->screen;
510
505
      util_queue_add_job(&screen->shader_compiler_queue, shader, &shader->ready,
534
529
      etna_destroy_shader(t);
535
530
   }
536
531
 
537
 
   tgsi_free_tokens(shader->tokens);
538
532
   ralloc_free(shader->nir);
539
533
   util_queue_fence_destroy(&shader->ready);
540
534
   FREE(shader);
564
558
{
565
559
   struct etna_screen *screen = etna_screen(pscreen);
566
560
 
567
 
   util_queue_adjust_num_threads(&screen->shader_compiler_queue, max_threads);
 
561
   util_queue_adjust_num_threads(&screen->shader_compiler_queue, max_threads,
 
562
                                 false);
568
563
}
569
564
 
570
565
static bool