Permalink
Browse files

Vulkan hw tess: Don't reuse the same dynamic texture for multiple dra…

…ws, not safe.
  • Loading branch information...
hrydgard committed Nov 11, 2017
1 parent 9f77d48 commit 5d6a830288dfad46a32d36035f76759570e54bca
Showing with 25 additions and 17 deletions.
  1. +19 −2 GPU/Vulkan/DrawEngineVulkan.cpp
  2. +6 −15 GPU/Vulkan/DrawEngineVulkan.h
@@ -582,8 +582,8 @@ VkDescriptorSet DrawEngineVulkan::GetOrCreateDescriptorSet(VkImageView imageView
VkSampler sampler = ((TessellationDataTransferVulkan *)tessDataTransfer)->GetSampler();
for (int i = 0; i < 3; i++) {
VulkanTexture *texture = ((TessellationDataTransferVulkan *)tessDataTransfer)->GetTexture(i);
VkImageView imageView = texture->GetImageView();
if (i == 0 || imageView) {
if (texture) {
VkImageView imageView = texture->GetImageView();
tess_tex[i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
tess_tex[i].imageView = imageView;
tess_tex[i].sampler = sampler;
@@ -1084,6 +1084,17 @@ void DrawEngineVulkan::UpdateUBOs(FrameData *frame) {
}
}
DrawEngineVulkan::TessellationDataTransferVulkan::TessellationDataTransferVulkan(VulkanContext *vulkan, Draw::DrawContext *draw)
: TessellationDataTransfer(), vulkan_(vulkan), draw_(draw) {
CreateSampler();
}
DrawEngineVulkan::TessellationDataTransferVulkan::~TessellationDataTransferVulkan() {
for (int i = 0; i < 3; i++)
delete data_tex[i];
vulkan_->Delete().QueueDeleteSampler(sampler);
}
void DrawEngineVulkan::TessellationDataTransferVulkan::PrepareBuffers(float *&pos, float *&tex, float *&col, int size, bool hasColor, bool hasTexCoords) {
int rowPitch;
ILOG("INIT : Prep tess");
@@ -1093,6 +1104,8 @@ void DrawEngineVulkan::TessellationDataTransferVulkan::PrepareBuffers(float *&po
if (prevSize < size) {
prevSize = size;
delete data_tex[0];
data_tex[0] = new VulkanTexture(vulkan_, nullptr); // TODO: Should really use an allocator.
data_tex[0]->CreateDirect(cmd, size, 1, 1, VK_FORMAT_R32G32B32A32_SFLOAT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
}
pos = (float *)data_tex[0]->Lock(0, &rowPitch);
@@ -1102,6 +1115,8 @@ void DrawEngineVulkan::TessellationDataTransferVulkan::PrepareBuffers(float *&po
if (prevSizeTex < size) {
prevSizeTex = size;
delete data_tex[1];
data_tex[1] = new VulkanTexture(vulkan_, nullptr); // TODO: Should really use an allocator.
data_tex[1]->CreateDirect(cmd, size, 1, 1, VK_FORMAT_R32G32B32A32_SFLOAT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
}
tex = (float *)data_tex[1]->Lock(0, &rowPitch);
@@ -1112,6 +1127,8 @@ void DrawEngineVulkan::TessellationDataTransferVulkan::PrepareBuffers(float *&po
if (prevSizeCol < sizeColor) {
prevSizeCol = sizeColor;
delete data_tex[2];
data_tex[2] = new VulkanTexture(vulkan_, nullptr); // TODO: Should really use an allocator.
data_tex[2]->CreateDirect(cmd, sizeColor, 1, 1, VK_FORMAT_R32G32B32A32_SFLOAT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
}
col = (float *)data_tex[2]->Lock(0, &rowPitch);
@@ -264,25 +264,16 @@ class DrawEngineVulkan : public DrawEngineCommon {
private:
VulkanContext *vulkan_;
Draw::DrawContext *draw_;
VulkanTexture *data_tex[3];
VkSampler sampler;
VulkanTexture *data_tex[3]{};
VkSampler sampler = VK_NULL_HANDLE;
public:
TessellationDataTransferVulkan(VulkanContext *vulkan, Draw::DrawContext *draw)
: TessellationDataTransfer(), vulkan_(vulkan), draw_(draw), data_tex(), sampler() {
for (int i = 0; i < 3; i++)
data_tex[i] = new VulkanTexture(vulkan_);
CreateSampler();
}
~TessellationDataTransferVulkan() {
for (int i = 0; i < 3; i++)
delete data_tex[i];
vulkan_->Delete().QueueDeleteSampler(sampler);
}
TessellationDataTransferVulkan(VulkanContext *vulkan, Draw::DrawContext *draw);
~TessellationDataTransferVulkan();
void SendDataToShader(const float *pos, const float *tex, const float *col, int size, bool hasColor, bool hasTexCoords) override;
void PrepareBuffers(float *&pos, float *&tex, float *&col, int size, bool hasColor, bool hasTexCoords) override;
VulkanTexture *GetTexture(int i) const { return data_tex[i]; }
VkSampler GetSampler() const { return sampler; }
void CreateSampler() {
VkSamplerCreateInfo samp = { VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO };

0 comments on commit 5d6a830

Please sign in to comment.