Skip to content

Commit

Permalink
[ScreenSpaceShadows] Removed light and surface building since it's no…
Browse files Browse the repository at this point in the history
…t used
  • Loading branch information
PanosK92 committed Nov 30, 2023
1 parent 3eec4d4 commit 38e9731
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 41 deletions.
2 changes: 1 addition & 1 deletion data/shaders/common_textures.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ struct MaterialProperties
RWTexture2D<float4> tex_uav : register(u0);
RWTexture2D<float4> tex_uav2 : register(u1);
RWTexture2D<float4> tex_uav3 : register(u2);
RWTexture2DArray<float4> tex_uav4 : register(u3);
RWTexture2DArray<float4> tex_uav_sss : register(u3);
RWStructuredBuffer<MaterialProperties> material_properties : register(u4); // matches ID/index to material properties, used by the lighting pass
globallycoherent RWStructuredBuffer<uint> g_atomic_counter : register(u5); // used by FidelityFX SPD
globallycoherent RWTexture2D<float4> tex_uav_mips[12] : register(u6); // used by FidelityFX SPD
10 changes: 1 addition & 9 deletions data/shaders/screen_space_shadows/bend_sss.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@ void mainCS
uint groupIndex : SV_GroupIndex
)
{
// create surface
Surface surface;
surface.Build(DTid.xy, true, true, true);

// create light
Light light;
light.Build(surface);

DispatchParameters in_parameters;
in_parameters.SetDefaults();
in_parameters.LightCoordinate = pass_get_f4_value(); // Values stored in DispatchList::LightCoordinate_Shader by BuildDispatchList()
Expand All @@ -56,7 +48,7 @@ void mainCS
in_parameters.ArraySliceIndex = pass_get_f3_value().z;
in_parameters.InvDepthTextureSize = pass_get_f3_value2().xy; // Inverse of the texture dimensions for 'DepthTexture' (used to convert from pixel coordinates to UVs)
in_parameters.DepthTexture = tex;
in_parameters.OutputTexture = tex_uav4;
in_parameters.OutputTexture = tex_uav_sss;
in_parameters.PointBorderSampler = samplers[sampler_point_wrap]; // A point sampler, with Wrap Mode set to Clamp-To-Border-Color (D3D12_TEXTURE_ADDRESS_MODE_BORDER), and Border Color set to "FarDepthValue" (typically zero), or some other far-depth value out of DepthBounds.
in_parameters.DebugOutputEdgeMask = false; // Use this to visualize edges, for tuning the 'BilinearThreshold' value.
in_parameters.DebugOutputThreadIndex = false; // Debug output to visualize layout of compute threads
Expand Down
10 changes: 3 additions & 7 deletions runtime/RHI/Vulkan/Vulkan_StructuredBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,13 @@ namespace Spartan
}
m_object_size_gpu = m_stride * m_element_count;

// define memory properties
// create buffer
VkMemoryPropertyFlags flags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; // mappable

// Create buffer
RHI_Device::MemoryBufferCreate(m_rhi_resource, m_object_size_gpu, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, flags, nullptr, name);
RHI_Device::SetResourceName(m_rhi_resource, RHI_Resource_Type::Buffer, name); // name the resource

// get mapped data pointer
m_mapped_data = RHI_Device::MemoryGetMappedDataFromBuffer(m_rhi_resource);

// set debug name
RHI_Device::SetResourceName(m_rhi_resource, RHI_Resource_Type::Buffer, name);
m_mapped_data = RHI_Device::MemoryGetMappedDataFromBuffer(m_rhi_resource);
}

RHI_StructuredBuffer::~RHI_StructuredBuffer()
Expand Down
40 changes: 20 additions & 20 deletions runtime/Rendering/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ namespace Spartan
RHI_CommandPool* Renderer::m_cmd_pool = nullptr;
shared_ptr<Camera> Renderer::m_camera = nullptr;
uint32_t Renderer::m_resource_index = 0;
array<Sb_MaterialProperties, 1024> materials;
bool materials_dirty = true;
array<Sb_MaterialProperties, 1024> material_properties;
bool material_properties_dirty = true;

