diff options
author | Juan Linietsky <reduzio@gmail.com> | 2019-10-05 10:27:43 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2020-02-11 12:03:49 +0100 |
commit | 6ee2f5e6b6663f5a4987954d43bb6df6d1f62d2a (patch) | |
tree | bef9b4f01f535c8736874199b2fbd928e1000d73 /servers | |
parent | 6075c5f9bf6cf3362c51e0915555361d34954215 (diff) |
More GIProbe work and fixes
Diffstat (limited to 'servers')
-rw-r--r-- | servers/visual/rasterizer_rd/rasterizer_rd.cpp | 6 | ||||
-rw-r--r-- | servers/visual/rasterizer_rd/rasterizer_scene_forward_rd.cpp | 9 | ||||
-rw-r--r-- | servers/visual/rasterizer_rd/rasterizer_scene_rd.cpp | 30 | ||||
-rw-r--r-- | servers/visual/rasterizer_rd/rasterizer_scene_rd.h | 3 | ||||
-rw-r--r-- | servers/visual/rasterizer_rd/shaders/giprobe.glsl | 26 | ||||
-rw-r--r-- | servers/visual/rasterizer_rd/shaders/giprobe_debug.glsl | 5 | ||||
-rw-r--r-- | servers/visual/rasterizer_rd/shaders/scene_forward.glsl | 6 | ||||
-rw-r--r-- | servers/visual/rendering_device.h | 13 | ||||
-rw-r--r-- | servers/visual/visual_server_scene.cpp | 35 | ||||
-rw-r--r-- | servers/visual_server.h | 1 |
10 files changed, 98 insertions, 36 deletions
diff --git a/servers/visual/rasterizer_rd/rasterizer_rd.cpp b/servers/visual/rasterizer_rd/rasterizer_rd.cpp index fc38b90b88..89465b580c 100644 --- a/servers/visual/rasterizer_rd/rasterizer_rd.cpp +++ b/servers/visual/rasterizer_rd/rasterizer_rd.cpp @@ -84,12 +84,10 @@ void RasterizerRD::begin_frame(double frame_step) { void RasterizerRD::end_frame(bool p_swap_buffers) { - RD::get_singleton()->finalize_frame(); #ifndef _MSC_VER -#warning not swapping buffers likely not an option for now, find another way +#warning TODO: likely passa bool to swap buffers to avoid display? #endif - OS::get_singleton()->swap_buffers(); //probably should pass some bool to avoid display? - RD::get_singleton()->advance_frame(); //advance frame here, so any new call happens on new frame + RD::get_singleton()->swap_buffers(); //probably should pass some bool to avoid display? } void RasterizerRD::initialize() { diff --git a/servers/visual/rasterizer_rd/rasterizer_scene_forward_rd.cpp b/servers/visual/rasterizer_rd/rasterizer_scene_forward_rd.cpp index 502ac9196f..55974846f2 100644 --- a/servers/visual/rasterizer_rd/rasterizer_scene_forward_rd.cpp +++ b/servers/visual/rasterizer_rd/rasterizer_scene_forward_rd.cpp @@ -1899,7 +1899,7 @@ void RasterizerSceneForwardRD::_render_scene(RenderBufferData *p_buffer_data, co _fill_instances(render_list.elements, render_list.element_count); bool can_continue = true; //unless the middle buffers are needed - bool debug_giprobes = debug_draw == VS::VIEWPORT_DEBUG_DRAW_GI_PROBE_ALBEDO || debug_draw == VS::VIEWPORT_DEBUG_DRAW_GI_PROBE_LIGHTING; + bool debug_giprobes = debug_draw == VS::VIEWPORT_DEBUG_DRAW_GI_PROBE_ALBEDO || debug_draw == VS::VIEWPORT_DEBUG_DRAW_GI_PROBE_LIGHTING || debug_draw == VS::VIEWPORT_DEBUG_DRAW_GI_PROBE_EMISSION; bool using_separate_specular = false; bool depth_pre_pass = depth_framebuffer.is_valid(); @@ -1930,7 +1930,7 @@ void RasterizerSceneForwardRD::_render_scene(RenderBufferData *p_buffer_data, co CameraMatrix cm = (dc * p_cam_projection) * CameraMatrix(p_cam_transform.affine_inverse()); RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(opaque_framebuffer, RD::INITIAL_ACTION_CONTINUE, will_continue ? RD::FINAL_ACTION_CONTINUE : RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_CONTINUE, will_continue ? RD::FINAL_ACTION_CONTINUE : RD::FINAL_ACTION_READ); for (int i = 0; i < p_gi_probe_cull_count; i++) { - _debug_giprobe(p_gi_probe_cull_result[i], draw_list, opaque_framebuffer, cm, debug_draw == VS::VIEWPORT_DEBUG_DRAW_GI_PROBE_LIGHTING, 1.0); + _debug_giprobe(p_gi_probe_cull_result[i], draw_list, opaque_framebuffer, cm, debug_draw == VS::VIEWPORT_DEBUG_DRAW_GI_PROBE_LIGHTING, debug_draw == VS::VIEWPORT_DEBUG_DRAW_GI_PROBE_EMISSION, 1.0); } RD::get_singleton()->draw_list_end(); } @@ -2204,10 +2204,15 @@ void RasterizerSceneForwardRD::_update_render_base_uniform_set() { } else { u.ids.resize(slot_count); } + + print_line("updating slots, probe count: " + itos(slot_count)); for (int i = 0; i < slot_count; i++) { RID probe = gi_probe_get_slots()[i]; + if (probe.is_valid()) { + print_line("probe valid: " + itos(i)); + } if (gi_probe_is_anisotropic()) { if (probe.is_null()) { RID empty_tex = storage->texture_rd_get_default(RasterizerStorageRD::DEFAULT_RD_TEXTURE_3D_WHITE); diff --git a/servers/visual/rasterizer_rd/rasterizer_scene_rd.cpp b/servers/visual/rasterizer_rd/rasterizer_scene_rd.cpp index 1b7d5a8e47..f039bae766 100644 --- a/servers/visual/rasterizer_rd/rasterizer_scene_rd.cpp +++ b/servers/visual/rasterizer_rd/rasterizer_scene_rd.cpp @@ -1439,6 +1439,7 @@ void RasterizerSceneRD::gi_probe_update(RID p_probe, const Vector<RID> &p_light_ } gi_probe->last_probe_data_version = data_version; + gi_probe_slots_dirty = true; } // UDPDATE TIME @@ -1510,6 +1511,8 @@ void RasterizerSceneRD::gi_probe_update(RID p_probe, const Vector<RID> &p_light_ RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin(); int passes = storage->gi_probe_is_using_two_bounces(gi_probe->probe) ? 2 : 1; + int wg_size = 64; + int wg_limit_x = RD::get_singleton()->limit_get(RD::LIMIT_MAX_COMPUTE_WORKGROUP_COUNT_X); for (int pass = 0; pass < passes; pass++) { @@ -1532,9 +1535,14 @@ void RasterizerSceneRD::gi_probe_update(RID p_probe, const Vector<RID> &p_light_ push_constant.cell_offset = gi_probe->mipmaps[i].cell_offset; push_constant.cell_count = gi_probe->mipmaps[i].cell_count; - RD::get_singleton()->compute_list_set_push_constant(compute_list, &push_constant, sizeof(GIProbePushConstant)); - - RD::get_singleton()->compute_list_dispatch(compute_list, (gi_probe->mipmaps[i].cell_count - 1) / 64 + 1, 1, 1); + int wg_todo = (gi_probe->mipmaps[i].cell_count - 1) / wg_size + 1; + while (wg_todo) { + int wg_count = MIN(wg_todo, wg_limit_x); + RD::get_singleton()->compute_list_set_push_constant(compute_list, &push_constant, sizeof(GIProbePushConstant)); + RD::get_singleton()->compute_list_dispatch(compute_list, wg_count, 1, 1); + wg_todo -= wg_count; + push_constant.cell_offset += wg_count * wg_size; + } } RD::get_singleton()->compute_list_add_barrier(compute_list); //wait til previous step is done @@ -1548,9 +1556,14 @@ void RasterizerSceneRD::gi_probe_update(RID p_probe, const Vector<RID> &p_light_ push_constant.cell_offset = gi_probe->mipmaps[i].cell_offset; push_constant.cell_count = gi_probe->mipmaps[i].cell_count; - RD::get_singleton()->compute_list_set_push_constant(compute_list, &push_constant, sizeof(GIProbePushConstant)); - - RD::get_singleton()->compute_list_dispatch(compute_list, (gi_probe->mipmaps[i].cell_count - 1) / 64 + 1, 1, 1); + int wg_todo = (gi_probe->mipmaps[i].cell_count - 1) / wg_size + 1; + while (wg_todo) { + int wg_count = MIN(wg_todo, wg_limit_x); + RD::get_singleton()->compute_list_set_push_constant(compute_list, &push_constant, sizeof(GIProbePushConstant)); + RD::get_singleton()->compute_list_dispatch(compute_list, wg_count, 1, 1); + wg_todo -= wg_count; + push_constant.cell_offset += wg_count * wg_size; + } } } @@ -1560,7 +1573,7 @@ void RasterizerSceneRD::gi_probe_update(RID p_probe, const Vector<RID> &p_light_ gi_probe->last_probe_version = storage->gi_probe_get_version(gi_probe->probe); } -void RasterizerSceneRD::_debug_giprobe(RID p_gi_probe, RD::DrawListID p_draw_list, RID p_framebuffer, const CameraMatrix &p_camera_with_transform, bool p_lighting, float p_alpha) { +void RasterizerSceneRD::_debug_giprobe(RID p_gi_probe, RD::DrawListID p_draw_list, RID p_framebuffer, const CameraMatrix &p_camera_with_transform, bool p_lighting, bool p_emission, float p_alpha) { GIProbeInstance *gi_probe = gi_probe_instance_owner.getornull(p_gi_probe); ERR_FAIL_COND(!gi_probe); @@ -1631,7 +1644,7 @@ void RasterizerSceneRD::_debug_giprobe(RID p_gi_probe, RD::DrawListID p_draw_lis } giprobe_debug_uniform_set = RD::get_singleton()->uniform_set_create(uniforms, giprobe_debug_shader_version_shaders[0], 0); - RD::get_singleton()->draw_list_bind_render_pipeline(p_draw_list, giprobe_debug_shader_version_pipelines[p_lighting ? GI_PROBE_DEBUG_LIGHT : GI_PROBE_DEBUG_COLOR].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_framebuffer))); + RD::get_singleton()->draw_list_bind_render_pipeline(p_draw_list, giprobe_debug_shader_version_pipelines[p_emission ? GI_PROBE_DEBUG_EMISSION : p_lighting ? GI_PROBE_DEBUG_LIGHT : GI_PROBE_DEBUG_COLOR].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_framebuffer))); RD::get_singleton()->draw_list_bind_uniform_set(p_draw_list, giprobe_debug_uniform_set, 0); RD::get_singleton()->draw_list_set_push_constant(p_draw_list, &push_constant, sizeof(GIProbeDebugPushConstant)); RD::get_singleton()->draw_list_draw(p_draw_list, false, cell_count, 36); @@ -2007,6 +2020,7 @@ RasterizerSceneRD::RasterizerSceneRD(RasterizerStorageRD *p_storage) { Vector<String> versions; versions.push_back("\n#define MODE_DEBUG_COLOR\n"); versions.push_back("\n#define MODE_DEBUG_LIGHT\n"); + versions.push_back("\n#define MODE_DEBUG_EMISSION\n"); giprobe_debug_shader.initialize(versions, defines); giprobe_debug_shader_version = giprobe_debug_shader.version_create(); diff --git a/servers/visual/rasterizer_rd/rasterizer_scene_rd.h b/servers/visual/rasterizer_rd/rasterizer_scene_rd.h index 7acb66c587..d05c9a9328 100644 --- a/servers/visual/rasterizer_rd/rasterizer_scene_rd.h +++ b/servers/visual/rasterizer_rd/rasterizer_scene_rd.h @@ -27,7 +27,7 @@ protected: virtual void _render_scene(RenderBufferData *p_buffer_data, const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID *p_light_cull_result, int p_light_cull_count, RID *p_reflection_probe_cull_result, int p_reflection_probe_cull_count, RID *p_gi_probe_cull_result, int p_gi_probe_cull_count, RID p_environment, RID p_shadow_atlas, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass) = 0; virtual void _render_shadow(RID p_framebuffer, InstanceBase **p_cull_result, int p_cull_count, const CameraMatrix &p_projection, const Transform &p_transform, float p_zfar, float p_bias, float p_normal_bias, bool p_use_dp, bool use_dp_flip) = 0; - virtual void _debug_giprobe(RID p_gi_probe, RenderingDevice::DrawListID p_draw_list, RID p_framebuffer, const CameraMatrix &p_camera_with_transform, bool p_lighting, float p_alpha); + virtual void _debug_giprobe(RID p_gi_probe, RenderingDevice::DrawListID p_draw_list, RID p_framebuffer, const CameraMatrix &p_camera_with_transform, bool p_lighting, bool p_emission, float p_alpha); private: int roughness_layers; @@ -210,6 +210,7 @@ private: enum { GI_PROBE_DEBUG_COLOR, GI_PROBE_DEBUG_LIGHT, + GI_PROBE_DEBUG_EMISSION, GI_PROBE_DEBUG_MAX }; diff --git a/servers/visual/rasterizer_rd/shaders/giprobe.glsl b/servers/visual/rasterizer_rd/shaders/giprobe.glsl index 35b8d6ba6b..a723490e8b 100644 --- a/servers/visual/rasterizer_rd/shaders/giprobe.glsl +++ b/servers/visual/rasterizer_rd/shaders/giprobe.glsl @@ -248,7 +248,7 @@ void main() { vec3 pos = vec3(posu) + vec3(0.5); - vec3 emission = vec3(ivec3(cell_data.data[cell_index].emission&0x3FF,(cell_data.data[cell_index].emission>>10)&0x7FF,cell_data.data[cell_index].emission>>21)) * params.emission_scale; + vec3 emission = vec3(uvec3(cell_data.data[cell_index].emission & 0x1ff,(cell_data.data[cell_index].emission >> 9) & 0x1ff,(cell_data.data[cell_index].emission >> 18) & 0x1ff)) * pow(2.0, float(cell_data.data[cell_index].emission >> 27) - 15.0 - 9.0); vec4 normal = unpackSnorm4x8(cell_data.data[cell_index].normal); #ifdef MODE_ANISOTROPIC @@ -271,8 +271,8 @@ void main() { float distance = length(light_dir); light_dir=normalize(light_dir); - if (length(normal.xyz) > 0.2 && dot(normal.xyz,light_dir)>=0) { - continue; //not facing the light + if (attenuation < 0.01 || (length(normal.xyz) > 0.2 && dot(normal.xyz,light_dir)>=0)) { + continue; //not facing the light, or attenuation is near zero } if (lights.data[i].has_shadow) { @@ -299,11 +299,11 @@ void main() { #ifdef MODE_ANISOTROPIC for(uint j=0;j<6;j++) { - accum[j]+=max(0.0,dot(accum_dirs[j],-light_dir))*light+emission; + accum[j]+=max(0.0,dot(accum_dirs[j],-light_dir))*light; } #else if (length(normal.xyz) > 0.2) { - accum+=max(0.0,dot(normal.xyz,-light_dir))*light+emission; + accum+=max(0.0,dot(normal.xyz,-light_dir))*light; } else { //all directions accum+=light+emission; @@ -314,14 +314,14 @@ void main() { #ifdef MODE_ANISOTROPIC - outputs.data[cell_index*6+0]=vec4(accum[0],0.0); - outputs.data[cell_index*6+1]=vec4(accum[1],0.0); - outputs.data[cell_index*6+2]=vec4(accum[2],0.0); - outputs.data[cell_index*6+3]=vec4(accum[3],0.0); - outputs.data[cell_index*6+4]=vec4(accum[4],0.0); - outputs.data[cell_index*6+5]=vec4(accum[5],0.0); + outputs.data[cell_index*6+0]=vec4(accum[0] + emission,0.0); + outputs.data[cell_index*6+1]=vec4(accum[1] + emission,0.0); + outputs.data[cell_index*6+2]=vec4(accum[2] + emission,0.0); + outputs.data[cell_index*6+3]=vec4(accum[3] + emission,0.0); + outputs.data[cell_index*6+4]=vec4(accum[4] + emission,0.0); + outputs.data[cell_index*6+5]=vec4(accum[5] + emission,0.0); #else - outputs.data[cell_index]=vec4(accum,0.0); + outputs.data[cell_index]=vec4(accum + emission,0.0); #endif @@ -420,7 +420,7 @@ void main() { } } - color *= cone_weights[i] * params.dynamic_range; //restore range + color *= cone_weights[i] * vec4(albedo.rgb,1.0) * params.dynamic_range; //restore range #ifdef MODE_ANISOTROPIC for(uint j=0;j<6;j++) { diff --git a/servers/visual/rasterizer_rd/shaders/giprobe_debug.glsl b/servers/visual/rasterizer_rd/shaders/giprobe_debug.glsl index deaeb771b9..71ecaffde7 100644 --- a/servers/visual/rasterizer_rd/shaders/giprobe_debug.glsl +++ b/servers/visual/rasterizer_rd/shaders/giprobe_debug.glsl @@ -85,9 +85,14 @@ void main() { uvec3 posu = uvec3(cell_data.data[cell_index].position&0x7FF,(cell_data.data[cell_index].position>>11)&0x3FF,cell_data.data[cell_index].position>>21); +#ifdef MODE_DEBUG_EMISSION + color_interp.xyz = vec3(uvec3(cell_data.data[cell_index].emission & 0x1ff,(cell_data.data[cell_index].emission >> 9) & 0x1ff,(cell_data.data[cell_index].emission >> 18) & 0x1ff)) * pow(2.0, float(cell_data.data[cell_index].emission >> 27) - 15.0 - 9.0); +#endif + #ifdef MODE_DEBUG_COLOR color_interp.xyz = unpackUnorm4x8(cell_data.data[cell_index].albedo).xyz; #endif + #ifdef MODE_DEBUG_LIGHT #ifdef USE_ANISOTROPY diff --git a/servers/visual/rasterizer_rd/shaders/scene_forward.glsl b/servers/visual/rasterizer_rd/shaders/scene_forward.glsl index 2070df3952..a54a84536a 100644 --- a/servers/visual/rasterizer_rd/shaders/scene_forward.glsl +++ b/servers/visual/rasterizer_rd/shaders/scene_forward.glsl @@ -326,9 +326,9 @@ layout(location =8) in float dp_clip; //defines to keep compatibility with vertex -#define world_matrix instances.data[instance_index].transform; -#define world_normal_matrix instances.data[instance_index].normal_transform; -#define projection_matrix scene_data.projection_matrix; +#define world_matrix instances.data[instance_index].transform +#define world_normal_matrix instances.data[instance_index].normal_transform +#define projection_matrix scene_data.projection_matrix #ifdef USE_MATERIAL_UNIFORMS layout(set = 3, binding = 0, std140) uniform MaterialUniforms { diff --git a/servers/visual/rendering_device.h b/servers/visual/rendering_device.h index f5a212b076..75eaab796a 100644 --- a/servers/visual/rendering_device.h +++ b/servers/visual/rendering_device.h @@ -1002,14 +1002,23 @@ public: LIMIT_MAX_VERTEX_INPUT_BINDINGS, LIMIT_MAX_VERTEX_INPUT_BINDING_STRIDE, LIMIT_MIN_UNIFORM_BUFFER_OFFSET_ALIGNMENT, + LIMIT_MAX_COMPUTE_SHARED_MEMORY_SIZE, + LIMIT_MAX_COMPUTE_WORKGROUP_COUNT_X, + LIMIT_MAX_COMPUTE_WORKGROUP_COUNT_Y, + LIMIT_MAX_COMPUTE_WORKGROUP_COUNT_Z, + LIMIT_MAX_COMPUTE_WORKGROUP_INVOCATIONS, + LIMIT_MAX_COMPUTE_WORKGROUP_SIZE_X, + LIMIT_MAX_COMPUTE_WORKGROUP_SIZE_Y, + LIMIT_MAX_COMPUTE_WORKGROUP_SIZE_Z, }; virtual int limit_get(Limit p_limit) = 0; //methods below not exposed, used by RenderingDeviceRD virtual void prepare_screen_for_drawing() = 0; - virtual void finalize_frame() = 0; - virtual void advance_frame() = 0; + + virtual void swap_buffers() = 0; + virtual uint32_t get_frame_delay() const = 0; static RenderingDevice *get_singleton(); diff --git a/servers/visual/visual_server_scene.cpp b/servers/visual/visual_server_scene.cpp index f7b118bfe5..8d38cf02b3 100644 --- a/servers/visual/visual_server_scene.cpp +++ b/servers/visual/visual_server_scene.cpp @@ -345,7 +345,11 @@ void VisualServerScene::instance_set_base(RID p_instance, RID p_base) { case VS::INSTANCE_LIGHT: { InstanceLightData *light = static_cast<InstanceLightData *>(instance->base_data); - +#ifdef DEBUG_ENABLED + if (light->geometries.size()) { + ERR_PRINT("BUG, indexing did not unpair geometries from light."); + } +#endif if (instance->scenario && light->D) { instance->scenario->directional_lights.erase(light->D); light->D = NULL; @@ -371,7 +375,16 @@ void VisualServerScene::instance_set_base(RID p_instance, RID p_base) { case VS::INSTANCE_GI_PROBE: { InstanceGIProbeData *gi_probe = static_cast<InstanceGIProbeData *>(instance->base_data); - +#ifdef DEBUG_ENABLED + if (gi_probe->geometries.size()) { + ERR_PRINT("BUG, indexing did not unpair geometries from GIProbe."); + } +#endif +#ifdef DEBUG_ENABLED + if (gi_probe->lights.size()) { + ERR_PRINT("BUG, indexing did not unpair lights from GIProbe."); + } +#endif if (gi_probe->update_element.in_list()) { gi_probe_update_list.remove(&gi_probe->update_element); } @@ -490,7 +503,11 @@ void VisualServerScene::instance_set_scenario(RID p_instance, RID p_scenario) { case VS::INSTANCE_LIGHT: { InstanceLightData *light = static_cast<InstanceLightData *>(instance->base_data); - +#ifdef DEBUG_ENABLED + if (light->geometries.size()) { + ERR_PRINT("BUG, indexing did not unpair geometries from light."); + } +#endif if (light->D) { instance->scenario->directional_lights.erase(light->D); light->D = NULL; @@ -504,6 +521,18 @@ void VisualServerScene::instance_set_scenario(RID p_instance, RID p_scenario) { case VS::INSTANCE_GI_PROBE: { InstanceGIProbeData *gi_probe = static_cast<InstanceGIProbeData *>(instance->base_data); + +#ifdef DEBUG_ENABLED + if (gi_probe->geometries.size()) { + ERR_PRINT("BUG, indexing did not unpair geometries from GIProbe."); + } +#endif +#ifdef DEBUG_ENABLED + if (gi_probe->lights.size()) { + ERR_PRINT("BUG, indexing did not unpair lights from GIProbe."); + } +#endif + if (gi_probe->update_element.in_list()) { gi_probe_update_list.remove(&gi_probe->update_element); } diff --git a/servers/visual_server.h b/servers/visual_server.h index 5408ad665b..3523afc305 100644 --- a/servers/visual_server.h +++ b/servers/visual_server.h @@ -652,6 +652,7 @@ public: VIEWPORT_DEBUG_DRAW_WIREFRAME, VIEWPORT_DEBUG_DRAW_GI_PROBE_ALBEDO, VIEWPORT_DEBUG_DRAW_GI_PROBE_LIGHTING, + VIEWPORT_DEBUG_DRAW_GI_PROBE_EMISSION, VIEWPORT_DEBUG_DRAW_SHADOW_ATLAS, VIEWPORT_DEBUG_DRAW_DIRECTIONAL_SHADOW_ATLAS, |