add texture layout transition to API

submit_rewrite
cosmonaut 2020-12-28 12:15:17 -08:00
parent ce0eea711b
commit 941cce595c
6 changed files with 97 additions and 0 deletions

View File

@ -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.

View File

@ -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,

View File

@ -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)

View File

@ -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,
&currentTexture->resourceAccessType
);
}
}
static void VULKAN_QueuePresent(
REFRESH_Renderer* driverData,
REFRESH_TextureSlice* textureSlice,

View File

@ -85,9 +85,11 @@
<ItemGroup>
<ClCompile Include="..\src\Refresh.c" />
<ClCompile Include="..\src\Refresh_Driver_Vulkan.c" />
<ClCompile Include="..\src\Refresh_Image.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\Refresh.h" />
<ClInclude Include="..\include\Refresh_Image.h" />
<ClInclude Include="..\src\Refresh_Driver.h" />
<ClInclude Include="..\src\Refresh_Driver_Vulkan_vkfuncs.h" />
</ItemGroup>

View File

@ -7,6 +7,9 @@
<ClCompile Include="..\src\Refresh_Driver_Vulkan.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\Refresh_Image.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\Refresh.h">
@ -18,6 +21,9 @@
<ClInclude Include="..\src\Refresh_Driver_Vulkan_vkfuncs.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\Refresh_Image.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="Header Files">