Path: blob/21.2-virgl/src/gallium/frontends/clover/core/resource.hpp
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#ifndef CLOVER_CORE_RESOURCE_HPP23#define CLOVER_CORE_RESOURCE_HPP2425#include <list>2627#include "core/queue.hpp"28#include "util/algebra.hpp"29#include "pipe/p_state.h"3031namespace clover {32class memory_obj;33class mapping;3435///36/// Class that represents a device-specific instance of some memory37/// object.38///39class resource {40public:41typedef std::array<size_t, 3> vector;4243virtual ~resource();4445resource(const resource &r) = delete;46resource &47operator=(const resource &r) = delete;4849void copy(command_queue &q, const vector &origin, const vector ®ion,50resource &src_resource, const vector &src_origin);5152void clear(command_queue &q, const vector &origin, const vector ®ion,53const std::string &data);5455mapping *add_map(command_queue &q, cl_map_flags flags, bool blocking,56const vector &origin, const vector ®ion);57void del_map(void *p);58unsigned map_count() const;5960const intrusive_ref<clover::device> device;61memory_obj &obj;6263friend class sub_resource;64friend class mapping;65friend class kernel;6667protected:68resource(clover::device &dev, memory_obj &obj);6970pipe_sampler_view *bind_sampler_view(command_queue &q);71void unbind_sampler_view(command_queue &q,72pipe_sampler_view *st);7374pipe_surface *bind_surface(command_queue &q, bool rw);75void unbind_surface(command_queue &q, pipe_surface *st);7677pipe_image_view create_image_view(command_queue &q);7879pipe_resource *pipe;80vector offset;8182private:83std::list<mapping> maps;84};8586///87/// Resource associated with its own top-level data storage88/// allocated in some device.89///90class root_resource : public resource {91public:92root_resource(clover::device &dev, memory_obj &obj,93command_queue &q, const void *data_ptr);94root_resource(clover::device &dev, memory_obj &obj, root_resource &r);95virtual ~root_resource();96};9798///99/// Resource that reuses a portion of some other resource as data100/// storage.101///102class sub_resource : public resource {103public:104sub_resource(resource &r, const vector &offset);105};106107///108/// Class that represents a mapping of some resource into the CPU109/// memory space.110///111class mapping {112public:113mapping(command_queue &q, resource &r, cl_map_flags flags,114bool blocking, const resource::vector &origin,115const resource::vector ®ion);116mapping(mapping &&m);117~mapping();118119mapping &120operator=(mapping m);121122mapping(const mapping &m) = delete;123124template<typename T>125operator T *() const {126return (T *)p;127}128129resource::vector pitch() const;130131private:132pipe_context *pctx;133pipe_transfer *pxfer;134pipe_resource *pres;135void *p;136};137}138139#endif140141142