From 4412766ddff6da43c81100b7fd0c3be8265dd8ee Mon Sep 17 00:00:00 2001 From: hyzboy Date: Thu, 11 Jul 2019 02:42:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=B2=E7=A1=AE=E8=AE=A4=E5=87=A0=E4=B8=AA2D?= =?UTF-8?q?=E8=8C=83=E4=BE=8B=E5=9D=87=E5=8F=AF=E6=AD=A3=E5=B8=B8DEPTH=20T?= =?UTF-8?q?EST/WRITE,=E4=BD=86=E5=9C=A8=E4=BD=BF=E7=94=A8CAMERA=E5=90=8E?= =?UTF-8?q?=E5=BE=97=E5=87=BA=E7=9A=84=E6=97=A0=E6=B3=95=E5=86=99=E5=85=A5?= =?UTF-8?q?DEPTH?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/Vulkan/Geometry2D.cpp | 2 -- example/Vulkan/InlineGeometryScene.cpp | 4 +--- example/Vulkan/VulkanAppFramework.h | 4 ++-- example/Vulkan/indices_rect.cpp | 2 -- example/Vulkan/main.cpp | 2 -- example/Vulkan/texture_rect.cpp | 2 -- inc/hgl/graph/vulkan/VKDevice.h | 4 ++-- inc/hgl/graph/vulkan/VKPipeline.h | 3 ++- res/shader/OnlyPosition3D.vert | 4 ++-- res/shader/PositionColor3D.vert | 4 ++-- src/RenderDevice/Vulkan/VKDeviceCreater.cpp | 6 ++++++ 11 files changed, 17 insertions(+), 20 deletions(-) diff --git a/example/Vulkan/Geometry2D.cpp b/example/Vulkan/Geometry2D.cpp index b0d1888e..6d8f837f 100644 --- a/example/Vulkan/Geometry2D.cpp +++ b/example/Vulkan/Geometry2D.cpp @@ -116,8 +116,6 @@ private: { AutoDelete pipeline_creater=new vulkan::PipelineCreater(device,material,device->GetMainRenderPass(),device->GetExtent()); - pipeline_creater->SetDepthTest(false); - pipeline_creater->SetDepthWrite(false); pipeline_creater->CloseCullFace(); pipeline_creater->Set(PRIM_TRIANGLE_FAN); diff --git a/example/Vulkan/InlineGeometryScene.cpp b/example/Vulkan/InlineGeometryScene.cpp index 1cd8b73b..81e12ac2 100644 --- a/example/Vulkan/InlineGeometryScene.cpp +++ b/example/Vulkan/InlineGeometryScene.cpp @@ -139,8 +139,6 @@ private: { AutoDelete pipeline_creater=new vulkan::PipelineCreater(device,material,device->GetMainRenderPass(),device->GetExtent()); - pipeline_creater->SetDepthTest(true); - pipeline_creater->SetDepthWrite(true); pipeline_creater->Set(PRIM_LINES); pipeline_line=pipeline_creater->Create(); @@ -172,7 +170,7 @@ private: bool InitScene() { render_root.Add(db->CreateRenderableInstance(pipeline_line,descriptor_sets,ro_plane_grid)); - render_root.Add(db->CreateRenderableInstance(pipeline_twoside,descriptor_sets,ro_dome)); + //render_root.Add(db->CreateRenderableInstance(pipeline_twoside,descriptor_sets,ro_dome)); render_root.Add(db->CreateRenderableInstance(pipeline_twoside,descriptor_sets,ro_torus)); render_root.Add(db->CreateRenderableInstance(pipeline_solid,descriptor_sets,ro_cube ),translate(-10, 0, 5)*scale(10,10,10)); render_root.Add(db->CreateRenderableInstance(pipeline_solid,descriptor_sets,ro_sphere ),translate( 10, 0, 5)*scale(10,10,10)); diff --git a/example/Vulkan/VulkanAppFramework.h b/example/Vulkan/VulkanAppFramework.h index 2ddc4d89..91c62b40 100644 --- a/example/Vulkan/VulkanAppFramework.h +++ b/example/Vulkan/VulkanAppFramework.h @@ -301,11 +301,11 @@ public: virtual void Draw()override { - const uint32_t index=AcquireNextImage(); - camera.Refresh(); //更新相机矩阵 ubo_world_matrix->Write(&camera.matrix); //写入缓冲区 + const uint32_t index=AcquireNextImage(); + BuildCommandBuffer(index); SubmitDraw(index); diff --git a/example/Vulkan/indices_rect.cpp b/example/Vulkan/indices_rect.cpp index 13c9aef5..f0598a62 100644 --- a/example/Vulkan/indices_rect.cpp +++ b/example/Vulkan/indices_rect.cpp @@ -105,8 +105,6 @@ private: { AutoDelete pipeline_creater=new vulkan::PipelineCreater(device,material,device->GetMainRenderPass(),device->GetExtent()); - pipeline_creater->SetDepthTest(false); - pipeline_creater->SetDepthWrite(false); pipeline_creater->CloseCullFace(); pipeline_creater->Set(PRIM_TRIANGLES); diff --git a/example/Vulkan/main.cpp b/example/Vulkan/main.cpp index 1426bd05..831dbd3e 100644 --- a/example/Vulkan/main.cpp +++ b/example/Vulkan/main.cpp @@ -109,8 +109,6 @@ private: { AutoDelete pipeline_creater=new vulkan::PipelineCreater(device,material,device->GetMainRenderPass(),device->GetExtent()); - pipeline_creater->SetDepthTest(false); - pipeline_creater->SetDepthWrite(false); pipeline_creater->CloseCullFace(); pipeline_creater->Set(PRIM_TRIANGLES); diff --git a/example/Vulkan/texture_rect.cpp b/example/Vulkan/texture_rect.cpp index d8459fef..d0ae186e 100644 --- a/example/Vulkan/texture_rect.cpp +++ b/example/Vulkan/texture_rect.cpp @@ -150,8 +150,6 @@ private: { AutoDelete pipeline_creater=new vulkan::PipelineCreater(device,material,device->GetMainRenderPass(),device->GetExtent()); - pipeline_creater->SetDepthTest(false); - pipeline_creater->SetDepthWrite(false); pipeline_creater->CloseCullFace(); pipeline_creater->Set(PRIM_TRIANGLES); diff --git a/inc/hgl/graph/vulkan/VKDevice.h b/inc/hgl/graph/vulkan/VKDevice.h index ce4932cd..63918266 100644 --- a/inc/hgl/graph/vulkan/VKDevice.h +++ b/inc/hgl/graph/vulkan/VKDevice.h @@ -125,7 +125,7 @@ public: //material相关 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); } - Texture2D *CreateAttachmentTexture(const VkFormat video_format,uint32_t width,uint32_t height,const VkImageAspectFlags aspectMask,const VkImageUsageFlagBits usage,const VkImageLayout image_layout) + Texture2D *CreateAttachmentTexture(const VkFormat video_format,uint32_t width,uint32_t height,const VkImageAspectFlags aspectMask,const uint usage,const VkImageLayout image_layout) { return CreateTexture2D(video_format,width,height,aspectMask,usage|VK_IMAGE_USAGE_SAMPLED_BIT,image_layout); } @@ -142,7 +142,7 @@ public: //material相关 { return CreateAttachmentTexture( video_format,width,height, VK_IMAGE_ASPECT_DEPTH_BIT,//|VK_IMAGE_ASPECT_STENCIL_BIT, - VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, + VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT|VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); } diff --git a/inc/hgl/graph/vulkan/VKPipeline.h b/inc/hgl/graph/vulkan/VKPipeline.h index 9f849de7..5c985d10 100644 --- a/inc/hgl/graph/vulkan/VKPipeline.h +++ b/inc/hgl/graph/vulkan/VKPipeline.h @@ -84,7 +84,8 @@ public: void SetDepthCompareOp( VkCompareOp op) {depthStencilState.depthCompareOp=op;} void SetDepthBoundsTest(bool dbt) {depthStencilState.depthBoundsTestEnable=dbt;} void SetDepthBounds( float min_depth, - float max_depth) {depthStencilState.minDepthBounds=min_depth; + float max_depth) {depthStencilState.depthBoundsTestEnable=VK_TRUE; + depthStencilState.minDepthBounds=min_depth; depthStencilState.maxDepthBounds=max_depth;} void SetStencilTest( bool st) {depthStencilState.stencilTestEnable=st;} diff --git a/res/shader/OnlyPosition3D.vert b/res/shader/OnlyPosition3D.vert index 8ccb9042..6a73d42b 100644 --- a/res/shader/OnlyPosition3D.vert +++ b/res/shader/OnlyPosition3D.vert @@ -8,7 +8,7 @@ layout(binding = 0) uniform WorldMatrix mat4 projection; mat4 modelview; mat4 mvp; - mat3 normal; + vec4 view_pos; } world; layout(push_constant) uniform Consts { @@ -21,5 +21,5 @@ void main() { FragmentColor=vec4(1.0); - gl_Position=vec4(Vertex,1.0)*pc.local_to_world*world.mvp; + gl_Position=vec4(Vertex,1.0)*(pc.local_to_world*world.mvp); } diff --git a/res/shader/PositionColor3D.vert b/res/shader/PositionColor3D.vert index dd539dd3..bd2eb4f5 100644 --- a/res/shader/PositionColor3D.vert +++ b/res/shader/PositionColor3D.vert @@ -9,7 +9,7 @@ layout(binding = 0) uniform WorldMatrix mat4 projection; mat4 modelview; mat4 mvp; - mat3 normal; + vec4 view_pos; } world; layout(push_constant) uniform Consts { @@ -22,5 +22,5 @@ void main() { FragmentColor=Color; - gl_Position=vec4(Vertex,1.0)*pc.local_to_world*world.mvp; + gl_Position=vec4(Vertex,1.0)*(pc.local_to_world*world.mvp); } diff --git a/src/RenderDevice/Vulkan/VKDeviceCreater.cpp b/src/RenderDevice/Vulkan/VKDeviceCreater.cpp index 10702f9f..73942f91 100644 --- a/src/RenderDevice/Vulkan/VKDeviceCreater.cpp +++ b/src/RenderDevice/Vulkan/VKDeviceCreater.cpp @@ -115,6 +115,12 @@ namespace swapchain_ci.imageColorSpace=VK_COLORSPACE_SRGB_NONLINEAR_KHR; swapchain_ci.imageUsage=VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; + if(rsa->surface_caps.supportedUsageFlags&VK_IMAGE_USAGE_TRANSFER_SRC_BIT) + swapchain_ci.imageUsage|=VK_IMAGE_USAGE_TRANSFER_SRC_BIT; + + if(rsa->surface_caps.supportedUsageFlags&VK_IMAGE_USAGE_TRANSFER_DST_BIT) + swapchain_ci.imageUsage|=VK_IMAGE_USAGE_TRANSFER_DST_BIT; + uint32_t queueFamilyIndices[2]={rsa->graphics_family, rsa->present_family}; if(rsa->graphics_family!=rsa->present_family) {