Skip to content

Commit edb9024

Browse files
committed
DLSS: fix dispatch error
1 parent 5751d20 commit edb9024

17 files changed

Lines changed: 114 additions & 219 deletions

data/shaders/common_structs.hlsl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ struct Surface
102102
depth = sample_depth;
103103
normal = sample_normal.xyz;
104104
flags = material.flags;
105+
// velocity.w is packed at gbuffer time so composition can find skids if the material index misses
106+
if (tex_velocity.SampleLevel(samplers[sampler_point_clamp], uv, 0).a > 0.5f)
107+
{
108+
flags |= uint(1U << 20);
109+
}
105110
albedo = replace_color_with_one ? 1.0f : sample_albedo.rgb;
106111
alpha = sample_albedo.a;
107112
roughness = sample_material.r;

data/shaders/g_buffer.hlsl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,8 @@ gbuffer main_ps(gbuffer_vertex vertex, bool is_front_face : SV_IsFrontFace)
373373
albedo.a = lerp(albedo.a, 1.0f, step(albedo_sample.a, 1.0f) * pass_is_opaque());
374374
if (surface.is_skid_mark())
375375
{
376-
albedo.a *= saturate(vertex.uv_misc.z);
376+
// stain mask is texture alpha times vertex fade, color.a is only the transparent pass ticket
377+
albedo.a = saturate(albedo_sample.a) * saturate(vertex.uv_misc.z);
377378
}
378379

379380
// emission
@@ -522,6 +523,6 @@ gbuffer main_ps(gbuffer_vertex vertex, bool is_front_face : SV_IsFrontFace)
522523
g_buffer.albedo = albedo;
523524
g_buffer.normal = float4(normal, pass_get_material_index());
524525
g_buffer.material = float4(roughness, metalness, emission, occlusion);
525-
g_buffer.velocity = float4(velocity, material.is_motion_blur_radial() ? 1.0f : 0.0f, 0.0f);
526+
g_buffer.velocity = float4(velocity, material.is_motion_blur_radial() ? 1.0f : 0.0f, surface.is_skid_mark() ? 1.0f : 0.0f);
526527
return g_buffer;
527528
}

data/shaders/light_composition.hlsl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,20 @@ void main_cs(uint3 thread_id : SV_DispatchThreadID)
7676
Surface surface;
7777
surface.Build(thread_id.xy, resolution_out, true, false);
7878

79-
// skip non transparent pixels during the transparent pass, the opaque pass already wrote them
80-
if (pass_is_transparent() && !surface.is_transparent())
81-
return;
82-
83-
// rubber stain, multiply the lit ground, glass overwrite is the wrong operator
79+
// rubber stain, multiply the lit ground from the opaque blit, glass overwrite is the wrong operator
8480
if (pass_is_transparent() && surface.is_skid_mark())
8581
{
86-
float coverage = saturate(surface.alpha);
87-
float3 dest = tex_uav[thread_id.xy].rgb;
88-
float3 stain = dest * lerp(float3(1.0f, 1.0f, 1.0f), surface.albedo, coverage);
82+
float mask = saturate(surface.alpha);
83+
float3 dest = tex[thread_id.xy].rgb;
84+
float3 stain = dest * lerp(float3(1.0f, 1.0f, 1.0f), surface.albedo, mask);
8985
tex_uav[thread_id.xy] = validate_output(float4(stain, 1.0f));
9086
return;
9187
}
9288

89+
// skip non transparent pixels during the transparent pass, the opaque pass already wrote them
90+
if (pass_is_transparent() && !surface.is_transparent())
91+
return;
92+
9393
float3 light_diffuse = 0.0f;
9494
float3 light_specular = 0.0f;
9595
float3 light_emissive = 0.0f;

data/shaders/reflections_apply.hlsl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ void main_cs(uint3 thread_id : SV_DispatchThreadID)
245245
float4 sample_material = tex_material.SampleLevel(samplers[sampler_point_clamp], uv, 0);
246246
MaterialParameters mat = material_parameters[uint(sample_normal.a)];
247247
bool is_water_pixel = (mat.flags & uint(1U << 13)) != 0;
248-
bool is_skid_pixel = (mat.flags & uint(1U << 20)) != 0;
248+
bool is_skid_pixel = (mat.flags & uint(1U << 20)) != 0
249+
|| tex_velocity.SampleLevel(samplers[sampler_point_clamp], uv, 0).a > 0.5f;
249250
bool is_glass_pixel = alpha > 0.0f && alpha < 1.0f && !is_skid_pixel;
250251

251252
// stain already multiplied into the frame, skip glass refraction and extra specular

data/shaders/skid_marks.hlsl

Lines changed: 0 additions & 85 deletions
This file was deleted.

