Merge pull request #2101 from vlj/rsx-refactor

Rsx refactor: Some cleanups
This commit is contained in:
vlj 2016-08-27 18:21:16 +02:00 committed by GitHub
commit c0ab0dee6b
15 changed files with 600 additions and 140 deletions

View File

@ -1,5 +1,5 @@
Standard: Cpp11
UseTab: ForIndentation
UseTab: Always
TabWidth: 1
IndentWidth: 1
AccessModifierOffset: -1
@ -7,7 +7,7 @@ PointerAlignment: Left
NamespaceIndentation: All
ColumnLimit: 0
BreakBeforeBraces: Allman
BreakConstructorInitializersBeforeComma: true
BreakConstructorInitializersBeforeComma: false
BreakBeforeBinaryOperators: false
BreakBeforeTernaryOperators: false
AlwaysBreakTemplateDeclarations: true
@ -20,7 +20,7 @@ Cpp11BracedListStyle: true
IndentCaseLabels: false
SortIncludes: false
ReflowComments: true
AlignConsecutiveAssignments: true
AlignConsecutiveAssignments: false
AlignTrailingComments: true
AlignAfterOpenBracket: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false

485
git-clang-format Normal file
View File

@ -0,0 +1,485 @@
#!/usr/bin/env python
#
#===- git-clang-format - ClangFormat Git Integration ---------*- python -*--===#
#
# The LLVM Compiler Infrastructure
#
# This file is distributed under the University of Illinois Open Source
# License. See LICENSE.TXT for details.
#
#===------------------------------------------------------------------------===#
r"""
clang-format git integration
============================
This file provides a clang-format integration for git. Put it somewhere in your
path and ensure that it is executable. Then, "git clang-format" will invoke
clang-format on the changes in current files or a specific commit.
For further details, run:
git clang-format -h
Requires Python 2.7
"""
import argparse
import collections
import contextlib
import errno
import os
import re
import subprocess
import sys
usage = 'git clang-format [OPTIONS] [<commit>] [--] [<file>...]'
desc = '''
Run clang-format on all lines that differ between the working directory
and <commit>, which defaults to HEAD. Changes are only applied to the working
directory.
The following git-config settings set the default of the corresponding option:
clangFormat.binary
clangFormat.commit
clangFormat.extension
clangFormat.style
'''
# Name of the temporary index file in which save the output of clang-format.
# This file is created within the .git directory.
temp_index_basename = 'clang-format-index'
Range = collections.namedtuple('Range', 'start, count')
def main():
config = load_git_config()
# In order to keep '--' yet allow options after positionals, we need to
# check for '--' ourselves. (Setting nargs='*' throws away the '--', while
# nargs=argparse.REMAINDER disallows options after positionals.)
argv = sys.argv[1:]
try:
idx = argv.index('--')
except ValueError:
dash_dash = []
else:
dash_dash = argv[idx:]
argv = argv[:idx]
default_extensions = ','.join([
# From clang/lib/Frontend/FrontendOptions.cpp, all lower case
'c', 'h', # C
'm', # ObjC
'mm', # ObjC++
'cc', 'cp', 'cpp', 'c++', 'cxx', 'hpp', # C++
# Other languages that clang-format supports
'proto', 'protodevel', # Protocol Buffers
'js', # JavaScript
'ts', # TypeScript
])
p = argparse.ArgumentParser(
usage=usage, formatter_class=argparse.RawDescriptionHelpFormatter,
description=desc)
p.add_argument('--binary',
default=config.get('clangformat.binary', 'clang-format'),
help='path to clang-format'),
p.add_argument('--commit',
default=config.get('clangformat.commit', 'HEAD'),
help='default commit to use if none is specified'),
p.add_argument('--diff', action='store_true',
help='print a diff instead of applying the changes')
p.add_argument('--extensions',
default=config.get('clangformat.extensions',
default_extensions),
help=('comma-separated list of file extensions to format, '
'excluding the period and case-insensitive')),
p.add_argument('-f', '--force', action='store_true',
help='allow changes to unstaged files')
p.add_argument('-p', '--patch', action='store_true',
help='select hunks interactively')
p.add_argument('-q', '--quiet', action='count', default=0,
help='print less information')
p.add_argument('--style',
default=config.get('clangformat.style', None),
help='passed to clang-format'),
p.add_argument('-v', '--verbose', action='count', default=0,
help='print extra information')
# We gather all the remaining positional arguments into 'args' since we need
# to use some heuristics to determine whether or not <commit> was present.
# However, to print pretty messages, we make use of metavar and help.
p.add_argument('args', nargs='*', metavar='<commit>',
help='revision from which to compute the diff')
p.add_argument('ignored', nargs='*', metavar='<file>...',
help='if specified, only consider differences in these files')
opts = p.parse_args(argv)
opts.verbose -= opts.quiet
del opts.quiet
commit, files = interpret_args(opts.args, dash_dash, opts.commit)
changed_lines = compute_diff_and_extract_lines(commit, files)
if opts.verbose >= 1:
ignored_files = set(changed_lines)
filter_by_extension(changed_lines, opts.extensions.lower().split(','))
if opts.verbose >= 1:
ignored_files.difference_update(changed_lines)
if ignored_files:
print 'Ignoring changes in the following files (wrong extension):'
for filename in ignored_files:
print ' ', filename
if changed_lines:
print 'Running clang-format on the following files:'
for filename in changed_lines:
print ' ', filename
if not changed_lines:
print 'no modified files to format'
return
# The computed diff outputs absolute paths, so we must cd before accessing
# those files.
cd_to_toplevel()
old_tree = create_tree_from_workdir(changed_lines)
new_tree = run_clang_format_and_save_to_tree(changed_lines,
binary=opts.binary,
style=opts.style)
if opts.verbose >= 1:
print 'old tree:', old_tree
print 'new tree:', new_tree
if old_tree == new_tree:
if opts.verbose >= 0:
print 'clang-format did not modify any files'
elif opts.diff:
print_diff(old_tree, new_tree)
else:
changed_files = apply_changes(old_tree, new_tree, force=opts.force,
patch_mode=opts.patch)
if (opts.verbose >= 0 and not opts.patch) or opts.verbose >= 1:
print 'changed files:'
for filename in changed_files:
print ' ', filename
def load_git_config(non_string_options=None):
"""Return the git configuration as a dictionary.
All options are assumed to be strings unless in `non_string_options`, in which
is a dictionary mapping option name (in lower case) to either "--bool" or
"--int"."""
if non_string_options is None:
non_string_options = {}
out = {}
for entry in run('git', 'config', '--list', '--null').split('\0'):
if entry:
name, value = entry.split('\n', 1)
if name in non_string_options:
value = run('git', 'config', non_string_options[name], name)
out[name] = value
return out
def interpret_args(args, dash_dash, default_commit):
"""Interpret `args` as "[commit] [--] [files...]" and return (commit, files).
It is assumed that "--" and everything that follows has been removed from
args and placed in `dash_dash`.
If "--" is present (i.e., `dash_dash` is non-empty), the argument to its
left (if present) is taken as commit. Otherwise, the first argument is
checked if it is a commit or a file. If commit is not given,
`default_commit` is used."""
if dash_dash:
if len(args) == 0:
commit = default_commit
elif len(args) > 1:
die('at most one commit allowed; %d given' % len(args))
else:
commit = args[0]
object_type = get_object_type(commit)
if object_type not in ('commit', 'tag'):
if object_type is None:
die("'%s' is not a commit" % commit)
else:
die("'%s' is a %s, but a commit was expected" % (commit, object_type))
files = dash_dash[1:]
elif args:
if disambiguate_revision(args[0]):
commit = args[0]
files = args[1:]
else:
commit = default_commit
files = args
else:
commit = default_commit
files = []
return commit, files
def disambiguate_revision(value):
"""Returns True if `value` is a revision, False if it is a file, or dies."""
# If `value` is ambiguous (neither a commit nor a file), the following
# command will die with an appropriate error message.
run('git', 'rev-parse', value, verbose=False)
object_type = get_object_type(value)
if object_type is None:
return False
if object_type in ('commit', 'tag'):
return True
die('`%s` is a %s, but a commit or filename was expected' %
(value, object_type))
def get_object_type(value):
"""Returns a string description of an object's type, or None if it is not
a valid git object."""
cmd = ['git', 'cat-file', '-t', value]
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
if p.returncode != 0:
return None
return stdout.strip()
def compute_diff_and_extract_lines(commit, files):
"""Calls compute_diff() followed by extract_lines()."""
diff_process = compute_diff(commit, files)
changed_lines = extract_lines(diff_process.stdout)
diff_process.stdout.close()
diff_process.wait()
if diff_process.returncode != 0:
# Assume error was already printed to stderr.
sys.exit(2)
return changed_lines
def compute_diff(commit, files):
"""Return a subprocess object producing the diff from `commit`.
The return value's `stdin` file object will produce a patch with the
differences between the working directory and `commit`, filtered on `files`
(if non-empty). Zero context lines are used in the patch."""
cmd = ['git', 'diff-index', '-p', '-U0', commit, '--']
cmd.extend(files)
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
p.stdin.close()
return p
def extract_lines(patch_file):
"""Extract the changed lines in `patch_file`.
The return value is a dictionary mapping filename to a list of (start_line,
line_count) pairs.
The input must have been produced with ``-U0``, meaning unidiff format with
zero lines of context. The return value is a dict mapping filename to a
list of line `Range`s."""
matches = {}
for line in patch_file:
match = re.search(r'^\+\+\+\ [^/]+/(.*)', line)
if match:
filename = match.group(1).rstrip('\r\n')
match = re.search(r'^@@ -[0-9,]+ \+(\d+)(,(\d+))?', line)
if match:
start_line = int(match.group(1))
line_count = 1
if match.group(3):
line_count = int(match.group(3))
if line_count > 0:
matches.setdefault(filename, []).append(Range(start_line, line_count))
return matches
def filter_by_extension(dictionary, allowed_extensions):
"""Delete every key in `dictionary` that doesn't have an allowed extension.
`allowed_extensions` must be a collection of lowercase file extensions,
excluding the period."""
allowed_extensions = frozenset(allowed_extensions)
for filename in dictionary.keys():
base_ext = filename.rsplit('.', 1)
if len(base_ext) == 1 or base_ext[1].lower() not in allowed_extensions:
del dictionary[filename]
def cd_to_toplevel():
"""Change to the top level of the git repository."""
toplevel = run('git', 'rev-parse', '--show-toplevel')
os.chdir(toplevel)
def create_tree_from_workdir(filenames):
"""Create a new git tree with the given files from the working directory.
Returns the object ID (SHA-1) of the created tree."""
return create_tree(filenames, '--stdin')
def run_clang_format_and_save_to_tree(changed_lines, binary='clang-format',
style=None):
"""Run clang-format on each file and save the result to a git tree.
Returns the object ID (SHA-1) of the created tree."""
def index_info_generator():
for filename, line_ranges in changed_lines.iteritems():
mode = oct(os.stat(filename).st_mode)
blob_id = clang_format_to_blob(filename, line_ranges, binary=binary,
style=style)
yield '%s %s\t%s' % (mode, blob_id, filename)
return create_tree(index_info_generator(), '--index-info')
def create_tree(input_lines, mode):
"""Create a tree object from the given input.
If mode is '--stdin', it must be a list of filenames. If mode is
'--index-info' is must be a list of values suitable for "git update-index
--index-info", such as "<mode> <SP> <sha1> <TAB> <filename>". Any other mode
is invalid."""
assert mode in ('--stdin', '--index-info')
cmd = ['git', 'update-index', '--add', '-z', mode]
with temporary_index_file():
p = subprocess.Popen(cmd, stdin=subprocess.PIPE)
for line in input_lines:
p.stdin.write('%s\0' % line)
p.stdin.close()
if p.wait() != 0:
die('`%s` failed' % ' '.join(cmd))
tree_id = run('git', 'write-tree')
return tree_id
def clang_format_to_blob(filename, line_ranges, binary='clang-format',
style=None):
"""Run clang-format on the given file and save the result to a git blob.
Returns the object ID (SHA-1) of the created blob."""
clang_format_cmd = [binary, filename]
if style:
clang_format_cmd.extend(['-style='+style])
clang_format_cmd.extend([
'-lines=%s:%s' % (start_line, start_line+line_count-1)
for start_line, line_count in line_ranges])
try:
clang_format = subprocess.Popen(clang_format_cmd, stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
except OSError as e:
if e.errno == errno.ENOENT:
die('cannot find executable "%s"' % binary)
else:
raise
clang_format.stdin.close()
hash_object_cmd = ['git', 'hash-object', '-w', '--path='+filename, '--stdin']
hash_object = subprocess.Popen(hash_object_cmd, stdin=clang_format.stdout,
stdout=subprocess.PIPE)
clang_format.stdout.close()
stdout = hash_object.communicate()[0]
if hash_object.returncode != 0:
die('`%s` failed' % ' '.join(hash_object_cmd))
if clang_format.wait() != 0:
die('`%s` failed' % ' '.join(clang_format_cmd))
return stdout.rstrip('\r\n')
@contextlib.contextmanager
def temporary_index_file(tree=None):
"""Context manager for setting GIT_INDEX_FILE to a temporary file and deleting
the file afterward."""
index_path = create_temporary_index(tree)
old_index_path = os.environ.get('GIT_INDEX_FILE')
os.environ['GIT_INDEX_FILE'] = index_path
try:
yield
finally:
if old_index_path is None:
del os.environ['GIT_INDEX_FILE']
else:
os.environ['GIT_INDEX_FILE'] = old_index_path
os.remove(index_path)
def create_temporary_index(tree=None):
"""Create a temporary index file and return the created file's path.
If `tree` is not None, use that as the tree to read in. Otherwise, an
empty index is created."""
gitdir = run('git', 'rev-parse', '--git-dir')
path = os.path.join(gitdir, temp_index_basename)
if tree is None:
tree = '--empty'
run('git', 'read-tree', '--index-output='+path, tree)
return path
def print_diff(old_tree, new_tree):
"""Print the diff between the two trees to stdout."""
# We use the porcelain 'diff' and not plumbing 'diff-tree' because the output
# is expected to be viewed by the user, and only the former does nice things
# like color and pagination.
subprocess.check_call(['git', 'diff', old_tree, new_tree, '--'])
def apply_changes(old_tree, new_tree, force=False, patch_mode=False):
"""Apply the changes in `new_tree` to the working directory.
Bails if there are local changes in those files and not `force`. If
`patch_mode`, runs `git checkout --patch` to select hunks interactively."""
changed_files = run('git', 'diff-tree', '-r', '-z', '--name-only', old_tree,
new_tree).rstrip('\0').split('\0')
if not force:
unstaged_files = run('git', 'diff-files', '--name-status', *changed_files)
if unstaged_files:
print >>sys.stderr, ('The following files would be modified but '
'have unstaged changes:')
print >>sys.stderr, unstaged_files
print >>sys.stderr, 'Please commit, stage, or stash them first.'
sys.exit(2)
if patch_mode:
# In patch mode, we could just as well create an index from the new tree
# and checkout from that, but then the user will be presented with a
# message saying "Discard ... from worktree". Instead, we use the old
# tree as the index and checkout from new_tree, which gives the slightly
# better message, "Apply ... to index and worktree". This is not quite
# right, since it won't be applied to the user's index, but oh well.
with temporary_index_file(old_tree):
subprocess.check_call(['git', 'checkout', '--patch', new_tree])
index_tree = old_tree
else:
with temporary_index_file(new_tree):
run('git', 'checkout-index', '-a', '-f')
return changed_files
def run(*args, **kwargs):
stdin = kwargs.pop('stdin', '')
verbose = kwargs.pop('verbose', True)
strip = kwargs.pop('strip', True)
for name in kwargs:
raise TypeError("run() got an unexpected keyword argument '%s'" % name)
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
stdin=subprocess.PIPE)
stdout, stderr = p.communicate(input=stdin)
if p.returncode == 0:
if stderr:
if verbose:
print >>sys.stderr, '`%s` printed to stderr:' % ' '.join(args)
print >>sys.stderr, stderr.rstrip()
if strip:
stdout = stdout.rstrip('\r\n')
return stdout
if verbose:
print >>sys.stderr, '`%s` returned %s' % (' '.join(args), p.returncode)
if stderr:
print >>sys.stderr, stderr.rstrip()
sys.exit(2)
def die(message):
print >>sys.stderr, 'error:', message
sys.exit(2)
if __name__ == '__main__':
main()

