Vulkan: Use a device allocator for tesselation data textures. Add comment about better solutions.

This commit is contained in:
Henrik Rydgård 2017-11-12 10:28:55 +01:00
parent 525cb40f84
commit ebac0143e0
3 changed files with 11 additions and 7 deletions

View file

@ -272,7 +272,7 @@ private:
VkPhysicalDeviceMemoryProperties memory_properties{}; VkPhysicalDeviceMemoryProperties memory_properties{};
// Custom collection of things that are good to know // Custom collection of things that are good to know
VulkanPhysicalDeviceInfo deviceInfo_; VulkanPhysicalDeviceInfo deviceInfo_{};
// Swap chain // Swap chain
int width_ = 0; int width_ = 0;
@ -299,8 +299,8 @@ private:
uint32_t queue_count = 0; uint32_t queue_count = 0;
VkPhysicalDeviceFeatures featuresAvailable_; VkPhysicalDeviceFeatures featuresAvailable_{};
VkPhysicalDeviceFeatures featuresEnabled_; VkPhysicalDeviceFeatures featuresEnabled_{};
std::vector<VkCommandBuffer> cmdQueue_; std::vector<VkCommandBuffer> cmdQueue_;
}; };

View file

@ -1097,25 +1097,27 @@ void DrawEngineVulkan::UpdateUBOs(FrameData *frame) {
} }
DrawEngineVulkan::TessellationDataTransferVulkan::TessellationDataTransferVulkan(VulkanContext *vulkan, Draw::DrawContext *draw) DrawEngineVulkan::TessellationDataTransferVulkan::TessellationDataTransferVulkan(VulkanContext *vulkan, Draw::DrawContext *draw)
: TessellationDataTransfer(), vulkan_(vulkan), draw_(draw) { : TessellationDataTransfer(), vulkan_(vulkan), draw_(draw), tessAlloc_(vulkan_, 128 * 1024, 4096 * 1024) {
CreateSampler(); CreateSampler();
} }
DrawEngineVulkan::TessellationDataTransferVulkan::~TessellationDataTransferVulkan() { DrawEngineVulkan::TessellationDataTransferVulkan::~TessellationDataTransferVulkan() {
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
delete data_tex[i]; delete data_tex[i];
tessAlloc_.Destroy();
vulkan_->Delete().QueueDeleteSampler(sampler); vulkan_->Delete().QueueDeleteSampler(sampler);
} }
// TODO: Consolidate the three textures into one, with height 3. // TODO: Consolidate the three textures into one, with height 3.
// This can be done for all the backends. // This can be done for all the backends.
// TODO: Actually, even better, avoid the usage of textures altogether and just use shader storage buffers from the current pushbuffer.
void DrawEngineVulkan::TessellationDataTransferVulkan::PrepareBuffers(float *&pos, float *&tex, float *&col, int size, bool hasColor, bool hasTexCoords) { void DrawEngineVulkan::TessellationDataTransferVulkan::PrepareBuffers(float *&pos, float *&tex, float *&col, int size, bool hasColor, bool hasTexCoords) {
assert(size > 0); assert(size > 0);
VkCommandBuffer cmd = (VkCommandBuffer)draw_->GetNativeObject(Draw::NativeObject::INIT_COMMANDBUFFER); VkCommandBuffer cmd = (VkCommandBuffer)draw_->GetNativeObject(Draw::NativeObject::INIT_COMMANDBUFFER);
// Position // Position
delete data_tex[0]; delete data_tex[0];
data_tex[0] = new VulkanTexture(vulkan_, nullptr); // TODO: Should really use an allocator. data_tex[0] = new VulkanTexture(vulkan_, &tessAlloc_);
bool success = data_tex[0]->CreateDirect(cmd, size, 1, 1, VK_FORMAT_R32G32B32A32_SFLOAT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); bool success = data_tex[0]->CreateDirect(cmd, size, 1, 1, VK_FORMAT_R32G32B32A32_SFLOAT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
assert(success); assert(success);
@ -1125,7 +1127,7 @@ void DrawEngineVulkan::TessellationDataTransferVulkan::PrepareBuffers(float *&po
// Texcoords // Texcoords
delete data_tex[1]; delete data_tex[1];
if (hasTexCoords) { if (hasTexCoords) {
data_tex[1] = new VulkanTexture(vulkan_, nullptr); // TODO: Should really use an allocator. data_tex[1] = new VulkanTexture(vulkan_, &tessAlloc_);
success = data_tex[1]->CreateDirect(cmd, size, 1, 1, VK_FORMAT_R32G32B32A32_SFLOAT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); success = data_tex[1]->CreateDirect(cmd, size, 1, 1, VK_FORMAT_R32G32B32A32_SFLOAT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
assert(success); assert(success);
@ -1140,7 +1142,7 @@ void DrawEngineVulkan::TessellationDataTransferVulkan::PrepareBuffers(float *&po
// Color // Color
colSize_ = hasColor ? size : 1; colSize_ = hasColor ? size : 1;
delete data_tex[2]; delete data_tex[2];
data_tex[2] = new VulkanTexture(vulkan_, nullptr); // TODO: Should really use an allocator. data_tex[2] = new VulkanTexture(vulkan_, &tessAlloc_);
success = data_tex[2]->CreateDirect(cmd, colSize_, 1, 1, VK_FORMAT_R32G32B32A32_SFLOAT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); success = data_tex[2]->CreateDirect(cmd, colSize_, 1, 1, VK_FORMAT_R32G32B32A32_SFLOAT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
assert(success); assert(success);

View file

@ -33,6 +33,7 @@
#include <unordered_map> #include <unordered_map>
#include "Common/Hashmaps.h" #include "Common/Hashmaps.h"
#include "Common/Vulkan/VulkanMemory.h"
#include "GPU/Vulkan/VulkanUtil.h" #include "GPU/Vulkan/VulkanUtil.h"
@ -281,6 +282,7 @@ private:
VulkanTexture *data_tex[3]{}; VulkanTexture *data_tex[3]{};
VkSampler sampler = VK_NULL_HANDLE; VkSampler sampler = VK_NULL_HANDLE;
VulkanPushBuffer *push_; // Updated each frame. VulkanPushBuffer *push_; // Updated each frame.
VulkanDeviceAllocator tessAlloc_;
int posSize_ = 0; int posSize_ = 0;
uint32_t posOffset_ = 0; uint32_t posOffset_ = 0;