source/rendering/Material.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,12 @@ namespace spartan
603603
if (texture_color && !texture_color->IsCompressedFormat())
604604
{
605605
texture_color->SetFlag(RHI_Texture_Compress);
606-
texture_color->SetCompressionFormat(texture_color->IsSemiTransparent() ? RHI_Format::BC3_Unorm : RHI_Format::BC1_Unorm);
606+
const bool has_alpha = texture_color->HasAlphaPixels();
607+
texture_color->SetCompressionFormat(has_alpha ? RHI_Format::BC3_Unorm : RHI_Format::BC1_Unorm);
608+
if (has_alpha)
609+
{
610+
texture_color->SetFlag(RHI_Texture_Transparent, true);
611+
}
607612
}
608613

609614
if (texture_normal && !texture_normal->IsCompressedFormat())
@@ -1363,6 +1368,12 @@ namespace spartan
13631368
bool Material::IsAlphaTested()
13641369
{
13651370
// hot path for draw sort and shadow passes, read slots directly
1371+
// skids keep texture alpha for a multiply mask, clipping would punch holes in the ribbon
1372+
if (GetProperty(MaterialProperty::IsSkidMark) != 0.0f)
1373+
{
1374+
return false;
1375+
}
1376+
13661377
RHI_Texture* color = m_textures[static_cast<uint32_t>(MaterialTextureType::Color) * slots_per_texture];
13671378
const bool albedo_mask = color && color->IsSemiTransparent();
13681379
return HasTextureOfType(MaterialTextureType::AlphaMask) || albedo_mask;

source/rendering/Renderer.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3239,13 +3239,10 @@ namespace spartan
32393239
continue;
32403240
}
32413241

3242-
const bool is_skid_mark = material->GetProperty(MaterialProperty::IsSkidMark) != 0.0f;
3243-
const bool skip_deferred = render->HasFlag(RenderFlags::SkipDeferred) || is_skid_mark;
3244-
32453242
// off-screen geometry is only kept when classic shadow maps need the caster
32463243
if (!render->IsVisible())
32473244
{
3248-
if (material->IsTransparent() && !skip_deferred)
3245+
if (material->IsTransparent())
32493246
{
32503247
m_transparents_present = true;
32513248
}
@@ -3259,7 +3256,7 @@ namespace spartan
32593256
}
32603257
}
32613258

3262-
if (material->IsTransparent() && !skip_deferred)
3259+
if (material->IsTransparent())
32633260
{
32643261
m_transparents_present = true;
32653262
}
@@ -3358,7 +3355,7 @@ namespace spartan
33583355
Render* render = dc.render;
33593356
Material* material = render->GetMaterial();
33603357

3361-
if (!material || material->IsTransparent() || render->HasFlag(RenderFlags::SkipDeferred))
3358+
if (!material || material->IsTransparent())
33623359
{
33633360
continue;
33643361
}
@@ -4619,7 +4616,6 @@ namespace spartan
46194616
Pass_Reflections_Denoise(eye_layer);
46204617

46214618
Pass_Reflections_Apply(eye_layer);
4622-
Pass_SkidMarks(eye_layer);
46234619
Pass_LightFlares(eye_layer);
46244620
if (clouds_prepared)
46254621
{

source/rendering/Renderer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,6 @@ namespace spartan
363363
void Pass_GBuffer(const bool is_transparent_pass);
364364
void Pass_GBuffer_Indirect();
365365
void Pass_GBuffer_TessellatedAndTransparent(const bool is_transparent_pass);
366-
bool Pass_SkidMarks(uint32_t eye_layer = rhi_all_mips);
367366
void Pass_MeshletVisualize();
368367
void Pass_ScreenSpaceAmbientOcclusion();
369368
void Pass_Reflections_Trace(uint32_t eye_layer = rhi_all_mips);

source/rendering/Renderer_Definitions.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,6 @@ namespace spartan
365365
outline_v,
366366
outline_p,
367367
outline_c,
368-
skid_marks_v,
369-
skid_marks_p,
370368
font_v,
371369
font_p,
372370
ssao_c,

source/rendering/Renderer_Passes_Geometry.cpp

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,10 +1024,6 @@ namespace spartan
10241024
}
10251025

10261026
const bool is_tessellated = material->GetProperty(MaterialProperty::Tessellation) > 0.0f;
1027-
if (render->HasFlag(RenderFlags::SkipDeferred) || material->GetProperty(MaterialProperty::IsSkidMark) != 0.0f)
1028-
{
1029-
continue;
1030-
}
10311027
if (is_transparent_pass)
10321028
{
10331029
if (!material->IsTransparent())
@@ -1081,99 +1077,6 @@ namespace spartan
10811077
RHI_CommandList::EndTimeblock();
10821078
}
10831079

