Load and add texture to the Rect.

This commit is contained in:
Anish Bhobe 2025-06-14 17:16:37 +02:00
parent 694147ce4d
commit 98c5f28146
12 changed files with 430 additions and 63 deletions

5
.gitattributes vendored Normal file
View File

@ -0,0 +1,5 @@
*.jpg filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.glb filter=lfs diff=lfs merge=lfs -text
*.hdr filter=lfs diff=lfs merge=lfs -text
*.exr filter=lfs diff=lfs merge=lfs -text

View File

@ -48,7 +48,7 @@ AppState* AppState_Create( GlobalMemory* memory, uint32_t const width, uint32_t
auto* miscDataAllocation = memory->allocate( sizeof( MiscData ) );
MiscData* miscData = new ( miscDataAllocation ) MiscData{};
miscData->init( *renderDevice );
if ( !miscData->init( *renderDevice ) ) return nullptr;
auto* allocation = memory->allocate( sizeof( AppState ) );
AppState* appState = new ( allocation ) AppState{ window, renderDevice, miscData };

View File

@ -208,7 +208,7 @@ void SDL_AppQuit( void* appstate, SDL_AppResult )
{
AppState* appState = static_cast<AppState*>( appstate );
appState->destroy();
if ( appState ) appState->destroy();
Blaze::Global::g_Memory.destroy();
}

View File

@ -154,6 +154,7 @@
<ClCompile Include="GlobalMemory.cpp" />
<ClCompile Include="MiscData.cpp" />
<ClCompile Include="RenderDevice.cpp" />
<ClCompile Include="StbImpl.cpp" />
<ClCompile Include="VmaImpl.cpp" />
</ItemGroup>
<ItemGroup>
@ -189,6 +190,10 @@
<ClInclude Include="MiscData.h" />
<ClInclude Include="RenderDevice.h" />
</ItemGroup>
<ItemGroup>
<Image Include="container2.png" />
<Image Include="wall.jpg" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>

View File

@ -39,6 +39,9 @@
<ClCompile Include="VmaImpl.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="StbImpl.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="vcpkg.json">
@ -88,4 +91,12 @@
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Image Include="container2.png">
<Filter>Resource Files</Filter>
</Image>
<Image Include="wall.jpg">
<Filter>Resource Files</Filter>
</Image>
</ItemGroup>
</Project>

View File

@ -1,18 +1,8 @@
const static float4 vertexPos[] = {
float4(0.0f, 0.5f, 0.5f, 1.0f),
float4(-0.5f, -0.5f, 0.5f, 1.0f),
float4(0.5f, -0.5f, 0.5f, 1.0f),
};
const static float4 vertexColors[] = {
float4(1.0f, 0.0f, 0.0f, 1.0f),
float4(0.0f, 1.0f, 0.0f, 1.0f),
float4(0.0f, 0.0f, 1.0f, 1.0f),
};
struct VertexOut {
float4 outPosition : SV_Position;
float4 vertexColor : CoarseColor;
float2 texCoord0 : TexCoord0;
};
struct CameraData {
@ -21,24 +11,32 @@ struct CameraData {
float4x4 proj;
};
ParameterBlock<CameraData> camera;
struct PerFrameData {
CameraData camera;
Sampler2D texture;
}
ParameterBlock<PerFrameData> perFrameData;
[shader("vertex")]
VertexOut VertexMain(
uint vertexId: SV_VertexID,
float4 position,
float4 color,
float3 position,
float3 color,
float2 texCoord0,
) {
VertexOut output;
output.outPosition = mul(camera.proj, mul(camera.view, mul(camera.model, position)));
output.vertexColor = color;
output.outPosition = mul(perFrameData.camera.proj, mul(perFrameData.camera.view, mul(perFrameData.camera.model, float4(position, 1.0f))));
output.vertexColor = float4(color, 1.0f);
output.texCoord0 = texCoord0 * 2.0f;
return output;
}
[shader("fragment")]
float4 FragmentMain(
float4 interpolatedColors: CoarseColor,
float4 interpolatedColors : CoarseColor,
float2 uv0 : TexCoord0,
) : SV_Target0 {
return float4(interpolatedColors.rgb, 1.0f);
return float4(perFrameData.texture.Sample(uv0).rgb, 1.0f) * interpolatedColors;
}

View File

@ -4,10 +4,13 @@
#include <SDL3/SDL_log.h>
#include <stb_image.h>
#include "Frame.h"
#include "MacroUtils.h"
#include "RenderDevice.h"
void MiscData::init( RenderDevice const& renderDevice )
bool MiscData::init( RenderDevice const& renderDevice )
{
VkDevice const device = renderDevice.device;
@ -22,7 +25,7 @@ void MiscData::init( RenderDevice const& renderDevice )
if ( !rawData )
{
SDL_LogError( SDL_LOG_CATEGORY_SYSTEM, "%s", SDL_GetError() );
abort();
return false;
}
uint32_t const* data = static_cast<uint32_t const*>( rawData );
@ -38,20 +41,29 @@ void MiscData::init( RenderDevice const& renderDevice )
VkShaderModule shaderModule;
VK_CHECK( vkCreateShaderModule( device, &shaderModuleCreateInfo, nullptr, &shaderModule ) );
VkDescriptorSetLayoutBinding constexpr descriptorSetLayoutBinding = {
std::array descriptorSetLayoutBindings{
VkDescriptorSetLayoutBinding{
.binding = 0,
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.descriptorCount = 1,
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT,
.pImmutableSamplers = nullptr,
},
VkDescriptorSetLayoutBinding{
.binding = 1,
.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
.descriptorCount = 1,
.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT,
.pImmutableSamplers = nullptr,
},
};
VkDescriptorSetLayoutCreateInfo const descriptorSetLayoutCreateInfo = {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
.pNext = nullptr,
.flags = 0,
.bindingCount = 1,
.pBindings = &descriptorSetLayoutBinding,
.bindingCount = static_cast<uint32_t>( descriptorSetLayoutBindings.size() ),
.pBindings = descriptorSetLayoutBindings.data(),
};
VK_CHECK( vkCreateDescriptorSetLayout( device, &descriptorSetLayoutCreateInfo, nullptr, &descriptorSetLayout ) );
@ -98,15 +110,21 @@ void MiscData::init( RenderDevice const& renderDevice )
VkVertexInputAttributeDescription{
.location = 0,
.binding = 0,
.format = VK_FORMAT_R32G32B32A32_SFLOAT,
.format = VK_FORMAT_R32G32B32_SFLOAT,
.offset = offsetof( Vertex, position ),
},
VkVertexInputAttributeDescription{
.location = 1,
.binding = 0,
.format = VK_FORMAT_R32G32B32A32_SFLOAT,
.format = VK_FORMAT_R32G32B32_SFLOAT,
.offset = offsetof( Vertex, color ),
},
VkVertexInputAttributeDescription{
.location = 2,
.binding = 0,
.format = VK_FORMAT_R32G32_SFLOAT,
.offset = offsetof( Vertex, texCoord0 ),
},
};
VkPipelineVertexInputStateCreateInfo const vertexInputState = {
@ -210,7 +228,7 @@ void MiscData::init( RenderDevice const& renderDevice )
.blendConstants = { 0.0f, 0.0f, 0.0f, 0.0f },
};
std::array constexpr dynamicStates = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR };
std::array constexpr dynamicStates{ VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR };
VkPipelineDynamicStateCreateInfo const dynamicStateCreateInfo = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
@ -271,23 +289,27 @@ void MiscData::init( RenderDevice const& renderDevice )
vertices = std::array{
// Bottom Left
Vertex{
.position = { -1.0f, -1.0f, 0.0f, 1.0f },
.color = { 0.0f, 0.0f, 1.0f, 1.0f },
.position = { -1.0f, -1.0f, 0.0f },
.color = { 0.0f, 0.0f, 1.0f },
.texCoord0 = { 0.0f, 0.0f },
},
// Bottom Right
Vertex{
.position = { 1.0f, -1.0f, 0.0f, 1.0f },
.color = { 1.0f, 0.0f, 0.0f, 1.0f },
.position = { 1.0f, -1.0f, 0.0f },
.color = { 1.0f, 0.0f, 0.0f },
.texCoord0 = { 1.0f, 0.0f },
},
// Top Left
Vertex{
.position = { -1.0f, 1.0f, 0.0f, 1.0f },
.color = { 0.0f, 1.0f, 0.0f, 1.0f },
.position = { -1.0f, 1.0f, 0.0f },
.color = { 0.0f, 1.0f, 0.0f },
.texCoord0 = { 0.0f, 1.0f },
},
// Top Right
Vertex{
.position = { 1.0f, 1.0f, 0.0f, 1.0f },
.color = { 1.0f, 1.0f, 0.0f, 1.0f },
.position = { 1.0f, 1.0f, 0.0f },
.color = { 1.0f, 1.0f, 0.0f },
.texCoord0 = { 1.0f, 1.0f },
}
};
@ -329,6 +351,277 @@ void MiscData::init( RenderDevice const& renderDevice )
}
}
// Texture
{
uint32_t width;
uint32_t height;
uint32_t numChannels = 4;
stbi_uc* textureData;
{
int w;
int h;
int nc;
int requestedChannels = static_cast<int>( numChannels );
textureData = stbi_load( "wall.jpg", &w, &h, &nc, requestedChannels );
ASSERT( nc <= requestedChannels );
if ( !textureData )
{
vkDestroyPipeline( device, Take( meshPipeline ), nullptr );
vmaDestroyBuffer( renderDevice.gpuAllocator, Take( vertexBuffer ), Take( vertexBufferAllocation ) );
SDL_LogError( SDL_LOG_CATEGORY_ERROR, "%s", stbi_failure_reason() );
return false;
}
width = static_cast<uint32_t>( w );
height = static_cast<uint32_t>( h );
}
VkImageCreateInfo const imageCreateInfo = {
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
.pNext = nullptr,
.flags = 0,
.imageType = VK_IMAGE_TYPE_2D,
.format = VK_FORMAT_R8G8B8A8_SRGB,
.extent = { .width = width, .height = height, .depth = 1 },
.mipLevels = 1,
.arrayLayers = 1,
.samples = VK_SAMPLE_COUNT_1_BIT,
.tiling = VK_IMAGE_TILING_OPTIMAL,
.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT,
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
.queueFamilyIndexCount = 0,
.pQueueFamilyIndices = nullptr,
.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
};
VmaAllocationCreateInfo constexpr allocationCreateInfo = {
.flags = 0,
.usage = VMA_MEMORY_USAGE_AUTO,
.requiredFlags = 0,
.preferredFlags = 0,
.memoryTypeBits = 0,
.pool = nullptr,
.pUserData = nullptr,
.priority = 1.0f,
};
VK_CHECK( vmaCreateImage(
renderDevice.gpuAllocator, &imageCreateInfo, &allocationCreateInfo, &texture, &textureAllocation, nullptr ) );
VkImageSubresourceRange constexpr subresourceRange = {
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
.baseMipLevel = 0,
.levelCount = 1,
.baseArrayLayer = 0,
.layerCount = 1,
};
VkComponentMapping constexpr componentMapping = {
.r = VK_COMPONENT_SWIZZLE_IDENTITY,
.g = VK_COMPONENT_SWIZZLE_IDENTITY,
.b = VK_COMPONENT_SWIZZLE_IDENTITY,
.a = VK_COMPONENT_SWIZZLE_IDENTITY,
};
VkImageViewCreateInfo const imageViewCreateInfo = {
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
.pNext = nullptr,
.flags = 0,
.image = texture,
.viewType = VK_IMAGE_VIEW_TYPE_2D,
.format = imageCreateInfo.format,
.components = componentMapping,
.subresourceRange = subresourceRange,
};
VK_CHECK( vkCreateImageView( device, &imageViewCreateInfo, nullptr, &textureView ) );
VkSamplerCreateInfo constexpr samplerCreateInfo = {
.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
.pNext = nullptr,
.flags = 0,
.magFilter = VK_FILTER_LINEAR,
.minFilter = VK_FILTER_LINEAR,
.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR,
.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT,
.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT,
.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT,
.mipLodBias = 0.0,
.anisotropyEnable = true,
.maxAnisotropy = 1.0f,
.compareEnable = false,
.compareOp = VK_COMPARE_OP_NEVER,
.minLod = 0.0f,
.maxLod = 0.0f,
.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK,
.unnormalizedCoordinates = false,
};
VK_CHECK( vkCreateSampler( device, &samplerCreateInfo, nullptr, &sampler ) );
// Staging Buffer Create
VkBuffer stagingBuffer;
VmaAllocation stagingAllocation;
{
VkBufferCreateInfo const stagingBufferCreateInfo = {
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
.pNext = nullptr,
.flags = 0,
.size = static_cast<VkDeviceSize>( width ) * height * numChannels * sizeof( textureData[0] ),
.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
.queueFamilyIndexCount = 0,
.pQueueFamilyIndices = nullptr,
};
VmaAllocationCreateInfo constexpr stagingAllocationCreateInfo = {
.flags = VMA_ALLOCATION_CREATE_MAPPED_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT,
.usage = VMA_MEMORY_USAGE_AUTO,
.requiredFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
.preferredFlags = 0,
.memoryTypeBits = 0,
.pool = nullptr,
.pUserData = nullptr,
.priority = 1.0f,
};
VmaAllocationInfo allocationInfo;
VK_CHECK( vmaCreateBuffer(
renderDevice.gpuAllocator,
&stagingBufferCreateInfo,
&stagingAllocationCreateInfo,
&stagingBuffer,
&stagingAllocation,
&allocationInfo ) );
if ( allocationInfo.pMappedData )
{
memcpy( allocationInfo.pMappedData, textureData, stagingBufferCreateInfo.size );
}
}
// All data is copied to stagingBuffer, don't need this.
stbi_image_free( textureData );
{
Frame& frameInUse = renderDevice.frames[0];
// This should just pass.
VK_CHECK( vkWaitForFences( device, 1, &frameInUse.frameReadyToReuse, VK_TRUE, INT64_MAX ) );
VK_CHECK( vkResetFences( device, 1, &frameInUse.frameReadyToReuse ) );
VkCommandBufferBeginInfo constexpr beginInfo = {
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
.pNext = nullptr,
.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,
.pInheritanceInfo = nullptr,
};
VkImageMemoryBarrier2 const creationToTransferImageBarrier = {
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2,
.pNext = nullptr,
.srcStageMask = VK_PIPELINE_STAGE_2_TOP_OF_PIPE_BIT,
.srcAccessMask = VK_ACCESS_2_NONE,
.dstStageMask = VK_PIPELINE_STAGE_2_COPY_BIT,
.dstAccessMask = VK_ACCESS_2_TRANSFER_WRITE_BIT,
.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.image = texture,
.subresourceRange = subresourceRange,
};
VkDependencyInfo const creationToTransferDependency = {
.sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
.pNext = nullptr,
.dependencyFlags = 0,
.memoryBarrierCount = 0,
.pMemoryBarriers = nullptr,
.bufferMemoryBarrierCount = 0,
.pBufferMemoryBarriers = nullptr,
.imageMemoryBarrierCount = 1,
.pImageMemoryBarriers = &creationToTransferImageBarrier,
};
VkImageMemoryBarrier2 const transferToReadyImageBarrier = {
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2,
.pNext = nullptr,
.srcStageMask = VK_PIPELINE_STAGE_2_COPY_BIT,
.srcAccessMask = VK_ACCESS_2_TRANSFER_WRITE_BIT,
.dstStageMask = VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT,
.dstAccessMask = VK_ACCESS_2_SHADER_SAMPLED_READ_BIT,
.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.image = texture,
.subresourceRange = subresourceRange,
};
VkDependencyInfo const transferToReadyDependency = {
.sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
.pNext = nullptr,
.dependencyFlags = 0,
.memoryBarrierCount = 0,
.pMemoryBarriers = nullptr,
.bufferMemoryBarrierCount = 0,
.pBufferMemoryBarriers = nullptr,
.imageMemoryBarrierCount = 1,
.pImageMemoryBarriers = &transferToReadyImageBarrier,
};
vkBeginCommandBuffer( frameInUse.commandBuffer, &beginInfo );
{
VkImageSubresourceLayers imageSubresourceLayers = {
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
.mipLevel = 0,
.baseArrayLayer = 0,
.layerCount = 1,
};
// TODO: Ensure `bufferRowLength` and `bufferImageHeight` are not required.
VkBufferImageCopy copyRegion = {
.bufferOffset = 0,
.bufferRowLength = 0,
.bufferImageHeight = 0,
.imageSubresource = imageSubresourceLayers,
.imageOffset = { 0, 0, 0 },
.imageExtent = imageCreateInfo.extent
};
vkCmdPipelineBarrier2( frameInUse.commandBuffer, &creationToTransferDependency );
vkCmdCopyBufferToImage(
frameInUse.commandBuffer, stagingBuffer, texture, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copyRegion );
vkCmdPipelineBarrier2( frameInUse.commandBuffer, &transferToReadyDependency );
}
vkEndCommandBuffer( frameInUse.commandBuffer );
VkSubmitInfo submitInfo = {
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
.pNext = nullptr,
.waitSemaphoreCount = 0,
.pWaitSemaphores = nullptr,
.pWaitDstStageMask = nullptr,
.commandBufferCount = 1,
.pCommandBuffers = &frameInUse.commandBuffer,
.signalSemaphoreCount = 0,
.pSignalSemaphores = nullptr,
};
VK_CHECK( vkQueueSubmit( renderDevice.directQueue, 1, &submitInfo, frameInUse.frameReadyToReuse ) );
// Do not reset this. Else, the frame will never be available to the main loop.
VK_CHECK( vkWaitForFences( device, 1, &frameInUse.frameReadyToReuse, VK_TRUE, INT64_MAX ) );
}
vmaDestroyBuffer( renderDevice.gpuAllocator, stagingBuffer, stagingAllocation );
}
// Camera
{
cameraPosition = DirectX::XMVectorSet( 0.0f, 0.0f, -5.0f, 1.0f );
@ -382,17 +675,23 @@ void MiscData::init( RenderDevice const& renderDevice )
// Descriptors
{
VkDescriptorPoolSize const poolSize = {
std::array poolSizes = {
VkDescriptorPoolSize{
.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.descriptorCount = renderDevice.getNumFrames(),
},
VkDescriptorPoolSize{
.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
.descriptorCount = renderDevice.getNumFrames(),
},
};
VkDescriptorPoolCreateInfo const descriptorPoolCreateInfo = {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
.pNext = nullptr,
.flags = 0,
.maxSets = renderDevice.getNumFrames(),
.poolSizeCount = 1,
.pPoolSizes = &poolSize,
.poolSizeCount = static_cast<uint32_t>( poolSizes.size() ),
.pPoolSizes = poolSizes.data(),
};
VK_CHECK( vkCreateDescriptorPool( device, &descriptorPoolCreateInfo, nullptr, &descriptorPool ) );
@ -413,7 +712,14 @@ void MiscData::init( RenderDevice const& renderDevice )
.range = sizeof CameraData,
};
VkWriteDescriptorSet writeDescriptorSet = {
VkDescriptorImageInfo const descriptorImageInfo = {
.sampler = sampler,
.imageView = textureView,
.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
};
std::array writeDescriptorSets = {
VkWriteDescriptorSet{
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.pNext = nullptr,
.dstSet = descriptorSet,
@ -424,9 +730,24 @@ void MiscData::init( RenderDevice const& renderDevice )
.pImageInfo = nullptr,
.pBufferInfo = &descriptorBufferInfo,
.pTexelBufferView = nullptr,
},
VkWriteDescriptorSet{
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.pNext = nullptr,
.dstSet = descriptorSet,
.dstBinding = 1,
.dstArrayElement = 0,
.descriptorCount = 1,
.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
.pImageInfo = &descriptorImageInfo,
.pBufferInfo = nullptr,
.pTexelBufferView = nullptr,
}
};
vkUpdateDescriptorSets( device, 1, &writeDescriptorSet, 0, nullptr );
vkUpdateDescriptorSets(
device, static_cast<uint32_t>( writeDescriptorSets.size() ), writeDescriptorSets.data(), 0, nullptr );
}
// Barrier Creation
@ -491,6 +812,8 @@ void MiscData::init( RenderDevice const& renderDevice )
.pImageMemoryBarriers = &renderToPresentBarrier,
};
}
return true;
}
void MiscData::destroy( RenderDevice const& renderDevice )
@ -499,6 +822,11 @@ void MiscData::destroy( RenderDevice const& renderDevice )
vkDestroyDescriptorPool( device, Take( descriptorPool ), nullptr );
vmaDestroyBuffer( renderDevice.gpuAllocator, Take( cameraUniformBuffer ), Take( cameraUniformBufferAllocation ) );
vkDestroySampler( device, Take( sampler ), nullptr );
vkDestroyImageView( device, Take( textureView ), nullptr );
vmaDestroyImage( renderDevice.gpuAllocator, Take( texture ), Take( textureAllocation ) );
vmaDestroyBuffer( renderDevice.gpuAllocator, Take( vertexBuffer ), Take( vertexBufferAllocation ) );
vkDestroyPipeline( device, Take( meshPipeline ), nullptr );

