diff --git a/include/Refresh.h b/include/Refresh.h
index 1cb735f..eda971e 100644
--- a/include/Refresh.h
+++ b/include/Refresh.h
@@ -141,6 +141,16 @@ typedef enum REFRESH_DepthFormat
REFRESH_DEPTHFORMAT_D32_SFLOAT_S8_UINT
} REFRESH_DepthFormat;
+typedef enum REFRESH_TextureLayout
+{
+ REFRESH_TEXTURELAYOUT_READ,
+ REFRESH_TEXTURELAYOUT_COLOR_TARGET,
+ REFRESH_TEXTURELAYOUT_DEPTHSTENCIL_TARGET,
+ REFRESH_TEXTURELAYOUT_VERTEX_SAMPLER,
+ REFRESH_TEXTURELAYOUT_FRAGMENT_SAMPLER,
+ REFRESH_TEXTURELAYOUT_WRITE
+} REFRESH_TextureLayout;
+
typedef enum REFRESH_SampleCount
{
REFRESH_SAMPLECOUNT_1,
@@ -1253,6 +1263,24 @@ REFRESHAPI void REFRESH_BindIndexBuffer(
REFRESH_IndexElementSize indexElementSize
);
+/* Transitions */
+
+/* Performs a texture layout transition.
+ * Texture layouts must be transitioned for different texture use cases.
+ *
+ * NOTE: It is an error to perform a layout transition in a render pass.
+ *
+ * layout: The layout to transition to.
+ * pTextures: A pointer to an array of textures to transition.
+ * textureCount: The number of textures in the array to transition.
+ */
+REFRESHAPI void REFRESH_TextureLayoutTransition(
+ REFRESH_Device *device,
+ REFRESH_TextureLayout layout,
+ REFRESH_Texture **pTextures,
+ uint32_t textureCount
+);
+
/* Submission/Presentation */
/* Queues an image to be presented to the screen.
diff --git a/src/Refresh.c b/src/Refresh.c
index 7105b4f..a37e848 100644
--- a/src/Refresh.c
+++ b/src/Refresh.c
@@ -811,6 +811,21 @@ void REFRESH_BindIndexBuffer(
);
}
+void REFRESH_TextureLayoutTransition(
+ REFRESH_Device *device,
+ REFRESH_TextureLayout layout,
+ REFRESH_Texture **pTextures,
+ uint32_t textureCount
+) {
+ NULL_RETURN(device);
+ device->TextureLayoutTransition(
+ device->driverData,
+ layout,
+ pTextures,
+ textureCount
+ );
+}
+
void REFRESH_QueuePresent(
REFRESH_Device *device,
REFRESH_TextureSlice* textureSlice,
diff --git a/src/Refresh_Driver.h b/src/Refresh_Driver.h
index d3a3c6d..e0a17b2 100644
--- a/src/Refresh_Driver.h
+++ b/src/Refresh_Driver.h
@@ -493,6 +493,13 @@ struct REFRESH_Device
REFRESH_IndexElementSize indexElementSize
);
+ void (*TextureLayoutTransition)(
+ REFRESH_Renderer *driverData,
+ REFRESH_TextureLayout layout,
+ REFRESH_Texture **pTextures,
+ uint32_t textureCount
+ );
+
void(*QueuePresent)(
REFRESH_Renderer *driverData,
REFRESH_TextureSlice *textureSlice,
@@ -555,6 +562,7 @@ struct REFRESH_Device
ASSIGN_DRIVER_FUNC(BindGraphicsPipeline, name) \
ASSIGN_DRIVER_FUNC(BindVertexBuffers, name) \
ASSIGN_DRIVER_FUNC(BindIndexBuffer, name) \
+ ASSIGN_DRIVER_FUNC(TextureLayoutTransition, name) \
ASSIGN_DRIVER_FUNC(QueuePresent, name) \
ASSIGN_DRIVER_FUNC(Submit, name)
diff --git a/src/Refresh_Driver_Vulkan.c b/src/Refresh_Driver_Vulkan.c
index e3c7dbd..8b1f615 100644
--- a/src/Refresh_Driver_Vulkan.c
+++ b/src/Refresh_Driver_Vulkan.c
@@ -188,6 +188,16 @@ static VkFormat RefreshToVK_DepthFormat[] =
VK_FORMAT_D32_SFLOAT_S8_UINT
};
+static VulkanResourceAccessType RefreshToVK_ImageLayout[] =
+{
+ RESOURCE_ACCESS_TRANSFER_READ,
+ RESOURCE_ACCESS_COLOR_ATTACHMENT_READ_WRITE,
+ RESOURCE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_WRITE,
+ RESOURCE_ACCESS_VERTEX_SHADER_READ_SAMPLED_IMAGE,
+ RESOURCE_ACCESS_FRAGMENT_SHADER_READ_SAMPLED_IMAGE,
+ RESOURCE_ACCESS_TRANSFER_WRITE
+};
+
static VkFormat RefreshToVK_VertexFormat[] =
{
VK_FORMAT_R32_SFLOAT, /* SINGLE */
@@ -5418,6 +5428,34 @@ static void VULKAN_BindIndexBuffer(
));
}
+static void VULKAN_TextureLayoutTransition(
+ REFRESH_Renderer *driverData,
+ REFRESH_TextureLayout layout,
+ REFRESH_Texture **pTextures,
+ uint32_t textureCount
+) {
+ uint32_t i;
+ VulkanTexture* currentTexture;
+ VulkanRenderer* renderer = (VulkanRenderer*) driverData;
+
+ for (i = 0; i < textureCount; i += 1)
+ {
+ currentTexture = (VulkanTexture*) pTextures[i];
+ VULKAN_INTERNAL_ImageMemoryBarrier(
+ renderer,
+ RefreshToVK_ImageLayout[layout],
+ VK_IMAGE_ASPECT_COLOR_BIT,
+ 0,
+ currentTexture->layerCount,
+ 0,
+ currentTexture->levelCount,
+ 0,
+ currentTexture->image,
+ ¤tTexture->resourceAccessType
+ );
+ }
+}
+
static void VULKAN_QueuePresent(
REFRESH_Renderer* driverData,
REFRESH_TextureSlice* textureSlice,
diff --git a/visualc/Refresh.vcxproj b/visualc/Refresh.vcxproj
index 4014e48..d84afff 100644
--- a/visualc/Refresh.vcxproj
+++ b/visualc/Refresh.vcxproj
@@ -85,9 +85,11 @@
+
+
diff --git a/visualc/Refresh.vcxproj.filters b/visualc/Refresh.vcxproj.filters
index c413c49..67135bd 100644
--- a/visualc/Refresh.vcxproj.filters
+++ b/visualc/Refresh.vcxproj.filters
@@ -7,6 +7,9 @@
Source Files
+
+ Source Files
+
@@ -18,6 +21,9 @@
Header Files
+
+ Header Files
+