| 174 | } |
| 175 | |
| 176 | void VulkanTexture::Bind(ref_ptr<dp::GraphicsContext> context) const |
| 177 | { |
| 178 | ref_ptr<dp::vulkan::VulkanBaseContext> vulkanContext = context; |
| 179 | VkCommandBuffer commandBuffer = vulkanContext->GetCurrentMemoryCommandBuffer(); |
| 180 | CHECK(commandBuffer != nullptr, ()); |
| 181 | |
| 182 | // Fill texture on the first bind. |
| 183 | if (m_creationStagingBuffer != nullptr) |
| 184 | { |
| 185 | // Here we use VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, because we also read textures |
| 186 | // in vertex shaders. |
| 187 | MakeImageLayoutTransition( |
| 188 | commandBuffer, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 189 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | VK_PIPELINE_STAGE_TRANSFER_BIT, |
| 190 | VK_PIPELINE_STAGE_TRANSFER_BIT); |
| 191 | |
| 192 | auto staging = m_creationStagingBuffer->GetReservationById(m_reservationId); |
| 193 | auto bufferCopyRegion = BufferCopyRegion(0, 0, GetWidth(), GetHeight(), staging.m_offset); |
| 194 | vkCmdCopyBufferToImage(commandBuffer, staging.m_stagingBuffer, m_textureObject.m_image, |
| 195 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &bufferCopyRegion); |
| 196 | |
| 197 | MakeImageLayoutTransition(commandBuffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_PIPELINE_STAGE_TRANSFER_BIT, |
| 198 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT); |
| 199 | |
| 200 | m_creationStagingBuffer.reset(); |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | void VulkanTexture::SetFilter(TextureFilter filter) |
| 205 | { |