View File

@ -7,12 +7,14 @@
#include <DirectXMath.h>
struct GlobalMemory;
struct RenderDevice;
struct Vertex
{
float position[4];
float color[4];
DirectX::XMFLOAT3 position;
DirectX::XMFLOAT3 color;
DirectX::XMFLOAT2 texCoord0;
};
struct MiscData
@ -35,6 +37,11 @@ struct MiscData
size_t vertexBufferSize;
std::array<Vertex, 4> vertices;
VkImage texture;
VmaAllocation textureAllocation;
VkImageView textureView;
VkSampler sampler;
uint64_t _padding; // TODO: Optimize out?
DirectX::XMVECTOR cameraPosition;
@ -53,6 +60,6 @@ struct MiscData
VkImageMemoryBarrier2 renderToPresentBarrier;
VkDependencyInfo renderToPresentDependency;
void init( RenderDevice const& renderDevice );
bool init( RenderDevice const& renderDevice );
void destroy( RenderDevice const& renderDevice );
};

6
StbImpl.cpp Normal file
View File

@ -0,0 +1,6 @@
#pragma warning( push, 1 )
#pragma warning( disable : 5045 )
#define STB_IMAGE_IMPLEMENTATION
#include <stb_image.h>
#pragma warning( pop )

BIN
container2.png (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -4,6 +4,7 @@
"shader-slang",
"vulkan-memory-allocator",
"directxmath",
"stb",
{
"name": "sdl3",
"features": [ "vulkan" ]

BIN
wall.jpg (Stored with Git LFS) Normal file

Binary file not shown.