~mmach/netext73/mesa-ryzen

« back to all changes in this revision

Viewing changes to src/gallium/auxiliary/util/u_threaded_context.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:
695
695
   if (tc->options.parse_renderpass_info) {
696
696
      int renderpass_info_idx = next->renderpass_info_idx;
697
697
      if (renderpass_info_idx > 0) {
 
698
         /* don't reset if fb state is unflushed */
 
699
         bool fb_no_draw = tc->seen_fb_state && !tc->renderpass_info_recording->has_draw;
 
700
         uint32_t fb_info = tc->renderpass_info_recording->data32[0];
698
701
         next->renderpass_info_idx = -1;
699
702
         tc_batch_increment_renderpass_info(tc, tc->next, false);
 
703
         if (fb_no_draw)
 
704
            tc->renderpass_info_recording->data32[0] = fb_info;
700
705
      } else if (tc->renderpass_info_recording->has_draw) {
701
706
         tc->renderpass_info_recording->data32[0] = 0;
702
707
      }
1380
1385
 
1381
1386
struct tc_sampler_states {
1382
1387
   struct tc_call_base base;
1383
 
   ubyte shader, start, count;
 
1388
   uint8_t shader, start, count;
1384
1389
   void *slot[0]; /* more will be allocated if needed */
1385
1390
};
1386
1391
 
1458
1463
 
1459
1464
 
1460
1465
   if (tc->options.parse_renderpass_info) {
 
1466
      /* ensure this is treated as the first fb set if no fb activity has occurred */
 
1467
      if (!tc->renderpass_info_recording->has_draw &&
 
1468
          !tc->renderpass_info_recording->cbuf_clear &&
 
1469
          !tc->renderpass_info_recording->cbuf_load &&
 
1470
          !tc->renderpass_info_recording->zsbuf_load &&
 
1471
          !tc->renderpass_info_recording->zsbuf_clear_partial)
 
1472
         tc->batch_slots[tc->next].first_set_fb = false;
1461
1473
      /* store existing zsbuf data for possible persistence */
1462
1474
      uint8_t zsbuf = tc->renderpass_info_recording->has_draw ?
1463
1475
                      0 :
1533
1545
 
1534
1546
struct tc_patch_vertices {
1535
1547
   struct tc_call_base base;
1536
 
   ubyte patch_vertices;
 
1548
   uint8_t patch_vertices;
1537
1549
};
1538
1550
 
1539
1551
static uint16_t
1556
1568
 
1557
1569
struct tc_constant_buffer_base {
1558
1570
   struct tc_call_base base;
1559
 
   ubyte shader, index;
 
1571
   uint8_t shader, index;
1560
1572
   bool is_null;
1561
1573
};
1562
1574
 
1639
1651
 
1640
1652
struct tc_inlinable_constants {
1641
1653
   struct tc_call_base base;
1642
 
   ubyte shader;
1643
 
   ubyte num_values;
 
1654
   uint8_t shader;
 
1655
   uint8_t num_values;
1644
1656
   uint32_t values[MAX_INLINABLE_UNIFORMS];
1645
1657
};
1646
1658
 
1696
1708
 
1697
1709
struct tc_scissors {
1698
1710
   struct tc_call_base base;
1699
 
   ubyte start, count;
 
1711
   uint8_t start, count;
1700
1712
   struct pipe_scissor_state slot[0]; /* more will be allocated if needed */
1701
1713
};
1702
1714
 
1725
1737
 
1726
1738
struct tc_viewports {
1727
1739
   struct tc_call_base base;
1728
 
   ubyte start, count;
 
1740
   uint8_t start, count;
1729
1741
   struct pipe_viewport_state slot[0]; /* more will be allocated if needed */
1730
1742
};
1731
1743
 
1758
1770
struct tc_window_rects {
1759
1771
   struct tc_call_base base;
1760
1772
   bool include;
1761
 
   ubyte count;
 
1773
   uint8_t count;
1762
1774
   struct pipe_scissor_state slot[0]; /* more will be allocated if needed */
1763
1775
};
1764
1776
 
1787
1799
 
1788
1800
struct tc_sampler_views {
1789
1801
   struct tc_call_base base;
1790
 
   ubyte shader, start, count, unbind_num_trailing_slots;
 
1802
   uint8_t shader, start, count, unbind_num_trailing_slots;
1791
1803
   struct pipe_sampler_view *slot[0]; /* more will be allocated if needed */
1792
1804
};
1793
1805
 
1864
1876
 
1865
1877
struct tc_shader_images {
1866
1878
   struct tc_call_base base;
1867
 
   ubyte shader, start, count;
1868
 
   ubyte unbind_num_trailing_slots;
 
1879
   uint8_t shader, start, count;
 
1880
   uint8_t unbind_num_trailing_slots;
1869
1881
   struct pipe_image_view slot[0]; /* more will be allocated if needed */
1870
1882
};
1871
1883
 
1955
1967
 
1956
1968
struct tc_shader_buffers {
1957
1969
   struct tc_call_base base;
1958
 
   ubyte shader, start, count;
 
1970
   uint8_t shader, start, count;
1959
1971
   bool unbind;
1960
1972
   unsigned writable_bitmask;
1961
1973
   struct pipe_shader_buffer slot[0]; /* more will be allocated if needed */
2039
2051
 
2040
2052
struct tc_vertex_buffers {
2041
2053
   struct tc_call_base base;
2042
 
   ubyte start, count;
2043
 
   ubyte unbind_num_trailing_slots;
 
2054
   uint8_t start, count;
 
2055
   uint8_t unbind_num_trailing_slots;
2044
2056
   struct pipe_vertex_buffer slot[0]; /* more will be allocated if needed */
2045
2057
};
2046
2058
 
3093
3105
 
3094
3106
struct tc_texture_subdata {
3095
3107
   struct tc_call_base base;
3096
 
   unsigned level, usage, stride, layer_stride;
 
3108
   unsigned level, usage, stride;
3097
3109
   struct pipe_box box;
3098
3110
   struct pipe_resource *resource;
 
3111
   uintptr_t layer_stride;
3099
3112
   char slot[0]; /* more will be allocated if needed */
3100
3113
};
3101
3114
 
3116
3129
                   unsigned level, unsigned usage,
3117
3130
                   const struct pipe_box *box,
3118
3131
                   const void *data, unsigned stride,
3119
 
                   unsigned layer_stride)
 
3132
                   uintptr_t layer_stride)
3120
3133
{
3121
3134
   struct threaded_context *tc = threaded_context(_pipe);
3122
 
   unsigned size;
 
3135
   uint64_t size;
3123
3136
 
3124
3137
   assert(box->height >= 1);
3125
3138
   assert(box->depth >= 1);
3126
3139
 
3127
3140
   size = (box->depth - 1) * layer_stride +
3128
 
          (box->height - 1) * stride +
 
3141
          (box->height - 1) * (uint64_t)stride +
3129
3142
          box->width * util_format_get_blocksize(resource->format);
3130
3143
   if (!size)
3131
3144
      return;
3152
3165
            format = util_format_get_depth_only(format);
3153
3166
         else if (usage & PIPE_MAP_STENCIL_ONLY)
3154
3167
            format = PIPE_FORMAT_S8_UINT;
3155
 
         unsigned stride = util_format_get_stride(format, box->width);
3156
 
         unsigned layer_stride = util_format_get_2d_size(format, stride, box->height);
3157
 
         struct pipe_resource *pres = pipe_buffer_create_with_data(pipe, 0, PIPE_USAGE_STREAM, layer_stride * box->depth, data);
 
3168
 
 
3169
         unsigned fmt_stride = util_format_get_stride(format, box->width);
 
3170
         uint64_t fmt_layer_stride = util_format_get_2d_size(format, stride, box->height);
 
3171
         assert(fmt_layer_stride * box->depth <= UINT32_MAX);
 
3172
 
 
3173
         struct pipe_resource *pres = pipe_buffer_create(pipe->screen, 0, PIPE_USAGE_STREAM, layer_stride * box->depth);
 
3174
         pipe->buffer_subdata(pipe, pres, PIPE_MAP_WRITE | TC_TRANSFER_MAP_THREADED_UNSYNC, 0, layer_stride * box->depth, data);
3158
3175
         struct pipe_box src_box = *box;
3159
3176
         src_box.x = src_box.y = src_box.z = 0;
3160
 
         tc->base.resource_copy_region(&tc->base, resource, level, box->x, box->y, box->z, pres, 0, &src_box);
 
3177
 
 
3178
         if (fmt_stride == stride && fmt_layer_stride == layer_stride) {
 
3179
            /* if stride matches, single copy is fine*/
 
3180
            tc->base.resource_copy_region(&tc->base, resource, level, box->x, box->y, box->z, pres, 0, &src_box);
 
3181
         } else {
 
3182
            /* if stride doesn't match, inline util_copy_box on the GPU and assume the driver will optimize */
 
3183
            src_box.depth = 1;
 
3184
            for (unsigned z = 0; z < box->depth; ++z, src_box.x = z * layer_stride) {
 
3185
               unsigned dst_x = box->x, dst_y = box->y, width = box->width, height = box->height, dst_z = box->z + z;
 
3186
               int blocksize = util_format_get_blocksize(format);
 
3187
               int blockwidth = util_format_get_blockwidth(format);
 
3188
               int blockheight = util_format_get_blockheight(format);
 
3189
 
 
3190
               assert(blocksize > 0);
 
3191
               assert(blockwidth > 0);
 
3192
               assert(blockheight > 0);
 
3193
 
 
3194
               dst_x /= blockwidth;
 
3195
               dst_y /= blockheight;
 
3196
               width = DIV_ROUND_UP(width, blockwidth);
 
3197
               height = DIV_ROUND_UP(height, blockheight);
 
3198
 
 
3199
               width *= blocksize;
 
3200
 
 
3201
               if (width == fmt_stride && width == (unsigned)stride) {
 
3202
                  ASSERTED uint64_t size = (uint64_t)height * width;
 
3203
 
 
3204
                  assert(size <= SIZE_MAX);
 
3205
                  assert(dst_x + src_box.width < u_minify(pres->width0, level));
 
3206
                  assert(dst_y + src_box.height < u_minify(pres->height0, level));
 
3207
                  assert(pres->target != PIPE_TEXTURE_3D ||  z + src_box.depth < u_minify(pres->depth0, level));
 
3208
                  tc->base.resource_copy_region(&tc->base, resource, level, dst_x, dst_y, dst_z, pres, 0, &src_box);
 
3209
               } else {
 
3210
                  src_box.height = 1;
 
3211
                  for (unsigned i = 0; i < height; i++, dst_y++, src_box.x += stride)
 
3212
                     tc->base.resource_copy_region(&tc->base, resource, level, dst_x, dst_y, dst_z, pres, 0, &src_box);
 
3213
               }
 
3214
            }
 
3215
         }
 
3216
 
3161
3217
         pipe_resource_reference(&pres, NULL);
3162
3218
      } else {
3163
3219
         tc_sync(tc);