From 83a5313a063bb7f5a93e3349342e0a9f5464363e Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Thu, 31 Dec 2015 01:33:23 +0100 Subject: [PATCH] More fixes --- ext/native/thin3d/thin3d.cpp | 2 +- ext/native/thin3d/thin3d_vulkan.cpp | 20 ++++++++++++-------- ext/native/thin3d/vulkan_utils.cpp | 3 ++- ext/native/thin3d/vulkan_utils.h | 2 +- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/ext/native/thin3d/thin3d.cpp b/ext/native/thin3d/thin3d.cpp index cafbf41e25..1fb65b34e4 100644 --- a/ext/native/thin3d/thin3d.cpp +++ b/ext/native/thin3d/thin3d.cpp @@ -35,7 +35,7 @@ static const char * const vulkan_fsTexCol = "layout(location = 1) in vec2 oTexCoord0;\n" "layout(location = 0) out vec4 fragColor0\n;" "layout(binding = 2) uniform sampler2D Sampler0;\n" -"void main() { fragColor0 = texture2D(Sampler0, oTexCoord0) * oColor0; }\n"; +"void main() { fragColor0 = texture(Sampler0, oTexCoord0) * oColor0; }\n"; static const char * const glsl_fsCol = "#ifdef GL_ES\n" diff --git a/ext/native/thin3d/thin3d_vulkan.cpp b/ext/native/thin3d/thin3d_vulkan.cpp index 3502331495..e6c96ba840 100644 --- a/ext/native/thin3d/thin3d_vulkan.cpp +++ b/ext/native/thin3d/thin3d_vulkan.cpp @@ -114,7 +114,7 @@ static inline void Uint8x4ToFloat4(uint32_t u, float f[4]) { // their own similar buffer solutions. class VulkanPushBuffer { public: - VulkanPushBuffer(VkDevice device, VulkanContext *vulkan, size_t size) : offset_(0), size_(size), writePtr_(nullptr) { + VulkanPushBuffer(VkDevice device, VulkanContext *vulkan, size_t size) : offset_(0), size_(size), writePtr_(nullptr), deviceMemory_(nullptr) { VkBufferCreateInfo b; b.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; b.pNext = nullptr; @@ -670,7 +670,6 @@ public: private: VulkanContext *vulkan_; - VkDevice device_; VulkanImage image_; VulkanImage staging_; VkImageView view_; @@ -699,7 +698,7 @@ Thin3DVKContext::Thin3DVKContext(VulkanContext *vulkan) VkCommandPoolCreateInfo p; p.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; p.pNext = nullptr; - p.flags = 0; + p.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; p.queueFamilyIndex = vulkan->GetGraphicsQueueFamilyIndex(); VkResult res = vkCreateCommandPool(device_, &p, nullptr, &cmdPool_); assert(VK_SUCCESS == res); @@ -733,14 +732,17 @@ Thin3DVKContext::Thin3DVKContext(VulkanContext *vulkan) bindings[0].pImmutableSamplers = nullptr; bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; + bindings[0].binding = 0; bindings[1].descriptorCount = 1; bindings[1].pImmutableSamplers = nullptr; bindings[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; bindings[1].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; + bindings[1].binding = 1; bindings[2].descriptorCount = 1; bindings[2].pImmutableSamplers = nullptr; bindings[2].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; bindings[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; + bindings[2].binding = 2; VkDescriptorSetLayoutCreateInfo dsl; dsl.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; @@ -781,10 +783,10 @@ Thin3DVKContext::Thin3DVKContext(VulkanContext *vulkan) res = vkCreateFence(device_, &f, nullptr, &cmdFences_[0]); assert(VK_SUCCESS == res); + f.flags = VK_FENCE_CREATE_SIGNALED_BIT; res = vkCreateFence(device_, &f, nullptr, &cmdFences_[1]); assert(VK_SUCCESS == res); // Create as already signalled, so we can wait for it the first time. - f.flags = VK_FENCE_CREATE_SIGNALED_BIT; res = vkCreateFence(device_, &f, nullptr, &initFence_); assert(VK_SUCCESS == res); pendingInitFence_ = false; @@ -800,6 +802,7 @@ Thin3DVKContext::Thin3DVKContext(VulkanContext *vulkan) push_ = pushBuffer_[0]; cmd_ = cmdBuffer_[0]; + cmdFence_ = cmdFences_[0]; } Thin3DVKContext::~Thin3DVKContext() { @@ -929,6 +932,7 @@ VkDescriptorSet Thin3DVKContext::GetOrCreateDescriptorSet() { imageDesc.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; VkWriteDescriptorSet writes[2]; + memset(writes, 0, sizeof(writes)); writes[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; writes[0].pNext = nullptr; writes[0].dstSet = descSet; @@ -1132,8 +1136,8 @@ void Thin3DVKTexture::SetImageData(int x, int y, int z, int width, int height, i // So we need to do a staging copy. We upload the data to the staging buffer immediately, then we actually do the final copy once it's used the first time // as we need a command buffer and the architecture of Thin3D doesn't really work the way we want.. if (!image_.IsValid()) { - staging_.Create2D(device_, vulkan_, vulkanFormat, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, width, height); - image_.Create2D(device_, vulkan_, vulkanFormat, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, (VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT), width, height); + staging_.Create2D(vulkan_, vulkanFormat, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, width, height); + image_.Create2D(vulkan_, vulkanFormat, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, (VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT), width, height); } VkImageViewCreateInfo iv; @@ -1152,11 +1156,11 @@ void Thin3DVKTexture::SetImageData(int x, int y, int z, int width, int height, i iv.subresourceRange.baseArrayLayer = 0; iv.subresourceRange.baseMipLevel = 0; iv.subresourceRange.levelCount = 1; - VkResult res = vkCreateImageView(device_, &iv, nullptr, &view_); + VkResult res = vkCreateImageView(vulkan_->GetDevice(), &iv, nullptr, &view_); assert(VK_SUCCESS == res); // TODO: Support setting only parts of the image efficiently. - staging_.SetImageData2D(device_, data, width, height, stride); + staging_.SetImageData2D(vulkan_->GetDevice(), data, width, height, stride); state_ = TextureState::STAGED; } diff --git a/ext/native/thin3d/vulkan_utils.cpp b/ext/native/thin3d/vulkan_utils.cpp index 44155f68d0..a94fd2955e 100644 --- a/ext/native/thin3d/vulkan_utils.cpp +++ b/ext/native/thin3d/vulkan_utils.cpp @@ -40,7 +40,8 @@ #include "thin3d/vulkan_utils.h" -void VulkanImage::Create2D(VkDevice device, VulkanContext *vulkan, VkFormat format, VkFlags required_props, VkImageUsageFlags usage, int width, int height) { +void VulkanImage::Create2D(VulkanContext *vulkan, VkFormat format, VkFlags required_props, VkImageUsageFlags usage, int width, int height) { + VkDevice device = vulkan->GetDevice(); width_ = width; height_ = height; diff --git a/ext/native/thin3d/vulkan_utils.h b/ext/native/thin3d/vulkan_utils.h index 7a0266fe20..9c194a78c3 100644 --- a/ext/native/thin3d/vulkan_utils.h +++ b/ext/native/thin3d/vulkan_utils.h @@ -32,7 +32,7 @@ public: bool IsValid() const { return image_ != nullptr; } // This can be done completely unsynchronized. - void Create2D(VkDevice device, VulkanContext *vulkan, VkFormat format, VkFlags required_props, VkImageUsageFlags usage, int width, int height); + void Create2D(VulkanContext *vulkan, VkFormat format, VkFlags required_props, VkImageUsageFlags usage, int width, int height); // This can only be used if you pass in VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT in required_props in Create2D. void SetImageData2D(VkDevice device, const uint8_t *data, int width, int height, int pitch);