Skip to content

Commit

Permalink
request fragment-shading-rate feature, enable triangle-culling mesh-s…
Browse files Browse the repository at this point in the history
…hader
  • Loading branch information
crocdialer committed Oct 6, 2024
1 parent 79b6b76 commit 24f4ab7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
7 changes: 3 additions & 4 deletions shaders/pbr/g_buffer.mesh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
layout(local_size_x_id = 0, local_size_y = 1, local_size_z = 1) in;
layout(triangles, max_vertices = 64, max_primitives = 64) out;

#define CULLING 0
#define CULLING 1

layout(buffer_reference, scalar) readonly buffer VertexBufferPtr { packed_vertex_t v[]; };
layout(binding = BINDING_VERTICES, set = 0) readonly buffer Vertices { VertexBufferPtr vertex_buffers[]; };
Expand Down Expand Up @@ -126,9 +126,8 @@ void main()

gl_PrimitiveTriangleIndicesEXT[i] = uvec3(a, b, c);

// // TODO: writing this causes a validation-bug (https://github.com/KhronosGroup/glslang/issues/3103)
// // keep track of primitive-id
// gl_MeshPrimitivesEXT[i].gl_PrimitiveID = int(base_index / 3);
// keep track of primitive-id // TODO: nice try, but no
gl_MeshPrimitivesEXT[i].gl_PrimitiveID = int(base_index / 3);
#if CULLING
bool culled = false;

Expand Down
2 changes: 1 addition & 1 deletion shaders/utils/hash.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ uint murmur_32_scramble(uint k)
//! condensed version of murmur3_32 for uint32_t
uint murmur3_32(const uint key, uint seed)
{
uint len = 4;// sizeof(key_t)
const uint len = 4;// sizeof(key_t)
uint h = seed;
h ^= murmur_32_scramble(key);
h = (h << 13) | (h >> 19);
Expand Down
14 changes: 14 additions & 0 deletions src/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,15 @@ Device::Device(const create_info_t &create_info) : m_physical_device(create_info
extensions.push_back(g_portability_ext_name);
}

// check if mesh-shading was requested and if so, enable fragment-rate-shading as well.
// this is for some weird reason required by primitive-culling in mesh-shaders
if(crocore::contains(extensions, VK_EXT_MESH_SHADER_EXTENSION_NAME) &&
vierkant::check_device_extension_support(create_info.physical_device,
{VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME}))
{
extensions.push_back(VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME);
}

if(!vierkant::check_device_extension_support(create_info.physical_device, extensions))
{
spdlog::critical("unsupported extension(s): {}", extensions);
Expand Down Expand Up @@ -261,6 +270,11 @@ Device::Device(const create_info_t &create_info) : m_physical_device(create_info
}
};

//------------------------------------ VK_KHR_fragment_shading_rate ------------------------------------------------
VkPhysicalDeviceFragmentShadingRateFeaturesKHR fragment_shading_rate_features = {};
fragment_shading_rate_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADING_RATE_FEATURES_KHR;
update_pnext(fragment_shading_rate_features, VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME);

//------------------------------------ VK_KHR_acceleration_structure -----------------------------------------------
VkPhysicalDeviceAccelerationStructureFeaturesKHR acceleration_structure_features = {};
acceleration_structure_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ACCELERATION_STRUCTURE_FEATURES_KHR;
Expand Down

0 comments on commit 24f4ab7

Please sign in to comment.