Fix issue with default textures requiring arrays when using multiview
This commit is contained in:
parent
e13fae1414
commit
467d735eb1
|
@ -2865,10 +2865,13 @@ RID RenderForwardClustered::_setup_render_pass_uniform_set(RenderListType p_rend
|
|||
RendererRD::TextureStorage *texture_storage = RendererRD::TextureStorage::get_singleton();
|
||||
RendererRD::LightStorage *light_storage = RendererRD::LightStorage::get_singleton();
|
||||
|
||||
bool is_multiview = false;
|
||||
|
||||
Ref<RenderSceneBuffersRD> rb; // handy for not having to fully type out p_render_data->render_buffers all the time...
|
||||
Ref<RenderBufferDataForwardClustered> rb_data;
|
||||
if (p_render_data && p_render_data->render_buffers.is_valid()) {
|
||||
rb = p_render_data->render_buffers;
|
||||
is_multiview = rb->get_view_count() > 1;
|
||||
if (rb->has_custom_data(RB_SCOPE_FORWARD_CLUSTERED)) {
|
||||
// Our forward clustered custom data buffer will only be available when we're rendering our normal view.
|
||||
// This will not be available when rendering reflection probes.
|
||||
|
@ -3011,7 +3014,7 @@ RID RenderForwardClustered::_setup_render_pass_uniform_set(RenderListType p_rend
|
|||
if (rb.is_valid() && rb->has_texture(RB_SCOPE_BUFFERS, RB_TEX_BACK_DEPTH)) {
|
||||
texture = rb->get_texture(RB_SCOPE_BUFFERS, RB_TEX_BACK_DEPTH);
|
||||
} else {
|
||||
texture = texture_storage->texture_rd_get_default(RendererRD::TextureStorage::DEFAULT_RD_TEXTURE_DEPTH);
|
||||
texture = texture_storage->texture_rd_get_default(is_multiview ? RendererRD::TextureStorage::DEFAULT_RD_TEXTURE_2D_ARRAY_DEPTH : RendererRD::TextureStorage::DEFAULT_RD_TEXTURE_DEPTH);
|
||||
}
|
||||
u.append_id(texture);
|
||||
uniforms.push_back(u);
|
||||
|
@ -3021,7 +3024,7 @@ RID RenderForwardClustered::_setup_render_pass_uniform_set(RenderListType p_rend
|
|||
u.binding = 11;
|
||||
u.uniform_type = RD::UNIFORM_TYPE_TEXTURE;
|
||||
RID bbt = rb_data.is_valid() ? rb->get_back_buffer_texture() : RID();
|
||||
RID texture = bbt.is_valid() ? bbt : texture_storage->texture_rd_get_default(RendererRD::TextureStorage::DEFAULT_RD_TEXTURE_BLACK);
|
||||
RID texture = bbt.is_valid() ? bbt : texture_storage->texture_rd_get_default(is_multiview ? RendererRD::TextureStorage::DEFAULT_RD_TEXTURE_2D_ARRAY_BLACK : RendererRD::TextureStorage::DEFAULT_RD_TEXTURE_BLACK);
|
||||
u.append_id(texture);
|
||||
uniforms.push_back(u);
|
||||
}
|
||||
|
@ -3030,7 +3033,7 @@ RID RenderForwardClustered::_setup_render_pass_uniform_set(RenderListType p_rend
|
|||
RD::Uniform u;
|
||||
u.binding = 12;
|
||||
u.uniform_type = RD::UNIFORM_TYPE_TEXTURE;
|
||||
RID texture = rb_data.is_valid() && rb_data->has_normal_roughness() ? rb_data->get_normal_roughness() : texture_storage->texture_rd_get_default(RendererRD::TextureStorage::DEFAULT_RD_TEXTURE_NORMAL);
|
||||
RID texture = rb_data.is_valid() && rb_data->has_normal_roughness() ? rb_data->get_normal_roughness() : texture_storage->texture_rd_get_default(is_multiview ? RendererRD::TextureStorage::DEFAULT_RD_TEXTURE_2D_ARRAY_NORMAL : RendererRD::TextureStorage::DEFAULT_RD_TEXTURE_NORMAL);
|
||||
u.append_id(texture);
|
||||
uniforms.push_back(u);
|
||||
}
|
||||
|
@ -3040,7 +3043,7 @@ RID RenderForwardClustered::_setup_render_pass_uniform_set(RenderListType p_rend
|
|||
u.binding = 13;
|
||||
u.uniform_type = RD::UNIFORM_TYPE_TEXTURE;
|
||||
RID aot = rb.is_valid() && rb->has_texture(RB_SCOPE_SSAO, RB_FINAL) ? rb->get_texture(RB_SCOPE_SSAO, RB_FINAL) : RID();
|
||||
RID texture = aot.is_valid() ? aot : texture_storage->texture_rd_get_default(RendererRD::TextureStorage::DEFAULT_RD_TEXTURE_BLACK);
|
||||
RID texture = aot.is_valid() ? aot : texture_storage->texture_rd_get_default(is_multiview ? RendererRD::TextureStorage::DEFAULT_RD_TEXTURE_2D_ARRAY_BLACK : RendererRD::TextureStorage::DEFAULT_RD_TEXTURE_BLACK);
|
||||
u.append_id(texture);
|
||||
uniforms.push_back(u);
|
||||
}
|
||||
|
@ -3049,7 +3052,7 @@ RID RenderForwardClustered::_setup_render_pass_uniform_set(RenderListType p_rend
|
|||
RD::Uniform u;
|
||||
u.binding = 14;
|
||||
u.uniform_type = RD::UNIFORM_TYPE_TEXTURE;
|
||||
RID texture = rb_data.is_valid() && rb->has_texture(RB_SCOPE_GI, RB_TEX_AMBIENT) ? rb->get_texture(RB_SCOPE_GI, RB_TEX_AMBIENT) : texture_storage->texture_rd_get_default(RendererRD::TextureStorage::DEFAULT_RD_TEXTURE_BLACK);
|
||||
RID texture = rb_data.is_valid() && rb->has_texture(RB_SCOPE_GI, RB_TEX_AMBIENT) ? rb->get_texture(RB_SCOPE_GI, RB_TEX_AMBIENT) : texture_storage->texture_rd_get_default(is_multiview ? RendererRD::TextureStorage::DEFAULT_RD_TEXTURE_2D_ARRAY_BLACK : RendererRD::TextureStorage::DEFAULT_RD_TEXTURE_BLACK);
|
||||
u.append_id(texture);
|
||||
uniforms.push_back(u);
|
||||
}
|
||||
|
@ -3058,7 +3061,7 @@ RID RenderForwardClustered::_setup_render_pass_uniform_set(RenderListType p_rend
|
|||
RD::Uniform u;
|
||||
u.binding = 15;
|
||||
u.uniform_type = RD::UNIFORM_TYPE_TEXTURE;
|
||||
RID texture = rb_data.is_valid() && rb->has_texture(RB_SCOPE_GI, RB_TEX_REFLECTION) ? rb->get_texture(RB_SCOPE_GI, RB_TEX_REFLECTION) : texture_storage->texture_rd_get_default(RendererRD::TextureStorage::DEFAULT_RD_TEXTURE_BLACK);
|
||||
RID texture = rb_data.is_valid() && rb->has_texture(RB_SCOPE_GI, RB_TEX_REFLECTION) ? rb->get_texture(RB_SCOPE_GI, RB_TEX_REFLECTION) : texture_storage->texture_rd_get_default(is_multiview ? RendererRD::TextureStorage::DEFAULT_RD_TEXTURE_2D_ARRAY_BLACK : RendererRD::TextureStorage::DEFAULT_RD_TEXTURE_BLACK);
|
||||
u.append_id(texture);
|
||||
uniforms.push_back(u);
|
||||
}
|
||||
|
@ -3126,7 +3129,7 @@ RID RenderForwardClustered::_setup_render_pass_uniform_set(RenderListType p_rend
|
|||
u.binding = 20;
|
||||
u.uniform_type = RD::UNIFORM_TYPE_TEXTURE;
|
||||
RID ssil = rb.is_valid() && rb->has_texture(RB_SCOPE_SSIL, RB_FINAL) ? rb->get_texture(RB_SCOPE_SSIL, RB_FINAL) : RID();
|
||||
RID texture = ssil.is_valid() ? ssil : texture_storage->texture_rd_get_default(RendererRD::TextureStorage::DEFAULT_RD_TEXTURE_BLACK);
|
||||
RID texture = ssil.is_valid() ? ssil : texture_storage->texture_rd_get_default(is_multiview ? RendererRD::TextureStorage::DEFAULT_RD_TEXTURE_2D_ARRAY_BLACK : RendererRD::TextureStorage::DEFAULT_RD_TEXTURE_BLACK);
|
||||
u.append_id(texture);
|
||||
uniforms.push_back(u);
|
||||
}
|
||||
|
|
|
@ -358,10 +358,13 @@ RID RenderForwardMobile::_setup_render_pass_uniform_set(RenderListType p_render_
|
|||
//there should always be enough uniform buffers for render passes, otherwise bugs
|
||||
ERR_FAIL_INDEX_V(p_index, (int)scene_state.uniform_buffers.size(), RID());
|
||||
|
||||
bool is_multiview = false;
|
||||
|
||||
Ref<RenderBufferDataForwardMobile> rb_data;
|
||||
Ref<RenderSceneBuffersRD> rb;
|
||||
if (p_render_data && p_render_data->render_buffers.is_valid()) {
|
||||
rb = p_render_data->render_buffers;
|
||||
is_multiview = rb->get_view_count() > 1;
|
||||
if (rb->has_custom_data(RB_SCOPE_MOBILE)) {
|
||||
// Our forward mobile custom data buffer will only be available when we're rendering our normal view.
|
||||
// This will not be available when rendering reflection probes.
|
||||
|
@ -495,6 +498,8 @@ RID RenderForwardMobile::_setup_render_pass_uniform_set(RenderListType p_render_
|
|||
RID texture;
|
||||
if (rb.is_valid() && rb->has_texture(RB_SCOPE_BUFFERS, RB_TEX_BACK_DEPTH)) {
|
||||
texture = rb->get_texture(RB_SCOPE_BUFFERS, RB_TEX_BACK_DEPTH);
|
||||
} else if (is_multiview) {
|
||||
texture = texture_storage->texture_rd_get_default(RendererRD::TextureStorage::DEFAULT_RD_TEXTURE_2D_ARRAY_DEPTH);
|
||||
} else {
|
||||
texture = texture_storage->texture_rd_get_default(RendererRD::TextureStorage::DEFAULT_RD_TEXTURE_DEPTH);
|
||||
}
|
||||
|
@ -505,8 +510,14 @@ RID RenderForwardMobile::_setup_render_pass_uniform_set(RenderListType p_render_
|
|||
RD::Uniform u;
|
||||
u.binding = 10;
|
||||
u.uniform_type = RD::UNIFORM_TYPE_TEXTURE;
|
||||
RID bbt = rb_data.is_valid() ? rb->get_back_buffer_texture() : RID();
|
||||
RID texture = bbt.is_valid() ? bbt : texture_storage->texture_rd_get_default(RendererRD::TextureStorage::DEFAULT_RD_TEXTURE_BLACK);
|
||||
RID texture = rb_data.is_valid() ? rb->get_back_buffer_texture() : RID();
|
||||
if (texture.is_null()) {
|
||||
if (is_multiview) {
|
||||
texture = texture_storage->texture_rd_get_default(RendererRD::TextureStorage::DEFAULT_RD_TEXTURE_2D_ARRAY_DEPTH);
|
||||
} else {
|
||||
texture = texture_storage->texture_rd_get_default(RendererRD::TextureStorage::DEFAULT_RD_TEXTURE_BLACK);
|
||||
}
|
||||
}
|
||||
u.append_id(texture);
|
||||
uniforms.push_back(u);
|
||||
}
|
||||
|
|
|
@ -486,6 +486,11 @@ Ref<RenderBufferCustomDataRD> RenderSceneBuffersRD::get_custom_data(const String
|
|||
// Depth texture
|
||||
|
||||
bool RenderSceneBuffersRD::has_depth_texture() {
|
||||
if (render_target.is_null()) {
|
||||
// not applicable when there is no render target (likely this is for a reflection probe)
|
||||
return false;
|
||||
}
|
||||
|
||||
RendererRD::TextureStorage *texture_storage = RendererRD::TextureStorage::get_singleton();
|
||||
RID depth = texture_storage->render_target_get_override_depth(render_target);
|
||||
if (depth.is_valid()) {
|
||||
|
@ -496,6 +501,11 @@ bool RenderSceneBuffersRD::has_depth_texture() {
|
|||
}
|
||||
|
||||
RID RenderSceneBuffersRD::get_depth_texture() {
|
||||
if (render_target.is_null()) {
|
||||
// not applicable when there is no render target (likely this is for a reflection probe)
|
||||
return RID();
|
||||
}
|
||||
|
||||
RendererRD::TextureStorage *texture_storage = RendererRD::TextureStorage::get_singleton();
|
||||
RID depth = texture_storage->render_target_get_override_depth(render_target);
|
||||
if (depth.is_valid()) {
|
||||
|
|
|
@ -362,7 +362,7 @@ TextureStorage::TextureStorage() {
|
|||
}
|
||||
}
|
||||
|
||||
{ //create default array
|
||||
{ //create default array white
|
||||
|
||||
RD::TextureFormat tformat;
|
||||
tformat.format = RD::DATA_FORMAT_R8G8B8A8_UNORM;
|
||||
|
@ -388,6 +388,82 @@ TextureStorage::TextureStorage() {
|
|||
}
|
||||
}
|
||||
|
||||
{ //create default array black
|
||||
|
||||
RD::TextureFormat tformat;
|
||||
tformat.format = RD::DATA_FORMAT_R8G8B8A8_UNORM;
|
||||
tformat.width = 4;
|
||||
tformat.height = 4;
|
||||
tformat.array_layers = 1;
|
||||
tformat.usage_bits = RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_CAN_UPDATE_BIT;
|
||||
tformat.texture_type = RD::TEXTURE_TYPE_2D_ARRAY;
|
||||
|
||||
Vector<uint8_t> pv;
|
||||
pv.resize(16 * 4);
|
||||
for (int i = 0; i < 16; i++) {
|
||||
pv.set(i * 4 + 0, 0);
|
||||
pv.set(i * 4 + 1, 0);
|
||||
pv.set(i * 4 + 2, 0);
|
||||
pv.set(i * 4 + 3, 0);
|
||||
}
|
||||
|
||||
{
|
||||
Vector<Vector<uint8_t>> vpv;
|
||||
vpv.push_back(pv);
|
||||
default_rd_textures[DEFAULT_RD_TEXTURE_2D_ARRAY_BLACK] = RD::get_singleton()->texture_create(tformat, RD::TextureView(), vpv);
|
||||
}
|
||||
}
|
||||
|
||||
{ //create default array normal
|
||||
|
||||
RD::TextureFormat tformat;
|
||||
tformat.format = RD::DATA_FORMAT_R8G8B8A8_UNORM;
|
||||
tformat.width = 4;
|
||||
tformat.height = 4;
|
||||
tformat.array_layers = 1;
|
||||
tformat.usage_bits = RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_CAN_UPDATE_BIT;
|
||||
tformat.texture_type = RD::TEXTURE_TYPE_2D_ARRAY;
|
||||
|
||||
Vector<uint8_t> pv;
|
||||
pv.resize(16 * 4);
|
||||
for (int i = 0; i < 16; i++) {
|
||||
pv.set(i * 4 + 0, 128);
|
||||
pv.set(i * 4 + 1, 128);
|
||||
pv.set(i * 4 + 2, 255);
|
||||
pv.set(i * 4 + 3, 255);
|
||||
}
|
||||
|
||||
{
|
||||
Vector<Vector<uint8_t>> vpv;
|
||||
vpv.push_back(pv);
|
||||
default_rd_textures[DEFAULT_RD_TEXTURE_2D_ARRAY_NORMAL] = RD::get_singleton()->texture_create(tformat, RD::TextureView(), vpv);
|
||||
}
|
||||
}
|
||||
|
||||
{ //create default array depth
|
||||
|
||||
RD::TextureFormat tformat;
|
||||
tformat.format = RD::DATA_FORMAT_D16_UNORM;
|
||||
tformat.width = 4;
|
||||
tformat.height = 4;
|
||||
tformat.array_layers = 1;
|
||||
tformat.usage_bits = RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_CAN_UPDATE_BIT | RD::TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
|
||||
tformat.texture_type = RD::TEXTURE_TYPE_2D_ARRAY;
|
||||
|
||||
Vector<uint8_t> sv;
|
||||
sv.resize(16 * 2);
|
||||
uint16_t *ptr = (uint16_t *)sv.ptrw();
|
||||
for (int i = 0; i < 16; i++) {
|
||||
ptr[i] = Math::make_half_float(1.0f);
|
||||
}
|
||||
|
||||
{
|
||||
Vector<Vector<uint8_t>> vsv;
|
||||
vsv.push_back(sv);
|
||||
default_rd_textures[DEFAULT_RD_TEXTURE_2D_ARRAY_DEPTH] = RD::get_singleton()->texture_create(tformat, RD::TextureView(), vsv);
|
||||
}
|
||||
}
|
||||
|
||||
{ // default atlas texture
|
||||
RD::TextureFormat tformat;
|
||||
tformat.format = RD::DATA_FORMAT_R8G8B8A8_UNORM;
|
||||
|
|
|
@ -62,6 +62,9 @@ public:
|
|||
DEFAULT_RD_TEXTURE_3D_WHITE,
|
||||
DEFAULT_RD_TEXTURE_3D_BLACK,
|
||||
DEFAULT_RD_TEXTURE_2D_ARRAY_WHITE,
|
||||
DEFAULT_RD_TEXTURE_2D_ARRAY_BLACK,
|
||||
DEFAULT_RD_TEXTURE_2D_ARRAY_NORMAL,
|
||||
DEFAULT_RD_TEXTURE_2D_ARRAY_DEPTH,
|
||||
DEFAULT_RD_TEXTURE_2D_UINT,
|
||||
DEFAULT_RD_TEXTURE_VRS,
|
||||
DEFAULT_RD_TEXTURE_MAX
|
||||
|
|
Loading…
Reference in New Issue