diff options
author | Juan Linietsky <reduzio@gmail.com> | 2019-08-20 17:54:03 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2020-02-11 11:59:27 +0100 |
commit | 8cee7703a6673f9505332de1581055c821b756f0 (patch) | |
tree | de822653547bc9c5e890cad851b5ea6347ddc672 /drivers/vulkan | |
parent | 449df8f688080c02bfbbfafc45421875b77deb1b (diff) |
Yay very basic 3D (only white) finally shows.
Diffstat (limited to 'drivers/vulkan')
-rw-r--r-- | drivers/vulkan/rendering_device_vulkan.cpp | 55 | ||||
-rw-r--r-- | drivers/vulkan/rendering_device_vulkan.h | 4 |
2 files changed, 41 insertions, 18 deletions
diff --git a/drivers/vulkan/rendering_device_vulkan.cpp b/drivers/vulkan/rendering_device_vulkan.cpp index 82ab8d6c2f..93e1b09cfd 100644 --- a/drivers/vulkan/rendering_device_vulkan.cpp +++ b/drivers/vulkan/rendering_device_vulkan.cpp @@ -1036,6 +1036,18 @@ uint32_t RenderingDeviceVulkan::get_compressed_image_format_pixel_rshift(DataFor return 0; } +bool RenderingDeviceVulkan::format_has_stencil(DataFormat p_format) { + switch (p_format) { + case DATA_FORMAT_S8_UINT: + case DATA_FORMAT_D16_UNORM_S8_UINT: + case DATA_FORMAT_D24_UNORM_S8_UINT: + case DATA_FORMAT_D32_SFLOAT_S8_UINT: { + return true; + } + } + return false; +} + uint32_t RenderingDeviceVulkan::get_image_format_required_size(DataFormat p_format, uint32_t p_width, uint32_t p_height, uint32_t p_depth, uint32_t p_mipmaps, uint32_t *r_blockw, uint32_t *r_blockh, uint32_t *r_depth) { ERR_FAIL_COND_V(p_mipmaps == 0, 0); @@ -1699,7 +1711,12 @@ RID RenderingDeviceVulkan::texture_create(const TextureFormat &p_format, const T //set bound and unbound layouts if (p_format.usage_bits & TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) { - texture.aspect_mask = VK_IMAGE_ASPECT_DEPTH_BIT; + + texture.read_aspect_mask = VK_IMAGE_ASPECT_DEPTH_BIT; + texture.barrier_aspect_mask = texture.read_aspect_mask; + if (format_has_stencil(p_format.format)) { + texture.barrier_aspect_mask |= VK_IMAGE_ASPECT_STENCIL_BIT; + } if (p_format.usage_bits & TEXTURE_USAGE_SAMPLING_BIT) { texture.unbound_layout = VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL; @@ -1710,7 +1727,9 @@ RID RenderingDeviceVulkan::texture_create(const TextureFormat &p_format, const T } else if (p_format.usage_bits & TEXTURE_USAGE_COLOR_ATTACHMENT_BIT) { - texture.aspect_mask = VK_IMAGE_ASPECT_COLOR_BIT; + texture.read_aspect_mask = VK_IMAGE_ASPECT_COLOR_BIT; + texture.barrier_aspect_mask = texture.read_aspect_mask; + if (p_format.usage_bits & TEXTURE_USAGE_SAMPLING_BIT) { texture.unbound_layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; } else { @@ -1718,7 +1737,9 @@ RID RenderingDeviceVulkan::texture_create(const TextureFormat &p_format, const T } texture.bound_layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; } else { - texture.aspect_mask = VK_IMAGE_ASPECT_COLOR_BIT; + texture.read_aspect_mask = VK_IMAGE_ASPECT_COLOR_BIT; + texture.barrier_aspect_mask = texture.read_aspect_mask; + texture.unbound_layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; texture.bound_layout = VK_IMAGE_LAYOUT_UNDEFINED; //will never be bound } @@ -1794,7 +1815,7 @@ RID RenderingDeviceVulkan::texture_create(const TextureFormat &p_format, const T image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; image_memory_barrier.image = texture.image; - image_memory_barrier.subresourceRange.aspectMask = texture.aspect_mask; + image_memory_barrier.subresourceRange.aspectMask = texture.barrier_aspect_mask; image_memory_barrier.subresourceRange.baseMipLevel = 0; image_memory_barrier.subresourceRange.levelCount = image_create_info.mipLevels; image_memory_barrier.subresourceRange.baseArrayLayer = 0; @@ -2053,7 +2074,7 @@ Error RenderingDeviceVulkan::texture_update(RID p_texture, uint32_t p_layer, con image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; image_memory_barrier.image = texture->image; - image_memory_barrier.subresourceRange.aspectMask = texture->aspect_mask; + image_memory_barrier.subresourceRange.aspectMask = texture->barrier_aspect_mask; image_memory_barrier.subresourceRange.baseMipLevel = 0; image_memory_barrier.subresourceRange.levelCount = texture->mipmaps; image_memory_barrier.subresourceRange.baseArrayLayer = p_layer; @@ -2156,7 +2177,7 @@ Error RenderingDeviceVulkan::texture_update(RID p_texture, uint32_t p_layer, con buffer_image_copy.bufferRowLength = 0; //tigthly packed buffer_image_copy.bufferImageHeight = 0; //tigthly packed - buffer_image_copy.imageSubresource.aspectMask = texture->aspect_mask; + buffer_image_copy.imageSubresource.aspectMask = texture->read_aspect_mask; buffer_image_copy.imageSubresource.mipLevel = mm_i; buffer_image_copy.imageSubresource.baseArrayLayer = p_layer; buffer_image_copy.imageSubresource.layerCount = 1; @@ -2191,7 +2212,7 @@ Error RenderingDeviceVulkan::texture_update(RID p_texture, uint32_t p_layer, con image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; image_memory_barrier.image = texture->image; - image_memory_barrier.subresourceRange.aspectMask = texture->aspect_mask; + image_memory_barrier.subresourceRange.aspectMask = texture->barrier_aspect_mask; image_memory_barrier.subresourceRange.baseMipLevel = 0; image_memory_barrier.subresourceRange.levelCount = texture->mipmaps; image_memory_barrier.subresourceRange.baseArrayLayer = p_layer; @@ -2340,7 +2361,7 @@ PoolVector<uint8_t> RenderingDeviceVulkan::texture_get_data(RID p_texture, uint3 image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; image_memory_barrier.image = tex->image; - image_memory_barrier.subresourceRange.aspectMask = tex->aspect_mask; + image_memory_barrier.subresourceRange.aspectMask = tex->barrier_aspect_mask; image_memory_barrier.subresourceRange.baseMipLevel = 0; image_memory_barrier.subresourceRange.levelCount = tex->mipmaps; image_memory_barrier.subresourceRange.baseArrayLayer = p_layer; @@ -2379,7 +2400,7 @@ PoolVector<uint8_t> RenderingDeviceVulkan::texture_get_data(RID p_texture, uint3 get_image_format_required_size(tex->format, tex->width, tex->height, tex->depth, i + 1, &mm_width, &mm_height, &mm_depth); VkImageCopy image_copy_region; - image_copy_region.srcSubresource.aspectMask = tex->aspect_mask; + image_copy_region.srcSubresource.aspectMask = tex->read_aspect_mask; image_copy_region.srcSubresource.baseArrayLayer = p_layer; image_copy_region.srcSubresource.layerCount = 1; image_copy_region.srcSubresource.mipLevel = i; @@ -2416,7 +2437,7 @@ PoolVector<uint8_t> RenderingDeviceVulkan::texture_get_data(RID p_texture, uint3 image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; image_memory_barrier.image = tex->image; - image_memory_barrier.subresourceRange.aspectMask = tex->aspect_mask; + image_memory_barrier.subresourceRange.aspectMask = tex->barrier_aspect_mask; image_memory_barrier.subresourceRange.baseMipLevel = 0; image_memory_barrier.subresourceRange.levelCount = tex->mipmaps; image_memory_barrier.subresourceRange.baseArrayLayer = p_layer; @@ -2528,7 +2549,7 @@ Error RenderingDeviceVulkan::texture_copy(RID p_from_texture, RID p_to_texture, image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; image_memory_barrier.image = src_tex->image; - image_memory_barrier.subresourceRange.aspectMask = src_tex->aspect_mask; + image_memory_barrier.subresourceRange.aspectMask = src_tex->barrier_aspect_mask; image_memory_barrier.subresourceRange.baseMipLevel = p_src_mipmap; image_memory_barrier.subresourceRange.levelCount = 1; image_memory_barrier.subresourceRange.baseArrayLayer = p_src_layer; @@ -2548,7 +2569,7 @@ Error RenderingDeviceVulkan::texture_copy(RID p_from_texture, RID p_to_texture, image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; image_memory_barrier.image = dst_tex->image; - image_memory_barrier.subresourceRange.aspectMask = dst_tex->aspect_mask; + image_memory_barrier.subresourceRange.aspectMask = dst_tex->read_aspect_mask; image_memory_barrier.subresourceRange.baseMipLevel = p_dst_mipmap; image_memory_barrier.subresourceRange.levelCount = 1; image_memory_barrier.subresourceRange.baseArrayLayer = p_dst_layer; @@ -2562,7 +2583,7 @@ Error RenderingDeviceVulkan::texture_copy(RID p_from_texture, RID p_to_texture, { VkImageCopy image_copy_region; - image_copy_region.srcSubresource.aspectMask = src_tex->aspect_mask; + image_copy_region.srcSubresource.aspectMask = src_tex->read_aspect_mask; image_copy_region.srcSubresource.baseArrayLayer = p_src_layer; image_copy_region.srcSubresource.layerCount = 1; image_copy_region.srcSubresource.mipLevel = p_src_mipmap; @@ -2570,7 +2591,7 @@ Error RenderingDeviceVulkan::texture_copy(RID p_from_texture, RID p_to_texture, image_copy_region.srcOffset.y = p_from.y; image_copy_region.srcOffset.z = p_from.z; - image_copy_region.dstSubresource.aspectMask = src_tex->aspect_mask; + image_copy_region.dstSubresource.aspectMask = src_tex->barrier_aspect_mask; image_copy_region.dstSubresource.baseArrayLayer = p_dst_layer; image_copy_region.dstSubresource.layerCount = 1; image_copy_region.dstSubresource.mipLevel = p_dst_mipmap; @@ -2598,7 +2619,7 @@ Error RenderingDeviceVulkan::texture_copy(RID p_from_texture, RID p_to_texture, image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; image_memory_barrier.image = src_tex->image; - image_memory_barrier.subresourceRange.aspectMask = src_tex->aspect_mask; + image_memory_barrier.subresourceRange.aspectMask = src_tex->barrier_aspect_mask; image_memory_barrier.subresourceRange.baseMipLevel = p_src_mipmap; image_memory_barrier.subresourceRange.levelCount = src_tex->mipmaps; image_memory_barrier.subresourceRange.baseArrayLayer = p_src_layer; @@ -3672,12 +3693,12 @@ RID RenderingDeviceVulkan::shader_create(const Vector<ShaderStageData> &p_stages Vector<SpvReflectInterfaceVariable *> input_vars; input_vars.resize(iv_count); - result = spvReflectEnumerateOutputVariables(&module, &iv_count, input_vars.ptrw()); + result = spvReflectEnumerateInputVariables(&module, &iv_count, input_vars.ptrw()); ERR_FAIL_COND_V_MSG(result != SPV_REFLECT_RESULT_SUCCESS, RID(), "Reflection of SPIR-V shader stage '" + String(shader_stage_names[p_stages[i].shader_stage]) + "' failed obtaining input variables."); for (uint32_t j = 0; j < iv_count; j++) { - if (input_vars[j]) { + if (input_vars[j] && input_vars[j]->decoration_flags == 0) { //regular input vertex_input_mask |= (1 << uint32_t(input_vars[j]->location)); } } diff --git a/drivers/vulkan/rendering_device_vulkan.h b/drivers/vulkan/rendering_device_vulkan.h index 2cd72fbac4..e2b43d9aeb 100644 --- a/drivers/vulkan/rendering_device_vulkan.h +++ b/drivers/vulkan/rendering_device_vulkan.h @@ -80,6 +80,7 @@ class RenderingDeviceVulkan : public RenderingDevice { static uint32_t get_compressed_image_format_pixel_rshift(DataFormat p_format); static uint32_t get_image_format_required_size(DataFormat p_format, uint32_t p_width, uint32_t p_height, uint32_t p_depth, uint32_t p_mipmaps, uint32_t *r_blockw = NULL, uint32_t *r_blockh = NULL, uint32_t *r_depth = NULL); static uint32_t get_image_required_mipmaps(uint32_t p_width, uint32_t p_height, uint32_t p_depth); + static bool format_has_stencil(DataFormat p_format); /***************************/ /**** ID INFRASTRUCTURE ****/ @@ -139,7 +140,8 @@ class RenderingDeviceVulkan : public RenderingDevice { VkImageLayout bound_layout; //layout used when bound to framebuffer being drawn VkImageLayout unbound_layout; //layout used otherwise - uint32_t aspect_mask; + uint32_t read_aspect_mask; + uint32_t barrier_aspect_mask; bool bound; //bound to framebffer RID owner; }; |