Path: blob/21.2-virgl/src/gallium/frontends/clover/core/sampler.cpp
4572 views
//1// Copyright 2012 Francisco Jerez2//3// Permission is hereby granted, free of charge, to any person obtaining a4// copy of this software and associated documentation files (the "Software"),5// to deal in the Software without restriction, including without limitation6// the rights to use, copy, modify, merge, publish, distribute, sublicense,7// and/or sell copies of the Software, and to permit persons to whom the8// Software is furnished to do so, subject to the following conditions:9//10// The above copyright notice and this permission notice shall be included in11// all copies or substantial portions of the Software.12//13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL16// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR17// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,18// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR19// OTHER DEALINGS IN THE SOFTWARE.20//2122#include "core/sampler.hpp"23#include "pipe/p_state.h"2425using namespace clover;2627sampler::sampler(clover::context &ctx, bool norm_mode,28cl_addressing_mode addr_mode,29cl_filter_mode filter_mode) :30context(ctx), _norm_mode(norm_mode),31_addr_mode(addr_mode), _filter_mode(filter_mode) {32}3334bool35sampler::norm_mode() {36return _norm_mode;37}3839cl_addressing_mode40sampler::addr_mode() {41return _addr_mode;42}4344cl_filter_mode45sampler::filter_mode() {46return _filter_mode;47}4849void *50sampler::bind(command_queue &q) {51struct pipe_sampler_state info {};5253info.normalized_coords = norm_mode();5455info.wrap_s = info.wrap_t = info.wrap_r =56(addr_mode() == CL_ADDRESS_CLAMP_TO_EDGE ? PIPE_TEX_WRAP_CLAMP_TO_EDGE :57addr_mode() == CL_ADDRESS_CLAMP ? PIPE_TEX_WRAP_CLAMP_TO_BORDER :58addr_mode() == CL_ADDRESS_REPEAT ? PIPE_TEX_WRAP_REPEAT :59addr_mode() == CL_ADDRESS_MIRRORED_REPEAT ? PIPE_TEX_WRAP_MIRROR_REPEAT :60PIPE_TEX_WRAP_CLAMP_TO_EDGE);6162info.min_img_filter = info.mag_img_filter =63(filter_mode() == CL_FILTER_LINEAR ? PIPE_TEX_FILTER_LINEAR :64PIPE_TEX_FILTER_NEAREST);6566return q.pipe->create_sampler_state(q.pipe, &info);67}6869void70sampler::unbind(command_queue &q, void *st) {71q.pipe->delete_sampler_state(q.pipe, st);72}737475