| 1776 | } |
| 1777 | |
| 1778 | void RenderingDevice::_texture_copy_shared(RID p_src_texture_rid, Texture *p_src_texture, RID p_dst_texture_rid, Texture *p_dst_texture) { |
| 1779 | // The only type of copying allowed is from the main texture to the slice texture, as slice textures are not allowed to be used for writing when using this fallback. |
| 1780 | DEV_ASSERT(p_src_texture != nullptr); |
| 1781 | DEV_ASSERT(p_dst_texture != nullptr); |
| 1782 | DEV_ASSERT(p_src_texture->owner.is_null()); |
| 1783 | DEV_ASSERT(p_dst_texture->owner == p_src_texture_rid); |
| 1784 | |
| 1785 | bool src_made_mutable = _texture_make_mutable(p_src_texture, p_src_texture_rid); |
| 1786 | bool dst_made_mutable = _texture_make_mutable(p_dst_texture, p_dst_texture_rid); |
| 1787 | if (src_made_mutable || dst_made_mutable) { |
| 1788 | draw_graph.add_synchronization(); |
| 1789 | } |
| 1790 | |
| 1791 | if (p_dst_texture->shared_fallback->raw_reinterpretation) { |
| 1792 | // If one of the textures is a main texture and they have a reinterpret buffer, we prefer using that as it's guaranteed to be big enough to hold |
| 1793 | // anything and it's how the shared textures that don't use slices are created. |
| 1794 | bool src_has_buffer = p_src_texture->shared_fallback->buffer.id != 0; |
| 1795 | bool dst_has_buffer = p_dst_texture->shared_fallback->buffer.id != 0; |
| 1796 | bool from_src = p_src_texture->owner.is_null() && src_has_buffer; |
| 1797 | bool from_dst = p_dst_texture->owner.is_null() && dst_has_buffer; |
| 1798 | if (!from_src && !from_dst) { |
| 1799 | // If neither texture passed the condition, we just pick whichever texture has a reinterpretation buffer. |
| 1800 | from_src = src_has_buffer; |
| 1801 | from_dst = dst_has_buffer; |
| 1802 | } |
| 1803 | |
| 1804 | // Pick the buffer and tracker to use from the right texture. |
| 1805 | RDD::BufferID shared_buffer; |
| 1806 | RDG::ResourceTracker *shared_buffer_tracker = nullptr; |
| 1807 | if (from_src) { |
| 1808 | shared_buffer = p_src_texture->shared_fallback->buffer; |
| 1809 | shared_buffer_tracker = p_src_texture->shared_fallback->buffer_tracker; |
| 1810 | } else if (from_dst) { |
| 1811 | shared_buffer = p_dst_texture->shared_fallback->buffer; |
| 1812 | shared_buffer_tracker = p_dst_texture->shared_fallback->buffer_tracker; |
| 1813 | } else { |
| 1814 | DEV_ASSERT(false && "This path should not be reachable."); |
| 1815 | } |
| 1816 | |
| 1817 | /// @todo FIXME: When using reinterpretation buffers, the only texture aspect supported is color. Depth or stencil contents won't get copied. |
| 1818 | RDD::BufferTextureCopyRegion get_data_region; |
| 1819 | RDG::RecordedBufferToTextureCopy update_copy; |
| 1820 | RDD::TextureCopyableLayout first_copyable_layout; |
| 1821 | RDD::TextureCopyableLayout copyable_layout; |
| 1822 | RDD::TextureSubresource texture_subresource; |
| 1823 | texture_subresource.aspect = RDD::TEXTURE_ASPECT_COLOR; |
| 1824 | texture_subresource.layer = 0; |
| 1825 | texture_subresource.mipmap = 0; |
| 1826 | driver->texture_get_copyable_layout(p_dst_texture->shared_fallback->texture, texture_subresource, &first_copyable_layout); |
| 1827 | |
| 1828 | // Copying each mipmap from main texture to a buffer and then to the slice texture. |
| 1829 | thread_local LocalVector<RDD::BufferTextureCopyRegion> get_data_vector; |
| 1830 | thread_local LocalVector<RDG::RecordedBufferToTextureCopy> update_vector; |
| 1831 | get_data_vector.clear(); |
| 1832 | update_vector.clear(); |
| 1833 | for (uint32_t i = 0; i < p_dst_texture->mipmaps; i++) { |
| 1834 | driver->texture_get_copyable_layout(p_dst_texture->shared_fallback->texture, texture_subresource, ©able_layout); |
| 1835 |
nothing calls this directly
no test coverage detected