diff options
Diffstat (limited to 'src/gallium/drivers/r600/sb/sb_bc_builder.h')
-rw-r--r-- | src/gallium/drivers/r600/sb/sb_bc_builder.h | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/src/gallium/drivers/r600/sb/sb_bc_builder.h b/src/gallium/drivers/r600/sb/sb_bc_builder.h new file mode 100644 index 0000000000..32978e0b85 --- /dev/null +++ b/src/gallium/drivers/r600/sb/sb_bc_builder.h @@ -0,0 +1,127 @@ +/* + * Copyright 2013 Vadim Girlin <vadimgirlin@gmail.com> + * + * 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 + * on 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 + * THE AUTHOR(S) AND/OR THEIR 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. + * + * Authors: + * Vadim Girlin + */ + +#ifndef SB_BC_BUILDER_H_ +#define SB_BC_BUILDER_H_ + +namespace r600_sb { + +class bytecode { + typedef std::vector<uint32_t> bc_vector; + sb_hw_class_bits hw_class_bit; + + bc_vector bc; + + unsigned pos; + +public: + + bytecode(sb_hw_class_bits hw, unsigned rdw = 256) + : hw_class_bit(hw), pos(0) { bc.reserve(rdw); } + + unsigned ndw() { return bc.size(); } + + void write_data(uint32_t* dst) { + memcpy(dst, bc.data(), 4 * bc.size()); + } + + void align(unsigned a) { + unsigned size = bc.size(); + size = (size + a - 1) & ~(a-1); + bc.resize(size); + } + + void set_size(unsigned sz) { + assert(sz >= bc.size()); + bc.resize(sz); + } + + void seek(unsigned p) { + if (p != pos) { + if (p > bc.size()) { + bc.resize(p); + } + pos = p; + } + } + + unsigned get_pos() { return pos; } + uint32_t *data() { return bc.data(); } + + bytecode & operator <<(uint32_t v) { + if (pos == ndw()) { + bc.push_back(v); + } else + bc.at(pos) = v; + ++pos; + return *this; + } + + bytecode & operator <<(const hw_encoding_format &e) { + *this << e.get_value(hw_class_bit); + return *this; + } + + bytecode & operator <<(const bytecode &b) { + bc.insert(bc.end(), b.bc.begin(), b.bc.end()); + return *this; + } + + uint32_t at(unsigned dw_id) { return bc.at(dw_id); } +}; + +class bc_builder { + shader &sh; + sb_context &ctx; + bytecode bb; + int error; + +public: + + bc_builder(shader &s); + int build(); + bytecode& get_bytecode() { assert(!error); return bb; } + +private: + + int build_cf(cf_node *n); + + int build_cf_alu(cf_node *n); + int build_cf_mem(cf_node *n); + int build_cf_exp(cf_node *n); + + int build_alu_clause(cf_node *n); + int build_alu_group(alu_group_node *n); + int build_alu(alu_node *n); + + int build_fetch_clause(cf_node *n); + int build_fetch_tex(fetch_node *n); + int build_fetch_vtx(fetch_node *n); +}; + +} // namespace r600_sb + +#endif /* SB_BC_BUILDER_H_ */ |