Skip to content

Commit

Permalink
Fix Apple M1 Crash
Browse files Browse the repository at this point in the history
  • Loading branch information
BoomingTech-YuqiaoZhang authored and hyv1001 committed Apr 7, 2022
1 parent 3714fbd commit a0e2f6e
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 64 deletions.
17 changes: 5 additions & 12 deletions engine/shader/glsl/mesh.vert
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#extension GL_GOOGLE_include_directive : enable

#include "constants.h"
#include "structures.h"

struct DirectionalLight
{
Expand Down Expand Up @@ -38,21 +39,13 @@ layout(set = 0, binding = 0) readonly buffer _unused_name_perframe

layout(set = 0, binding = 1) readonly buffer _unused_name_per_drawcall
{
mat4 model_matrices[m_mesh_per_drawcall_max_instance_count];
float enable_vertex_blendings[m_mesh_per_drawcall_max_instance_count];
VulkanMeshInstance mesh_instances[m_mesh_per_drawcall_max_instance_count];
};

layout(set = 0, binding = 2) readonly buffer _unused_name_per_drawcall_vertex_blending
{
mat4 joint_matrices[m_mesh_vertex_blending_max_joint_count * m_mesh_per_drawcall_max_instance_count];
highp mat4 joint_matrices[m_mesh_vertex_blending_max_joint_count * m_mesh_per_drawcall_max_instance_count];
};

struct VulkanMeshVertexJointBinding
{
highp ivec4 indices;
highp vec4 weights;
};

layout(set = 1, binding = 0) readonly buffer _unused_name_per_mesh_joint_binding
{
VulkanMeshVertexJointBinding indices_and_weights[];
Expand All @@ -70,8 +63,8 @@ layout(location = 3) out vec2 out_texcoord;

void main()
{
highp mat4 model_matrix = model_matrices[gl_InstanceIndex];
highp float enable_vertex_blending = enable_vertex_blendings[gl_InstanceIndex];
highp mat4 model_matrix = mesh_instances[gl_InstanceIndex].model_matrix;
highp float enable_vertex_blending = mesh_instances[gl_InstanceIndex].enable_vertex_blending;

highp vec3 model_position;
highp vec3 model_normal;
Expand Down
14 changes: 4 additions & 10 deletions engine/shader/glsl/mesh_directional_light_shadow.vert
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#extension GL_GOOGLE_include_directive : enable

#include "constants.h"
#include "structures.h"

layout(set = 0, binding = 0) readonly buffer _unused_name_global_set_per_frame_binding_buffer
{
Expand All @@ -11,21 +12,14 @@ layout(set = 0, binding = 0) readonly buffer _unused_name_global_set_per_frame_b

layout(set = 0, binding = 1) readonly buffer _unused_name_per_drawcall
{
mat4 model_matrices[m_mesh_per_drawcall_max_instance_count];
float enable_vertex_blendings[m_mesh_per_drawcall_max_instance_count];
VulkanMeshInstance mesh_instances[m_mesh_per_drawcall_max_instance_count];
};

layout(set = 0, binding = 2) readonly buffer _unused_name_per_drawcall_vertex_blending
{
mat4 joint_matrices[m_mesh_vertex_blending_max_joint_count * m_mesh_per_drawcall_max_instance_count];
};

struct VulkanMeshVertexJointBinding
{
highp ivec4 indices;
highp vec4 weights;
};

layout(set = 1, binding = 0) readonly buffer _unused_name_per_mesh_joint_binding
{
VulkanMeshVertexJointBinding indices_and_weights[];
Expand All @@ -35,8 +29,8 @@ layout(location = 0) in highp vec3 in_position;

void main()
{
highp mat4 model_matrix = model_matrices[gl_InstanceIndex];
highp float enable_vertex_blending = enable_vertex_blendings[gl_InstanceIndex];
highp mat4 model_matrix = mesh_instances[gl_InstanceIndex].model_matrix;
highp float enable_vertex_blending = mesh_instances[gl_InstanceIndex].enable_vertex_blending;

highp vec3 model_position;
if (enable_vertex_blending > 0.0)
Expand Down
7 changes: 1 addition & 6 deletions engine/shader/glsl/mesh_inefficient_pick.vert
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#extension GL_GOOGLE_include_directive : enable

#include "constants.h"
#include "structures.h"

layout(set = 0, binding = 0) readonly buffer _unused_name_perframe
{
Expand All @@ -23,12 +24,6 @@ layout(set = 0, binding = 2) readonly buffer _unused_name_per_drawcall_vertex_bl
mat4 joint_matrices[m_mesh_vertex_blending_max_joint_count * m_mesh_per_drawcall_max_instance_count];
};

struct VulkanMeshVertexJointBinding
{
highp ivec4 indices;
highp vec4 weights;
};

layout(set = 1, binding = 0) readonly buffer _unused_name_per_mesh_joint_binding
{
VulkanMeshVertexJointBinding indices_and_weights[];
Expand Down
14 changes: 4 additions & 10 deletions engine/shader/glsl/mesh_point_light_shadow.vert
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,18 @@
#extension GL_GOOGLE_include_directive : enable

#include "constants.h"
#include "structures.h"

layout(set = 0, binding = 1) readonly buffer _unused_name_per_drawcall
{
mat4 model_matrices[m_mesh_per_drawcall_max_instance_count];
float enable_vertex_blendings[m_mesh_per_drawcall_max_instance_count];
VulkanMeshInstance mesh_instances[m_mesh_per_drawcall_max_instance_count];
};

layout(set = 0, binding = 2) readonly buffer _unused_name_per_drawcall_vertex_blending
{
mat4 joint_matrices[m_mesh_vertex_blending_max_joint_count * m_mesh_per_drawcall_max_instance_count];
};

struct VulkanMeshVertexJointBinding
{
highp ivec4 indices;
highp vec4 weights;
};

layout(set = 1, binding = 0) readonly buffer _unused_name_per_mesh_joint_binding
{
VulkanMeshVertexJointBinding indices_and_weights[];
Expand All @@ -32,8 +26,8 @@ layout(location = 0) out highp vec3 out_position_world_space;

void main()
{
highp mat4 model_matrix = model_matrices[gl_InstanceIndex];
highp float enable_vertex_blending = enable_vertex_blendings[gl_InstanceIndex];
highp mat4 model_matrix = mesh_instances[gl_InstanceIndex].model_matrix;
highp float enable_vertex_blending = mesh_instances[gl_InstanceIndex].enable_vertex_blending;

highp vec3 model_position;
if (enable_vertex_blending > 0.0)
Expand Down
14 changes: 14 additions & 0 deletions engine/shader/include/structures.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
struct VulkanMeshInstance
{
highp float enable_vertex_blending;
highp float _padding_enable_vertex_blending_1;
highp float _padding_enable_vertex_blending_2;
highp float _padding_enable_vertex_blending_3;
highp mat4 model_matrix;
};

struct VulkanMeshVertexJointBinding
{
highp ivec4 indices;
highp vec4 weights;
};
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,18 @@ namespace Pilot
glm::mat4 directional_light_proj_view;
};

struct VulkanMeshInstance
{
float enable_vertex_blending;
float _padding_enable_vertex_blending_1;
float _padding_enable_vertex_blending_2;
float _padding_enable_vertex_blending_3;
glm::mat4 model_matrix;
};

struct MeshPerdrawcallStorageBufferObject
{
glm::mat4 model_matrices[m_mesh_per_drawcall_max_instance_count];
float enable_vertex_blendings[m_mesh_per_drawcall_max_instance_count];
VulkanMeshInstance mesh_instances[m_mesh_per_drawcall_max_instance_count];
};

struct MeshPerdrawcallVertexBlendingStorageBufferObject
Expand Down Expand Up @@ -87,8 +95,7 @@ namespace Pilot

struct MeshPointLightShadowPerdrawcallStorageBufferObject
{
glm::mat4 model_matrices[m_mesh_per_drawcall_max_instance_count];
float enable_vertex_blendings[m_mesh_per_drawcall_max_instance_count];
VulkanMeshInstance mesh_instances[m_mesh_per_drawcall_max_instance_count];
};

struct MeshPointLightShadowPerdrawcallVertexBlendingStorageBufferObject
Expand All @@ -103,8 +110,7 @@ namespace Pilot

struct MeshDirectionalLightShadowPerdrawcallStorageBufferObject
{
glm::mat4 model_matrices[m_mesh_per_drawcall_max_instance_count];
float enable_vertex_blendings[m_mesh_per_drawcall_max_instance_count];
VulkanMeshInstance mesh_instances[m_mesh_per_drawcall_max_instance_count];
};

struct MeshDirectionalLightShadowPerdrawcallVertexBlendingStorageBufferObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,8 @@ namespace Pilot
m_command_info._current_command_buffer, mesh.mesh_index_buffer, 0, VK_INDEX_TYPE_UINT16);

uint32_t drawcall_max_instance_count =
(sizeof(MeshDirectionalLightShadowPerdrawcallStorageBufferObject::model_matrices) /
sizeof(MeshDirectionalLightShadowPerdrawcallStorageBufferObject::model_matrices[0]));
(sizeof(MeshDirectionalLightShadowPerdrawcallStorageBufferObject::mesh_instances) /
sizeof(MeshDirectionalLightShadowPerdrawcallStorageBufferObject::mesh_instances[0]));
uint32_t drawcall_count =
roundUp(total_instance_count, drawcall_max_instance_count) / drawcall_max_instance_count;

Expand Down Expand Up @@ -625,9 +625,9 @@ namespace Pilot
perdrawcall_dynamic_offset));
for (uint32_t i = 0; i < current_instance_count; ++i)
{
perdrawcall_storage_buffer_object.model_matrices[i] =
perdrawcall_storage_buffer_object.mesh_instances[i].model_matrix =
mesh_nodes[drawcall_max_instance_count * drawcall_index + i].model_matrix;
perdrawcall_storage_buffer_object.enable_vertex_blendings[i] =
perdrawcall_storage_buffer_object.mesh_instances[i].enable_vertex_blending =
mesh_nodes[drawcall_max_instance_count * drawcall_index + i]
.enable_vertex_blending ?
1.0 :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1401,8 +1401,8 @@ namespace Pilot
m_command_info._current_command_buffer, mesh.mesh_index_buffer, 0, VK_INDEX_TYPE_UINT16);

uint32_t drawcall_max_instance_count =
(sizeof(MeshPerdrawcallStorageBufferObject::model_matrices) /
sizeof(MeshPerdrawcallStorageBufferObject::model_matrices[0]));
(sizeof(MeshPerdrawcallStorageBufferObject::mesh_instances) /
sizeof(MeshPerdrawcallStorageBufferObject::mesh_instances[0]));
uint32_t drawcall_count =
roundUp(total_instance_count, drawcall_max_instance_count) / drawcall_max_instance_count;

Expand Down Expand Up @@ -1436,9 +1436,9 @@ namespace Pilot
perdrawcall_dynamic_offset));
for (uint32_t i = 0; i < current_instance_count; ++i)
{
perdrawcall_storage_buffer_object.model_matrices[i] =
perdrawcall_storage_buffer_object.mesh_instances[i].model_matrix =
mesh_nodes[drawcall_max_instance_count * drawcall_index + i].model_matrix;
perdrawcall_storage_buffer_object.enable_vertex_blendings[i] =
perdrawcall_storage_buffer_object.mesh_instances[i].enable_vertex_blending =
mesh_nodes[drawcall_max_instance_count * drawcall_index + i].enable_vertex_blending ?
1.0 :
-1.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,8 @@ namespace Pilot
m_command_info._current_command_buffer, mesh.mesh_index_buffer, 0, VK_INDEX_TYPE_UINT16);

uint32_t drawcall_max_instance_count =
(sizeof(MeshPointLightShadowPerdrawcallStorageBufferObject::model_matrices) /
sizeof(MeshPointLightShadowPerdrawcallStorageBufferObject::model_matrices[0]));
(sizeof(MeshPointLightShadowPerdrawcallStorageBufferObject::mesh_instances) /
sizeof(MeshPointLightShadowPerdrawcallStorageBufferObject::mesh_instances[0]));
uint32_t drawcall_count =
roundUp(total_instance_count, drawcall_max_instance_count) / drawcall_max_instance_count;

Expand Down Expand Up @@ -632,9 +632,9 @@ namespace Pilot
perdrawcall_dynamic_offset));
for (uint32_t i = 0; i < current_instance_count; ++i)
{
perdrawcall_storage_buffer_object.model_matrices[i] =
perdrawcall_storage_buffer_object.mesh_instances[i].model_matrix =
mesh_nodes[drawcall_max_instance_count * drawcall_index + i].model_matrix;
perdrawcall_storage_buffer_object.enable_vertex_blendings[i] =
perdrawcall_storage_buffer_object.mesh_instances[i].enable_vertex_blending =
mesh_nodes[drawcall_max_instance_count * drawcall_index + i]
.enable_vertex_blending ?
1.0 :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,12 @@ void Pilot::PGlobalRenderResource::initializeStorageBuffer(PVulkanContext& conte
// null descriptor
PVulkanUtil::createBuffer(context._physical_device,
context._device,
1,
64,
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
0,
_storage_buffer._global_null_descriptor_storage_buffer,
_storage_buffer._global_null_descriptor_storage_buffer_memory);
static_assert(64 >= sizeof(PMeshVertex::VulkanMeshVertexJointBinding), "");
}

void Pilot::PGlobalRenderResource::mapStorageBuffer(PVulkanContext& context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,6 @@ void Pilot::PVulkanManager::beginFrame()

m_vulkan_context._vkCmdBeginRenderPass(
m_command_buffers[m_current_frame_index], &renderpass_begin_info, VK_SUBPASS_CONTENTS_INLINE);

if (m_enable_debug_untils_label)
{
VkDebugUtilsLabelEXT label_info = {
VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT, NULL, "Lighting", {1.0f, 1.0f, 1.0f, 1.0f}};
m_vulkan_context._vkCmdBeginDebugUtilsLabelEXT(m_command_buffers[m_current_frame_index], &label_info);
}
}

m_mesh_lighting_pass.draw();
Expand Down

0 comments on commit a0e2f6e

Please sign in to comment.