Commit 18308802 authored by Keith Whitwell's avatar Keith Whitwell

Merge branch 'gallium-sampler-view' into gallium-resources

Conflicts:
	src/gallium/include/pipe/p_context.h
	src/mesa/state_tracker/st_atom_texture.c
	src/mesa/state_tracker/st_cb_bitmap.c
	src/mesa/state_tracker/st_cb_drawpixels.c
	src/mesa/state_tracker/st_cb_texture.c
	src/mesa/state_tracker/st_context.c
	src/mesa/state_tracker/st_context.h
	src/mesa/state_tracker/st_texture.h
parents 90b4045f 47bfbd45
......@@ -119,6 +119,7 @@ C_SOURCES = \
util/u_mm.c \
util/u_rect.c \
util/u_ringbuffer.c \
util/u_sampler.c \
util/u_simple_shaders.c \
util/u_snprintf.c \
util/u_surface.c \
......@@ -126,12 +127,13 @@ C_SOURCES = \
util/u_tile.c \
util/u_timed_winsys.c \
util/u_upload_mgr.c \
util/u_simple_screen.c \
vl/vl_bitstream_parser.c \
vl/vl_mpeg12_mc_renderer.c \
vl/vl_compositor.c \
vl/vl_csc.c \
vl/vl_shader_build.c \
util/u_simple_screen.c
# Disabling until pipe-video branch gets merged in
#vl/vl_bitstream_parser.c \
#vl/vl_mpeg12_mc_renderer.c \
#vl/vl_compositor.c \
#vl/vl_csc.c \
#vl/vl_shader_build.c \
target-helpers/wrap_screen.c
GALLIVM_SOURCES = \
......
......@@ -162,6 +162,7 @@ source = [
'util/u_mm.c',
'util/u_rect.c',
'util/u_ringbuffer.c',
'util/u_sampler.c',
'util/u_simple_shaders.c',
'util/u_snprintf.c',
'util/u_surface.c',
......@@ -170,11 +171,12 @@ source = [
'util/u_timed_winsys.c',
'util/u_upload_mgr.c',
'util/u_simple_screen.c',
'vl/vl_bitstream_parser.c',
'vl/vl_mpeg12_mc_renderer.c',
'vl/vl_compositor.c',
'vl/vl_csc.c',
'vl/vl_shader_build.c',
# Disabling until pipe-video branch gets merged in
#'vl/vl_bitstream_parser.c',
#'vl/vl_mpeg12_mc_renderer.c',
#'vl/vl_compositor.c',
#'vl/vl_csc.c',
#'vl/vl_shader_build.c',
'target-helpers/wrap_screen.c',
]
......
......@@ -111,17 +111,6 @@ void cso_save_sampler_textures( struct cso_context *cso );
void cso_restore_sampler_textures( struct cso_context *cso );
enum pipe_error
cso_set_vertex_sampler_textures(struct cso_context *cso,
uint count,
struct pipe_texture **textures);
void
cso_save_vertex_sampler_textures(struct cso_context *cso);
void
cso_restore_vertex_sampler_textures(struct cso_context *cso);
enum pipe_error cso_set_vertex_elements(struct cso_context *ctx,
unsigned count,
const struct pipe_vertex_element *states);
......@@ -198,6 +187,34 @@ void
cso_restore_clip(struct cso_context *cso);
/* fragment sampler view state */
void
cso_set_fragment_sampler_views(struct cso_context *cso,
uint count,
struct pipe_sampler_view **views);
void
cso_save_fragment_sampler_views(struct cso_context *cso);
void
cso_restore_fragment_sampler_views(struct cso_context *cso);
/* vertex sampler view state */
void
cso_set_vertex_sampler_views(struct cso_context *cso,
uint count,
struct pipe_sampler_view **views);
void
cso_save_vertex_sampler_views(struct cso_context *cso);
void
cso_restore_vertex_sampler_views(struct cso_context *cso);
#ifdef __cplusplus
}
#endif
......
......@@ -40,6 +40,7 @@
#include "util/u_format.h"
#include "util/u_math.h"
#include "util/u_memory.h"
#include "util/u_sampler.h"
#include "tgsi/tgsi_transform.h"
#include "tgsi/tgsi_dump.h"
......@@ -88,8 +89,9 @@ struct aaline_stage
void *sampler_cso;
struct pipe_texture *texture;
struct pipe_sampler_view *sampler_view;
uint num_samplers;
uint num_textures;
uint num_sampler_views;
/*
......@@ -98,7 +100,7 @@ struct aaline_stage
struct aaline_fragment_shader *fs;
struct {
void *sampler[PIPE_MAX_SAMPLERS];
struct pipe_texture *texture[PIPE_MAX_SAMPLERS];
struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS];
} state;
/*
......@@ -111,8 +113,9 @@ struct aaline_stage
void (*driver_bind_sampler_states)(struct pipe_context *, unsigned,
void **);
void (*driver_set_sampler_textures)(struct pipe_context *, unsigned,
struct pipe_texture **);
void (*driver_set_sampler_views)(struct pipe_context *,
unsigned,
struct pipe_sampler_view **);
struct pipe_context *pipe;
};
......@@ -394,6 +397,7 @@ aaline_create_texture(struct aaline_stage *aaline)
struct pipe_context *pipe = aaline->pipe;
struct pipe_screen *screen = pipe->screen;
struct pipe_texture texTemp;
struct pipe_sampler_view viewTempl;
uint level;
memset(&texTemp, 0, sizeof(texTemp));
......@@ -408,6 +412,16 @@ aaline_create_texture(struct aaline_stage *aaline)
if (!aaline->texture)
return FALSE;
u_sampler_view_default_template(&viewTempl,
aaline->texture,
aaline->texture->format);
aaline->sampler_view = pipe->create_sampler_view(pipe,
aaline->texture,
&viewTempl);
if (!aaline->sampler_view) {
return FALSE;
}
/* Fill in mipmap images.
* Basically each level is solid opaque, except for the outermost
* texels which are zero. Special case the 1x1 and 2x2 levels.
......@@ -669,16 +683,16 @@ aaline_first_line(struct draw_stage *stage, struct prim_header *header)
/* how many samplers? */
/* we'll use sampler/texture[pstip->sampler_unit] for the stipple */
num_samplers = MAX2(aaline->num_textures, aaline->num_samplers);
num_samplers = MAX2(aaline->num_sampler_views, aaline->num_samplers);
num_samplers = MAX2(num_samplers, aaline->fs->sampler_unit + 1);
aaline->state.sampler[aaline->fs->sampler_unit] = aaline->sampler_cso;
pipe_texture_reference(&aaline->state.texture[aaline->fs->sampler_unit],
aaline->texture);
pipe_sampler_view_reference(&aaline->state.sampler_views[aaline->fs->sampler_unit],
aaline->sampler_view);
draw->suspend_flushing = TRUE;
aaline->driver_bind_sampler_states(pipe, num_samplers, aaline->state.sampler);
aaline->driver_set_sampler_textures(pipe, num_samplers, aaline->state.texture);
aaline->driver_set_sampler_views(pipe, num_samplers, aaline->state.sampler_views);
draw->suspend_flushing = FALSE;
/* now really draw first line */
......@@ -702,8 +716,9 @@ aaline_flush(struct draw_stage *stage, unsigned flags)
aaline->driver_bind_fs_state(pipe, aaline->fs->driver_fs);
aaline->driver_bind_sampler_states(pipe, aaline->num_samplers,
aaline->state.sampler);
aaline->driver_set_sampler_textures(pipe, aaline->num_textures,
aaline->state.texture);
aaline->driver_set_sampler_views(pipe,
aaline->num_sampler_views,
aaline->state.sampler_views);
draw->suspend_flushing = FALSE;
draw->extra_shader_outputs.slot = 0;
......@@ -724,7 +739,7 @@ aaline_destroy(struct draw_stage *stage)
uint i;
for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
pipe_texture_reference(&aaline->state.texture[i], NULL);
pipe_sampler_view_reference(&aaline->state.sampler_views[i], NULL);
}
if (aaline->sampler_cso)
......@@ -733,6 +748,10 @@ aaline_destroy(struct draw_stage *stage)
if (aaline->texture)
pipe_texture_reference(&aaline->texture, NULL);
if (aaline->sampler_view) {
pipe_sampler_view_reference(&aaline->sampler_view, NULL);
}
draw_free_temp_verts( stage );
FREE( stage );
......@@ -844,23 +863,24 @@ aaline_bind_sampler_states(struct pipe_context *pipe,
static void
aaline_set_sampler_textures(struct pipe_context *pipe,
unsigned num, struct pipe_texture **texture)
aaline_set_sampler_views(struct pipe_context *pipe,
unsigned num,
struct pipe_sampler_view **views)
{
struct aaline_stage *aaline = aaline_stage_from_pipe(pipe);
uint i;
/* save current */
for (i = 0; i < num; i++) {
pipe_texture_reference(&aaline->state.texture[i], texture[i]);
pipe_sampler_view_reference(&aaline->state.sampler_views[i], views[i]);
}
for ( ; i < PIPE_MAX_SAMPLERS; i++) {
pipe_texture_reference(&aaline->state.texture[i], NULL);
pipe_sampler_view_reference(&aaline->state.sampler_views[i], NULL);
}
aaline->num_textures = num;
aaline->num_sampler_views = num;
/* pass-through */
aaline->driver_set_sampler_textures(aaline->pipe, num, texture);
aaline->driver_set_sampler_views(aaline->pipe, num, views);
}
......@@ -898,7 +918,7 @@ draw_install_aaline_stage(struct draw_context *draw, struct pipe_context *pipe)
aaline->driver_delete_fs_state = pipe->delete_fs_state;
aaline->driver_bind_sampler_states = pipe->bind_fragment_sampler_states;
aaline->driver_set_sampler_textures = pipe->set_fragment_sampler_textures;
aaline->driver_set_sampler_views = pipe->set_fragment_sampler_views;
/* override the driver's functions */
pipe->create_fs_state = aaline_create_fs_state;
......@@ -906,7 +926,7 @@ draw_install_aaline_stage(struct draw_context *draw, struct pipe_context *pipe)
pipe->delete_fs_state = aaline_delete_fs_state;
pipe->bind_fragment_sampler_states = aaline_bind_sampler_states;
pipe->set_fragment_sampler_textures = aaline_set_sampler_textures;
pipe->set_fragment_sampler_views = aaline_set_sampler_views;
/* Install once everything is known to be OK:
*/
......
......@@ -42,6 +42,7 @@
#include "util/u_format.h"
#include "util/u_math.h"
#include "util/u_memory.h"
#include "util/u_sampler.h"
#include "tgsi/tgsi_transform.h"
#include "tgsi/tgsi_dump.h"
......@@ -75,8 +76,9 @@ struct pstip_stage
void *sampler_cso;
struct pipe_texture *texture;
struct pipe_sampler_view *sampler_view;
uint num_samplers;
uint num_textures;
uint num_sampler_views;
/*
* Currently bound state
......@@ -84,7 +86,7 @@ struct pstip_stage
struct pstip_fragment_shader *fs;
struct {
void *samplers[PIPE_MAX_SAMPLERS];
struct pipe_texture *textures[PIPE_MAX_SAMPLERS];
struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS];
const struct pipe_poly_stipple *stipple;
} state;
......@@ -98,8 +100,9 @@ struct pstip_stage
void (*driver_bind_sampler_states)(struct pipe_context *, unsigned, void **);
void (*driver_set_sampler_textures)(struct pipe_context *, unsigned,
struct pipe_texture **);
void (*driver_set_sampler_views)(struct pipe_context *,
unsigned,
struct pipe_sampler_view **);
void (*driver_set_polygon_stipple)(struct pipe_context *,
const struct pipe_poly_stipple *);
......@@ -424,6 +427,7 @@ pstip_create_texture(struct pstip_stage *pstip)
struct pipe_context *pipe = pstip->pipe;
struct pipe_screen *screen = pipe->screen;
struct pipe_texture texTemp;
struct pipe_sampler_view viewTempl;
memset(&texTemp, 0, sizeof(texTemp));
texTemp.target = PIPE_TEXTURE_2D;
......@@ -437,6 +441,16 @@ pstip_create_texture(struct pstip_stage *pstip)
if (pstip->texture == NULL)
return FALSE;
u_sampler_view_default_template(&viewTempl,
pstip->texture,
pstip->texture->format);
pstip->sampler_view = pipe->create_sampler_view(pipe,
pstip->texture,
&viewTempl);
if (!pstip->sampler_view) {
return FALSE;
}
return TRUE;
}
......@@ -515,19 +529,19 @@ pstip_first_tri(struct draw_stage *stage, struct prim_header *header)
/* how many samplers? */
/* we'll use sampler/texture[pstip->sampler_unit] for the stipple */
num_samplers = MAX2(pstip->num_textures, pstip->num_samplers);
num_samplers = MAX2(pstip->num_sampler_views, pstip->num_samplers);
num_samplers = MAX2(num_samplers, pstip->fs->sampler_unit + 1);
/* plug in our sampler, texture */
pstip->state.samplers[pstip->fs->sampler_unit] = pstip->sampler_cso;
pipe_texture_reference(&pstip->state.textures[pstip->fs->sampler_unit],
pstip->texture);
pipe_sampler_view_reference(&pstip->state.sampler_views[pstip->fs->sampler_unit],
pstip->sampler_view);
assert(num_samplers <= PIPE_MAX_SAMPLERS);
draw->suspend_flushing = TRUE;
pstip->driver_bind_sampler_states(pipe, num_samplers, pstip->state.samplers);
pstip->driver_set_sampler_textures(pipe, num_samplers, pstip->state.textures);
pstip->driver_set_sampler_views(pipe, num_samplers, pstip->state.sampler_views);
draw->suspend_flushing = FALSE;
/* now really draw first triangle */
......@@ -551,8 +565,9 @@ pstip_flush(struct draw_stage *stage, unsigned flags)
pstip->driver_bind_fs_state(pipe, pstip->fs->driver_fs);
pstip->driver_bind_sampler_states(pipe, pstip->num_samplers,
pstip->state.samplers);
pstip->driver_set_sampler_textures(pipe, pstip->num_textures,
pstip->state.textures);
pstip->driver_set_sampler_views(pipe,
pstip->num_sampler_views,
pstip->state.sampler_views);
draw->suspend_flushing = FALSE;
}
......@@ -571,13 +586,17 @@ pstip_destroy(struct draw_stage *stage)
uint i;
for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
pipe_texture_reference(&pstip->state.textures[i], NULL);
pipe_sampler_view_reference(&pstip->state.sampler_views[i], NULL);
}
pstip->pipe->delete_sampler_state(pstip->pipe, pstip->sampler_cso);
pipe_texture_reference(&pstip->texture, NULL);
if (pstip->sampler_view) {
pipe_sampler_view_reference(&pstip->sampler_view, NULL);
}
draw_free_temp_verts( stage );
FREE( stage );
}
......@@ -682,24 +701,25 @@ pstip_bind_sampler_states(struct pipe_context *pipe,
static void
pstip_set_sampler_textures(struct pipe_context *pipe,
unsigned num, struct pipe_texture **texture)
pstip_set_sampler_views(struct pipe_context *pipe,
unsigned num,
struct pipe_sampler_view **views)
{
struct pstip_stage *pstip = pstip_stage_from_pipe(pipe);
uint i;
/* save current */
for (i = 0; i < num; i++) {
pipe_texture_reference(&pstip->state.textures[i], texture[i]);
pipe_sampler_view_reference(&pstip->state.sampler_views[i], views[i]);
}
for (; i < PIPE_MAX_SAMPLERS; i++) {
pipe_texture_reference(&pstip->state.textures[i], NULL);
pipe_sampler_view_reference(&pstip->state.sampler_views[i], NULL);
}
pstip->num_textures = num;
pstip->num_sampler_views = num;
/* pass-through */
pstip->driver_set_sampler_textures(pstip->pipe, num, texture);
pstip->driver_set_sampler_views(pstip->pipe, num, views);
}
......@@ -756,7 +776,7 @@ draw_install_pstipple_stage(struct draw_context *draw,
pstip->driver_delete_fs_state = pipe->delete_fs_state;
pstip->driver_bind_sampler_states = pipe->bind_fragment_sampler_states;
pstip->driver_set_sampler_textures = pipe->set_fragment_sampler_textures;
pstip->driver_set_sampler_views = pipe->set_fragment_sampler_views;
pstip->driver_set_polygon_stipple = pipe->set_polygon_stipple;
/* override the driver's functions */
......@@ -765,7 +785,7 @@ draw_install_pstipple_stage(struct draw_context *draw,
pipe->delete_fs_state = pstip_delete_fs_state;
pipe->bind_fragment_sampler_states = pstip_bind_sampler_states;
pipe->set_fragment_sampler_textures = pstip_set_sampler_textures;
pipe->set_fragment_sampler_views = pstip_set_sampler_views;
pipe->set_polygon_stipple = pstip_set_polygon_stipple;
return TRUE;
......
......@@ -45,6 +45,7 @@
#include "util/u_draw_quad.h"
#include "util/u_pack_color.h"
#include "util/u_rect.h"
#include "util/u_sampler.h"
#include "util/u_simple_shaders.h"
#include "util/u_texture.h"
......@@ -96,6 +97,8 @@ struct blitter_context_priv
/* Rasterizer state. */
void *rs_state;
struct pipe_sampler_view *sampler_view;
/* Viewport state. */
struct pipe_viewport_state viewport;
......@@ -127,7 +130,7 @@ struct blitter_context *util_blitter_create(struct pipe_context *pipe)
ctx->blitter.saved_vs = INVALID_PTR;
ctx->blitter.saved_velem_state = INVALID_PTR;
ctx->blitter.saved_fb_state.nr_cbufs = ~0;
ctx->blitter.saved_num_textures = ~0;
ctx->blitter.saved_num_sampler_views = ~0;
ctx->blitter.saved_num_sampler_states = ~0;
/* blend state objects */
......@@ -252,6 +255,10 @@ void util_blitter_destroy(struct blitter_context *blitter)
if (ctx->sampler_state[i])
pipe->delete_sampler_state(pipe, ctx->sampler_state[i]);
if (ctx->sampler_view) {
pipe_sampler_view_reference(&ctx->sampler_view, NULL);
}
pipe_buffer_reference(&ctx->vbuf, NULL);
FREE(ctx);
}
......@@ -305,11 +312,11 @@ static void blitter_restore_CSOs(struct blitter_context_priv *ctx)
ctx->blitter.saved_num_sampler_states = ~0;
}
if (ctx->blitter.saved_num_textures != ~0) {
pipe->set_fragment_sampler_textures(pipe,
ctx->blitter.saved_num_textures,
ctx->blitter.saved_textures);
ctx->blitter.saved_num_textures = ~0;
if (ctx->blitter.saved_num_sampler_views != ~0) {
pipe->set_fragment_sampler_views(pipe,
ctx->blitter.saved_num_sampler_views,
ctx->blitter.saved_sampler_views);
ctx->blitter.saved_num_sampler_views = ~0;
}
}
......@@ -621,9 +628,10 @@ static void util_blitter_do_copy(struct blitter_context *blitter,
struct blitter_context_priv *ctx = (struct blitter_context_priv*)blitter;
struct pipe_context *pipe = ctx->pipe;
struct pipe_framebuffer_state fb_state;
struct pipe_sampler_view viewTempl, *view;
assert(blitter->saved_fb_state.nr_cbufs != ~0);
assert(blitter->saved_num_textures != ~0);
assert(blitter->saved_num_sampler_views != ~0);
assert(blitter->saved_num_sampler_states != ~0);
assert(src->texture->target < PIPE_MAX_TEXTURE_TYPES);
......@@ -651,12 +659,24 @@ static void util_blitter_do_copy(struct blitter_context *blitter,
fb_state.zsbuf = 0;
}
u_sampler_view_default_template(&viewTempl,
src->texture,
src->texture->format);
view = pipe->create_sampler_view(pipe,
src->texture,
&viewTempl);
if (ctx->sampler_view) {
pipe_sampler_view_reference(&ctx->sampler_view, NULL);
}
ctx->sampler_view = view;
pipe->bind_rasterizer_state(pipe, ctx->rs_state);
pipe->bind_vs_state(pipe, ctx->vs_tex);
pipe->bind_fragment_sampler_states(pipe, 1,
blitter_get_sampler_state(ctx, src->level));
pipe->bind_vertex_elements_state(pipe, ctx->velem_state);
pipe->set_fragment_sampler_textures(pipe, 1, &src->texture);
pipe->set_fragment_sampler_views(pipe, 1, &view);
pipe->set_framebuffer_state(pipe, &fb_state);
/* set texture coordinates */
......
......@@ -53,10 +53,10 @@ struct blitter_context
struct pipe_clip_state saved_clip;
int saved_num_sampler_states;
void *saved_sampler_states[32];
void *saved_sampler_states[PIPE_MAX_SAMPLERS];
int saved_num_textures;
struct pipe_texture *saved_textures[32]; /* is 32 enough? */
int saved_num_sampler_views;
struct pipe_sampler_view *saved_sampler_views[PIPE_MAX_SAMPLERS];
};
/**
......@@ -242,17 +242,17 @@ void util_blitter_save_fragment_sampler_states(
num_sampler_states * sizeof(void *));
}
static INLINE
void util_blitter_save_fragment_sampler_textures(
struct blitter_context *blitter,
int num_textures,
struct pipe_texture **textures)
static INLINE void
util_blitter_save_fragment_sampler_views(struct blitter_context *blitter,
int num_views,
struct pipe_sampler_view **views)
{
assert(num_textures <= Elements(blitter->saved_textures));
assert(num_views <= Elements(blitter->saved_sampler_views));
blitter->saved_num_textures = num_textures;
memcpy(blitter->saved_textures, textures,
num_textures * sizeof(struct pipe_texture *));
blitter->saved_num_sampler_views = num_views;
memcpy(blitter->saved_sampler_views,
views,
num_views * sizeof(struct pipe_sampler_view *));
}
#ifdef __cplusplus
......
......@@ -131,6 +131,16 @@ pipe_resource_reference(struct pipe_resource **ptr, struct pipe_resource *tex)
*ptr = tex;
}
static INLINE void
pipe_sampler_view_reference(struct pipe_sampler_view **ptr, struct pipe_sampler_view *view)
{
struct pipe_sampler_view *old_view = *ptr;
if (pipe_reference(&(*ptr)->reference, &view->reference))
old_view->context->sampler_view_destroy(old_view->context, old_view);
*ptr = view;
}
/*
* Convenience wrappers for screen buffer functions.
......
/**************************************************************************
*
* Copyright 2010 VMware, Inc.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
#include "u_format.h"
#include "u_sampler.h"
static void
default_template(struct pipe_sampler_view *view,
const struct pipe_texture *texture,
enum pipe_format format,
unsigned expand_green_blue)
{
/* XXX: Check if format is compatible with texture->format.
*/
view->format = format;
view->first_level = 0;
view->last_level = texture->last_level;
view->swizzle_r = PIPE_SWIZZLE_RED;
view->swizzle_g = PIPE_SWIZZLE_GREEN;
view->swizzle_b = PIPE_SWIZZLE_BLUE;
view->swizzle_a = PIPE_SWIZZLE_ALPHA;
/* Override default green and blue component expansion to the requested
* one.
*
* Gallium expands nonexistent components to (0,0,0,1), DX9 expands
* to (1,1,1,1). Since alpha is always expanded to 1, and red is
* always present, we only really care about green and blue
* components.
*
* To make it look less hackish, one would have to add
* UTIL_FORMAT_SWIZZLE_EXPAND to indicate components for expansion
* and then override without exceptions or favoring one component
* over another.
*/
if (format != PIPE_FORMAT_A8_UNORM) {
const struct util_format_description *desc = util_format_description(format);
assert(desc);
if (desc) {
if (desc->swizzle[1] == UTIL_FORMAT_SWIZZLE_0) {
view->swizzle_g = expand_green_blue;
}
if (desc->swizzle[2] == UTIL_FORMAT_SWIZZLE_0) {
view->swizzle_b = expand_green_blue;
}
}
}
}
void
u_sampler_view_default_template(struct pipe_sampler_view *view,
const struct pipe_texture *texture,
enum pipe_format format)
{
/* Expand to (0, 0, 0, 1) */
default_template(view,
texture,
format,
PIPE_SWIZZLE_ZERO);
}
void
u_sampler_view_default_dx9_template(struct pipe_sampler_view *view,
const struct pipe_texture *texture,
enum pipe_format format)
{
/* Expand to (1, 1, 1, 1) */
default_template(view,
texture,
format,
PIPE_SWIZZLE_ONE);