| 3120 | } |
| 3121 | |
| 3122 | static bool DrawSetup(VulkanContext* context, VkCommandBuffer vk_command_buffer, ScratchBuffer* scratchBuffer, DeviceBuffer* indexBuffer, Type indexBufferType) |
| 3123 | { |
| 3124 | VulkanRenderTarget* current_rt = GetAssetFromContainer<VulkanRenderTarget>(context->m_BaseContext.m_AssetHandleContainer, context->m_CurrentRenderTarget); |
| 3125 | BeginRenderPass(context, context->m_CurrentRenderTarget); |
| 3126 | |
| 3127 | VulkanProgram* program_ptr = context->m_CurrentProgram; |
| 3128 | VkDevice vk_device = context->m_LogicalDevice.m_Device; |
| 3129 | |
| 3130 | VkBuffer vk_buffers[MAX_VERTEX_BUFFERS] = {}; |
| 3131 | VkDeviceSize vk_buffer_offsets[MAX_VERTEX_BUFFERS] = {}; |
| 3132 | VertexDeclaration* vx_declarations[MAX_VERTEX_BUFFERS] = {}; |
| 3133 | uint32_t num_vx_buffers = 0; |
| 3134 | |
| 3135 | for (int i = 0; i < MAX_VERTEX_BUFFERS; ++i) |
| 3136 | { |
| 3137 | if (context->m_CurrentVertexBuffer[i] && context->m_CurrentVertexDeclaration[i]) |
| 3138 | { |
| 3139 | TouchResource(context, context->m_CurrentVertexBuffer[i]); |
| 3140 | vx_declarations[num_vx_buffers] = context->m_CurrentVertexDeclaration[i]; |
| 3141 | vk_buffers[num_vx_buffers] = context->m_CurrentVertexBuffer[i]->m_Handle.m_Buffer; |
| 3142 | vk_buffer_offsets[num_vx_buffers] = context->m_CurrentVertexBufferOffset[i]; |
| 3143 | num_vx_buffers++; |
| 3144 | } |
| 3145 | } |
| 3146 | |
| 3147 | PrepareScatchBuffer(context, scratchBuffer, program_ptr); |
| 3148 | |
| 3149 | // Write the uniform data to the descriptors |
| 3150 | uint32_t dynamic_alignment = (uint32_t) context->m_PhysicalDevice.m_Properties.limits.minUniformBufferOffsetAlignment; |
| 3151 | VkResult res = CommitUniforms(context, vk_command_buffer, vk_device, program_ptr, VK_PIPELINE_BIND_POINT_GRAPHICS, scratchBuffer, context->m_DynamicOffsetBuffer, dynamic_alignment); |
| 3152 | CHECK_VK_ERROR(res); |
| 3153 | |
| 3154 | PipelineState pipeline_state_draw = context->m_PipelineState; |
| 3155 | |
| 3156 | // Offscreen Vulkan rendering uses the opposite effective winding from |
| 3157 | // OpenGL, so flip the cull side to preserve the existing culling |
| 3158 | // semantics used by render scripts. |
| 3159 | if (current_rt->m_Base.m_Id != DM_RENDERTARGET_BACKBUFFER_ID) |
| 3160 | { |
| 3161 | if (pipeline_state_draw.m_CullFaceType == FACE_TYPE_BACK) |
| 3162 | { |
| 3163 | pipeline_state_draw.m_CullFaceType = FACE_TYPE_FRONT; |
| 3164 | } |
| 3165 | else if (pipeline_state_draw.m_CullFaceType == FACE_TYPE_FRONT) |
| 3166 | { |
| 3167 | pipeline_state_draw.m_CullFaceType = FACE_TYPE_BACK; |
| 3168 | } |
| 3169 | } |
| 3170 | |
| 3171 | // Update the viewport |
| 3172 | if (context->m_ViewportChanged) |
| 3173 | { |
| 3174 | Viewport& vp = context->m_MainViewport; |
| 3175 | |
| 3176 | // If we are rendering to the backbuffer, we must invert the viewport on |
| 3177 | // the y axis. Otherwise we just use the values as-is. |
| 3178 | // If we don't, all FBO rendering will be upside down. |
| 3179 | if (current_rt->m_Base.m_Id == DM_RENDERTARGET_BACKBUFFER_ID) |
no test coverage detected