1084-
bool Renderer::Pass_SkidMarks(uint32_t eye_layer)
1085-
{
1086-
(void)eye_layer;
1087-
1088-
RHI_Shader* shader_v = GetShader(Renderer_Shader::skid_marks_v);
1089-
RHI_Shader* shader_p = GetShader(Renderer_Shader::skid_marks_p);
1090-
if (!shader_v || !shader_p || !shader_v->IsCompiled() || !shader_p->IsCompiled())
1091-
{
1092-
return false;
1093-
}
1094-
1095-
RHI_Texture* tex_out = GetRenderTarget(Renderer_RenderTarget::frame_render);
1096-
RHI_Texture* tex_lit = GetRenderTarget(Renderer_RenderTarget::frame_render_opaque);
1097-
RHI_Texture* tex_depth = GetRenderTarget(Renderer_RenderTarget::gbuffer_depth);
1098-
if (!tex_out || !tex_lit || !tex_depth)
1099-
{
1100-
return false;
1101-
}
1102-
1103-
bool has_skid = false;
1104-
for (uint32_t i = 0; i < m_draw_call_count; i++)
1105-
{
1106-
Render* render = m_draw_calls[i].render;
1107-
if (render && render->HasFlag(RenderFlags::SkipDeferred) && m_draw_calls[i].camera_visible)
1108-
{
1109-
has_skid = true;
1110-
break;
1111-
}
1112-
}
1113-
if (!has_skid)
1114-
{
1115-
return false;
1116-
}
1117-
1118-
RHI_CommandList::Blit(tex_out, tex_lit, false);
1119-
1120-
RHI_PipelineState pso;
1121-
pso.name = "skid_marks";
1122-
pso.shaders[RHI_Shader_Type::Vertex] = shader_v;
1123-
pso.shaders[RHI_Shader_Type::Pixel] = shader_p;
1124-
pso.blend_state = GetBlendState(Renderer_BlendState::Off);
1125-
pso.rasterizer_state = GetRasterizerState(Renderer_RasterizerState::Solid);
1126-
pso.primitive_topology = RHI_PrimitiveTopology::TriangleList;
1127-
pso.depth_stencil_state = GetDepthStencilState(Renderer_DepthStencilState::ReadGreaterEqual);
1128-
pso.resolution_scale = true;
1129-
pso.render_target_color_textures[0] = tex_out;
1130-
pso.render_target_depth_texture = tex_depth;
1131-
pso.clear_color[0] = rhi_color_load;
1132-
pso.cull_mode = RHI_CullMode::None;
1133-
1134-
RHI_CommandList::BeginTimeblock("skid_marks");
1135-
RHI_CommandList::SetPipelineState(pso);
1136-
RHI_CommandList::SetCullMode(RHI_CullMode::None);
1137-
RHI_CommandList::SetTexture(static_cast<uint32_t>(Renderer_BindingsSrv::tex), tex_lit);
1138-
1139-
RHI_Buffer* instance_buffer = GeometryBuffer::GetInstanceBuffer()
1140-
? GeometryBuffer::GetInstanceBuffer()
1141-
: GetBuffer(Renderer_Buffer::DummyInstance);
1142-
1143-
for (uint32_t i = 0; i < m_draw_call_count; i++)
1144-
{
1145-
const Renderer_DrawCall& draw_call = m_draw_calls[i];
1146-
Render* render = draw_call.render;
1147-
if (!render || !draw_call.camera_visible || !render->HasFlag(RenderFlags::SkipDeferred))
1148-
{
1149-
continue;
1150-
}
1151-
1152-
Material* material = render->GetMaterial();
1153-
if (!material)
1154-
{
1155-
continue;
1156-
}
1157-
1158-
m_pcb_pass_cpu.draw_index = draw_call.draw_data_index;
1159-
m_pcb_pass_cpu.material_index = material->GetIndex();
1160-
RHI_CommandList::PushConstants(m_pcb_pass_cpu);
1161-
1162-
RHI_CommandList::SetBufferVertex(render->GetVertexBuffer(), instance_buffer);
1163-
RHI_CommandList::SetBufferIndex(render->GetIndexBuffer());
1164-
RHI_CommandList::DrawIndexed(
1165-
render->GetIndexCount(draw_call.lod_index),
1166-
render->GetIndexOffset(draw_call.lod_index),
1167-
render->GetVertexOffset(draw_call.lod_index),
1168-
render->GetGlobalInstanceOffset() + draw_call.instance_index,
1169-
draw_call.instance_count
1170-
);
1171-
}
1172-
1173-
RHI_CommandList::EndTimeblock();
1174-
return true;
1175-
}
1176-
11771080
void Renderer::Pass_GBuffer(const bool is_transparent_pass)
11781081
{
11791082
RHI_CommandList::BeginTimeblock(is_transparent_pass ? "g_buffer_transparent" : "g_buffer");

0 commit comments

Comments
 (0)