### Godot version

4.0.2

### System information

Windows 10

### Issue description

I have a meshinstance3d with a shader attached, and this is inside a subviewport. ( I instanced a bunch to make the memory rise faster, for testing purposes ).
The shader uses render_mode wireframe.
Whenever the object is onscreen, the memory will increase continuously! If the object goes offscreen, it will stop.
If I remove render_mode wireframe from the shader, the memory won't increase.
If I set debug_mode to wireframe on the subviewport, the memory won't increase.

Edit: I originally thought a subviewport was required, but it isn't. It happens even when there are no subviewports being used!


### Steps to reproduce

Open the attached project, and run the test.tscn
Watch as your memory continues to go up.
It stops if you either remove render_mode wireframe from the shader, or if you set the subviewport debug_mode to wireframe.
It also stops if the object isn't onscreen.

### Minimal reproduction project

[subViewportWireframeBug.zip](https://github.com/godotengine/godot/files/11267138/subViewportWireframeBug.zip)

RD::PipelineMultisampleState multisample_state_version = multisample_state;
	multisample_state_version.sample_count = RD::get_singleton()->framebuffer_format_get_texture_samples(p_framebuffer_format_id, p_render_pass);
	bool wireframe = p_wireframe || rasterization_state.wireframe;
	RD::PipelineRasterizationState raster_state_version = rasterization_state;
	raster_state_version.wireframe = wireframe;
	Vector<RD::PipelineSpecializationConstant> specialization_constants = base_specialization_constants;
	uint32_t bool_index = 0;
	uint32_t bool_specializations = p_bool_specializations;
	while (bool_specializations) {
		if (bool_specializations & (1 << bool_index)) {
			RD::PipelineSpecializationConstant sc;
			sc.bool_value = true;
			sc.constant_id = bool_index;
			sc.type = RD::PIPELINE_SPECIALIZATION_CONSTANT_TYPE_BOOL;
			specialization_constants.push_back(sc);
			bool_specializations &= ~(1 << bool_index);
		}
		bool_index++;
	}
	RID pipeline = RD::get_singleton()->render_pipeline_create(shader, p_framebuffer_format_id, p_vertex_format_id, render_primitive, raster_state_version, multisample_state_version, depth_stencil_state, blend_state, dynamic_state_flags, p_render_pass, specialization_constants);
	ERR_FAIL_COND_V(pipeline.is_null(), RID());
	versions = static_cast<Version *>(memrealloc(versions, sizeof(Version) * (version_count + 1)));
	versions[version_count].framebuffer_id = p_framebuffer_format_id;
	versions[version_count].vertex_id = p_vertex_format_id;
	versions[version_count].wireframe = wireframe;
	versions[version_count].pipeline = pipeline;
	versions[version_count].render_pass = p_render_pass;
	versions[version_count].bool_specializations = p_bool_specializations;
	version_count++;