14 std::shared_ptr<TextureSourceVK> source)
15 :
Texture(source->GetTextureDescriptor()),
16 context_(
std::move(context)),
17 source_(
std::move(source)) {}
21 void TextureVK::SetLabel(std::string_view label) {
22 auto context = context_.lock();
31 bool TextureVK::OnSetContents(
const uint8_t* contents,
34 if (!IsValid() || !contents) {
41 if (length != desc.GetByteSizeOfBaseMipLevel()) {
46 auto context = context_.lock();
48 VALIDATION_LOG <<
"Context died before setting contents on texture.";
53 context->GetResourceAllocator()->CreateBufferWithCopy(contents, length);
55 if (!staging_buffer) {
60 auto cmd_buffer = context->CreateCommandBuffer();
68 if (!encoder->Track(staging_buffer) || !encoder->Track(source_)) {
72 const auto& vk_cmd_buffer = encoder->GetCommandBuffer();
75 barrier.cmd_buffer = vk_cmd_buffer;
76 barrier.new_layout = vk::ImageLayout::eTransferDstOptimal;
77 barrier.src_access = {};
78 barrier.src_stage = vk::PipelineStageFlagBits::eTopOfPipe;
79 barrier.dst_access = vk::AccessFlagBits::eTransferWrite;
80 barrier.dst_stage = vk::PipelineStageFlagBits::eTransfer;
86 vk::BufferImageCopy copy;
87 copy.bufferOffset = 0u;
88 copy.bufferRowLength = 0u;
89 copy.bufferImageHeight = 0u;
90 copy.imageOffset.x = 0u;
91 copy.imageOffset.y = 0u;
92 copy.imageOffset.z = 0u;
93 copy.imageExtent.width = desc.size.width;
94 copy.imageExtent.height = desc.size.height;
95 copy.imageExtent.depth = 1u;
96 copy.imageSubresource.aspectMask =
98 copy.imageSubresource.mipLevel = 0u;
99 copy.imageSubresource.baseArrayLayer = slice;
100 copy.imageSubresource.layerCount = 1u;
102 vk_cmd_buffer.copyBufferToImage(
110 return cmd_buffer->SubmitCommands();
113 bool TextureVK::OnSetContents(std::shared_ptr<const fml::Mapping> mapping,
117 return OnSetContents(mapping->GetMapping(), mapping->GetSize(), slice);
120 bool TextureVK::IsValid()
const {
124 ISize TextureVK::GetSize()
const {
129 return source_->GetImage();
133 return source_->GetImageView();
141 return source_ ? source_->SetLayout(barrier).ok() :
false;
145 vk::ImageLayout layout)
const {
146 return source_ ? source_->SetLayoutWithoutEncoding(layout)
147 : vk::ImageLayout::eUndefined;
151 return source_ ? source_->GetLayout() : vk::ImageLayout::eUndefined;