35 assert(
Filter == VK_FILTER_NEAREST);
37 for (
const VkImageBlit &Region :
Regions)
39 uint32_t SrcLevel = Region.srcSubresource.mipLevel;
40 uint32_t DstLevel = Region.dstSubresource.mipLevel;
42 int32_t XMin = std::min(Region.dstOffsets[0].x, Region.dstOffsets[1].x);
43 int32_t XMax = std::max(Region.dstOffsets[0].x, Region.dstOffsets[1].x);
44 int32_t YMin = std::min(Region.dstOffsets[0].y, Region.dstOffsets[1].y);
45 int32_t YMax = std::max(Region.dstOffsets[0].y, Region.dstOffsets[1].y);
46 int32_t ZMin = std::min(Region.dstOffsets[0].z, Region.dstOffsets[1].z);
47 int32_t ZMax = std::max(Region.dstOffsets[0].z, Region.dstOffsets[1].z);
50 for (uint32_t LayerOffset = 0;
51 LayerOffset < Region.dstSubresource.layerCount; LayerOffset++)
53 for (int32_t Z = ZMin; Z < ZMax; Z++)
55 for (int32_t Y = YMin; Y < YMax; Y++)
57 for (int32_t X = XMin; X < XMax; X++)
60 float U = X + 0.5f - Region.dstOffsets[0].x;
61 float V = Y + 0.5f - Region.dstOffsets[0].y;
62 float W = Z + 0.5f - Region.dstOffsets[0].z;
63 U *= (float)(Region.srcOffsets[1].x - Region.srcOffsets[0].x) /
64 (float)(Region.dstOffsets[1].x - Region.dstOffsets[0].x);
65 V *= (float)(Region.srcOffsets[1].y - Region.srcOffsets[0].y) /
66 (float)(Region.dstOffsets[1].y - Region.dstOffsets[0].y);
67 W *= (float)(Region.srcOffsets[1].z - Region.srcOffsets[0].z) /
68 (float)(Region.dstOffsets[1].z - Region.dstOffsets[0].z);
69 U += Region.srcOffsets[0].x;
70 V += Region.srcOffsets[0].y;
71 W += Region.srcOffsets[0].z;
72 int32_t SrcX = std::clamp<int32_t>(std::floor(U), 0,
74 int32_t SrcY = std::clamp<int32_t>(std::floor(V), 0,
76 int32_t SrcZ = std::clamp<int32_t>(std::floor(W), 0,
80 Region.srcSubresource.baseArrayLayer + LayerOffset;
82 Region.dstSubresource.baseArrayLayer + LayerOffset;
105 assert(Attachment.aspectMask == VK_IMAGE_ASPECT_COLOR_BIT);
116 uint32_t XMin = Rect.rect.offset.x;
117 uint32_t XMax = XMin + Rect.rect.extent.width;
118 uint32_t YMin = Rect.rect.offset.y;
119 uint32_t YMax = YMin + Rect.rect.extent.height;
120 uint32_t LastLayer = Rect.baseArrayLayer + Rect.layerCount - 1;
123 for (uint32_t Layer = Rect.baseArrayLayer; Layer <= LastLayer; Layer++)
126 for (uint32_t Y = YMin; Y < YMax; Y++)
128 for (uint32_t X = XMin; X < XMax; X++)
130 DstImage->
write(Attachment.clearValue.color, X, Y, 0, Layer);
141 for (
auto &Range :
Ranges)
144 uint32_t LastLevel = Range.baseMipLevel + Range.levelCount - 1;
145 if (Range.levelCount == VK_REMAINING_MIP_LEVELS)
149 uint32_t LastLayer = Range.baseArrayLayer + Range.layerCount - 1;
150 if (Range.layerCount == VK_REMAINING_ARRAY_LAYERS)
154 for (uint32_t Level = Range.baseMipLevel; Level <= LastLevel; Level++)
157 for (uint32_t Layer = Range.baseArrayLayer; Layer <= LastLayer; Layer++)
178 for (
const VkBufferCopy &Region :
Regions)
190 for (
const VkBufferImageCopy &Region :
Regions)
192 uint32_t MipLevel = Region.imageSubresource.mipLevel;
197 uint32_t ImageLayerSize = ImageWidth * ImageHeight * ImageDepth;
200 for (uint32_t LayerOffset = 0;
201 LayerOffset < Region.imageSubresource.layerCount; LayerOffset++)
203 uint32_t BufferWidth = Region.bufferRowLength ? Region.bufferRowLength
204 : Region.imageExtent.width;
205 uint32_t BufferHeight = Region.bufferImageHeight
206 ? Region.bufferImageHeight
207 : Region.imageExtent.height;
208 uint64_t SrcBase =
SrcAddr + Region.bufferOffset;
209 SrcBase += BufferWidth * BufferHeight * ElementSize * LayerOffset;
213 (Region.imageOffset.x +
214 (Region.imageOffset.y + (Region.imageOffset.z * ImageHeight)) *
217 DstBase += ImageLayerSize * ElementSize *
218 (Region.imageSubresource.baseArrayLayer + LayerOffset);
221 for (uint32_t z = 0; z < Region.imageExtent.depth; z++)
223 for (uint32_t y = 0; y < Region.imageExtent.height; y++)
226 DstBase + (((z * ImageHeight) + y) * ImageWidth) * ElementSize,
228 SrcBase + (((z * BufferHeight) + y) * BufferWidth) * ElementSize,
241 assert(SrcElementSize == DstElementSize);
242 for (
const VkImageCopy &Region :
Regions)
245 assert(Region.srcSubresource.mipLevel == 0 &&
246 Region.dstSubresource.mipLevel == 0);
249 assert(Region.srcSubresource.baseArrayLayer == 0 &&
250 Region.srcSubresource.layerCount == 1);
251 assert(Region.srcSubresource.baseArrayLayer == 0 &&
252 Region.dstSubresource.layerCount == 1);
258 (Region.dstOffset.x +
259 (Region.dstOffset.y + (Region.dstOffset.z * DstImageHeight)) *
267 (Region.srcOffset.x +
268 (Region.srcOffset.y + (Region.srcOffset.z * SrcImageHeight)) *
273 for (uint32_t z = 0; z < Region.extent.depth; z++)
275 for (uint32_t y = 0; y < Region.extent.height; y++)
277 Memory::copy(DstBase + (((z * DstImageHeight) + y) * DstImageWidth) *
280 SrcBase + (((z * SrcImageHeight) + y) * SrcImageWidth) *
283 Region.extent.width * SrcElementSize);
293 for (
const VkBufferImageCopy &Region :
Regions)
295 uint32_t MipLevel = Region.imageSubresource.mipLevel;
300 uint32_t ImageLayerSize = ImageWidth * ImageHeight * ImageDepth;
303 for (uint32_t LayerOffset = 0;
304 LayerOffset < Region.imageSubresource.layerCount; LayerOffset++)
306 uint32_t BufferWidth = Region.bufferRowLength ? Region.bufferRowLength
307 : Region.imageExtent.width;
308 uint32_t BufferHeight = Region.bufferImageHeight
309 ? Region.bufferImageHeight
310 : Region.imageExtent.height;
311 uint64_t DstBase =
DstAddr + Region.bufferOffset;
312 DstBase += BufferWidth * BufferHeight * ElementSize * LayerOffset;
316 (Region.imageOffset.x +
317 (Region.imageOffset.y + (Region.imageOffset.z * ImageHeight)) *
320 SrcBase += ImageLayerSize * ElementSize *
321 (Region.imageSubresource.baseArrayLayer + LayerOffset);
324 for (uint32_t z = 0; z < Region.imageExtent.depth; z++)
326 for (uint32_t y = 0; y < Region.imageExtent.height; y++)
329 DstBase + (((z * BufferHeight) + y) * BufferWidth) * ElementSize,
331 SrcBase + (((z * ImageHeight) + y) * ImageWidth) * ElementSize,
370 :
Command(UPDATE_BUFFER), Base(Base), NumBytes(NumBytes)
373 memcpy(this->Data, Data, NumBytes);
386 for (
volatile bool *Event :
Events)
void run(Device &Dev) const
Run this command on Dev.
uint32_t getSubpassIndex() const
Returns the index of the current subpass.
virtual void runImpl(Device &Dev) const override
Command execution handler.
std::vector< VkClearAttachment > ClearAttachments
The attachments to clear.
const Subpass & getSubpass(uint32_t Index) const
Returns the subpass at index Index.
std::shared_ptr< RenderPassInstance > RPI
The render pass instance.
uint8_t * Data
The data to update the buffer with.
const Image & SrcImage
The source image.
const Image & SrcImage
The source image.
This file declares the Device class.
void write(const Image::Texel &T, uint32_t X, uint32_t Y=0, uint32_t Z=0, uint32_t Layer=0, uint32_t MipLevel=0) const
Write a texel to the image view at the specified coordinate.
uint64_t getMipLevelOffset(uint32_t Level) const
Returns the offset in bytes to the beginning of the specified mip level.
uint64_t DstAddr
The memory address of the destination buffer.
This structure describes the attachments used by a subpass.
static void copy(uint64_t DstAddress, Memory &DstMem, uint64_t SrcAddress, const Memory &SrcMem, uint64_t NumBytes)
Copy data between memory instances.
virtual void runImpl(Device &Dev) const override
Command execution handler.
void run(const DispatchCommand &Cmd)
Run a compute dispatch command to completion.
std::shared_ptr< RenderPassInstance > RPI
The render pass instance.
uint64_t NumBytes
The number of bytes to fill.
const RenderPassInstance & RPI
The render pass instance this command is operating inside.
virtual void runImpl(Device &Dev) const override
Command execution handler.
virtual void runImpl(Device &Dev) const override
Command execution handler.
virtual void runImpl(Device &Dev) const override
Command execution handler.
std::vector< VkImageBlit > Regions
The regions to copy.
std::vector< VkBufferCopy > Regions
The regions to copy.
This class represents a view into a range of image subresources.
virtual void runImpl(Device &Dev) const override
Command execution handler.
void write(const Texel &T, uint64_t Address) const
Write a texel to the image at the specified address.
VkFilter Filter
The filter to use when scaling.
std::vector< VkBufferImageCopy > Regions
The regions to copy.
const Framebuffer & getFramebuffer() const
Returns the framebuffer associated with this render pass instance.
uint32_t getWidth(uint32_t Level=0) const
Returns the width of the image at the specified mip level.
std::vector< VkBufferImageCopy > Regions
The regions to copy.
uint32_t Data
The data to fill the buffer with.
uint32_t getNumArrayLayers() const
Returns the number of array layers in the image.
std::vector< VkClearRect > ClearRects
The regions to clear.
std::vector< volatile bool * > Events
The events to wait for.
uint64_t Base
The memory address to begin updating from.
This class is a base class for all commands.
std::vector< VkImageSubresourceRange > Ranges
The image subranges to clear.
This class represents a single texel with four 32-bit component values.
virtual void runImpl(Device &Dev) const override
Command execution handler.
const Image & DstImage
The destination image.
const Image & DstImage
The image to clear.
uint64_t Base
The memory address to begin filling from.
std::shared_ptr< RenderPassInstance > RPI
The render pass instance.
volatile bool * Event
The flag to reset when this command executes.
const Image & SrcImage
The source image.
const Image & DstImage
The destination image.
void reportCommandBegin(const Command *Cmd)
virtual void runImpl(Device &Dev) const override
Command execution handler.
uint64_t SrcAddr
The memory address of the source buffer.
volatile bool * Event
The flag to set when this command executes.
This file declares the PipelineExecutor class.
uint64_t DstAddr
The memory address of the destination buffer.
virtual void runImpl(Device &Dev) const override
Command execution handler.
uint32_t getHeight(uint32_t Level=0) const
Returns the height of the image at the specified mip level.
This file declares data structures and functions for handling images.
std::vector< VkImageCopy > Regions
The regions to copy.
VkClearColorValue Color
The clear color to use.
virtual void runImpl(Device &Dev) const =0
Command execution method for subclasses.
A Device instance encapsulates properties and state for the virtual device.
uint32_t getDepth(uint32_t Level=0) const
Returns the depth of the image at the specified mip level.
uint64_t NumBytes
The number of bytes to update.
const std::vector< ImageView * > & getAttachments() const
Returns the list of attachments backing this framebuffer.
void read(Texel &T, uint64_t Address) const
Read a texel from the image at the specified address.
This file declares the RenderPass class and related data structures.
virtual void runImpl(Device &Dev) const override
Command execution handler.
const RenderPass & getRenderPass() const
Returns the render pass.
This file declares the Memory class.
uint64_t SrcAddr
The memory address of the source buffer.
virtual void runImpl(Device &Dev) const override
Command execution handler.
uint32_t getElementSize() const
Returns the size in bytes of a single pixel in the image.
PipelineExecutor & getPipelineExecutor()
Returns the PipelineExecutor for this device.
Memory & getGlobalMemory()
Get the global memory instance associated with this device.
VkExtent3D getExtent() const
Returns the size of a single layer of the image.
std::vector< uint32_t > ColorAttachments
This file declares the Command base class and its subclasses.
const Image & DstImage
The destination image.
virtual void runImpl(Device &Dev) const override
Command execution handler.
uint64_t getTexelAddress(uint32_t X, uint32_t Y=0, uint32_t Z=0, uint32_t Layer=0, uint32_t MipLevel=0) const
Returns the address in memory of the texel at the specified coordinate.
virtual void runImpl(Device &Dev) const override
Command execution handler.
void store(uint64_t Address, uint64_t NumBytes, const uint8_t *Data)
Store NumBytes of data from Data to Address.
void reportCommandComplete(const Command *Cmd)
virtual void runImpl(Device &Dev) const override
Command execution handler.
UpdateBufferCommand(uint64_t Base, uint64_t NumBytes, const void *Data)
Create a new UpdateBufferCommand.
uint64_t getAddress() const
Returns the memory address of the beginning of the image.
virtual void runImpl(Device &Dev) const override
Command execution handler.
virtual void runImpl(Device &Dev) const override
Command execution handler.
virtual void runImpl(Device &Dev) const override
Command execution handler.
virtual void runImpl(Device &Dev) const override
Command execution handler.
uint32_t getNumMipLevels() const
Returns the number of mip levels in the image.