1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/************************************************************************** 2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Copyright 2010 VMware, Inc. 4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * All Rights Reserved. 5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Permission is hereby granted, free of charge, to any person obtaining a 7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * copy of this software and associated documentation files (the 8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * "Software"), to deal in the Software without restriction, including 9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * without limitation the rights to use, copy, modify, merge, publish, 10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * distribute, sub license, and/or sell copies of the Software, and to 11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * permit persons to whom the Software is furnished to do so, subject to 12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * the following conditions: 13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * The above copyright notice and this permission notice (including the 15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * next paragraph) shall be included in all copies or substantial portions 16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * of the Software. 17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org **************************************************************************/ 27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "u_format.h" 30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "u_sampler.h" 31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/** 34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Initialize a pipe_sampler_view. 'view' is considered to have 35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * uninitialized contents. 36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic void 38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgdefault_template(struct pipe_sampler_view *view, 39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const struct pipe_resource *texture, 40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org enum pipe_format format, 41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned expand_green_blue) 42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org memset(view, 0, sizeof(*view)); 44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* XXX: Check if format is compatible with texture->format. 46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org view->format = format; 49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org view->u.tex.first_level = 0; 50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org view->u.tex.last_level = texture->last_level; 51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org view->u.tex.first_layer = 0; 52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org view->u.tex.last_layer = texture->target == PIPE_TEXTURE_3D ? 53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org texture->depth0 - 1 : texture->array_size - 1; 54f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org view->swizzle_r = PIPE_SWIZZLE_RED; 55f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org view->swizzle_g = PIPE_SWIZZLE_GREEN; 56f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org view->swizzle_b = PIPE_SWIZZLE_BLUE; 57f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org view->swizzle_a = PIPE_SWIZZLE_ALPHA; 58f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 59f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* Override default green and blue component expansion to the requested 60f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * one. 61f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 62f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Gallium expands nonexistent components to (0,0,0,1), DX9 expands 63f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * to (1,1,1,1). Since alpha is always expanded to 1, and red is 64f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * always present, we only really care about green and blue 65f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * components. 66f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 67f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * To make it look less hackish, one would have to add 68f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * UTIL_FORMAT_SWIZZLE_EXPAND to indicate components for expansion 69f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * and then override without exceptions or favoring one component 70f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * over another. 71f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 72f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (format != PIPE_FORMAT_A8_UNORM) { 73f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const struct util_format_description *desc = util_format_description(format); 74f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 75f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org assert(desc); 76f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (desc) { 77f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (desc->swizzle[1] == UTIL_FORMAT_SWIZZLE_0) { 78f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org view->swizzle_g = expand_green_blue; 79f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 80f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (desc->swizzle[2] == UTIL_FORMAT_SWIZZLE_0) { 81f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org view->swizzle_b = expand_green_blue; 82f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 83f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 84f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 85f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 86f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 87f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid 88f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgu_sampler_view_default_template(struct pipe_sampler_view *view, 89f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const struct pipe_resource *texture, 90f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org enum pipe_format format) 91f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 92f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* Expand to (0, 0, 0, 1) */ 93f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org default_template(view, 94f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org texture, 95f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org format, 96f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org PIPE_SWIZZLE_ZERO); 97f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 98f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 99f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid 100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgu_sampler_view_default_dx9_template(struct pipe_sampler_view *view, 101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const struct pipe_resource *texture, 102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org enum pipe_format format) 103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* Expand to (1, 1, 1, 1) */ 105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org default_template(view, 106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org texture, 107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org format, 108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org PIPE_SWIZZLE_ONE); 109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 110