From 9af0f095d8843e7e5f9e06432c344c3580b67f6b Mon Sep 17 00:00:00 2001 From: hyzboy Date: Tue, 28 May 2019 21:26:18 +0800 Subject: [PATCH] =?UTF-8?q?CommandBuffer=E5=A2=9E=E5=8A=A0PushConstants(co?= =?UTF-8?q?nst=20PushConstant128/256)=E5=87=BD=E6=95=B0=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/hgl/graph/vulkan/VK.h | 14 -------------- inc/hgl/graph/vulkan/VKCommandBuffer.h | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/inc/hgl/graph/vulkan/VK.h b/inc/hgl/graph/vulkan/VK.h index b2f08098..2c8888fa 100644 --- a/inc/hgl/graph/vulkan/VK.h +++ b/inc/hgl/graph/vulkan/VK.h @@ -63,20 +63,6 @@ enum class ShaderType Compute =VK_SHADER_STAGE_COMPUTE_BIT };// -struct PushConstant256 -{ - Matrix4f projection; - Matrix4f modelview; - Matrix4f mvp; - Matrix3f normal; -};// - -struct PushConstant128 -{ - Matrix4f projection; - Matrix4f modelview; -};// - #ifdef _DEBUG bool CheckStrideBytesByFormat(); ///<检验所有数据类型长度数组是否符合规则 #endif//_DEBUG diff --git a/inc/hgl/graph/vulkan/VKCommandBuffer.h b/inc/hgl/graph/vulkan/VKCommandBuffer.h index 25a84301..7071e9ef 100644 --- a/inc/hgl/graph/vulkan/VKCommandBuffer.h +++ b/inc/hgl/graph/vulkan/VKCommandBuffer.h @@ -5,6 +5,23 @@ #include #include VK_NAMESPACE_BEGIN +//push constant 一般只有128/256字节,仅能存在矩阵。 +//所以我们将每个对象的独立变换矩阵存在push constant中 + +struct PushConstant256 +{ + Matrix4f projection; + Matrix4f modelview; + Matrix4f mvp; + Matrix3f normal; +};// + +struct PushConstant128 +{ + Matrix4f projection; + Matrix4f modelview; +};// + class CommandBuffer { VkDevice device; @@ -95,6 +112,9 @@ public: vkCmdPushConstants(cmd_buf,pipeline_layout,(VkShaderStageFlagBits)shader_type,offset,size,pValues); } + void PushConstants(const PushConstant256 *pc){vkCmdPushConstants(cmd_buf,pipeline_layout,VK_SHADER_STAGE_VERTEX_BIT,0,sizeof(PushConstant256),pc);} + void PushConstants(const PushConstant128 *pc){vkCmdPushConstants(cmd_buf,pipeline_layout,VK_SHADER_STAGE_VERTEX_BIT,0,sizeof(PushConstant128),pc);} + bool Bind(Renderable *); void SetViewport (uint32_t first,uint32_t count,const VkViewport *vp) {vkCmdSetViewport(cmd_buf,first,count,vp);}