Skip to content

Commit

Permalink
Vulkan hw tess: Assorted minor fixes. Works on Mali now.
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Nov 11, 2017
1 parent 9cd4db5 commit 8d7bcd9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Common/Vulkan/VulkanImage.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -350,11 +350,11 @@ void VulkanTexture::UploadMip(VkCommandBuffer cmd, int mip, int mipWidth, int mi
vkCmdCopyBufferToImage(cmd, buffer, image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region); vkCmdCopyBufferToImage(cmd, buffer, image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
} }


void VulkanTexture::EndCreate(VkCommandBuffer cmd) { void VulkanTexture::EndCreate(VkCommandBuffer cmd, bool vertexTexture) {
TransitionImageLayout2(cmd, image, TransitionImageLayout2(cmd, image,
VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_ASPECT_COLOR_BIT,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, vertexTexture ? VK_PIPELINE_STAGE_VERTEX_SHADER_BIT : VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT); VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT);
} }


Expand Down
2 changes: 1 addition & 1 deletion Common/Vulkan/VulkanImage.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class VulkanTexture {
// When using UploadMip, initialLayout should be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL. // When using UploadMip, initialLayout should be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL.
bool CreateDirect(VkCommandBuffer cmd, int w, int h, int numMips, VkFormat format, VkImageLayout initialLayout, VkImageUsageFlags usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, const VkComponentMapping *mapping = nullptr); bool CreateDirect(VkCommandBuffer cmd, int w, int h, int numMips, VkFormat format, VkImageLayout initialLayout, VkImageUsageFlags usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, const VkComponentMapping *mapping = nullptr);
void UploadMip(VkCommandBuffer cmd, int mip, int mipWidth, int mipHeight, VkBuffer buffer, uint32_t offset, size_t rowLength); // rowLength is in pixels void UploadMip(VkCommandBuffer cmd, int mip, int mipWidth, int mipHeight, VkBuffer buffer, uint32_t offset, size_t rowLength); // rowLength is in pixels
void EndCreate(VkCommandBuffer cmd); void EndCreate(VkCommandBuffer cmd, bool vertexTexture = false);


void Destroy(); void Destroy();


Expand Down
35 changes: 21 additions & 14 deletions GPU/Vulkan/DrawEngineVulkan.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -542,8 +542,8 @@ VkDescriptorSet DrawEngineVulkan::GetOrCreateDescriptorSet(VkImageView imageView
_assert_msg_(G3D, result == VK_SUCCESS, "Ran out of descriptors in pool. sz=%d", (int)frame->descSets.size()); _assert_msg_(G3D, result == VK_SUCCESS, "Ran out of descriptors in pool. sz=%d", (int)frame->descSets.size());


// We just don't write to the slots we don't care about. // We just don't write to the slots we don't care about.
VkWriteDescriptorSet writes[7]; // We need 8 now that we support secondary texture bindings.
memset(writes, 0, sizeof(writes)); VkWriteDescriptorSet writes[8]{};
// Main texture // Main texture
int n = 0; int n = 0;
VkDescriptorImageInfo tex{}; VkDescriptorImageInfo tex{};
Expand Down Expand Up @@ -586,7 +586,9 @@ VkDescriptorSet DrawEngineVulkan::GetOrCreateDescriptorSet(VkImageView imageView
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
VulkanTexture *texture = ((TessellationDataTransferVulkan *)tessDataTransfer)->GetTexture(i); VulkanTexture *texture = ((TessellationDataTransferVulkan *)tessDataTransfer)->GetTexture(i);
if (texture) { if (texture) {
assert(texture->GetImageView());
VkImageView imageView = texture->GetImageView(); VkImageView imageView = texture->GetImageView();

tess_tex[i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; tess_tex[i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
tess_tex[i].imageView = imageView; tess_tex[i].imageView = imageView;
tess_tex[i].sampler = sampler; tess_tex[i].sampler = sampler;
Expand Down Expand Up @@ -1098,56 +1100,61 @@ DrawEngineVulkan::TessellationDataTransferVulkan::~TessellationDataTransferVulka
vulkan_->Delete().QueueDeleteSampler(sampler); vulkan_->Delete().QueueDeleteSampler(sampler);
} }


// TODO: Consolidate the three textures into one, with height 3.
// This can be done for all the backends.
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) {
ILOG("INIT : Prep tess"); 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_, 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); bool success = data_tex[0]->CreateDirect(cmd, size, 1, 1, VK_FORMAT_R32G32B32A32_SFLOAT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
assert(success);


posSize_ = size;
pos = (float *)push_->Push(size * sizeof(float) * 4, &posOffset_, &posBuf_); pos = (float *)push_->Push(size * sizeof(float) * 4, &posOffset_, &posBuf_);
posSize_ = size;


// Texcoords // Texcoords
delete data_tex[1]; delete data_tex[1];
data_tex[1] = nullptr;
if (hasTexCoords) { if (hasTexCoords) {
data_tex[1] = new VulkanTexture(vulkan_, nullptr); // TODO: Should really use an allocator. 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); success = data_tex[1]->CreateDirect(cmd, size, 1, 1, VK_FORMAT_R32G32B32A32_SFLOAT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
assert(success);


tex = (float *)push_->Push(size * sizeof(float) * 4, &texOffset_, &texBuf_); tex = (float *)push_->Push(size * sizeof(float) * 4, &texOffset_, &texBuf_);
texSize_ = size; texSize_ = size;
} else { } else {
texSize_ = 0; data_tex[1] = nullptr;
tex = nullptr; tex = nullptr;
texSize_ = 0;
} }


// 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_, nullptr); // TODO: Should really use an allocator.
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);


col = (float *)push_->Push(size * sizeof(float) * 4, &colOffset_, &colBuf_); col = (float *)push_->Push(colSize_ * sizeof(float) * 4, &colOffset_, &colBuf_);
} }


void DrawEngineVulkan::TessellationDataTransferVulkan::SendDataToShader(const float *pos, const float *tex, const float *col, int size, bool hasColor, bool hasTexCoords) { void DrawEngineVulkan::TessellationDataTransferVulkan::SendDataToShader(const float *pos, const float *tex, const float *col, int size, bool hasColor, bool hasTexCoords) {
VkCommandBuffer cmd = (VkCommandBuffer)draw_->GetNativeObject(Draw::NativeObject::INIT_COMMANDBUFFER); VkCommandBuffer cmd = (VkCommandBuffer)draw_->GetNativeObject(Draw::NativeObject::INIT_COMMANDBUFFER);
// Position // Position
data_tex[0]->UploadMip(cmd, 0, posSize_, 1, posBuf_, posOffset_, posSize_); data_tex[0]->UploadMip(cmd, 0, posSize_, 1, posBuf_, posOffset_, posSize_);
data_tex[0]->EndCreate(cmd); data_tex[0]->EndCreate(cmd, true);


// Texcoords // Texcoords
if (hasTexCoords) { if (hasTexCoords) {
data_tex[1]->UploadMip(cmd, 0, texSize_, 1, texBuf_, texOffset_, texSize_); data_tex[1]->UploadMip(cmd, 0, texSize_, 1, texBuf_, texOffset_, texSize_);
data_tex[1]->EndCreate(cmd); data_tex[1]->EndCreate(cmd, true);
} }


// Color // Color
data_tex[2]->UploadMip(cmd, 0, colSize_, 1, colBuf_, colOffset_, colSize_); data_tex[2]->UploadMip(cmd, 0, colSize_, 1, colBuf_, colOffset_, colSize_);
data_tex[2]->EndCreate(cmd); data_tex[2]->EndCreate(cmd, true);
} }


void DrawEngineVulkan::TessellationDataTransferVulkan::CreateSampler() { void DrawEngineVulkan::TessellationDataTransferVulkan::CreateSampler() {
Expand Down Expand Up @@ -1177,4 +1184,4 @@ void DrawEngineVulkan::TessellationDataTransferVulkan::CreateSampler() {


VkResult res = vkCreateSampler(vulkan_->GetDevice(), &samp, nullptr, &sampler); VkResult res = vkCreateSampler(vulkan_->GetDevice(), &samp, nullptr, &sampler);
assert(res == VK_SUCCESS); assert(res == VK_SUCCESS);
} }

0 comments on commit 8d7bcd9

Please sign in to comment.