Compare commits
2 commits
31b93deecb
...
7cc871fb48
Author | SHA1 | Date | |
---|---|---|---|
Mars | 7cc871fb48 | ||
Mars | c2ee7e8677 |
|
@ -1,10 +1,6 @@
|
||||||
# This file was generated by nvfetcher, please do not modify it manually.
|
# This file was generated by nvfetcher, please do not modify it manually.
|
||||||
|
{ fetchgit, fetchurl, fetchFromGitHub, dockerTools }:
|
||||||
{
|
{
|
||||||
fetchgit,
|
|
||||||
fetchurl,
|
|
||||||
fetchFromGitHub,
|
|
||||||
dockerTools,
|
|
||||||
}: {
|
|
||||||
fmt = {
|
fmt = {
|
||||||
pname = "fmt";
|
pname = "fmt";
|
||||||
version = "11.0.2";
|
version = "11.0.2";
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1728001300,
|
"lastModified": 1728588307,
|
||||||
"narHash": "sha256-W7PYJ6s+A91V1WZOTef8y3t1BGQKCfcLtHjOKcP5ScA=",
|
"narHash": "sha256-Y1mO+iz3RUNfmu2m2c42BggOLV5q0z2CWyJzf1ypDLA=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "e00cc9f2fa7eaac3232e0de9b0b86dfd58b1f43c",
|
"rev": "45093dff80ae7cdefc55abb77075d2931d6b47ca",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
82
src/main.cpp
82
src/main.cpp
|
@ -578,31 +578,87 @@ class VulkanApp {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn createVertexBuffer() -> void {
|
fn createVertexBuffer() -> void {
|
||||||
|
vk::DeviceSize bufferSize = sizeof(mVertices[0]) * mVertices.size();
|
||||||
|
|
||||||
|
vk::UniqueBuffer stagingBuffer;
|
||||||
|
vk::UniqueDeviceMemory stagingBufferMemory;
|
||||||
|
|
||||||
|
createBuffer(
|
||||||
|
bufferSize,
|
||||||
|
vk::BufferUsageFlagBits::eVertexBuffer,
|
||||||
|
vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent,
|
||||||
|
stagingBuffer,
|
||||||
|
stagingBufferMemory
|
||||||
|
);
|
||||||
|
|
||||||
|
void* data = mDevice->mapMemory(stagingBufferMemory.get(), 0, bufferSize);
|
||||||
|
memcpy(data, mVertices.data(), static_cast<usize>(bufferSize));
|
||||||
|
mDevice->unmapMemory(stagingBufferMemory.get());
|
||||||
|
|
||||||
|
createBuffer(
|
||||||
|
bufferSize,
|
||||||
|
vk::BufferUsageFlagBits::eVertexBuffer | vk::BufferUsageFlagBits::eTransferDst,
|
||||||
|
vk::MemoryPropertyFlagBits::eDeviceLocal,
|
||||||
|
mVertexBuffer,
|
||||||
|
mVertexBufferMemory
|
||||||
|
);
|
||||||
|
|
||||||
|
copyBuffer(stagingBuffer.get(), mVertexBuffer.get(), bufferSize);
|
||||||
|
|
||||||
|
stagingBuffer.reset();
|
||||||
|
stagingBufferMemory.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn createBuffer(
|
||||||
|
vk::DeviceSize deviceSize,
|
||||||
|
vk::BufferUsageFlags bufferUsageFlags,
|
||||||
|
vk::MemoryPropertyFlags memoryPropertyFlags,
|
||||||
|
vk::UniqueBuffer& buffer,
|
||||||
|
vk::UniqueDeviceMemory& bufferMemory
|
||||||
|
) -> void {
|
||||||
vk::BufferCreateInfo bufferInfo {
|
vk::BufferCreateInfo bufferInfo {
|
||||||
.size = sizeof(mVertices[0]) * mVertices.size(),
|
.size = deviceSize,
|
||||||
.usage = vk::BufferUsageFlagBits::eVertexBuffer,
|
.usage = bufferUsageFlags,
|
||||||
.sharingMode = vk::SharingMode::eExclusive,
|
.sharingMode = vk::SharingMode::eExclusive,
|
||||||
};
|
};
|
||||||
|
|
||||||
mVertexBuffer = mDevice->createBufferUnique(bufferInfo, nullptr);
|
buffer = mDevice->createBufferUnique(bufferInfo);
|
||||||
|
|
||||||
vk::MemoryRequirements memRequirements = mDevice->getBufferMemoryRequirements(mVertexBuffer.get());
|
vk::MemoryRequirements memRequirements = mDevice->getBufferMemoryRequirements(buffer.get());
|
||||||
|
|
||||||
vk::MemoryAllocateInfo allocInfo {
|
vk::MemoryAllocateInfo allocInfo {
|
||||||
.allocationSize = memRequirements.size,
|
.allocationSize = memRequirements.size,
|
||||||
.memoryTypeIndex = findMemoryType(
|
.memoryTypeIndex = findMemoryType(memRequirements.memoryTypeBits, memoryPropertyFlags),
|
||||||
memRequirements.memoryTypeBits,
|
|
||||||
vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent
|
|
||||||
),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
mVertexBufferMemory = mDevice->allocateMemoryUnique(allocInfo);
|
bufferMemory = mDevice->allocateMemoryUnique(allocInfo);
|
||||||
|
|
||||||
mDevice->bindBufferMemory(mVertexBuffer.get(), mVertexBufferMemory.get(), 0);
|
mDevice->bindBufferMemory(buffer.get(), bufferMemory.get(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
void* data = mDevice->mapMemory(mVertexBufferMemory.get(), 0, bufferInfo.size);
|
fn copyBuffer(vk::Buffer srcBuffer, vk::Buffer dstBuffer, vk::DeviceSize deviceSize) -> void {
|
||||||
memcpy(data, mVertices.data(), static_cast<usize>(bufferInfo.size));
|
vk::CommandBufferAllocateInfo allocInfo {
|
||||||
mDevice->unmapMemory(mVertexBufferMemory.get());
|
.commandPool = mCommandPool.get(),
|
||||||
|
.level = vk::CommandBufferLevel::ePrimary,
|
||||||
|
.commandBufferCount = 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
vk::UniqueCommandBuffer commandBuffer = std::move(mDevice->allocateCommandBuffersUnique(allocInfo)[0]);
|
||||||
|
|
||||||
|
vk::CommandBufferBeginInfo beginInfo { .flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit };
|
||||||
|
|
||||||
|
commandBuffer->begin(beginInfo);
|
||||||
|
|
||||||
|
vk::BufferCopy copyRegion { .size = deviceSize };
|
||||||
|
|
||||||
|
commandBuffer->copyBuffer(srcBuffer, dstBuffer, 1, ©Region);
|
||||||
|
|
||||||
|
commandBuffer->end();
|
||||||
|
|
||||||
|
vk::SubmitInfo submitInfo { .commandBufferCount = 1, .pCommandBuffers = &commandBuffer.get() };
|
||||||
|
|
||||||
|
mGraphicsQueue.submit(submitInfo, nullptr);
|
||||||
|
mGraphicsQueue.waitIdle();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn findMemoryType(u32 typeFilter, vk::MemoryPropertyFlags properties) -> u32 {
|
fn findMemoryType(u32 typeFilter, vk::MemoryPropertyFlags properties) -> u32 {
|
||||||
|
|
Loading…
Reference in a new issue