@@ -418,14 +418,12 @@ vTensor::vTensor(
418418 padded_sizes_{calculate_padded_sizes (sizes, memory_layout_)},
419419 unsqueezed_strides_{unsqueeze_strides (strides_, numel_)},
420420 padded_numel_ (utils::multiply_integers(padded_sizes_)),
421- texture_limits_{{0 , 0 , 0 }},
422421 logical_limits_{{0 , 0 , 0 }},
423422 // Utility Uniform Buffers that can be passed to shaders as arguments
424423 sizes_uniform_ (),
425424 strides_uniform_(),
426425 numel_uniform_(),
427426 axis_map_uniform_(),
428- texture_limits_uniform_(),
429427 logical_limits_uniform_(),
430428 // Construct Tensor storage
431429 storage_(
@@ -440,12 +438,7 @@ vTensor::vTensor(
440438 dim_order_is_valid (dim_order_), " computed dim order is invalid" );
441439
442440 if (storage_type != utils::kBuffer ) {
443- texture_limits_.limits = utils::ivec3{
444- utils::safe_downcast<int32_t >(storage_.image_extents_ [0 ]),
445- utils::safe_downcast<int32_t >(storage_.image_extents_ [1 ]),
446- utils::safe_downcast<int32_t >(storage_.image_extents_ [2 ])};
447-
448- update_logical_limits ();
441+ set_logical_limits (storage_.image_extents_ );
449442 }
450443
451444 if (dtype == vkapi::kHalf ) {
@@ -470,14 +463,12 @@ vTensor::vTensor(const vTensor& other)
470463 other.unsqueezed_strides_ .begin (),
471464 other.unsqueezed_strides_ .end ()},
472465 padded_numel_ (other.padded_numel_),
473- texture_limits_{other.texture_limits_ },
474466 logical_limits_{other.logical_limits_ },
475467 // Empty initialize Utility Uniform Buffers
476468 sizes_uniform_ (),
477469 strides_uniform_(),
478470 numel_uniform_(),
479471 axis_map_uniform_(),
480- texture_limits_uniform_(),
481472 logical_limits_uniform_(),
482473 // Copy Tensor storage
483474 storage_(other.storage_) {}
@@ -498,14 +489,12 @@ vTensor::vTensor(
498489 padded_sizes_{calculate_padded_sizes (sizes, memory_layout_)},
499490 unsqueezed_strides_{unsqueeze_strides (strides_, numel_)},
500491 padded_numel_ (utils::multiply_integers(padded_sizes_)),
501- texture_limits_{other.texture_limits_ },
502492 logical_limits_(other.logical_limits_),
503493 // Empty initialize Utility Uniform Buffers
504494 sizes_uniform_(),
505495 strides_uniform_(),
506496 numel_uniform_(),
507497 axis_map_uniform_(),
508- texture_limits_uniform_(),
509498 logical_limits_uniform_(),
510499 // Copy Tensor storage
511500 storage_(other.storage_, vkapi::element_size(dtype_) * offset_numel) {
@@ -547,18 +536,10 @@ vkapi::VulkanBuffer& vTensor::buffer(
547536 return storage_.buffer_ ;
548537}
549538
550- void vTensor::update_logical_limits () {
551- logical_limits_.limits [0 ] = texture_limits_.limits [axis_map_.at (0 )];
552- logical_limits_.limits [1 ] = texture_limits_.limits [axis_map_.at (1 )];
553- logical_limits_.limits [2 ] = texture_limits_.limits [axis_map_.at (2 )];
554- }
555-
556- utils::uvec3 vTensor::logical_extents () const {
557- utils::uvec3 logical_extents (
558- {utils::safe_downcast<uint32_t >(logical_limits_.limits [0 ]),
559- utils::safe_downcast<uint32_t >(logical_limits_.limits [1 ]),
560- utils::safe_downcast<uint32_t >(logical_limits_.limits [2 ])});
561- return logical_extents;
539+ void vTensor::set_logical_limits (const utils::uvec3& image_extents) {
540+ logical_limits_.limits [0 ] = image_extents[axis_map_.at (0 )];
541+ logical_limits_.limits [1 ] = image_extents[axis_map_.at (1 )];
542+ logical_limits_.limits [2 ] = image_extents[axis_map_.at (2 )];
562543}
563544
564545const vkapi::BufferBindInfo vTensor::sizes_ubo () {
@@ -585,13 +566,6 @@ const vkapi::BufferBindInfo vTensor::axis_map_ubo() {
585566 return vkapi::BufferBindInfo (axis_map_uniform_.buffer ());
586567}
587568
588- const vkapi::BufferBindInfo vTensor::texture_limits_ubo () {
589- if (!texture_limits_uniform_.buffer ()) {
590- texture_limits_uniform_ = ParamsBuffer (storage_.context_ , texture_limits_);
591- }
592- return vkapi::BufferBindInfo (texture_limits_uniform_.buffer ());
593- }
594-
595569const vkapi::BufferBindInfo vTensor::logical_limits_ubo () {
596570 if (!logical_limits_uniform_.buffer ()) {
597571 logical_limits_uniform_ = ParamsBuffer (storage_.context_ , logical_limits_);
@@ -655,18 +629,10 @@ void vTensor::update_metadata() {
655629 unsqueezed_strides_ = unsqueeze_strides (strides_, numel_);
656630 padded_numel_ = utils::multiply_integers (padded_sizes_);
657631
658- // Calculate the extents of the image texture that would have been required
659- // for a tensor of the new sizes.
660- utils::uvec3 virtual_extents =
661- calculate_image_extents (padded_sizes_, axis_map_, memory_layout_);
662-
663- // Update the texture limits to reflect the new virtual extents.
664- texture_limits_.limits = utils::ivec3{
665- utils::safe_downcast<int32_t >(virtual_extents[0 ]),
666- utils::safe_downcast<int32_t >(virtual_extents[1 ]),
667- utils::safe_downcast<int32_t >(virtual_extents[2 ])};
668-
669- update_logical_limits ();
632+ // Calculate the image extents that would have been used to allocate a texture
633+ // withthe current sizes, and use that to set the logical limits.
634+ set_logical_limits (
635+ calculate_image_extents (padded_sizes_, axis_map_, memory_layout_));
670636
671637 if (sizes_uniform_.buffer ()) {
672638 sizes_uniform_.update (utils::make_whcn_ivec4 (sizes_));
@@ -680,9 +646,6 @@ void vTensor::update_metadata() {
680646 if (axis_map_uniform_.buffer ()) {
681647 axis_map_uniform_.update (utils::make_ivec4 (axis_map_));
682648 }
683- if (texture_limits_uniform_.buffer ()) {
684- texture_limits_uniform_.update (texture_limits_);
685- }
686649 if (logical_limits_uniform_.buffer ()) {
687650 logical_limits_uniform_.update (logical_limits_);
688651 }
@@ -695,9 +658,11 @@ void vTensor::check_sizes(const std::vector<int64_t>& sizes) const {
695658 utils::uvec3 virtual_extents =
696659 calculate_image_extents (padded_sizes_, axis_map_, memory_layout_);
697660
698- bool valid_resize = virtual_extents[0 ] <= image_extents ()[0 ];
699- valid_resize = valid_resize && virtual_extents[1 ] <= image_extents ()[1 ];
700- valid_resize = valid_resize && virtual_extents[2 ] <= image_extents ()[2 ];
661+ bool valid_resize = virtual_extents[0 ] <= storage_.image_extents_ [0 ];
662+ valid_resize =
663+ valid_resize && virtual_extents[1 ] <= storage_.image_extents_ [1 ];
664+ valid_resize =
665+ valid_resize && virtual_extents[2 ] <= storage_.image_extents_ [2 ];
701666
702667 VK_CHECK_COND (
703668 valid_resize,
0 commit comments