namespace
{
Expand Down Expand Up @@ -634,7 +634,7 @@ namespace Spartan
if (!m_entities_to_add.empty())
{
// clear previous state
materials.fill(Sb_MaterialProperties{});
material_properties.fill(Sb_MaterialProperties{});
m_renderables.clear();
m_camera = nullptr;

Expand All @@ -650,20 +650,20 @@ namespace Spartan
is_transparent = material->GetProperty(MaterialProperty::ColorA) < 1.0f;
is_visible = material->GetProperty(MaterialProperty::ColorA) != 0.0f;

// save the material properties (used in the lighting pass)
// save material properties - used in the lighting pass
{
Sb_MaterialProperties material_properties = {};
material_properties.anisotropic = material->GetProperty(MaterialProperty::Anisotropic);
material_properties.anisotropic_rotation = material->GetProperty(MaterialProperty::AnisotropicRotation);
material_properties.clearcoat = material->GetProperty(MaterialProperty::Clearcoat);
material_properties.clearcoat_roughness = material->GetProperty(MaterialProperty::Clearcoat_Roughness);
material_properties.sheen = material->GetProperty(MaterialProperty::Sheen);
material_properties.sheen_tint = material->GetProperty(MaterialProperty::SheenTint);
material_properties.subsurface_scattering = material->GetProperty(MaterialProperty::MultiplierSubsurfaceScattering);
material_properties.ior = material->GetProperty(MaterialProperty::Ior);

uint32_t index = static_cast<uint32_t>(material->GetObjectId() % materials.size());
materials[index] = material_properties;
Sb_MaterialProperties properties = {};
properties.anisotropic = material->GetProperty(MaterialProperty::Anisotropic);
properties.anisotropic_rotation = material->GetProperty(MaterialProperty::AnisotropicRotation);
properties.clearcoat = material->GetProperty(MaterialProperty::Clearcoat);
properties.clearcoat_roughness = material->GetProperty(MaterialProperty::Clearcoat_Roughness);
properties.sheen = material->GetProperty(MaterialProperty::Sheen);
properties.sheen_tint = material->GetProperty(MaterialProperty::SheenTint);
properties.subsurface_scattering = material->GetProperty(MaterialProperty::MultiplierSubsurfaceScattering);
properties.ior = material->GetProperty(MaterialProperty::Ior);

uint32_t index = static_cast<uint32_t>(material->GetObjectId() % material_properties.size());
material_properties[index] = properties;
}
}

Expand Down Expand Up @@ -708,7 +708,7 @@ namespace Spartan
sort_renderables(m_camera.get(), &m_renderables[Renderer_Entity::GeometryTransparent], true);

m_entities_to_add.clear();
materials_dirty = true;
material_properties_dirty = true;
}

// generate mips
Expand Down Expand Up @@ -922,10 +922,10 @@ namespace Spartan
cmd_list->SetTexture(Renderer_BindingsSrv::gbuffer_velocity_previous, GetRenderTarget(Renderer_RenderTexture::gbuffer_velocity_previous));

// update material array
if (materials_dirty)
if (material_properties_dirty)
{
GetStructuredBuffer(Renderer_StructuredBuffer::Material)->Update(&materials[0]);
materials_dirty = false;
GetStructuredBuffer(Renderer_StructuredBuffer::Material)->Update(&material_properties[0]);
material_properties_dirty = false;
}

cmd_list->SetStructuredBuffer(Renderer_BindingsUav::sb_materials, GetStructuredBuffer(Renderer_StructuredBuffer::Material));
Expand Down
8 changes: 4 additions & 4 deletions runtime/Rendering/Renderer_Resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ namespace Spartan
array<shared_ptr<RHI_StructuredBuffer>, 2> m_structured_buffers;

// asset resources
array<shared_ptr<RHI_Texture>, 10> m_standard_textures;
array<shared_ptr<Mesh>, 7> m_standard_meshes;
array<shared_ptr<Font>, 5> m_fonts; // as many as m_resources_frame_lifetime
array<shared_ptr<RHI_Texture>, 10> m_standard_textures;
array<shared_ptr<Mesh>, 7> m_standard_meshes;
array<shared_ptr<Font>, resources_frame_lifetime> m_fonts;
}

void Renderer::CreateConstantBuffers()
Expand All @@ -88,7 +88,7 @@ namespace Spartan
#define structured_buffer(x) m_structured_buffers[static_cast<uint8_t>(x)]

uint32_t stride = static_cast<uint32_t>(sizeof(uint32_t));
uint32_t element_count = 32 * resources_frame_lifetime;
uint32_t element_count = 16 * resources_frame_lifetime; // SPD is used less than 5 times per frame so 16 should cover it
structured_buffer(Renderer_StructuredBuffer::Spd) = make_shared<RHI_StructuredBuffer>(stride, element_count, "spd_counter");

stride = static_cast<uint32_t>(sizeof(Sb_MaterialProperties)) * 1024;
Expand Down

0 comments on commit 38e9731

Please sign in to comment.