1b8e80941Smrg/* 2b8e80941Smrg * Copyright (c) 2012-2015 Etnaviv Project 3b8e80941Smrg * 4b8e80941Smrg * Permission is hereby granted, free of charge, to any person obtaining a 5b8e80941Smrg * copy of this software and associated documentation files (the "Software"), 6b8e80941Smrg * to deal in the Software without restriction, including without limitation 7b8e80941Smrg * the rights to use, copy, modify, merge, publish, distribute, sub license, 8b8e80941Smrg * and/or sell copies of the Software, and to permit persons to whom the 9b8e80941Smrg * Software is furnished to do so, subject to the following conditions: 10b8e80941Smrg * 11b8e80941Smrg * The above copyright notice and this permission notice (including the 12b8e80941Smrg * next paragraph) shall be included in all copies or substantial portions 13b8e80941Smrg * of the Software. 14b8e80941Smrg * 15b8e80941Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16b8e80941Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17b8e80941Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 18b8e80941Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19b8e80941Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20b8e80941Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21b8e80941Smrg * DEALINGS IN THE SOFTWARE. 22b8e80941Smrg */ 23b8e80941Smrg 24b8e80941Smrg#include "etnaviv_rasterizer.h" 25b8e80941Smrg#include "etnaviv_context.h" 26b8e80941Smrg#include "etnaviv_screen.h" 27b8e80941Smrg 28b8e80941Smrg#include "hw/common.xml.h" 29b8e80941Smrg 30b8e80941Smrg#include "etnaviv_translate.h" 31b8e80941Smrg#include "util/u_math.h" 32b8e80941Smrg#include "util/u_memory.h" 33b8e80941Smrg 34b8e80941Smrgvoid * 35b8e80941Smrgetna_rasterizer_state_create(struct pipe_context *pctx, 36b8e80941Smrg const struct pipe_rasterizer_state *so) 37b8e80941Smrg{ 38b8e80941Smrg struct etna_rasterizer_state *cs; 39b8e80941Smrg struct etna_context *ctx = etna_context(pctx); 40b8e80941Smrg 41b8e80941Smrg if (so->fill_front != so->fill_back) 42b8e80941Smrg DBG("Different front and back fill mode not supported"); 43b8e80941Smrg 44b8e80941Smrg cs = CALLOC_STRUCT(etna_rasterizer_state); 45b8e80941Smrg if (!cs) 46b8e80941Smrg return NULL; 47b8e80941Smrg 48b8e80941Smrg cs->base = *so; 49b8e80941Smrg 50b8e80941Smrg cs->PA_CONFIG = (so->flatshade ? VIVS_PA_CONFIG_SHADE_MODEL_FLAT : VIVS_PA_CONFIG_SHADE_MODEL_SMOOTH) | 51b8e80941Smrg translate_cull_face(so->cull_face, so->front_ccw) | 52b8e80941Smrg translate_polygon_mode(so->fill_front) | 53b8e80941Smrg COND(so->point_quad_rasterization, VIVS_PA_CONFIG_POINT_SPRITE_ENABLE) | 54b8e80941Smrg COND(so->point_size_per_vertex, VIVS_PA_CONFIG_POINT_SIZE_ENABLE) | 55b8e80941Smrg COND(VIV_FEATURE(ctx->screen, chipMinorFeatures1, WIDE_LINE), VIVS_PA_CONFIG_WIDE_LINE); 56b8e80941Smrg cs->PA_LINE_WIDTH = fui(so->line_width / 2.0f); 57b8e80941Smrg cs->PA_POINT_SIZE = fui(so->point_size / 2.0f); 58b8e80941Smrg cs->SE_DEPTH_SCALE = fui(so->offset_scale); 59b8e80941Smrg cs->SE_DEPTH_BIAS = fui(so->offset_units) / 65535.0f; 60b8e80941Smrg cs->SE_CONFIG = COND(so->line_last_pixel, VIVS_SE_CONFIG_LAST_PIXEL_ENABLE); 61b8e80941Smrg /* XXX anything else? */ 62b8e80941Smrg /* XXX bottom_edge_rule */ 63b8e80941Smrg cs->PA_SYSTEM_MODE = 64b8e80941Smrg COND(!so->flatshade_first, VIVS_PA_SYSTEM_MODE_PROVOKING_VERTEX_LAST) | 65b8e80941Smrg COND(so->half_pixel_center, VIVS_PA_SYSTEM_MODE_HALF_PIXEL_CENTER); 66b8e80941Smrg 67b8e80941Smrg /* so->scissor overrides the scissor, defaulting to the whole framebuffer, 68b8e80941Smrg * with the scissor state */ 69b8e80941Smrg cs->scissor = so->scissor; 70b8e80941Smrg 71b8e80941Smrg /* point size per vertex adds a vertex shader output */ 72b8e80941Smrg cs->point_size_per_vertex = so->point_size_per_vertex; 73b8e80941Smrg 74b8e80941Smrg assert(!so->clip_halfz); /* could be supported with shader magic, actually 75b8e80941Smrg D3D z is default on older gc */ 76b8e80941Smrg 77b8e80941Smrg return cs; 78b8e80941Smrg} 79