10
pre-commit.readme Normal file
View File

@ -0,0 +1,10 @@
#!/bin/bash
# git pre-commit hook that run git-clang-format when committing.
# To use it install clang-format and python 2.7 then copy this
# file to .git/hooks/ and remove the extension
git clang-format --style=file --diff > style.patch
git apply --index style.patch
rm style.patch
exit 0

View File

@ -49,12 +49,11 @@ namespace
D3D12_SHADER_RESOURCE_VIEW_DESC get_vertex_attribute_srv(const rsx::data_array_format_info &info, UINT64 offset_in_vertex_buffers_buffer, UINT buffer_size)
{
u32 element_size = rsx::get_vertex_type_size_on_host(info.type, info.size);
u32 element_size = rsx::get_vertex_type_size_on_host(info.type(), info.size());
D3D12_SHADER_RESOURCE_VIEW_DESC vertex_buffer_view = {
get_vertex_attribute_format(info.type, info.size),
D3D12_SRV_DIMENSION_BUFFER,
get_component_mapping_from_vector_size(info.size)
};
get_vertex_attribute_format(info.type(), info.size()),
D3D12_SRV_DIMENSION_BUFFER,
get_component_mapping_from_vector_size(info.size())};
vertex_buffer_view.Buffer.FirstElement = offset_in_vertex_buffers_buffer / element_size;
vertex_buffer_view.Buffer.NumElements = buffer_size / element_size;
return vertex_buffer_view;
@ -186,10 +185,10 @@ std::tuple<std::vector<D3D12_SHADER_RESOURCE_VIEW_DESC>, size_t> upload_inlined_
{
initial_offsets[index++] = stride;
if (!info.size) // disabled
if (!info.size()) // disabled
continue;
stride += rsx::get_vertex_type_size_on_host(info.type, info.size);
stride += rsx::get_vertex_type_size_on_host(info.type(), info.size());
}
u32 element_count = ::narrow<u32>(inlined_array_raw_data.size_bytes()) / stride;
@ -199,13 +198,13 @@ std::tuple<std::vector<D3D12_SHADER_RESOURCE_VIEW_DESC>, size_t> upload_inlined_
index = 0;
for (const auto &info : vertex_attribute_infos)
{
if (!info.size)
if (!info.size())
{
index++;
continue;
}
u32 element_size = rsx::get_vertex_type_size_on_host(info.type, info.size);
u32 element_size = rsx::get_vertex_type_size_on_host(info.type(), info.size());
UINT buffer_size = element_size * element_count;
size_t heap_offset = ring_buffer_data.alloc<D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT>(buffer_size);
@ -216,7 +215,7 @@ std::tuple<std::vector<D3D12_SHADER_RESOURCE_VIEW_DESC>, size_t> upload_inlined_
{
auto subdst = dst.subspan(i * element_size, element_size);
auto subsrc = inlined_array_raw_data.subspan(initial_offsets[index] + (i * stride), element_size);
if (info.type == rsx::vertex_base_type::ub && info.size == 4)
if (info.type() == rsx::vertex_base_type::ub && info.size() == 4)
{
subdst[0] = subsrc[3];
subdst[1] = subsrc[2];

View File

@ -220,7 +220,7 @@ void GLGSRender::begin()
blend_factor(rsx::method_registers.blend_func_sfactor_a()),
blend_factor(rsx::method_registers.blend_func_dfactor_a()));
if (m_surface.color_format == rsx::surface_color_format::w16z16y16x16) //TODO: check another color formats
if (rsx::method_registers.surface_color() == rsx::surface_color_format::w16z16y16x16) //TODO: check another color formats
{
u16 blend_color_r = rsx::method_registers.blend_color_16b_r();
u16 blend_color_g = rsx::method_registers.blend_color_16b_g();

View File

@ -20,7 +20,6 @@ private:
gl::glsl::program *m_program;
rsx::surface_info m_surface;
gl_render_targets m_rtts;
gl::gl_texture_cache m_gl_texture_cache;

View File

@ -204,7 +204,7 @@ void GLGSRender::read_buffers()
if (g_cfg_rsx_read_color_buffers)
{
auto color_format = rsx::internals::surface_color_format_to_gl(m_surface.color_format);
auto color_format = rsx::internals::surface_color_format_to_gl(rsx::method_registers.surface_color());
auto read_color_buffers = [&](int index, int count)
{
@ -293,16 +293,16 @@ void GLGSRender::read_buffers()
//Read failed. Fall back to slow s/w path...
auto depth_format = rsx::internals::surface_depth_format_to_gl(m_surface.depth_format);
int pixel_size = rsx::internals::get_pixel_size(m_surface.depth_format);
auto depth_format = rsx::internals::surface_depth_format_to_gl(rsx::method_registers.surface_depth_fmt());
int pixel_size = rsx::internals::get_pixel_size(rsx::method_registers.surface_depth_fmt());
gl::buffer pbo_depth;
__glcheck pbo_depth.create(m_surface.width * m_surface.height * pixel_size);
__glcheck pbo_depth.create(rsx::method_registers.surface_clip_width() * rsx::method_registers.surface_clip_height() * pixel_size);
__glcheck pbo_depth.map([&](GLubyte* pixels)
{
u32 depth_address = rsx::get_address(rsx::method_registers.surface_z_offset(), rsx::method_registers.surface_z_dma());
if (m_surface.depth_format == rsx::surface_depth_format::z16)
if (rsx::method_registers.surface_depth_fmt() == rsx::surface_depth_format::z16)
{
u16 *dst = (u16*)pixels;
const be_t<u16>* src = vm::ps3::_ptr<u16>(depth_address);
@ -336,7 +336,7 @@ void GLGSRender::write_buffers()
if (g_cfg_rsx_write_color_buffers)
{
auto color_format = rsx::internals::surface_color_format_to_gl(m_surface.color_format);
auto color_format = rsx::internals::surface_color_format_to_gl(rsx::method_registers.surface_color());
auto write_color_buffers = [&](int index, int count)
{
@ -404,11 +404,11 @@ void GLGSRender::write_buffers()
if (pitch <= 64)
return;
auto depth_format = rsx::internals::surface_depth_format_to_gl(m_surface.depth_format);
auto depth_format = rsx::internals::surface_depth_format_to_gl(rsx::method_registers.surface_depth_fmt());
u32 depth_address = rsx::get_address(rsx::method_registers.surface_z_offset(), rsx::method_registers.surface_z_dma());
u32 range = std::get<1>(m_rtts.m_bound_depth_stencil)->width() * std::get<1>(m_rtts.m_bound_depth_stencil)->height() * 2;
if (m_surface.depth_format != rsx::surface_depth_format::z16) range *= 2;
if (rsx::method_registers.surface_depth_fmt() != rsx::surface_depth_format::z16) range *= 2;
m_gl_texture_cache.save_render_target(depth_address, range, (*std::get<1>(m_rtts.m_bound_depth_stencil)));
}

View File

@ -214,7 +214,7 @@ std::tuple<u32, std::optional<std::tuple<GLenum, u32> > > GLGSRender::set_vertex
for (u8 index = 0; index < rsx::limits::vertex_count; ++index)
{
if (rsx::method_registers.vertex_arrays_info[index].size || rsx::method_registers.register_vertex_info[index].size)
if (rsx::method_registers.vertex_arrays_info[index].size() || rsx::method_registers.register_vertex_info[index].size)
{
max_vertex_attrib_size += 16;
}
@ -412,10 +412,10 @@ u32 GLGSRender::upload_inline_array(const u32 &max_vertex_attrib_size, const u32
for (u32 i = 0; i < rsx::limits::vertex_count; ++i)
{
const auto &info = rsx::method_registers.vertex_arrays_info[i];
if (!info.size) continue;
if (!info.size()) continue;
offsets[i] = stride;
stride += rsx::get_vertex_type_size_on_host(info.type, info.size);
stride += rsx::get_vertex_type_size_on_host(info.type(), info.size());
}
u32 vertex_draw_count = (u32)(inline_vertex_array.size() * sizeof(u32)) / stride;
@ -429,7 +429,7 @@ u32 GLGSRender::upload_inline_array(const u32 &max_vertex_attrib_size, const u32
if (!m_program->uniforms.has_location(s_reg_table[index], &location))
continue;
if (!vertex_info.size) // disabled, bind a null sampler
if (!vertex_info.size()) // disabled, bind a null sampler
{
glActiveTexture(GL_TEXTURE0 + index + texture_index_offset);
glBindTexture(GL_TEXTURE_BUFFER, 0);
@ -437,9 +437,9 @@ u32 GLGSRender::upload_inline_array(const u32 &max_vertex_attrib_size, const u32
continue;
}
const u32 element_size = rsx::get_vertex_type_size_on_host(vertex_info.type, vertex_info.size);
const u32 element_size = rsx::get_vertex_type_size_on_host(vertex_info.type(), vertex_info.size());
u32 data_size = element_size * vertex_draw_count;
u32 gl_type = to_gl_internal_type(vertex_info.type, vertex_info.size);
u32 gl_type = to_gl_internal_type(vertex_info.type(), vertex_info.size());
auto &texture = m_gl_attrib_buffers[index];
@ -448,12 +448,12 @@ u32 GLGSRender::upload_inline_array(const u32 &max_vertex_attrib_size, const u32
u8 *dst = static_cast<u8*>(mapping.first);
src += offsets[index];
prepare_buffer_for_writing(dst, vertex_info.type, vertex_info.size, vertex_draw_count);
prepare_buffer_for_writing(dst, vertex_info.type(), vertex_info.size(), vertex_draw_count);
//TODO: properly handle compressed data
for (u32 i = 0; i < vertex_draw_count; ++i)
{
if (vertex_info.type == rsx::vertex_base_type::ub && vertex_info.size == 4)
if (vertex_info.type() == rsx::vertex_base_type::ub && vertex_info.size() == 4)
{
dst[0] = src[3];
dst[1] = src[2];

View File

@ -327,7 +327,6 @@ namespace rsx
void thread::begin()
{
draw_inline_vertex_array = false;
inline_vertex_array.clear();
}
@ -532,12 +531,12 @@ namespace rsx
{
const auto &info = rsx::method_registers.vertex_arrays_info[index];
if (!info.size) // disabled
if (!info.size()) // disabled
continue;
u32 element_size = rsx::get_vertex_type_size_on_host(info.type, info.size);
u32 element_size = rsx::get_vertex_type_size_on_host(info.type(), info.size());
if (info.type == vertex_base_type::ub && info.size == 4)
if (info.type() == vertex_base_type::ub && info.size() == 4)
{
dst[0] = src[3];
dst[1] = src[2];
@ -588,7 +587,7 @@ namespace rsx
u32 offset = vertex_array_info.offset();
u32 address = base_offset + rsx::get_address(offset & 0x7fffffff, offset >> 31);
u32 element_size = rsx::get_vertex_type_size_on_host(vertex_array_info.type, vertex_array_info.size);
u32 element_size = rsx::get_vertex_type_size_on_host(vertex_array_info.type(), vertex_array_info.size());
// Disjoint first_counts ranges not supported atm
for (int i = 0; i < vertex_ranges.size() - 1; i++)
@ -601,7 +600,7 @@ namespace rsx
u32 count = std::get<0>(vertex_ranges.back()) + std::get<1>(vertex_ranges.back()) - first;
const gsl::byte* ptr = gsl::narrow_cast<const gsl::byte*>(vm::base(address));
return {ptr + first * vertex_array_info.stride, count * vertex_array_info.stride + element_size};
return {ptr + first * vertex_array_info.stride(), count * vertex_array_info.stride() + element_size};
}
std::vector<std::variant<vertex_array_buffer, vertex_array_register, empty_vertex_array>> thread::get_vertex_buffers(const rsx::rsx_state& state, const std::vector<std::pair<u32, u32>>& vertex_ranges) const
@ -614,10 +613,10 @@ namespace rsx
if (!enabled)
continue;
if (state.vertex_arrays_info[index].size > 0)
if (state.vertex_arrays_info[index].size() > 0)
{
const rsx::data_array_format_info& info = state.vertex_arrays_info[index];
result.push_back(vertex_array_buffer{info.type, info.size, info.stride,
result.push_back(vertex_array_buffer{info.type(), info.size(), info.stride(),
get_raw_vertex_buffer(info, state.vertex_data_base_offset(), vertex_ranges), index});
continue;
}
@ -761,31 +760,25 @@ namespace rsx
if (!enabled)
continue;
if (rsx::method_registers.vertex_arrays_info[index].size > 0)
if (rsx::method_registers.vertex_arrays_info[index].size() > 0)
{
result.rsx_vertex_inputs.push_back(
{
index,
rsx::method_registers.vertex_arrays_info[index].size,
rsx::method_registers.vertex_arrays_info[index].frequency,
!!((modulo_mask >> index) & 0x1),
true,
is_int_type(rsx::method_registers.vertex_arrays_info[index].type)
}
);
{index,
rsx::method_registers.vertex_arrays_info[index].size(),
rsx::method_registers.vertex_arrays_info[index].frequency(),
!!((modulo_mask >> index) & 0x1),
true,
is_int_type(rsx::method_registers.vertex_arrays_info[index].type())});
}
else if (rsx::method_registers.register_vertex_info[index].size > 0)
{
result.rsx_vertex_inputs.push_back(
{
index,
rsx::method_registers.register_vertex_info[index].size,
rsx::method_registers.register_vertex_info[index].frequency,
!!((modulo_mask >> index) & 0x1),
false,
is_int_type(rsx::method_registers.vertex_arrays_info[index].type)
}
);
{index,
rsx::method_registers.register_vertex_info[index].size,
rsx::method_registers.register_vertex_info[index].frequency,
!!((modulo_mask >> index) & 0x1),
false,
is_int_type(rsx::method_registers.vertex_arrays_info[index].type())});
}
}
return result;
@ -844,10 +837,10 @@ namespace rsx
{
bool is_int = false;
if (rsx::method_registers.vertex_arrays_info[index].size > 0)
if (rsx::method_registers.vertex_arrays_info[index].size() > 0)
{
is_int = is_int_type(rsx::method_registers.vertex_arrays_info[index].type);
result.state.frequency[index] = rsx::method_registers.vertex_arrays_info[index].frequency;
is_int = is_int_type(rsx::method_registers.vertex_arrays_info[index].type());
result.state.frequency[index] = rsx::method_registers.vertex_arrays_info[index].frequency();
}
else if (rsx::method_registers.register_vertex_info[index].size > 0)
{

View File

@ -117,33 +117,6 @@ namespace rsx
void read(void *dst, u32 width, u32 height, u32 pitch);
};
struct surface_info
{
u8 log2height;
u8 log2width;
surface_antialiasing antialias;
surface_depth_format depth_format;
surface_color_format color_format;
u32 width;
u32 height;
u32 format;
void unpack(u32 surface_format)
{
format = surface_format;
log2height = surface_format >> 24;
log2width = (surface_format >> 16) & 0xff;
antialias = to_surface_antialiasing((surface_format >> 12) & 0xf);
depth_format = to_surface_depth_format((surface_format >> 5) & 0x7);
color_format = to_surface_color_format(surface_format & 0x1f);
width = 1 << (u32(log2width) + 1);
height = 1 << (u32(log2width) + 1);
}
};
struct vertex_array_buffer
{
rsx::vertex_base_type type;
@ -210,7 +183,6 @@ namespace rsx
u32 local_mem_addr, main_mem_addr;
bool strict_ordering[0x1000];
bool draw_inline_vertex_array;
std::vector<u32> inline_vertex_array;
bool m_rtts_dirty;
@ -222,8 +194,6 @@ namespace rsx
RSXVertexProgram get_current_vertex_program() const;
RSXFragmentProgram get_current_fragment_program() const;
public:
u32 draw_array_count;
u32 draw_array_first;
double fps_limit = 59.94;
public:

View File

@ -388,10 +388,10 @@ u32 VKGSRender::upload_inlined_array()
for (u32 i = 0; i < rsx::limits::vertex_count; ++i)
{
const auto &info = rsx::method_registers.vertex_arrays_info[i];
if (!info.size) continue;
if (!info.size()) continue;
offsets[i] = stride;
stride += rsx::get_vertex_type_size_on_host(info.type, info.size);
stride += rsx::get_vertex_type_size_on_host(info.type(), info.size());
}
u32 vertex_draw_count = (u32)(inline_vertex_array.size() * sizeof(u32)) / stride;
@ -403,48 +403,48 @@ u32 VKGSRender::upload_inlined_array()
if (!m_program->has_uniform(s_reg_table[index]))
continue;
if (!vertex_info.size) // disabled
if (!vertex_info.size()) // disabled
{
continue;
}
const u32 element_size = vk::get_suitable_vk_size(vertex_info.type, vertex_info.size);
const u32 element_size = vk::get_suitable_vk_size(vertex_info.type(), vertex_info.size());
const u32 data_size = element_size * vertex_draw_count;
const VkFormat format = vk::get_suitable_vk_format(vertex_info.type, vertex_info.size);
const VkFormat format = vk::get_suitable_vk_format(vertex_info.type(), vertex_info.size());
u32 offset_in_attrib_buffer = m_attrib_ring_info.alloc<256>(data_size);
u8 *src = reinterpret_cast<u8*>(inline_vertex_array.data());
u8 *dst = static_cast<u8*>(m_attrib_ring_info.map(offset_in_attrib_buffer, data_size));
src += offsets[index];
u8 opt_size = vertex_info.size;
u8 opt_size = vertex_info.size();
if (vertex_info.size == 3)
if (vertex_info.size() == 3)
opt_size = 4;
//TODO: properly handle cmp type
if (vertex_info.type == rsx::vertex_base_type::cmp)
if (vertex_info.type() == rsx::vertex_base_type::cmp)
LOG_ERROR(RSX, "Compressed vertex attributes not supported for inlined arrays yet");
switch (vertex_info.type)
switch (vertex_info.type())
{
case rsx::vertex_base_type::f:
vk::copy_inlined_data_to_buffer<float, 1>(src, dst, vertex_draw_count, vertex_info.type, vertex_info.size, opt_size, element_size, stride);
vk::copy_inlined_data_to_buffer<float, 1>(src, dst, vertex_draw_count, vertex_info.type(), vertex_info.size(), opt_size, element_size, stride);
break;
case rsx::vertex_base_type::sf:
vk::copy_inlined_data_to_buffer<u16, 0x3c00>(src, dst, vertex_draw_count, vertex_info.type, vertex_info.size, opt_size, element_size, stride);
vk::copy_inlined_data_to_buffer<u16, 0x3c00>(src, dst, vertex_draw_count, vertex_info.type(), vertex_info.size(), opt_size, element_size, stride);
break;
case rsx::vertex_base_type::s1:
case rsx::vertex_base_type::ub:
case rsx::vertex_base_type::ub256:
vk::copy_inlined_data_to_buffer<u8, 1>(src, dst, vertex_draw_count, vertex_info.type, vertex_info.size, opt_size, element_size, stride);
vk::copy_inlined_data_to_buffer<u8, 1>(src, dst, vertex_draw_count, vertex_info.type(), vertex_info.size(), opt_size, element_size, stride);
break;
case rsx::vertex_base_type::s32k:
case rsx::vertex_base_type::cmp:
vk::copy_inlined_data_to_buffer<u16, 1>(src, dst, vertex_draw_count, vertex_info.type, vertex_info.size, opt_size, element_size, stride);
vk::copy_inlined_data_to_buffer<u16, 1>(src, dst, vertex_draw_count, vertex_info.type(), vertex_info.size(), opt_size, element_size, stride);
break;
default:
fmt::throw_exception("Unknown base type %d" HERE, (u32)vertex_info.type);
fmt::throw_exception("Unknown base type %d" HERE, (u32)vertex_info.type());
}
m_attrib_ring_info.unmap();

View File

@ -185,19 +185,6 @@ namespace rsx
}
};
template<u32 index>
struct set_vertex_data_array_format
{
static void impl(thread* rsx, u32 _reg, u32 arg)
{
const typename rsx::registers_decoder<NV4097_SET_VERTEX_DATA_ARRAY_FORMAT + index>::decoded_type decoded_value(arg);
rsx::method_registers.vertex_arrays_info[index].frequency = decoded_value.frequency();
rsx::method_registers.vertex_arrays_info[index].stride = decoded_value.stride();
rsx::method_registers.vertex_arrays_info[index].size = decoded_value.size();
rsx::method_registers.vertex_arrays_info[index].type = decoded_value.type();
}
};
void draw_arrays(thread* rsx, u32 _reg, u32 arg)
{
rsx::method_registers.current_draw_clause.command = rsx::draw_command::array;
@ -219,7 +206,6 @@ namespace rsx
void draw_inline_array(thread* rsx, u32 _reg, u32 arg)
{
rsx::method_registers.current_draw_clause.command = rsx::draw_command::inlined_array;
rsx->draw_inline_vertex_array = true;
rsx->inline_vertex_array.push_back(arg);
}
@ -878,7 +864,6 @@ namespace rsx
registers[NV4097_SET_ZSTENCIL_CLEAR_VALUE] = 0xffffffff;
for (auto& info : vertex_arrays_info) info.size = 0;
for (auto& tex : fragment_textures) tex.init();
for (auto& tex : vertex_textures) tex.init();
}
@ -1276,7 +1261,6 @@ namespace rsx
bind<NV4097_DRAW_ARRAYS, nv4097::draw_arrays>();
bind<NV4097_DRAW_INDEX_ARRAY, nv4097::draw_index_array>();
bind<NV4097_INLINE_ARRAY, nv4097::draw_inline_array>();
bind_range<NV4097_SET_VERTEX_DATA_ARRAY_FORMAT, 1, 16, nv4097::set_vertex_data_array_format>();
bind_range<NV4097_SET_VERTEX_DATA4UB_M, 1, 16, nv4097::set_vertex_data4ub_m>();
bind_range<NV4097_SET_VERTEX_DATA1F_M, 1, 16, nv4097::set_vertex_data1f_m>();
bind_range<NV4097_SET_VERTEX_DATA2F_M, 1, 32, nv4097::set_vertex_data2f_m>();

View File

@ -137,13 +137,6 @@ namespace rsx
transform_program = in.transform_program;
transform_constants = in.transform_constants;
register_vertex_info = in.register_vertex_info;
for (int i = 0; i < 16; i++)
{
vertex_arrays_info[i].size = in.vertex_arrays_info[i].size;
vertex_arrays_info[i].stride = in.vertex_arrays_info[i].stride;
vertex_arrays_info[i].frequency = in.vertex_arrays_info[i].frequency;
vertex_arrays_info[i].type = in.vertex_arrays_info[i].type;
}
return *this;
}

View File

@ -9,19 +9,46 @@ namespace rsx
struct data_array_format_info
{
private:
u32& m_offset_register;
public:
u16 frequency = 0;
u8 stride = 0;
u8 size = 0;
vertex_base_type type = vertex_base_type::f;
u8 index;
std::array<u32, 0x10000 / 4>& registers;
data_array_format_info(int id, std::array<u32, 0x10000 / 4> &registers)
: m_offset_register(registers[NV4097_SET_VERTEX_DATA_ARRAY_OFFSET + id]) {}
auto decode_reg() const
{
const typename rsx::registers_decoder<NV4097_SET_VERTEX_DATA_ARRAY_FORMAT>::decoded_type
decoded_value(registers[NV4097_SET_VERTEX_DATA_ARRAY_FORMAT + index]);
return decoded_value;
}
public:
data_array_format_info(int id, std::array<u32, 0x10000 / 4>& r)
: registers(r)
, index(id)
{
}
u32 offset() const
{
return m_offset_register;
return registers[NV4097_SET_VERTEX_DATA_ARRAY_OFFSET + index];
}
u8 stride() const
{
return decode_reg().stride();
}
u8 size() const
{
return decode_reg().size();
}
u16 frequency() const
{
return decode_reg().frequency();
}
vertex_base_type type() const
{
return decode_reg().type();
}
};

View File

@ -213,8 +213,8 @@ SettingsDialog::SettingsDialog(wxWindow* parent)
std::vector<std::unique_ptr<cfg_adapter>> pads;
static const u32 width = 458 * 2;
static const u32 height = 400 * 2;
static const u32 width = 458;
static const u32 height = 400;
// Settings panels
wxNotebook* nb_config = new wxNotebook(this, wxID_ANY, wxPoint(6, 6), wxSize(width, height));
@ -521,7 +521,7 @@ SettingsDialog::SettingsDialog(wxWindow* parent)
SetSizerAndFit(s_subpanel_system, false);
SetSizerAndFit(s_b_panel, false);
SetSize(width + 26 * 2, height + 80 * 2);
SetSize(width + 26, height + 80);
if (ShowModal() == wxID_OK)
{