/** * If GL_FRAMEBUFFER_SRGB is enabled, then output colorspace is * expected to be sRGB if blending is not enabled. * If GL_FRAMEBUFFER_SRGB is disabled, then we can use * copy_region_vgpu10() * Following table basically tells when copy_region_vgpu10 can be * used if GL_FRAMEBUFFER_SRGB is enabled. * ______________________________________________________________ * | src fmt | dst_fmt | blending |Can use | * | | | |copy_region | * ______________________________________________________________ * | linear | linear | N | Y | * | linear | linear | Y | Y | * | linear | sRGB | N | N | * | linear | sRGB | Y | Y | * | sRGB | linear | N | N | * | sRGB | linear | Y | N | * | sRGB | sRGB | N | Y | * | sRGB | sRGB | Y | N | * ______________________________________________________________ * */ static bool check_blending_and_srgb_cond(struct svga_context *svga, const struct pipe_blit_info *blit) { enum pipe_format sFmt = blit->src.format; enum pipe_format dFmt = blit->dst.format; if (is_blending_enabled(svga, blit)) { if (!util_format_is_srgb(blit->src.format)) return true; } else { if (util_format_is_srgb(sFmt) && util_format_is_srgb(dFmt)) return true; else if (!util_format_is_srgb(sFmt)){ if (!util_format_is_srgb(dFmt)) return true; else { /** * State tracker converts all sRGB src blit format * to linear if GL_FRAMEBUFFER_SRGB is disabled. * So if src resource format is sRGB and * blit format is linear then it means, * GL_FRAMEBUFFER_SRGB is disabled. In this case also * we can use copy_region_vgpu10(). */ if (util_format_is_srgb(blit->src.resource->format)) return true; } } } return false; }
void Material::use(Graphics *graphics, ResourceCache *cache, DepthTexture *shadowmap) { Texture *albedo = cache->get<Texture2D>(get_albedo_texture()); Texture *normal = cache->get<Texture2D>(get_normal_texture()); Texture *roughness = cache->get<Texture2D>(get_roughness_texture()); Texture *metallic = cache->get<Texture2D>(get_metallic_texture()); Texture *env = cache->get<TextureCube>(get_env_texture()); graphics->set_texture(0, albedo); graphics->set_texture(1, normal); graphics->set_texture(2, roughness); graphics->set_texture(3, metallic); graphics->set_texture(4, g_env_brdf); graphics->set_texture(5, shadowmap); graphics->set_texture(6, env); Program *program = cache->get_program(m_vert_shader, m_frag_shader); update_program(program); graphics->set_cull_mode(get_cull_mode()); graphics->set_blend_enabled(is_blending_enabled()); }
/** * Try issuing a quad blit. */ static bool try_blit(struct svga_context *svga, const struct pipe_blit_info *blit_info) { struct svga_winsys_screen *sws = svga_screen(svga->pipe.screen)->sws; struct pipe_resource *src = blit_info->src.resource; struct pipe_resource *dst = blit_info->dst.resource; struct pipe_resource *newSrc = NULL; struct pipe_resource *newDst = NULL; bool can_create_src_view; bool can_create_dst_view; bool ret = true; struct pipe_blit_info blit = *blit_info; SVGA_STATS_TIME_PUSH(sws, SVGA_STATS_TIME_BLITBLITTER); /** * Avoid using util_blitter_blit() for these depth formats on non-vgpu10 * devices because these depth formats only support comparison mode * and not ordinary sampling. */ if (!svga_have_vgpu10(svga) && (blit.mask & PIPE_MASK_Z) && (svga_texture(dst)->key.format == SVGA3D_Z_D16 || svga_texture(dst)->key.format == SVGA3D_Z_D24X8 || svga_texture(dst)->key.format == SVGA3D_Z_D24S8)) { ret = false; goto done; } /** * If format is srgb and blend is enabled then color values need * to be converted into linear format. */ if (is_blending_enabled(svga, &blit)) { blit.src.format = util_format_linear(blit.src.format); blit.dst.format = util_format_linear(blit.dst.format); } /* Check if we can create shader resource view and * render target view for the quad blitter to work */ can_create_src_view = is_view_format_compatible(src->format, svga_texture(src)->key.format, blit.src.format); can_create_dst_view = is_view_format_compatible(dst->format, svga_texture(dst)->key.format, blit.dst.format); if ((blit.mask & PIPE_MASK_S) || ((!can_create_dst_view || !can_create_src_view) && !svga_have_vgpu10(svga))) { /* Can't do stencil blits with textured quad blitter */ debug_warn_once("using software stencil blit"); ret = false; goto done; } if (!util_blitter_is_blit_supported(svga->blitter, &blit)) { debug_printf("svga: blit unsupported %s -> %s\n", util_format_short_name(blit.src.resource->format), util_format_short_name(blit.dst.resource->format)); ret = false; goto done; } /* XXX turn off occlusion and streamout queries */ util_blitter_save_vertex_buffer_slot(svga->blitter, svga->curr.vb); util_blitter_save_vertex_elements(svga->blitter, (void*)svga->curr.velems); util_blitter_save_vertex_shader(svga->blitter, svga->curr.vs); util_blitter_save_geometry_shader(svga->blitter, svga->curr.user_gs); util_blitter_save_so_targets(svga->blitter, svga->num_so_targets, (struct pipe_stream_output_target**)svga->so_targets); util_blitter_save_rasterizer(svga->blitter, (void*)svga->curr.rast); util_blitter_save_viewport(svga->blitter, &svga->curr.viewport); util_blitter_save_scissor(svga->blitter, &svga->curr.scissor); util_blitter_save_fragment_shader(svga->blitter, svga->curr.fs); util_blitter_save_blend(svga->blitter, (void*)svga->curr.blend); util_blitter_save_depth_stencil_alpha(svga->blitter, (void*)svga->curr.depth); util_blitter_save_stencil_ref(svga->blitter, &svga->curr.stencil_ref); util_blitter_save_sample_mask(svga->blitter, svga->curr.sample_mask); util_blitter_save_framebuffer(svga->blitter, &svga->curr.framebuffer); util_blitter_save_fragment_sampler_states(svga->blitter, svga->curr.num_samplers[PIPE_SHADER_FRAGMENT], (void**)svga->curr.sampler[PIPE_SHADER_FRAGMENT]); util_blitter_save_fragment_sampler_views(svga->blitter, svga->curr.num_sampler_views[PIPE_SHADER_FRAGMENT], svga->curr.sampler_views[PIPE_SHADER_FRAGMENT]); if (!can_create_src_view) { struct pipe_resource template; struct pipe_blit_info copy_region_blit;