Merge pull request #1447 from RPCS3/rsx_cache

RSX vertex/OpenGL texture cache preparation
This commit is contained in:
DHrpcs3 2016-01-20 21:44:48 +03:00
commit 52110e0647
26 changed files with 925 additions and 827 deletions

View file

@ -794,16 +794,18 @@ size_t get_x64_access_size(x64_context* context, x64_op_t op, x64_reg_t reg, siz
return d_size; return d_size;
} }
/** namespace rsx
* Callback that can be customised by GSRender backends to track memory access. {
* Backends can protect memory pages and get this callback called when an access extern std::function<bool(u32 addr, bool is_writing)> g_access_violation_handler;
* violation is met. }
* Should return true if the backend handles the access violation.
*/
std::function<bool(u32 addr)> gfxHandler = [](u32) { return false; };
bool handle_access_violation(u32 addr, bool is_writing, x64_context* context) bool handle_access_violation(u32 addr, bool is_writing, x64_context* context)
{ {
if (rsx::g_access_violation_handler && rsx::g_access_violation_handler(addr, is_writing))
{
return true;
}
auto code = (const u8*)RIP(context); auto code = (const u8*)RIP(context);
x64_op_t op; x64_op_t op;
@ -811,9 +813,6 @@ bool handle_access_violation(u32 addr, bool is_writing, x64_context* context)
size_t d_size; size_t d_size;
size_t i_size; size_t i_size;
if (gfxHandler(addr))
return true;
// decode single x64 instruction that causes memory access // decode single x64 instruction that causes memory access
decode_x64_reg_op(code, op, reg, d_size, i_size); decode_x64_reg_op(code, op, reg, d_size, i_size);

View file

@ -50,12 +50,12 @@ void write_vertex_array_data_to_buffer(void *buffer, u32 first, u32 count, size_
switch (vertex_array_desc.type) switch (vertex_array_desc.type)
{ {
case Vertex_base_type::ub: case rsx::vertex_base_type::ub:
memcpy(dst, src, vertex_array_desc.size); memcpy(dst, src, vertex_array_desc.size);
break; break;
case Vertex_base_type::s1: case rsx::vertex_base_type::s1:
case Vertex_base_type::sf: case rsx::vertex_base_type::sf:
{ {
auto* c_src = (const be_t<u16>*)src; auto* c_src = (const be_t<u16>*)src;
u16* c_dst = (u16*)dst; u16* c_dst = (u16*)dst;
@ -69,9 +69,9 @@ void write_vertex_array_data_to_buffer(void *buffer, u32 first, u32 count, size_
break; break;
} }
case Vertex_base_type::f: case rsx::vertex_base_type::f:
case Vertex_base_type::s32k: case rsx::vertex_base_type::s32k:
case Vertex_base_type::ub256: case rsx::vertex_base_type::ub256:
{ {
auto* c_src = (const be_t<u32>*)src; auto* c_src = (const be_t<u32>*)src;
u32* c_dst = (u32*)dst; u32* c_dst = (u32*)dst;
@ -82,7 +82,7 @@ void write_vertex_array_data_to_buffer(void *buffer, u32 first, u32 count, size_
} }
break; break;
} }
case Vertex_base_type::cmp: case rsx::vertex_base_type::cmp:
{ {
auto* c_src = (const be_t<u32>*)src; auto* c_src = (const be_t<u32>*)src;
const auto& decoded_vector = decode_cmp_vector(*c_src); const auto& decoded_vector = decode_cmp_vector(*c_src);
@ -244,21 +244,21 @@ std::tuple<T, T> expand_indexed_quads(gsl::span<to_be_t<const T>> src, gsl::span
} }
// Only handle quads and triangle fan now // Only handle quads and triangle fan now
bool is_primitive_native(Primitive_type m_draw_mode) bool is_primitive_native(rsx::primitive_type draw_mode)
{ {
switch (m_draw_mode) switch (draw_mode)
{ {
case Primitive_type::points: case rsx::primitive_type::points:
case Primitive_type::lines: case rsx::primitive_type::lines:
case Primitive_type::line_loop: case rsx::primitive_type::line_loop:
case Primitive_type::line_strip: case rsx::primitive_type::line_strip:
case Primitive_type::triangles: case rsx::primitive_type::triangles:
case Primitive_type::triangle_strip: case rsx::primitive_type::triangle_strip:
case Primitive_type::quad_strip: case rsx::primitive_type::quad_strip:
return true; return true;
case Primitive_type::polygon: case rsx::primitive_type::polygon:
case Primitive_type::triangle_fan: case rsx::primitive_type::triangle_fan:
case Primitive_type::quads: case rsx::primitive_type::quads:
return false; return false;
} }
throw new EXCEPTION("Wrong primitive type"); throw new EXCEPTION("Wrong primitive type");
@ -269,41 +269,41 @@ bool is_primitive_native(Primitive_type m_draw_mode)
* see http://www.gamedev.net/page/resources/_/technical/graphics-programming-and-theory/polygon-triangulation-r3334 * see http://www.gamedev.net/page/resources/_/technical/graphics-programming-and-theory/polygon-triangulation-r3334
*/ */
size_t get_index_count(Primitive_type m_draw_mode, unsigned initial_index_count) size_t get_index_count(rsx::primitive_type draw_mode, unsigned initial_index_count)
{ {
// Index count // Index count
if (is_primitive_native(m_draw_mode)) if (is_primitive_native(draw_mode))
return initial_index_count; return initial_index_count;
switch (m_draw_mode) switch (draw_mode)
{ {
case Primitive_type::polygon: case rsx::primitive_type::polygon:
case Primitive_type::triangle_fan: case rsx::primitive_type::triangle_fan:
return (initial_index_count - 2) * 3; return (initial_index_count - 2) * 3;
case Primitive_type::quads: case rsx::primitive_type::quads:
return (6 * initial_index_count) / 4; return (6 * initial_index_count) / 4;
default: default:
return 0; return 0;
} }
} }
size_t get_index_type_size(Index_array_type type) size_t get_index_type_size(rsx::index_array_type type)
{ {
switch (type) switch (type)
{ {
case Index_array_type::unsigned_16b: return 2; case rsx::index_array_type::u16: return sizeof(u16);
case Index_array_type::unsigned_32b: return 4; case rsx::index_array_type::u32: return sizeof(u32);
} }
throw new EXCEPTION("Wrong index type"); throw new EXCEPTION("Wrong index type");
} }
void write_index_array_for_non_indexed_non_native_primitive_to_buffer(char* dst, Primitive_type draw_mode, unsigned first, unsigned count) void write_index_array_for_non_indexed_non_native_primitive_to_buffer(char* dst, rsx::primitive_type draw_mode, unsigned first, unsigned count)
{ {
unsigned short *typedDst = (unsigned short *)(dst); unsigned short *typedDst = (unsigned short *)(dst);
switch (draw_mode) switch (draw_mode)
{ {
case Primitive_type::triangle_fan: case rsx::primitive_type::triangle_fan:
case Primitive_type::polygon: case rsx::primitive_type::polygon:
for (unsigned i = 0; i < (count - 2); i++) for (unsigned i = 0; i < (count - 2); i++)
{ {
typedDst[3 * i] = first; typedDst[3 * i] = first;
@ -311,7 +311,7 @@ void write_index_array_for_non_indexed_non_native_primitive_to_buffer(char* dst,
typedDst[3 * i + 2] = i + 2; typedDst[3 * i + 2] = i + 2;
} }
return; return;
case Primitive_type::quads: case rsx::primitive_type::quads:
for (unsigned i = 0; i < count / 4; i++) for (unsigned i = 0; i < count / 4; i++)
{ {
// First triangle // First triangle
@ -324,13 +324,13 @@ void write_index_array_for_non_indexed_non_native_primitive_to_buffer(char* dst,
typedDst[6 * i + 5] = 4 * i + first; typedDst[6 * i + 5] = 4 * i + first;
} }
return; return;
case Primitive_type::points: case rsx::primitive_type::points:
case Primitive_type::lines: case rsx::primitive_type::lines:
case Primitive_type::line_loop: case rsx::primitive_type::line_loop:
case Primitive_type::line_strip: case rsx::primitive_type::line_strip:
case Primitive_type::triangles: case rsx::primitive_type::triangles:
case Primitive_type::triangle_strip: case rsx::primitive_type::triangle_strip:
case Primitive_type::quad_strip: case rsx::primitive_type::quad_strip:
throw new EXCEPTION("Native primitive type doesn't require expansion"); throw new EXCEPTION("Native primitive type doesn't require expansion");
} }
} }
@ -338,10 +338,10 @@ void write_index_array_for_non_indexed_non_native_primitive_to_buffer(char* dst,
// TODO: Unify indexed and non indexed primitive expansion ? // TODO: Unify indexed and non indexed primitive expansion ?
template<typename T> template<typename T>
std::tuple<T, T> write_index_array_data_to_buffer_impl(gsl::span<T, gsl::dynamic_range> dst, Primitive_type m_draw_mode, const std::vector<std::pair<u32, u32> > &first_count_arguments) std::tuple<T, T> write_index_array_data_to_buffer_impl(gsl::span<T, gsl::dynamic_range> dst, rsx::primitive_type draw_mode, const std::vector<std::pair<u32, u32> > &first_count_arguments)
{ {
u32 address = rsx::get_address(rsx::method_registers[NV4097_SET_INDEX_ARRAY_ADDRESS], rsx::method_registers[NV4097_SET_INDEX_ARRAY_DMA] & 0xf); u32 address = rsx::get_address(rsx::method_registers[NV4097_SET_INDEX_ARRAY_ADDRESS], rsx::method_registers[NV4097_SET_INDEX_ARRAY_DMA] & 0xf);
Index_array_type type = to_index_array_type(rsx::method_registers[NV4097_SET_INDEX_ARRAY_DMA] >> 4); rsx::index_array_type type = rsx::to_index_array_type(rsx::method_registers[NV4097_SET_INDEX_ARRAY_DMA] >> 4);
u32 type_size = gsl::narrow<u32>(get_index_type_size(type)); u32 type_size = gsl::narrow<u32>(get_index_type_size(type));
@ -362,40 +362,40 @@ std::tuple<T, T> write_index_array_data_to_buffer_impl(gsl::span<T, gsl::dynamic
u32 count = std::get<0>(first_count_arguments.back()) + std::get<1>(first_count_arguments.back()) - first; u32 count = std::get<0>(first_count_arguments.back()) + std::get<1>(first_count_arguments.back()) - first;
auto ptr = vm::ps3::_ptr<const T>(address + first * type_size); auto ptr = vm::ps3::_ptr<const T>(address + first * type_size);
switch (m_draw_mode) switch (draw_mode)
{ {
case Primitive_type::points: case rsx::primitive_type::points:
case Primitive_type::lines: case rsx::primitive_type::lines:
case Primitive_type::line_loop: case rsx::primitive_type::line_loop:
case Primitive_type::line_strip: case rsx::primitive_type::line_strip:
case Primitive_type::triangles: case rsx::primitive_type::triangles:
case Primitive_type::triangle_strip: case rsx::primitive_type::triangle_strip:
case Primitive_type::quad_strip: case rsx::primitive_type::quad_strip:
return upload_untouched<T>({ ptr, count }, dst, is_primitive_restart_enabled, primitive_restart_index); return upload_untouched<T>({ ptr, count }, dst, is_primitive_restart_enabled, primitive_restart_index);
case Primitive_type::polygon: case rsx::primitive_type::polygon:
case Primitive_type::triangle_fan: case rsx::primitive_type::triangle_fan:
return expand_indexed_triangle_fan<T>({ ptr, count }, dst, is_primitive_restart_enabled, primitive_restart_index); return expand_indexed_triangle_fan<T>({ ptr, count }, dst, is_primitive_restart_enabled, primitive_restart_index);
case Primitive_type::quads: case rsx::primitive_type::quads:
return expand_indexed_quads<T>({ ptr, count }, dst, is_primitive_restart_enabled, primitive_restart_index); return expand_indexed_quads<T>({ ptr, count }, dst, is_primitive_restart_enabled, primitive_restart_index);
} }
throw new EXCEPTION("Unknow draw mode"); throw new EXCEPTION("Unknow draw mode");
} }
std::tuple<u32, u32> write_index_array_data_to_buffer(gsl::span<u32, gsl::dynamic_range> dst, Primitive_type m_draw_mode, const std::vector<std::pair<u32, u32> > &first_count_arguments) std::tuple<u32, u32> write_index_array_data_to_buffer(gsl::span<u32, gsl::dynamic_range> dst, rsx::primitive_type draw_mode, const std::vector<std::pair<u32, u32> > &first_count_arguments)
{ {
return write_index_array_data_to_buffer_impl(dst, m_draw_mode, first_count_arguments); return write_index_array_data_to_buffer_impl(dst, draw_mode, first_count_arguments);
} }
std::tuple<u16, u16> write_index_array_data_to_buffer(gsl::span<u16, gsl::dynamic_range> dst, Primitive_type m_draw_mode, const std::vector<std::pair<u32, u32> > &first_count_arguments) std::tuple<u16, u16> write_index_array_data_to_buffer(gsl::span<u16, gsl::dynamic_range> dst, rsx::primitive_type draw_mode, const std::vector<std::pair<u32, u32> > &first_count_arguments)
{ {
return write_index_array_data_to_buffer_impl(dst, m_draw_mode, first_count_arguments); return write_index_array_data_to_buffer_impl(dst, draw_mode, first_count_arguments);
} }
std::tuple<u32, u32> write_index_array_data_to_buffer_untouched(gsl::span<u32, gsl::dynamic_range> dst, const std::vector<std::pair<u32, u32> > &first_count_arguments) std::tuple<u32, u32> write_index_array_data_to_buffer_untouched(gsl::span<u32, gsl::dynamic_range> dst, const std::vector<std::pair<u32, u32> > &first_count_arguments)
{ {
u32 address = rsx::get_address(rsx::method_registers[NV4097_SET_INDEX_ARRAY_ADDRESS], rsx::method_registers[NV4097_SET_INDEX_ARRAY_DMA] & 0xf); u32 address = rsx::get_address(rsx::method_registers[NV4097_SET_INDEX_ARRAY_ADDRESS], rsx::method_registers[NV4097_SET_INDEX_ARRAY_DMA] & 0xf);
Index_array_type type = to_index_array_type(rsx::method_registers[NV4097_SET_INDEX_ARRAY_DMA] >> 4); rsx::index_array_type type = rsx::to_index_array_type(rsx::method_registers[NV4097_SET_INDEX_ARRAY_DMA] >> 4);
u32 type_size = gsl::narrow<u32>(get_index_type_size(type)); u32 type_size = gsl::narrow<u32>(get_index_type_size(type));
bool is_primitive_restart_enabled = !!rsx::method_registers[NV4097_SET_RESTART_INDEX_ENABLE]; bool is_primitive_restart_enabled = !!rsx::method_registers[NV4097_SET_RESTART_INDEX_ENABLE];
@ -418,7 +418,7 @@ std::tuple<u32, u32> write_index_array_data_to_buffer_untouched(gsl::span<u32, g
std::tuple<u16, u16> write_index_array_data_to_buffer_untouched(gsl::span<u16, gsl::dynamic_range> dst, const std::vector<std::pair<u32, u32> > &first_count_arguments) std::tuple<u16, u16> write_index_array_data_to_buffer_untouched(gsl::span<u16, gsl::dynamic_range> dst, const std::vector<std::pair<u32, u32> > &first_count_arguments)
{ {
u32 address = rsx::get_address(rsx::method_registers[NV4097_SET_INDEX_ARRAY_ADDRESS], rsx::method_registers[NV4097_SET_INDEX_ARRAY_DMA] & 0xf); u32 address = rsx::get_address(rsx::method_registers[NV4097_SET_INDEX_ARRAY_ADDRESS], rsx::method_registers[NV4097_SET_INDEX_ARRAY_DMA] & 0xf);
Index_array_type type = to_index_array_type(rsx::method_registers[NV4097_SET_INDEX_ARRAY_DMA] >> 4); rsx::index_array_type type = rsx::to_index_array_type(rsx::method_registers[NV4097_SET_INDEX_ARRAY_DMA] >> 4);
u32 type_size = gsl::narrow<u32>(get_index_type_size(type)); u32 type_size = gsl::narrow<u32>(get_index_type_size(type));
bool is_primitive_restart_enabled = !!rsx::method_registers[NV4097_SET_RESTART_INDEX_ENABLE]; bool is_primitive_restart_enabled = !!rsx::method_registers[NV4097_SET_RESTART_INDEX_ENABLE];

View file

@ -11,25 +11,25 @@ void write_vertex_array_data_to_buffer(void *buffer, u32 first, u32 count, size_
/* /*
* If primitive mode is not supported and need to be emulated (using an index buffer) returns false. * If primitive mode is not supported and need to be emulated (using an index buffer) returns false.
*/ */
bool is_primitive_native(Primitive_type m_draw_mode); bool is_primitive_native(rsx::primitive_type m_draw_mode);
/** /**
* Returns a fixed index count for emulated primitive, otherwise returns initial_index_count * Returns a fixed index count for emulated primitive, otherwise returns initial_index_count
*/ */
size_t get_index_count(Primitive_type m_draw_mode, unsigned initial_index_count); size_t get_index_count(rsx::primitive_type m_draw_mode, unsigned initial_index_count);
/** /**
* Returns index type size in byte * Returns index type size in byte
*/ */
size_t get_index_type_size(Index_array_type type); size_t get_index_type_size(rsx::index_array_type type);
/** /**
* Write count indexes using (first, first + count) ranges. * Write count indexes using (first, first + count) ranges.
* Returns min/max index found during the process. * Returns min/max index found during the process.
* The function expands index buffer for non native primitive type. * The function expands index buffer for non native primitive type.
*/ */
std::tuple<u32, u32> write_index_array_data_to_buffer(gsl::span<u32, gsl::dynamic_range> dst, Primitive_type m_draw_mode, const std::vector<std::pair<u32, u32> > &first_count_arguments); std::tuple<u32, u32> write_index_array_data_to_buffer(gsl::span<u32, gsl::dynamic_range> dst, rsx::primitive_type draw_mode, const std::vector<std::pair<u32, u32> > &first_count_arguments);
std::tuple<u16, u16> write_index_array_data_to_buffer(gsl::span<u16, gsl::dynamic_range> dst, Primitive_type m_draw_mode, const std::vector<std::pair<u32, u32> > &first_count_arguments); std::tuple<u16, u16> write_index_array_data_to_buffer(gsl::span<u16, gsl::dynamic_range> dst, rsx::primitive_type draw_mode, const std::vector<std::pair<u32, u32> > &first_count_arguments);
/** /**
* Doesn't expand index * Doesn't expand index
@ -40,7 +40,7 @@ std::tuple<u16, u16> write_index_array_data_to_buffer_untouched(gsl::span<u16, g
/** /**
* Write index data needed to emulate non indexed non native primitive mode. * Write index data needed to emulate non indexed non native primitive mode.
*/ */
void write_index_array_for_non_indexed_non_native_primitive_to_buffer(char* dst, Primitive_type m_draw_mode, unsigned first, unsigned count); void write_index_array_for_non_indexed_non_native_primitive_to_buffer(char* dst, rsx::primitive_type draw_mode, unsigned first, unsigned count);
/** /**
* Stream a 128 bits vector to dst. * Stream a 128 bits vector to dst.

View file

@ -5,60 +5,60 @@ namespace rsx
{ {
namespace utility namespace utility
{ {
std::vector<u8> get_rtt_indexes(Surface_target color_target) std::vector<u8> get_rtt_indexes(surface_target color_target)
{ {
switch (color_target) switch (color_target)
{ {
case Surface_target::none: return{}; case surface_target::none: return{};
case Surface_target::surface_a: return{ 0 }; case surface_target::surface_a: return{ 0 };
case Surface_target::surface_b: return{ 1 }; case surface_target::surface_b: return{ 1 };
case Surface_target::surfaces_a_b: return{ 0, 1 }; case surface_target::surfaces_a_b: return{ 0, 1 };
case Surface_target::surfaces_a_b_c: return{ 0, 1, 2 }; case surface_target::surfaces_a_b_c: return{ 0, 1, 2 };
case Surface_target::surfaces_a_b_c_d: return{ 0, 1, 2, 3 }; case surface_target::surfaces_a_b_c_d: return{ 0, 1, 2, 3 };
} }
throw EXCEPTION("Wrong color_target"); throw EXCEPTION("Wrong color_target");
} }
size_t get_aligned_pitch(Surface_color_format format, u32 width) size_t get_aligned_pitch(surface_color_format format, u32 width)
{ {
switch (format) switch (format)
{ {
case Surface_color_format::b8: return align(width, 256); case surface_color_format::b8: return align(width, 256);
case Surface_color_format::g8b8: case surface_color_format::g8b8:
case Surface_color_format::x1r5g5b5_o1r5g5b5: case surface_color_format::x1r5g5b5_o1r5g5b5:
case Surface_color_format::x1r5g5b5_z1r5g5b5: case surface_color_format::x1r5g5b5_z1r5g5b5:
case Surface_color_format::r5g6b5: return align(width * 2, 256); case surface_color_format::r5g6b5: return align(width * 2, 256);
case Surface_color_format::a8b8g8r8: case surface_color_format::a8b8g8r8:
case Surface_color_format::x8b8g8r8_o8b8g8r8: case surface_color_format::x8b8g8r8_o8b8g8r8:
case Surface_color_format::x8b8g8r8_z8b8g8r8: case surface_color_format::x8b8g8r8_z8b8g8r8:
case Surface_color_format::x8r8g8b8_o8r8g8b8: case surface_color_format::x8r8g8b8_o8r8g8b8:
case Surface_color_format::x8r8g8b8_z8r8g8b8: case surface_color_format::x8r8g8b8_z8r8g8b8:
case Surface_color_format::x32: case surface_color_format::x32:
case Surface_color_format::a8r8g8b8: return align(width * 4, 256); case surface_color_format::a8r8g8b8: return align(width * 4, 256);
case Surface_color_format::w16z16y16x16: return align(width * 8, 256); case surface_color_format::w16z16y16x16: return align(width * 8, 256);
case Surface_color_format::w32z32y32x32: return align(width * 16, 256); case surface_color_format::w32z32y32x32: return align(width * 16, 256);
} }
throw EXCEPTION("Unknow color surface format"); throw EXCEPTION("Unknow color surface format");
} }
size_t get_packed_pitch(Surface_color_format format, u32 width) size_t get_packed_pitch(surface_color_format format, u32 width)
{ {
switch (format) switch (format)
{ {
case Surface_color_format::b8: return width; case surface_color_format::b8: return width;
case Surface_color_format::g8b8: case surface_color_format::g8b8:
case Surface_color_format::x1r5g5b5_o1r5g5b5: case surface_color_format::x1r5g5b5_o1r5g5b5:
case Surface_color_format::x1r5g5b5_z1r5g5b5: case surface_color_format::x1r5g5b5_z1r5g5b5:
case Surface_color_format::r5g6b5: return width * 2; case surface_color_format::r5g6b5: return width * 2;
case Surface_color_format::a8b8g8r8: case surface_color_format::a8b8g8r8:
case Surface_color_format::x8b8g8r8_o8b8g8r8: case surface_color_format::x8b8g8r8_o8b8g8r8:
case Surface_color_format::x8b8g8r8_z8b8g8r8: case surface_color_format::x8b8g8r8_z8b8g8r8:
case Surface_color_format::x8r8g8b8_o8r8g8b8: case surface_color_format::x8r8g8b8_o8r8g8b8:
case Surface_color_format::x8r8g8b8_z8r8g8b8: case surface_color_format::x8r8g8b8_z8r8g8b8:
case Surface_color_format::x32: case surface_color_format::x32:
case Surface_color_format::a8r8g8b8: return width * 4; case surface_color_format::a8r8g8b8: return width * 4;
case Surface_color_format::w16z16y16x16: return width * 8; case surface_color_format::w16z16y16x16: return width * 8;
case Surface_color_format::w32z32y32x32: return width * 16; case surface_color_format::w32z32y32x32: return width * 16;
} }
throw EXCEPTION("Unknow color surface format"); throw EXCEPTION("Unknow color surface format");
} }

View file

@ -7,9 +7,9 @@ namespace rsx
{ {
namespace utility namespace utility
{ {
std::vector<u8> get_rtt_indexes(Surface_target color_target); std::vector<u8> get_rtt_indexes(surface_target color_target);
size_t get_aligned_pitch(Surface_color_format format, u32 width); size_t get_aligned_pitch(surface_color_format format, u32 width);
size_t get_packed_pitch(Surface_color_format format, u32 width); size_t get_packed_pitch(surface_color_format format, u32 width);
} }
/** /**
@ -86,7 +86,7 @@ namespace rsx
gsl::not_null<surface_type> bind_address_as_render_targets( gsl::not_null<surface_type> bind_address_as_render_targets(
command_list_type command_list, command_list_type command_list,
u32 address, u32 address,
Surface_color_format surface_color_format, size_t width, size_t height, surface_color_format color_format, size_t width, size_t height,
Args&&... extra_params) Args&&... extra_params)
{ {
auto It = m_render_targets_storage.find(address); auto It = m_render_targets_storage.find(address);
@ -96,7 +96,7 @@ namespace rsx
if (It != m_render_targets_storage.end()) if (It != m_render_targets_storage.end())
{ {
surface_storage_type &rtt = It->second; surface_storage_type &rtt = It->second;
if (Traits::rtt_has_format_width_height(rtt, surface_color_format, width, height)) if (Traits::rtt_has_format_width_height(rtt, color_format, width, height))
{ {
Traits::prepare_rtt_for_drawing(command_list, Traits::get(rtt)); Traits::prepare_rtt_for_drawing(command_list, Traits::get(rtt));
return Traits::get(rtt); return Traits::get(rtt);
@ -105,7 +105,7 @@ namespace rsx
m_render_targets_storage.erase(address); m_render_targets_storage.erase(address);
} }
m_render_targets_storage[address] = Traits::create_new_surface(address, surface_color_format, width, height, std::forward<Args>(extra_params)...); m_render_targets_storage[address] = Traits::create_new_surface(address, color_format, width, height, std::forward<Args>(extra_params)...);
return Traits::get(m_render_targets_storage[address]); return Traits::get(m_render_targets_storage[address]);
} }
@ -113,14 +113,14 @@ namespace rsx
gsl::not_null<surface_type> bind_address_as_depth_stencil( gsl::not_null<surface_type> bind_address_as_depth_stencil(
command_list_type command_list, command_list_type command_list,
u32 address, u32 address,
Surface_depth_format surface_depth_format, size_t width, size_t height, surface_depth_format depth_format, size_t width, size_t height,
Args&&... extra_params) Args&&... extra_params)
{ {
auto It = m_depth_stencil_storage.find(address); auto It = m_depth_stencil_storage.find(address);
if (It != m_depth_stencil_storage.end()) if (It != m_depth_stencil_storage.end())
{ {
surface_storage_type &ds = It->second; surface_storage_type &ds = It->second;
if (Traits::ds_has_format_width_height(ds, surface_depth_format, width, height)) if (Traits::ds_has_format_width_height(ds, depth_format, width, height))
{ {
Traits::prepare_ds_for_drawing(command_list, Traits::get(ds)); Traits::prepare_ds_for_drawing(command_list, Traits::get(ds));
return Traits::get(ds); return Traits::get(ds);
@ -129,7 +129,7 @@ namespace rsx
m_depth_stencil_storage.erase(address); m_depth_stencil_storage.erase(address);
} }
m_depth_stencil_storage[address] = Traits::create_new_surface(address, surface_depth_format, width, height, std::forward<Args>(extra_params)...); m_depth_stencil_storage[address] = Traits::create_new_surface(address, depth_format, width, height, std::forward<Args>(extra_params)...);
return Traits::get(m_depth_stencil_storage[address]); return Traits::get(m_depth_stencil_storage[address]);
} }
public: public:
@ -142,7 +142,7 @@ namespace rsx
command_list_type command_list, command_list_type command_list,
u32 set_surface_format_reg, u32 set_surface_format_reg,
u32 clip_horizontal_reg, u32 clip_vertical_reg, u32 clip_horizontal_reg, u32 clip_vertical_reg,
Surface_target set_surface_target, surface_target set_surface_target,
const std::array<u32, 4> &surface_addresses, u32 address_z, const std::array<u32, 4> &surface_addresses, u32 address_z,
Args&&... extra_params) Args&&... extra_params)
{ {
@ -151,8 +151,8 @@ namespace rsx
u32 clip_x = clip_horizontal_reg; u32 clip_x = clip_horizontal_reg;
u32 clip_y = clip_vertical_reg; u32 clip_y = clip_vertical_reg;
Surface_color_format color_format = to_surface_color_format(set_surface_format_reg & 0x1f); surface_color_format color_format = to_surface_color_format(set_surface_format_reg & 0x1f);
Surface_depth_format depth_format = to_surface_depth_format((set_surface_format_reg >> 5) & 0x7); surface_depth_format depth_format = to_surface_depth_format((set_surface_format_reg >> 5) & 0x7);
// Make previous RTTs sampleable // Make previous RTTs sampleable
for (std::tuple<u32, surface_type> &rtt : m_bound_render_targets) for (std::tuple<u32, surface_type> &rtt : m_bound_render_targets)
@ -216,7 +216,7 @@ namespace rsx
*/ */
template <typename... Args> template <typename... Args>
std::array<std::vector<gsl::byte>, 4> get_render_targets_data( std::array<std::vector<gsl::byte>, 4> get_render_targets_data(
Surface_color_format surface_color_format, size_t width, size_t height, surface_color_format color_format, size_t width, size_t height,
Args&& ...args Args&& ...args
) )
{ {
@ -230,7 +230,7 @@ namespace rsx
surface_type surface_resource = std::get<1>(m_bound_render_targets[i]); surface_type surface_resource = std::get<1>(m_bound_render_targets[i]);
download_data[i] = std::move( download_data[i] = std::move(
Traits::issue_download_command(surface_resource, surface_color_format, width, height, std::forward<Args&&>(args)...) Traits::issue_download_command(surface_resource, color_format, width, height, std::forward<Args&&>(args)...)
); );
} }
@ -244,50 +244,50 @@ namespace rsx
gsl::span<const gsl::byte> raw_src = Traits::map_downloaded_buffer(download_data[i], std::forward<Args&&>(args)...); gsl::span<const gsl::byte> raw_src = Traits::map_downloaded_buffer(download_data[i], std::forward<Args&&>(args)...);
size_t src_pitch = utility::get_aligned_pitch(surface_color_format, gsl::narrow<u32>(width)); size_t src_pitch = utility::get_aligned_pitch(color_format, gsl::narrow<u32>(width));
size_t dst_pitch = utility::get_packed_pitch(surface_color_format, gsl::narrow<u32>(width)); size_t dst_pitch = utility::get_packed_pitch(color_format, gsl::narrow<u32>(width));
result[i].resize(dst_pitch * height); result[i].resize(dst_pitch * height);
// Note: MSVC + GSL doesn't support span<byte> -> span<T> for non const span atm // Note: MSVC + GSL doesn't support span<byte> -> span<T> for non const span atm
// thus manual conversion // thus manual conversion
switch (surface_color_format) switch (color_format)
{ {
case Surface_color_format::a8b8g8r8: case surface_color_format::a8b8g8r8:
case Surface_color_format::x8b8g8r8_o8b8g8r8: case surface_color_format::x8b8g8r8_o8b8g8r8:
case Surface_color_format::x8b8g8r8_z8b8g8r8: case surface_color_format::x8b8g8r8_z8b8g8r8:
case Surface_color_format::a8r8g8b8: case surface_color_format::a8r8g8b8:
case Surface_color_format::x8r8g8b8_o8r8g8b8: case surface_color_format::x8r8g8b8_o8r8g8b8:
case Surface_color_format::x8r8g8b8_z8r8g8b8: case surface_color_format::x8r8g8b8_z8r8g8b8:
case Surface_color_format::x32: case surface_color_format::x32:
{ {
gsl::span<be_t<u32>> dst_span{ (be_t<u32>*)result[i].data(), gsl::narrow<int>(dst_pitch * width / sizeof(be_t<u32>)) }; gsl::span<be_t<u32>> dst_span{ (be_t<u32>*)result[i].data(), gsl::narrow<int>(dst_pitch * width / sizeof(be_t<u32>)) };
copy_pitched_src_to_dst(dst_span, gsl::as_span<const u32>(raw_src), src_pitch, width, height); copy_pitched_src_to_dst(dst_span, gsl::as_span<const u32>(raw_src), src_pitch, width, height);
break; break;
} }
case Surface_color_format::b8: case surface_color_format::b8:
{ {
gsl::span<u8> dst_span{ (u8*)result[i].data(), gsl::narrow<int>(dst_pitch * width / sizeof(u8)) }; gsl::span<u8> dst_span{ (u8*)result[i].data(), gsl::narrow<int>(dst_pitch * width / sizeof(u8)) };
copy_pitched_src_to_dst(dst_span, gsl::as_span<const u8>(raw_src), src_pitch, width, height); copy_pitched_src_to_dst(dst_span, gsl::as_span<const u8>(raw_src), src_pitch, width, height);
break; break;
} }
case Surface_color_format::g8b8: case surface_color_format::g8b8:
case Surface_color_format::r5g6b5: case surface_color_format::r5g6b5:
case Surface_color_format::x1r5g5b5_o1r5g5b5: case surface_color_format::x1r5g5b5_o1r5g5b5:
case Surface_color_format::x1r5g5b5_z1r5g5b5: case surface_color_format::x1r5g5b5_z1r5g5b5:
{ {
gsl::span<be_t<u16>> dst_span{ (be_t<u16>*)result[i].data(), gsl::narrow<int>(dst_pitch * width / sizeof(be_t<u16>)) }; gsl::span<be_t<u16>> dst_span{ (be_t<u16>*)result[i].data(), gsl::narrow<int>(dst_pitch * width / sizeof(be_t<u16>)) };
copy_pitched_src_to_dst(dst_span, gsl::as_span<const u16>(raw_src), src_pitch, width, height); copy_pitched_src_to_dst(dst_span, gsl::as_span<const u16>(raw_src), src_pitch, width, height);
break; break;
} }
// Note : may require some big endian swap // Note : may require some big endian swap
case Surface_color_format::w32z32y32x32: case surface_color_format::w32z32y32x32:
{ {
gsl::span<u128> dst_span{ (u128*)result[i].data(), gsl::narrow<int>(dst_pitch * width / sizeof(u128)) }; gsl::span<u128> dst_span{ (u128*)result[i].data(), gsl::narrow<int>(dst_pitch * width / sizeof(u128)) };
copy_pitched_src_to_dst(dst_span, gsl::as_span<const u128>(raw_src), src_pitch, width, height); copy_pitched_src_to_dst(dst_span, gsl::as_span<const u128>(raw_src), src_pitch, width, height);
break; break;
} }
case Surface_color_format::w16z16y16x16: case surface_color_format::w16z16y16x16:
{ {
gsl::span<u64> dst_span{ (u64*)result[i].data(), gsl::narrow<int>(dst_pitch * width / sizeof(u64)) }; gsl::span<u64> dst_span{ (u64*)result[i].data(), gsl::narrow<int>(dst_pitch * width / sizeof(u64)) };
copy_pitched_src_to_dst(dst_span, gsl::as_span<const u64>(raw_src), src_pitch, width, height); copy_pitched_src_to_dst(dst_span, gsl::as_span<const u64>(raw_src), src_pitch, width, height);
@ -305,7 +305,7 @@ namespace rsx
*/ */
template <typename... Args> template <typename... Args>
std::array<std::vector<gsl::byte>, 2> get_depth_stencil_data( std::array<std::vector<gsl::byte>, 2> get_depth_stencil_data(
Surface_depth_format surface_depth_format, size_t width, size_t height, surface_depth_format depth_format, size_t width, size_t height,
Args&& ...args Args&& ...args
) )
{ {
@ -315,18 +315,18 @@ namespace rsx
size_t row_pitch = align(width * 4, 256); size_t row_pitch = align(width * 4, 256);
download_buffer_object stencil_data = {}; download_buffer_object stencil_data = {};
download_buffer_object depth_data = Traits::issue_depth_download_command(std::get<1>(m_bound_depth_stencil), surface_depth_format, width, height, std::forward<Args&&>(args)...); download_buffer_object depth_data = Traits::issue_depth_download_command(std::get<1>(m_bound_depth_stencil), depth_format, width, height, std::forward<Args&&>(args)...);
if (surface_depth_format == Surface_depth_format::z24s8) if (depth_format == surface_depth_format::z24s8)
stencil_data = std::move(Traits::issue_stencil_download_command(std::get<1>(m_bound_depth_stencil), width, height, std::forward<Args&&>(args)...)); stencil_data = std::move(Traits::issue_stencil_download_command(std::get<1>(m_bound_depth_stencil), width, height, std::forward<Args&&>(args)...));
gsl::span<const gsl::byte> depth_buffer_raw_src = Traits::map_downloaded_buffer(depth_data, std::forward<Args&&>(args)...); gsl::span<const gsl::byte> depth_buffer_raw_src = Traits::map_downloaded_buffer(depth_data, std::forward<Args&&>(args)...);
if (surface_depth_format == Surface_depth_format::z16) if (depth_format == surface_depth_format::z16)
{ {
result[0].resize(width * height * 2); result[0].resize(width * height * 2);
gsl::span<u16> dest{ (u16*)result[0].data(), gsl::narrow<int>(width * height) }; gsl::span<u16> dest{ (u16*)result[0].data(), gsl::narrow<int>(width * height) };
copy_pitched_src_to_dst(dest, gsl::as_span<const u16>(depth_buffer_raw_src), row_pitch, width, height); copy_pitched_src_to_dst(dest, gsl::as_span<const u16>(depth_buffer_raw_src), row_pitch, width, height);
} }
if (surface_depth_format == Surface_depth_format::z24s8) if (depth_format == surface_depth_format::z24s8)
{ {
result[0].resize(width * height * 4); result[0].resize(width * height * 4);
gsl::span<u32> dest{ (u32*)result[0].data(), gsl::narrow<int>(width * height) }; gsl::span<u32> dest{ (u32*)result[0].data(), gsl::narrow<int>(width * height) };
@ -334,7 +334,7 @@ namespace rsx
} }
Traits::unmap_downloaded_buffer(depth_data, std::forward<Args&&>(args)...); Traits::unmap_downloaded_buffer(depth_data, std::forward<Args&&>(args)...);
if (surface_depth_format == Surface_depth_format::z16) if (depth_format == surface_depth_format::z16)
return result; return result;
gsl::span<const gsl::byte> stencil_buffer_raw_src = Traits::map_downloaded_buffer(stencil_data, std::forward<Args&&>(args)...); gsl::span<const gsl::byte> stencil_buffer_raw_src = Traits::map_downloaded_buffer(stencil_data, std::forward<Args&&>(args)...);

View file

@ -13,7 +13,7 @@ std::vector<D3D12_VERTEX_BUFFER_VIEW> D3D12GSRender::upload_vertex_attributes(co
{ {
std::vector<D3D12_VERTEX_BUFFER_VIEW> vertex_buffer_views; std::vector<D3D12_VERTEX_BUFFER_VIEW> vertex_buffer_views;
m_IASet.clear(); m_ia_set.clear();
size_t input_slot = 0; size_t input_slot = 0;
size_t vertex_count = 0; size_t vertex_count = 0;
@ -55,7 +55,7 @@ std::vector<D3D12_VERTEX_BUFFER_VIEW> D3D12GSRender::upload_vertex_attributes(co
}; };
vertex_buffer_views.push_back(vertex_buffer_view); vertex_buffer_views.push_back(vertex_buffer_view);
m_timers.m_buffer_upload_size += buffer_size; m_timers.buffer_upload_size += buffer_size;
D3D12_INPUT_ELEMENT_DESC IAElement = {}; D3D12_INPUT_ELEMENT_DESC IAElement = {};
IAElement.SemanticName = "TEXCOORD"; IAElement.SemanticName = "TEXCOORD";
@ -65,7 +65,7 @@ std::vector<D3D12_VERTEX_BUFFER_VIEW> D3D12GSRender::upload_vertex_attributes(co
IAElement.AlignedByteOffset = 0; IAElement.AlignedByteOffset = 0;
IAElement.InputSlotClass = D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA; IAElement.InputSlotClass = D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA;
IAElement.InstanceDataStepRate = 0; IAElement.InstanceDataStepRate = 0;
m_IASet.push_back(IAElement); m_ia_set.push_back(IAElement);
} }
else if (register_vertex_info[index].size > 0) else if (register_vertex_info[index].size > 0)
{ {
@ -98,7 +98,7 @@ std::vector<D3D12_VERTEX_BUFFER_VIEW> D3D12GSRender::upload_vertex_attributes(co
IAElement.AlignedByteOffset = 0; IAElement.AlignedByteOffset = 0;
IAElement.InputSlotClass = D3D12_INPUT_CLASSIFICATION_PER_INSTANCE_DATA; IAElement.InputSlotClass = D3D12_INPUT_CLASSIFICATION_PER_INSTANCE_DATA;
IAElement.InstanceDataStepRate = 1; IAElement.InstanceDataStepRate = 1;
m_IASet.push_back(IAElement); m_ia_set.push_back(IAElement);
} }
} }
@ -141,7 +141,7 @@ void D3D12GSRender::upload_and_bind_scale_offset_matrix(size_t descriptorIndex)
}; };
m_device->CreateConstantBufferView(&constant_buffer_view_desc, m_device->CreateConstantBufferView(&constant_buffer_view_desc,
CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().descriptors_heap->GetCPUDescriptorHandleForHeapStart()) CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().descriptors_heap->GetCPUDescriptorHandleForHeapStart())
.Offset((INT)descriptorIndex, g_descriptor_stride_srv_cbv_uav)); .Offset((INT)descriptorIndex, m_descriptor_stride_srv_cbv_uav));
} }
void D3D12GSRender::upload_and_bind_vertex_shader_constants(size_t descriptor_index) void D3D12GSRender::upload_and_bind_vertex_shader_constants(size_t descriptor_index)
@ -160,13 +160,13 @@ void D3D12GSRender::upload_and_bind_vertex_shader_constants(size_t descriptor_in
}; };
m_device->CreateConstantBufferView(&constant_buffer_view_desc, m_device->CreateConstantBufferView(&constant_buffer_view_desc,
CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().descriptors_heap->GetCPUDescriptorHandleForHeapStart()) CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().descriptors_heap->GetCPUDescriptorHandleForHeapStart())
.Offset((INT)descriptor_index, g_descriptor_stride_srv_cbv_uav)); .Offset((INT)descriptor_index, m_descriptor_stride_srv_cbv_uav));
} }
void D3D12GSRender::upload_and_bind_fragment_shader_constants(size_t descriptor_index) void D3D12GSRender::upload_and_bind_fragment_shader_constants(size_t descriptor_index)
{ {
// Get constant from fragment program // Get constant from fragment program
size_t buffer_size = m_pso_cache.get_fragment_constants_buffer_size(fragment_program); size_t buffer_size = m_pso_cache.get_fragment_constants_buffer_size(m_fragment_program);
// Multiple of 256 never 0 // Multiple of 256 never 0
buffer_size = (buffer_size + 255) & ~255; buffer_size = (buffer_size + 255) & ~255;
@ -174,7 +174,7 @@ void D3D12GSRender::upload_and_bind_fragment_shader_constants(size_t descriptor_
size_t offset = 0; size_t offset = 0;
float *mapped_buffer = m_buffer_data.map<float>(CD3DX12_RANGE(heap_offset, heap_offset + buffer_size)); float *mapped_buffer = m_buffer_data.map<float>(CD3DX12_RANGE(heap_offset, heap_offset + buffer_size));
m_pso_cache.fill_fragment_constans_buffer({ mapped_buffer, gsl::narrow<int>(buffer_size) }, fragment_program); m_pso_cache.fill_fragment_constans_buffer({ mapped_buffer, gsl::narrow<int>(buffer_size) }, m_fragment_program);
m_buffer_data.unmap(CD3DX12_RANGE(heap_offset, heap_offset + buffer_size)); m_buffer_data.unmap(CD3DX12_RANGE(heap_offset, heap_offset + buffer_size));
D3D12_CONSTANT_BUFFER_VIEW_DESC constant_buffer_view_desc = { D3D12_CONSTANT_BUFFER_VIEW_DESC constant_buffer_view_desc = {
@ -183,14 +183,14 @@ void D3D12GSRender::upload_and_bind_fragment_shader_constants(size_t descriptor_
}; };
m_device->CreateConstantBufferView(&constant_buffer_view_desc, m_device->CreateConstantBufferView(&constant_buffer_view_desc,
CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().descriptors_heap->GetCPUDescriptorHandleForHeapStart()) CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().descriptors_heap->GetCPUDescriptorHandleForHeapStart())
.Offset((INT)descriptor_index, g_descriptor_stride_srv_cbv_uav)); .Offset((INT)descriptor_index, m_descriptor_stride_srv_cbv_uav));
} }
std::tuple<D3D12_VERTEX_BUFFER_VIEW, size_t> D3D12GSRender::upload_inlined_vertex_array() std::tuple<D3D12_VERTEX_BUFFER_VIEW, size_t> D3D12GSRender::upload_inlined_vertex_array()
{ {
UINT offset = 0; UINT offset = 0;
m_IASet.clear(); m_ia_set.clear();
// Bind attributes // Bind attributes
for (int index = 0; index < rsx::limits::vertex_count; ++index) for (int index = 0; index < rsx::limits::vertex_count; ++index)
{ {
@ -207,7 +207,7 @@ std::tuple<D3D12_VERTEX_BUFFER_VIEW, size_t> D3D12GSRender::upload_inlined_verte
IAElement.AlignedByteOffset = offset; IAElement.AlignedByteOffset = offset;
IAElement.InputSlotClass = D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA; IAElement.InputSlotClass = D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA;
IAElement.InstanceDataStepRate = 0; IAElement.InstanceDataStepRate = 0;
m_IASet.push_back(IAElement); m_ia_set.push_back(IAElement);
offset += rsx::get_vertex_type_size_on_host(info.type, info.size); offset += rsx::get_vertex_type_size_on_host(info.type, info.size);
} }
@ -260,7 +260,7 @@ std::tuple<D3D12_INDEX_BUFFER_VIEW, size_t> D3D12GSRender::generate_index_buffer
std::tuple<bool, size_t> D3D12GSRender::upload_and_set_vertex_index_data(ID3D12GraphicsCommandList *command_list) std::tuple<bool, size_t> D3D12GSRender::upload_and_set_vertex_index_data(ID3D12GraphicsCommandList *command_list)
{ {
if (draw_command == Draw_command::draw_command_inlined_array) if (draw_command == rsx::draw_command::inlined_array)
{ {
size_t vertex_count; size_t vertex_count;
D3D12_VERTEX_BUFFER_VIEW vertex_buffer_view; D3D12_VERTEX_BUFFER_VIEW vertex_buffer_view;
@ -277,7 +277,7 @@ std::tuple<bool, size_t> D3D12GSRender::upload_and_set_vertex_index_data(ID3D12G
return std::make_tuple(true, index_count); return std::make_tuple(true, index_count);
} }
if (draw_command == Draw_command::draw_command_array) if (draw_command == rsx::draw_command::array)
{ {
const std::vector<D3D12_VERTEX_BUFFER_VIEW> &vertex_buffer_views = upload_vertex_attributes(first_count_commands); const std::vector<D3D12_VERTEX_BUFFER_VIEW> &vertex_buffer_views = upload_vertex_attributes(first_count_commands);
command_list->IASetVertexBuffers(0, (UINT)vertex_buffer_views.size(), vertex_buffer_views.data()); command_list->IASetVertexBuffers(0, (UINT)vertex_buffer_views.size(), vertex_buffer_views.data());
@ -298,7 +298,7 @@ std::tuple<bool, size_t> D3D12GSRender::upload_and_set_vertex_index_data(ID3D12G
return std::make_tuple(true, index_count); return std::make_tuple(true, index_count);
} }
assert(draw_command == Draw_command::draw_command_indexed); assert(draw_command == rsx::draw_command::indexed);
// Index count // Index count
size_t index_count = 0; size_t index_count = 0;
@ -306,7 +306,7 @@ std::tuple<bool, size_t> D3D12GSRender::upload_and_set_vertex_index_data(ID3D12G
index_count += pair.second; index_count += pair.second;
index_count = get_index_count(draw_mode, gsl::narrow<int>(index_count)); index_count = get_index_count(draw_mode, gsl::narrow<int>(index_count));
Index_array_type indexed_type = to_index_array_type(rsx::method_registers[NV4097_SET_INDEX_ARRAY_DMA] >> 4); rsx::index_array_type indexed_type = rsx::to_index_array_type(rsx::method_registers[NV4097_SET_INDEX_ARRAY_DMA] >> 4);
size_t index_size = get_index_type_size(indexed_type); size_t index_size = get_index_type_size(indexed_type);
// Alloc // Alloc
@ -316,13 +316,13 @@ std::tuple<bool, size_t> D3D12GSRender::upload_and_set_vertex_index_data(ID3D12G
void *mapped_buffer = m_buffer_data.map<void>(CD3DX12_RANGE(heap_offset, heap_offset + buffer_size)); void *mapped_buffer = m_buffer_data.map<void>(CD3DX12_RANGE(heap_offset, heap_offset + buffer_size));
u32 min_index, max_index; u32 min_index, max_index;
if (indexed_type == Index_array_type::unsigned_16b) if (indexed_type == rsx::index_array_type::u16)
{ {
gsl::span<u16> dst = { (u16*)mapped_buffer, gsl::narrow<int>(buffer_size / index_size) }; gsl::span<u16> dst = { (u16*)mapped_buffer, gsl::narrow<int>(buffer_size / index_size) };
std::tie(min_index, max_index) = write_index_array_data_to_buffer(dst, draw_mode, first_count_commands); std::tie(min_index, max_index) = write_index_array_data_to_buffer(dst, draw_mode, first_count_commands);
} }
if (indexed_type == Index_array_type::unsigned_32b) if (indexed_type == rsx::index_array_type::u32)
{ {
gsl::span<u32> dst = { (u32*)mapped_buffer, gsl::narrow<int>(buffer_size / index_size) }; gsl::span<u32> dst = { (u32*)mapped_buffer, gsl::narrow<int>(buffer_size / index_size) };
std::tie(min_index, max_index) = write_index_array_data_to_buffer(dst, draw_mode, first_count_commands); std::tie(min_index, max_index) = write_index_array_data_to_buffer(dst, draw_mode, first_count_commands);
@ -334,7 +334,7 @@ std::tuple<bool, size_t> D3D12GSRender::upload_and_set_vertex_index_data(ID3D12G
(UINT)buffer_size, (UINT)buffer_size,
get_index_type(indexed_type) get_index_type(indexed_type)
}; };
m_timers.m_buffer_upload_size += buffer_size; m_timers.buffer_upload_size += buffer_size;
command_list->IASetIndexBuffer(&index_buffer_view); command_list->IASetIndexBuffer(&index_buffer_view);
const std::vector<D3D12_VERTEX_BUFFER_VIEW> &vertex_buffer_views = upload_vertex_attributes({ std::make_pair(0, max_index + 1) }); const std::vector<D3D12_VERTEX_BUFFER_VIEW> &vertex_buffer_views = upload_vertex_attributes({ std::make_pair(0, max_index + 1) });

View file

@ -262,99 +262,99 @@ D3D12_FILTER get_texture_filter(u8 min_filter, u8 mag_filter)
return D3D12_ENCODE_BASIC_FILTER(min, mag, mip, D3D12_FILTER_REDUCTION_TYPE_STANDARD); return D3D12_ENCODE_BASIC_FILTER(min, mag, mip, D3D12_FILTER_REDUCTION_TYPE_STANDARD);
} }
D3D12_PRIMITIVE_TOPOLOGY get_primitive_topology(Primitive_type draw_mode) D3D12_PRIMITIVE_TOPOLOGY get_primitive_topology(rsx::primitive_type draw_mode)
{ {
switch (draw_mode) switch (draw_mode)
{ {
case Primitive_type::points: return D3D_PRIMITIVE_TOPOLOGY_POINTLIST; case rsx::primitive_type::points: return D3D_PRIMITIVE_TOPOLOGY_POINTLIST;
case Primitive_type::lines: return D3D_PRIMITIVE_TOPOLOGY_LINELIST; case rsx::primitive_type::lines: return D3D_PRIMITIVE_TOPOLOGY_LINELIST;
case Primitive_type::line_loop: return D3D_PRIMITIVE_TOPOLOGY_LINELIST_ADJ; case rsx::primitive_type::line_loop: return D3D_PRIMITIVE_TOPOLOGY_LINELIST_ADJ;
case Primitive_type::line_strip: return D3D_PRIMITIVE_TOPOLOGY_LINESTRIP; case rsx::primitive_type::line_strip: return D3D_PRIMITIVE_TOPOLOGY_LINESTRIP;
case Primitive_type::triangles: return D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST; case rsx::primitive_type::triangles: return D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
case Primitive_type::triangle_strip: return D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP; case rsx::primitive_type::triangle_strip: return D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP;
case Primitive_type::triangle_fan: return D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST; case rsx::primitive_type::triangle_fan: return D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
case Primitive_type::quads: return D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST; case rsx::primitive_type::quads: return D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
case Primitive_type::quad_strip: return D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST; case rsx::primitive_type::quad_strip: return D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
case Primitive_type::polygon: return D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST; case rsx::primitive_type::polygon: return D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
} }
throw EXCEPTION("Invalid draw mode (0x%x)", draw_mode); throw EXCEPTION("Invalid draw mode (0x%x)", draw_mode);
} }
D3D12_PRIMITIVE_TOPOLOGY_TYPE get_primitive_topology_type(Primitive_type draw_mode) D3D12_PRIMITIVE_TOPOLOGY_TYPE get_primitive_topology_type(rsx::primitive_type draw_mode)
{ {
switch (draw_mode) switch (draw_mode)
{ {
case Primitive_type::points: return D3D12_PRIMITIVE_TOPOLOGY_TYPE_POINT; case rsx::primitive_type::points: return D3D12_PRIMITIVE_TOPOLOGY_TYPE_POINT;
case Primitive_type::lines: return D3D12_PRIMITIVE_TOPOLOGY_TYPE_LINE; case rsx::primitive_type::lines: return D3D12_PRIMITIVE_TOPOLOGY_TYPE_LINE;
case Primitive_type::line_strip: return D3D12_PRIMITIVE_TOPOLOGY_TYPE_LINE; case rsx::primitive_type::line_strip: return D3D12_PRIMITIVE_TOPOLOGY_TYPE_LINE;
case Primitive_type::triangles: return D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE; case rsx::primitive_type::triangles: return D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
case Primitive_type::triangle_strip: return D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE; case rsx::primitive_type::triangle_strip: return D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
case Primitive_type::triangle_fan: return D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE; case rsx::primitive_type::triangle_fan: return D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
case Primitive_type::quads: return D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE; case rsx::primitive_type::quads: return D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
case Primitive_type::quad_strip: return D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE; case rsx::primitive_type::quad_strip: return D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
case Primitive_type::polygon: return D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE; case rsx::primitive_type::polygon: return D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
case Primitive_type::line_loop: return D3D12_PRIMITIVE_TOPOLOGY_TYPE_LINE; case rsx::primitive_type::line_loop: return D3D12_PRIMITIVE_TOPOLOGY_TYPE_LINE;
} }
throw EXCEPTION("Invalid or unsupported draw mode (0x%x)", draw_mode); throw EXCEPTION("Invalid or unsupported draw mode (0x%x)", draw_mode);
} }
DXGI_FORMAT get_color_surface_format(Surface_color_format format) DXGI_FORMAT get_color_surface_format(rsx::surface_color_format format)
{ {
switch (format) switch (format)
{ {
case Surface_color_format::r5g6b5: return DXGI_FORMAT_B5G6R5_UNORM; case rsx::surface_color_format::r5g6b5: return DXGI_FORMAT_B5G6R5_UNORM;
case Surface_color_format::x8r8g8b8_o8r8g8b8: case rsx::surface_color_format::x8r8g8b8_o8r8g8b8:
case Surface_color_format::x8r8g8b8_z8r8g8b8: case rsx::surface_color_format::x8r8g8b8_z8r8g8b8:
case Surface_color_format::x8b8g8r8_o8b8g8r8: case rsx::surface_color_format::x8b8g8r8_o8b8g8r8:
case Surface_color_format::x8b8g8r8_z8b8g8r8: case rsx::surface_color_format::x8b8g8r8_z8b8g8r8:
return DXGI_FORMAT_B8G8R8X8_UNORM; //BIT.TRIP Runner2 use this return DXGI_FORMAT_B8G8R8X8_UNORM; //BIT.TRIP Runner2 use this
case Surface_color_format::a8b8g8r8: case rsx::surface_color_format::a8b8g8r8:
case Surface_color_format::a8r8g8b8: return DXGI_FORMAT_R8G8B8A8_UNORM; case rsx::surface_color_format::a8r8g8b8: return DXGI_FORMAT_R8G8B8A8_UNORM;
case Surface_color_format::b8: return DXGI_FORMAT_R8_UNORM; case rsx::surface_color_format::b8: return DXGI_FORMAT_R8_UNORM;
case Surface_color_format::g8b8: return DXGI_FORMAT_R8G8_UNORM; case rsx::surface_color_format::g8b8: return DXGI_FORMAT_R8G8_UNORM;
case Surface_color_format::w16z16y16x16: return DXGI_FORMAT_R16G16B16A16_FLOAT; case rsx::surface_color_format::w16z16y16x16: return DXGI_FORMAT_R16G16B16A16_FLOAT;
case Surface_color_format::w32z32y32x32: return DXGI_FORMAT_R32G32B32A32_FLOAT; case rsx::surface_color_format::w32z32y32x32: return DXGI_FORMAT_R32G32B32A32_FLOAT;
case Surface_color_format::x32: return DXGI_FORMAT_R32_FLOAT; case rsx::surface_color_format::x32: return DXGI_FORMAT_R32_FLOAT;
} }
throw EXCEPTION("Invalid format (0x%x)", format); throw EXCEPTION("Invalid format (0x%x)", format);
} }
DXGI_FORMAT get_depth_stencil_surface_format(Surface_depth_format format) DXGI_FORMAT get_depth_stencil_surface_format(rsx::surface_depth_format format)
{ {
switch (format) switch (format)
{ {
case Surface_depth_format::z16: return DXGI_FORMAT_D16_UNORM; case rsx::surface_depth_format::z16: return DXGI_FORMAT_D16_UNORM;
case Surface_depth_format::z24s8: return DXGI_FORMAT_D24_UNORM_S8_UINT; case rsx::surface_depth_format::z24s8: return DXGI_FORMAT_D24_UNORM_S8_UINT;
} }
throw EXCEPTION("Invalid format (0x%x)", format); throw EXCEPTION("Invalid format (0x%x)", format);
} }
DXGI_FORMAT get_depth_stencil_surface_clear_format(Surface_depth_format format) DXGI_FORMAT get_depth_stencil_surface_clear_format(rsx::surface_depth_format format)
{ {
switch (format) switch (format)
{ {
case Surface_depth_format::z16: return DXGI_FORMAT_D16_UNORM; case rsx::surface_depth_format::z16: return DXGI_FORMAT_D16_UNORM;
case Surface_depth_format::z24s8: return DXGI_FORMAT_D24_UNORM_S8_UINT; case rsx::surface_depth_format::z24s8: return DXGI_FORMAT_D24_UNORM_S8_UINT;
} }
throw EXCEPTION("Invalid format (0x%x)", format); throw EXCEPTION("Invalid format (0x%x)", format);
} }
DXGI_FORMAT get_depth_stencil_typeless_surface_format(Surface_depth_format format) DXGI_FORMAT get_depth_stencil_typeless_surface_format(rsx::surface_depth_format format)
{ {
switch (format) switch (format)
{ {
case Surface_depth_format::z16: return DXGI_FORMAT_R16_TYPELESS; case rsx::surface_depth_format::z16: return DXGI_FORMAT_R16_TYPELESS;
case Surface_depth_format::z24s8: return DXGI_FORMAT_R24G8_TYPELESS; case rsx::surface_depth_format::z24s8: return DXGI_FORMAT_R24G8_TYPELESS;
} }
throw EXCEPTION("Invalid format (0x%x)", format); throw EXCEPTION("Invalid format (0x%x)", format);
} }
DXGI_FORMAT get_depth_samplable_surface_format(Surface_depth_format format) DXGI_FORMAT get_depth_samplable_surface_format(rsx::surface_depth_format format)
{ {
switch (format) switch (format)
{ {
case Surface_depth_format::z16: return DXGI_FORMAT_R16_UNORM; case rsx::surface_depth_format::z16: return DXGI_FORMAT_R16_UNORM;
case Surface_depth_format::z24s8: return DXGI_FORMAT_R24_UNORM_X8_TYPELESS; case rsx::surface_depth_format::z24s8: return DXGI_FORMAT_R24_UNORM_X8_TYPELESS;
} }
throw EXCEPTION("Invalid format (0x%x)", format); throw EXCEPTION("Invalid format (0x%x)", format);
} }
@ -370,21 +370,21 @@ BOOL get_front_face_ccw(u32 ffv)
throw EXCEPTION("Invalid front face value (0x%x)", ffv); throw EXCEPTION("Invalid front face value (0x%x)", ffv);
} }
DXGI_FORMAT get_index_type(Index_array_type index_type) DXGI_FORMAT get_index_type(rsx::index_array_type index_type)
{ {
switch (index_type) switch (index_type)
{ {
case Index_array_type::unsigned_16b: return DXGI_FORMAT_R16_UINT; case rsx::index_array_type::u16: return DXGI_FORMAT_R16_UINT;
case Index_array_type::unsigned_32b: return DXGI_FORMAT_R32_UINT; case rsx::index_array_type::u32: return DXGI_FORMAT_R32_UINT;
} }
throw EXCEPTION("Invalid index_type (0x%x)", index_type); throw EXCEPTION("Invalid index_type (0x%x)", index_type);
} }
DXGI_FORMAT get_vertex_attribute_format(Vertex_base_type type, u8 size) DXGI_FORMAT get_vertex_attribute_format(rsx::vertex_base_type type, u8 size)
{ {
switch (type) switch (type)
{ {
case Vertex_base_type::s1: case rsx::vertex_base_type::s1:
{ {
switch (size) switch (size)
{ {
@ -395,7 +395,7 @@ DXGI_FORMAT get_vertex_attribute_format(Vertex_base_type type, u8 size)
} }
break; break;
} }
case Vertex_base_type::f: case rsx::vertex_base_type::f:
{ {
switch (size) switch (size)
{ {
@ -406,7 +406,7 @@ DXGI_FORMAT get_vertex_attribute_format(Vertex_base_type type, u8 size)
} }
break; break;
} }
case Vertex_base_type::sf: case rsx::vertex_base_type::sf:
{ {
switch (size) switch (size)
{ {
@ -417,7 +417,7 @@ DXGI_FORMAT get_vertex_attribute_format(Vertex_base_type type, u8 size)
} }
break; break;
} }
case Vertex_base_type::ub: case rsx::vertex_base_type::ub:
{ {
switch (size) switch (size)
{ {
@ -428,7 +428,7 @@ DXGI_FORMAT get_vertex_attribute_format(Vertex_base_type type, u8 size)
} }
break; break;
} }
case Vertex_base_type::s32k: case rsx::vertex_base_type::s32k:
{ {
switch (size) switch (size)
{ {
@ -439,7 +439,7 @@ DXGI_FORMAT get_vertex_attribute_format(Vertex_base_type type, u8 size)
} }
break; break;
} }
case Vertex_base_type::cmp: case rsx::vertex_base_type::cmp:
{ {
switch (size) switch (size)
{ {
@ -450,7 +450,7 @@ DXGI_FORMAT get_vertex_attribute_format(Vertex_base_type type, u8 size)
} }
break; break;
} }
case Vertex_base_type::ub256: case rsx::vertex_base_type::ub256:
{ {
switch (size) switch (size)
{ {

View file

@ -56,37 +56,37 @@ D3D12_FILTER get_texture_filter(u8 min_filter, u8 mag_filter);
/** /**
* Convert draw mode to D3D12_PRIMITIVE_TOPOLOGY * Convert draw mode to D3D12_PRIMITIVE_TOPOLOGY
*/ */
D3D12_PRIMITIVE_TOPOLOGY get_primitive_topology(Primitive_type draw_mode); D3D12_PRIMITIVE_TOPOLOGY get_primitive_topology(rsx::primitive_type draw_mode);
/** /**
* Convert draw mode to D3D12_PRIMITIVE_TOPOLOGY_TYPE * Convert draw mode to D3D12_PRIMITIVE_TOPOLOGY_TYPE
*/ */
D3D12_PRIMITIVE_TOPOLOGY_TYPE get_primitive_topology_type(Primitive_type draw_mode); D3D12_PRIMITIVE_TOPOLOGY_TYPE get_primitive_topology_type(rsx::primitive_type draw_mode);
/** /**
* Convert color surface format to DXGI_FORMAT * Convert color surface format to DXGI_FORMAT
*/ */
DXGI_FORMAT get_color_surface_format(Surface_color_format format); DXGI_FORMAT get_color_surface_format(rsx::surface_color_format format);
/** /**
* Convert depth stencil surface format to DXGI_FORMAT * Convert depth stencil surface format to DXGI_FORMAT
*/ */
DXGI_FORMAT get_depth_stencil_surface_format(Surface_depth_format format); DXGI_FORMAT get_depth_stencil_surface_format(rsx::surface_depth_format format);
/** /**
*Convert depth stencil surface format to DXGI_FORMAT suited for clear value *Convert depth stencil surface format to DXGI_FORMAT suited for clear value
*/ */
DXGI_FORMAT get_depth_stencil_surface_clear_format(Surface_depth_format format); DXGI_FORMAT get_depth_stencil_surface_clear_format(rsx::surface_depth_format format);
/** /**
* Convert depth surface format to a typeless DXGI_FORMAT * Convert depth surface format to a typeless DXGI_FORMAT
*/ */
DXGI_FORMAT get_depth_stencil_typeless_surface_format(Surface_depth_format format); DXGI_FORMAT get_depth_stencil_typeless_surface_format(rsx::surface_depth_format format);
/** /**
* Convert depth surface format to a DXGI_FORMAT that can be depth sampled * Convert depth surface format to a DXGI_FORMAT that can be depth sampled
*/ */
DXGI_FORMAT get_depth_samplable_surface_format(Surface_depth_format format); DXGI_FORMAT get_depth_samplable_surface_format(rsx::surface_depth_format format);
/** /**
* Convert front face value to bool value telling wheter front face is counterclockwise or not * Convert front face value to bool value telling wheter front face is counterclockwise or not
@ -96,12 +96,12 @@ BOOL get_front_face_ccw(u32 set_front_face_value);
/** /**
* Convert index type to DXGI_FORMAT * Convert index type to DXGI_FORMAT
*/ */
DXGI_FORMAT get_index_type(Index_array_type index_type); DXGI_FORMAT get_index_type(rsx::index_array_type index_type);
/** /**
* Convert vertex attribute format and size to DXGI_FORMAT * Convert vertex attribute format and size to DXGI_FORMAT
*/ */
DXGI_FORMAT get_vertex_attribute_format(Vertex_base_type type, u8 size); DXGI_FORMAT get_vertex_attribute_format(rsx::vertex_base_type type, u8 size);
/** /**
* Convert scissor register value to D3D12_RECT * Convert scissor register value to D3D12_RECT

View file

@ -58,17 +58,15 @@ void wait_for_command_queue(ID3D12Device *device, ID3D12CommandQueue *command_qu
} }
} }
void D3D12GSRender::Shader::Release() void D3D12GSRender::shader::release()
{ {
m_PSO->Release(); pso->Release();
m_rootSignature->Release(); root_signature->Release();
m_vertexBuffer->Release(); vertex_buffer->Release();
m_textureDescriptorHeap->Release(); texture_descriptor_heap->Release();
m_samplerDescriptorHeap->Release(); sampler_descriptor_heap->Release();
} }
extern std::function<bool(u32 addr)> gfxHandler;
bool D3D12GSRender::invalidate_address(u32 addr) bool D3D12GSRender::invalidate_address(u32 addr)
{ {
bool result = false; bool result = false;
@ -89,12 +87,6 @@ D3D12DLLManagement::~D3D12DLLManagement()
D3D12GSRender::D3D12GSRender() D3D12GSRender::D3D12GSRender()
: GSRender(frame_type::DX12), m_d3d12_lib(), m_current_pso({}) : GSRender(frame_type::DX12), m_d3d12_lib(), m_current_pso({})
{ {
gfxHandler = [this](u32 addr) {
bool result = invalidate_address(addr);
if (result)
LOG_WARNING(RSX, "Reporting Cell writing to 0x%x", addr);
return result;
};
if (rpcs3::config.rsx.d3d12.debug_output.value()) if (rpcs3::config.rsx.d3d12.debug_output.value())
{ {
Microsoft::WRL::ComPtr<ID3D12Debug> debugInterface; Microsoft::WRL::ComPtr<ID3D12Debug> debugInterface;
@ -113,10 +105,10 @@ D3D12GSRender::D3D12GSRender()
D3D12_COMMAND_QUEUE_DESC graphic_queue_desc = { D3D12_COMMAND_LIST_TYPE_DIRECT }; D3D12_COMMAND_QUEUE_DESC graphic_queue_desc = { D3D12_COMMAND_LIST_TYPE_DIRECT };
CHECK_HRESULT(m_device->CreateCommandQueue(&graphic_queue_desc, IID_PPV_ARGS(m_command_queue.GetAddressOf()))); CHECK_HRESULT(m_device->CreateCommandQueue(&graphic_queue_desc, IID_PPV_ARGS(m_command_queue.GetAddressOf())));
g_descriptor_stride_srv_cbv_uav = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); m_descriptor_stride_srv_cbv_uav = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
g_descriptor_stride_dsv = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_DSV); m_descriptor_stride_dsv = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_DSV);
g_descriptor_stride_rtv = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV); m_descriptor_stride_rtv = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
g_descriptor_stride_samplers = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER); m_descriptor_stride_samplers = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER);
// Create swap chain and put them in a descriptor heap as rendertarget // Create swap chain and put them in a descriptor heap as rendertarget
DXGI_SWAP_CHAIN_DESC swap_chain = {}; DXGI_SWAP_CHAIN_DESC swap_chain = {};
@ -177,8 +169,8 @@ D3D12GSRender::D3D12GSRender()
m_per_frame_storage[1].init(m_device.Get()); m_per_frame_storage[1].init(m_device.Get());
m_per_frame_storage[1].reset(); m_per_frame_storage[1].reset();
initConvertShader(); init_convert_shader();
m_output_scaling_pass.Init(m_device.Get(), m_command_queue.Get()); m_output_scaling_pass.init(m_device.Get(), m_command_queue.Get());
CHECK_HRESULT( CHECK_HRESULT(
m_device->CreateCommittedResource( m_device->CreateCommittedResource(
@ -204,13 +196,12 @@ D3D12GSRender::~D3D12GSRender()
m_texture_cache.unprotect_all(); m_texture_cache.unprotect_all();
gfxHandler = [this](u32) { return false; };
m_dummy_texture->Release(); m_dummy_texture->Release();
m_convertPSO->Release(); m_convert_pso->Release();
m_convertRootSignature->Release(); m_convert_root_signature->Release();
m_per_frame_storage[0].release(); m_per_frame_storage[0].release();
m_per_frame_storage[1].release(); m_per_frame_storage[1].release();
m_output_scaling_pass.Release(); m_output_scaling_pass.release();
release_d2d_structures(); release_d2d_structures();
} }
@ -246,7 +237,7 @@ void D3D12GSRender::end()
prepare_render_targets(get_current_resource_storage().command_list.Get()); prepare_render_targets(get_current_resource_storage().command_list.Get());
std::chrono::time_point<std::chrono::system_clock> rtt_duration_end = std::chrono::system_clock::now(); std::chrono::time_point<std::chrono::system_clock> rtt_duration_end = std::chrono::system_clock::now();
m_timers.m_prepare_rtt_duration += std::chrono::duration_cast<std::chrono::microseconds>(rtt_duration_end - rtt_duration_start).count(); m_timers.prepare_rtt_duration += std::chrono::duration_cast<std::chrono::microseconds>(rtt_duration_end - rtt_duration_start).count();
std::chrono::time_point<std::chrono::system_clock> vertex_index_duration_start = std::chrono::system_clock::now(); std::chrono::time_point<std::chrono::system_clock> vertex_index_duration_start = std::chrono::system_clock::now();
@ -255,12 +246,12 @@ void D3D12GSRender::end()
std::tie(indexed_draw, vertex_count) = upload_and_set_vertex_index_data(get_current_resource_storage().command_list.Get()); std::tie(indexed_draw, vertex_count) = upload_and_set_vertex_index_data(get_current_resource_storage().command_list.Get());
std::chrono::time_point<std::chrono::system_clock> vertex_index_duration_end = std::chrono::system_clock::now(); std::chrono::time_point<std::chrono::system_clock> vertex_index_duration_end = std::chrono::system_clock::now();
m_timers.m_vertex_index_duration += std::chrono::duration_cast<std::chrono::microseconds>(vertex_index_duration_end - vertex_index_duration_start).count(); m_timers.vertex_index_duration += std::chrono::duration_cast<std::chrono::microseconds>(vertex_index_duration_end - vertex_index_duration_start).count();
std::chrono::time_point<std::chrono::system_clock> program_load_start = std::chrono::system_clock::now(); std::chrono::time_point<std::chrono::system_clock> program_load_start = std::chrono::system_clock::now();
load_program(); load_program();
std::chrono::time_point<std::chrono::system_clock> program_load_end = std::chrono::system_clock::now(); std::chrono::time_point<std::chrono::system_clock> program_load_end = std::chrono::system_clock::now();
m_timers.m_program_load_duration += std::chrono::duration_cast<std::chrono::microseconds>(program_load_end - program_load_start).count(); m_timers.program_load_duration += std::chrono::duration_cast<std::chrono::microseconds>(program_load_end - program_load_start).count();
get_current_resource_storage().command_list->SetGraphicsRootSignature(m_root_signatures[std::get<2>(m_current_pso)].Get()); get_current_resource_storage().command_list->SetGraphicsRootSignature(m_root_signatures[std::get<2>(m_current_pso)].Get());
get_current_resource_storage().command_list->OMSetStencilRef(rsx::method_registers[NV4097_SET_STENCIL_FUNC_REF]); get_current_resource_storage().command_list->OMSetStencilRef(rsx::method_registers[NV4097_SET_STENCIL_FUNC_REF]);
@ -274,7 +265,7 @@ void D3D12GSRender::end()
upload_and_bind_fragment_shader_constants(currentDescriptorIndex + 2); upload_and_bind_fragment_shader_constants(currentDescriptorIndex + 2);
std::chrono::time_point<std::chrono::system_clock> constants_duration_end = std::chrono::system_clock::now(); std::chrono::time_point<std::chrono::system_clock> constants_duration_end = std::chrono::system_clock::now();
m_timers.m_constants_duration += std::chrono::duration_cast<std::chrono::microseconds>(constants_duration_end - constants_duration_start).count(); m_timers.constants_duration += std::chrono::duration_cast<std::chrono::microseconds>(constants_duration_end - constants_duration_start).count();
get_current_resource_storage().command_list->SetPipelineState(std::get<0>(m_current_pso).Get()); get_current_resource_storage().command_list->SetPipelineState(std::get<0>(m_current_pso).Get());
@ -286,11 +277,11 @@ void D3D12GSRender::end()
get_current_resource_storage().command_list->SetGraphicsRootDescriptorTable(0, get_current_resource_storage().command_list->SetGraphicsRootDescriptorTable(0,
CD3DX12_GPU_DESCRIPTOR_HANDLE(get_current_resource_storage().descriptors_heap->GetGPUDescriptorHandleForHeapStart()) CD3DX12_GPU_DESCRIPTOR_HANDLE(get_current_resource_storage().descriptors_heap->GetGPUDescriptorHandleForHeapStart())
.Offset((INT)currentDescriptorIndex, g_descriptor_stride_srv_cbv_uav) .Offset((INT)currentDescriptorIndex, m_descriptor_stride_srv_cbv_uav)
); );
get_current_resource_storage().command_list->SetGraphicsRootDescriptorTable(1, get_current_resource_storage().command_list->SetGraphicsRootDescriptorTable(1,
CD3DX12_GPU_DESCRIPTOR_HANDLE(get_current_resource_storage().sampler_descriptor_heap[get_current_resource_storage().sampler_descriptors_heap_index]->GetGPUDescriptorHandleForHeapStart()) CD3DX12_GPU_DESCRIPTOR_HANDLE(get_current_resource_storage().sampler_descriptor_heap[get_current_resource_storage().sampler_descriptors_heap_index]->GetGPUDescriptorHandleForHeapStart())
.Offset((INT)get_current_resource_storage().current_sampler_index, g_descriptor_stride_samplers) .Offset((INT)get_current_resource_storage().current_sampler_index, m_descriptor_stride_samplers)
); );
get_current_resource_storage().current_sampler_index += std::get<2>(m_current_pso); get_current_resource_storage().current_sampler_index += std::get<2>(m_current_pso);
@ -301,13 +292,13 @@ void D3D12GSRender::end()
get_current_resource_storage().command_list->SetDescriptorHeaps(1, get_current_resource_storage().descriptors_heap.GetAddressOf()); get_current_resource_storage().command_list->SetDescriptorHeaps(1, get_current_resource_storage().descriptors_heap.GetAddressOf());
get_current_resource_storage().command_list->SetGraphicsRootDescriptorTable(0, get_current_resource_storage().command_list->SetGraphicsRootDescriptorTable(0,
CD3DX12_GPU_DESCRIPTOR_HANDLE(get_current_resource_storage().descriptors_heap->GetGPUDescriptorHandleForHeapStart()) CD3DX12_GPU_DESCRIPTOR_HANDLE(get_current_resource_storage().descriptors_heap->GetGPUDescriptorHandleForHeapStart())
.Offset((INT)currentDescriptorIndex, g_descriptor_stride_srv_cbv_uav) .Offset((INT)currentDescriptorIndex, m_descriptor_stride_srv_cbv_uav)
); );
get_current_resource_storage().descriptors_heap_index += 3; get_current_resource_storage().descriptors_heap_index += 3;
} }
std::chrono::time_point<std::chrono::system_clock> texture_duration_end = std::chrono::system_clock::now(); std::chrono::time_point<std::chrono::system_clock> texture_duration_end = std::chrono::system_clock::now();
m_timers.m_texture_duration += std::chrono::duration_cast<std::chrono::microseconds>(texture_duration_end - texture_duration_start).count(); m_timers.texture_duration += std::chrono::duration_cast<std::chrono::microseconds>(texture_duration_end - texture_duration_start).count();
set_rtt_and_ds(get_current_resource_storage().command_list.Get()); set_rtt_and_ds(get_current_resource_storage().command_list.Get());
int clip_w = rsx::method_registers[NV4097_SET_SURFACE_CLIP_HORIZONTAL] >> 16; int clip_w = rsx::method_registers[NV4097_SET_SURFACE_CLIP_HORIZONTAL] >> 16;
@ -334,8 +325,8 @@ void D3D12GSRender::end()
get_current_resource_storage().command_list->DrawInstanced((UINT)vertex_count, 1, 0, 0); get_current_resource_storage().command_list->DrawInstanced((UINT)vertex_count, 1, 0, 0);
std::chrono::time_point<std::chrono::system_clock> end_duration = std::chrono::system_clock::now(); std::chrono::time_point<std::chrono::system_clock> end_duration = std::chrono::system_clock::now();
m_timers.m_draw_calls_duration += std::chrono::duration_cast<std::chrono::microseconds>(end_duration - start_duration).count(); m_timers.draw_calls_duration += std::chrono::duration_cast<std::chrono::microseconds>(end_duration - start_duration).count();
m_timers.m_draw_calls_count++; m_timers.draw_calls_count++;
if (rpcs3::config.rsx.d3d12.debug_output.value()) if (rpcs3::config.rsx.d3d12.debug_output.value())
{ {
@ -348,17 +339,17 @@ void D3D12GSRender::end()
namespace namespace
{ {
bool is_flip_surface_in_global_memory(Surface_target color_target) bool is_flip_surface_in_global_memory(rsx::surface_target color_target)
{ {
switch (color_target) switch (color_target)
{ {
case Surface_target::surface_a: case rsx::surface_target::surface_a:
case Surface_target::surface_b: case rsx::surface_target::surface_b:
case Surface_target::surfaces_a_b: case rsx::surface_target::surfaces_a_b:
case Surface_target::surfaces_a_b_c: case rsx::surface_target::surfaces_a_b_c:
case Surface_target::surfaces_a_b_c_d: case rsx::surface_target::surfaces_a_b_c_d:
return true; return true;
case Surface_target::none: case rsx::surface_target::none:
return false; return false;
} }
throw EXCEPTION("Wrong color_target"); throw EXCEPTION("Wrong color_target");
@ -370,7 +361,7 @@ void D3D12GSRender::flip(int buffer)
ID3D12Resource *resource_to_flip; ID3D12Resource *resource_to_flip;
float viewport_w, viewport_h; float viewport_w, viewport_h;
if (!is_flip_surface_in_global_memory(to_surface_target(rsx::method_registers[NV4097_SET_SURFACE_COLOR_TARGET]))) if (!is_flip_surface_in_global_memory(rsx::to_surface_target(rsx::method_registers[NV4097_SET_SURFACE_COLOR_TARGET])))
{ {
resource_storage &storage = get_current_resource_storage(); resource_storage &storage = get_current_resource_storage();
assert(storage.ram_framebuffer == nullptr); assert(storage.ram_framebuffer == nullptr);
@ -451,15 +442,15 @@ void D3D12GSRender::flip(int buffer)
(LONG)m_backbuffer[m_swap_chain->GetCurrentBackBufferIndex()]->GetDesc().Height, (LONG)m_backbuffer[m_swap_chain->GetCurrentBackBufferIndex()]->GetDesc().Height,
}; };
get_current_resource_storage().command_list->RSSetScissorRects(1, &box); get_current_resource_storage().command_list->RSSetScissorRects(1, &box);
get_current_resource_storage().command_list->SetGraphicsRootSignature(m_output_scaling_pass.m_rootSignature); get_current_resource_storage().command_list->SetGraphicsRootSignature(m_output_scaling_pass.root_signature);
get_current_resource_storage().command_list->SetPipelineState(m_output_scaling_pass.m_PSO); get_current_resource_storage().command_list->SetPipelineState(m_output_scaling_pass.pso);
D3D12_SHADER_RESOURCE_VIEW_DESC shader_resource_view_desc = {}; D3D12_SHADER_RESOURCE_VIEW_DESC shader_resource_view_desc = {};
// FIXME: Not always true // FIXME: Not always true
shader_resource_view_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; shader_resource_view_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
shader_resource_view_desc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D; shader_resource_view_desc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
shader_resource_view_desc.Texture2D.MipLevels = 1; shader_resource_view_desc.Texture2D.MipLevels = 1;
if (is_flip_surface_in_global_memory(to_surface_target(rsx::method_registers[NV4097_SET_SURFACE_COLOR_TARGET]))) if (is_flip_surface_in_global_memory(rsx::to_surface_target(rsx::method_registers[NV4097_SET_SURFACE_COLOR_TARGET])))
shader_resource_view_desc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; shader_resource_view_desc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
else else
shader_resource_view_desc.Shader4ComponentMapping = D3D12_ENCODE_SHADER_4_COMPONENT_MAPPING( shader_resource_view_desc.Shader4ComponentMapping = D3D12_ENCODE_SHADER_4_COMPONENT_MAPPING(
@ -469,7 +460,7 @@ void D3D12GSRender::flip(int buffer)
D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_0 D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_0
); );
m_device->CreateShaderResourceView(resource_to_flip, &shader_resource_view_desc, m_device->CreateShaderResourceView(resource_to_flip, &shader_resource_view_desc,
CD3DX12_CPU_DESCRIPTOR_HANDLE(m_output_scaling_pass.m_textureDescriptorHeap->GetCPUDescriptorHandleForHeapStart()).Offset(m_swap_chain->GetCurrentBackBufferIndex(), g_descriptor_stride_srv_cbv_uav)); CD3DX12_CPU_DESCRIPTOR_HANDLE(m_output_scaling_pass.texture_descriptor_heap->GetCPUDescriptorHandleForHeapStart()).Offset(m_swap_chain->GetCurrentBackBufferIndex(), m_descriptor_stride_srv_cbv_uav));
D3D12_SAMPLER_DESC sampler_desc = {}; D3D12_SAMPLER_DESC sampler_desc = {};
sampler_desc.Filter = D3D12_FILTER_MIN_MAG_LINEAR_MIP_POINT; sampler_desc.Filter = D3D12_FILTER_MIN_MAG_LINEAR_MIP_POINT;
@ -477,24 +468,24 @@ void D3D12GSRender::flip(int buffer)
sampler_desc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP; sampler_desc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
sampler_desc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP; sampler_desc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
m_device->CreateSampler(&sampler_desc, m_device->CreateSampler(&sampler_desc,
CD3DX12_CPU_DESCRIPTOR_HANDLE(m_output_scaling_pass.m_samplerDescriptorHeap->GetCPUDescriptorHandleForHeapStart()).Offset(m_swap_chain->GetCurrentBackBufferIndex(), g_descriptor_stride_samplers)); CD3DX12_CPU_DESCRIPTOR_HANDLE(m_output_scaling_pass.sampler_descriptor_heap->GetCPUDescriptorHandleForHeapStart()).Offset(m_swap_chain->GetCurrentBackBufferIndex(), m_descriptor_stride_samplers));
ID3D12DescriptorHeap *descriptors_heaps[] = ID3D12DescriptorHeap *descriptors_heaps[] =
{ {
m_output_scaling_pass.m_textureDescriptorHeap, m_output_scaling_pass.texture_descriptor_heap,
m_output_scaling_pass.m_samplerDescriptorHeap m_output_scaling_pass.sampler_descriptor_heap
}; };
get_current_resource_storage().command_list->SetDescriptorHeaps(2, descriptors_heaps); get_current_resource_storage().command_list->SetDescriptorHeaps(2, descriptors_heaps);
get_current_resource_storage().command_list->SetGraphicsRootDescriptorTable(0, get_current_resource_storage().command_list->SetGraphicsRootDescriptorTable(0,
CD3DX12_GPU_DESCRIPTOR_HANDLE(m_output_scaling_pass.m_textureDescriptorHeap->GetGPUDescriptorHandleForHeapStart()).Offset(m_swap_chain->GetCurrentBackBufferIndex(), g_descriptor_stride_srv_cbv_uav)); CD3DX12_GPU_DESCRIPTOR_HANDLE(m_output_scaling_pass.texture_descriptor_heap->GetGPUDescriptorHandleForHeapStart()).Offset(m_swap_chain->GetCurrentBackBufferIndex(), m_descriptor_stride_srv_cbv_uav));
get_current_resource_storage().command_list->SetGraphicsRootDescriptorTable(1, get_current_resource_storage().command_list->SetGraphicsRootDescriptorTable(1,
CD3DX12_GPU_DESCRIPTOR_HANDLE(m_output_scaling_pass.m_samplerDescriptorHeap->GetGPUDescriptorHandleForHeapStart()).Offset(m_swap_chain->GetCurrentBackBufferIndex(), g_descriptor_stride_samplers)); CD3DX12_GPU_DESCRIPTOR_HANDLE(m_output_scaling_pass.sampler_descriptor_heap->GetGPUDescriptorHandleForHeapStart()).Offset(m_swap_chain->GetCurrentBackBufferIndex(), m_descriptor_stride_samplers));
get_current_resource_storage().command_list->OMSetRenderTargets(1, get_current_resource_storage().command_list->OMSetRenderTargets(1,
&CD3DX12_CPU_DESCRIPTOR_HANDLE(m_backbuffer_descriptor_heap[m_swap_chain->GetCurrentBackBufferIndex()]->GetCPUDescriptorHandleForHeapStart()), &CD3DX12_CPU_DESCRIPTOR_HANDLE(m_backbuffer_descriptor_heap[m_swap_chain->GetCurrentBackBufferIndex()]->GetCPUDescriptorHandleForHeapStart()),
true, nullptr); true, nullptr);
D3D12_VERTEX_BUFFER_VIEW vertex_buffer_view = {}; D3D12_VERTEX_BUFFER_VIEW vertex_buffer_view = {};
vertex_buffer_view.BufferLocation = m_output_scaling_pass.m_vertexBuffer->GetGPUVirtualAddress(); vertex_buffer_view.BufferLocation = m_output_scaling_pass.vertex_buffer->GetGPUVirtualAddress();
vertex_buffer_view.StrideInBytes = 4 * sizeof(float); vertex_buffer_view.StrideInBytes = 4 * sizeof(float);
vertex_buffer_view.SizeInBytes = 16 * sizeof(float); vertex_buffer_view.SizeInBytes = 16 * sizeof(float);
get_current_resource_storage().command_list->IASetVertexBuffers(0, 1, &vertex_buffer_view); get_current_resource_storage().command_list->IASetVertexBuffers(0, 1, &vertex_buffer_view);
@ -504,7 +495,7 @@ void D3D12GSRender::flip(int buffer)
if (!rpcs3::config.rsx.d3d12.overlay.value()) if (!rpcs3::config.rsx.d3d12.overlay.value())
get_current_resource_storage().command_list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_backbuffer[m_swap_chain->GetCurrentBackBufferIndex()].Get(), D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PRESENT)); get_current_resource_storage().command_list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_backbuffer[m_swap_chain->GetCurrentBackBufferIndex()].Get(), D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PRESENT));
if (is_flip_surface_in_global_memory(to_surface_target(rsx::method_registers[NV4097_SET_SURFACE_COLOR_TARGET])) && resource_to_flip != nullptr) if (is_flip_surface_in_global_memory(rsx::to_surface_target(rsx::method_registers[NV4097_SET_SURFACE_COLOR_TARGET])) && resource_to_flip != nullptr)
get_current_resource_storage().command_list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(resource_to_flip, D3D12_RESOURCE_STATE_GENERIC_READ, D3D12_RESOURCE_STATE_RENDER_TARGET)); get_current_resource_storage().command_list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(resource_to_flip, D3D12_RESOURCE_STATE_GENERIC_READ, D3D12_RESOURCE_STATE_RENDER_TARGET));
CHECK_HRESULT(get_current_resource_storage().command_list->Close()); CHECK_HRESULT(get_current_resource_storage().command_list->Close());
m_command_queue->ExecuteCommandLists(1, (ID3D12CommandList**)get_current_resource_storage().command_list.GetAddressOf()); m_command_queue->ExecuteCommandLists(1, (ID3D12CommandList**)get_current_resource_storage().command_list.GetAddressOf());
@ -549,20 +540,36 @@ void D3D12GSRender::flip(int buffer)
std::chrono::time_point<std::chrono::system_clock> flip_end = std::chrono::system_clock::now(); std::chrono::time_point<std::chrono::system_clock> flip_end = std::chrono::system_clock::now();
m_timers.m_flip_duration += std::chrono::duration_cast<std::chrono::microseconds>(flip_end - flip_start).count(); m_timers.flip_duration += std::chrono::duration_cast<std::chrono::microseconds>(flip_end - flip_start).count();
}
bool D3D12GSRender::on_access_violation(u32 address, bool is_writing)
{
if (!is_writing)
{
return false;
}
if (invalidate_address(address))
{
LOG_WARNING(RSX, "Reporting Cell writing to 0x%x", address);
return true;
}
return false;
} }
void D3D12GSRender::reset_timer() void D3D12GSRender::reset_timer()
{ {
m_timers.m_draw_calls_count = 0; m_timers.draw_calls_count = 0;
m_timers.m_draw_calls_duration = 0; m_timers.draw_calls_duration = 0;
m_timers.m_prepare_rtt_duration = 0; m_timers.prepare_rtt_duration = 0;
m_timers.m_vertex_index_duration = 0; m_timers.vertex_index_duration = 0;
m_timers.m_buffer_upload_size = 0; m_timers.buffer_upload_size = 0;
m_timers.m_program_load_duration = 0; m_timers.program_load_duration = 0;
m_timers.m_constants_duration = 0; m_timers.constants_duration = 0;
m_timers.m_texture_duration = 0; m_timers.texture_duration = 0;
m_timers.m_flip_duration = 0; m_timers.flip_duration = 0;
} }
resource_storage& D3D12GSRender::get_current_resource_storage() resource_storage& D3D12GSRender::get_current_resource_storage()

View file

@ -64,49 +64,49 @@ private:
rsx::surface_info m_surface; rsx::surface_info m_surface;
RSXVertexProgram vertex_program; RSXVertexProgram m_vertex_program;
RSXFragmentProgram fragment_program; RSXFragmentProgram m_fragment_program;
PipelineStateObjectCache m_pso_cache; PipelineStateObjectCache m_pso_cache;
std::tuple<ComPtr<ID3D12PipelineState>, std::vector<size_t>, size_t> m_current_pso; std::tuple<ComPtr<ID3D12PipelineState>, std::vector<size_t>, size_t> m_current_pso;
struct struct
{ {
size_t m_draw_calls_duration; size_t draw_calls_duration;
size_t m_draw_calls_count; size_t draw_calls_count;
size_t m_prepare_rtt_duration; size_t prepare_rtt_duration;
size_t m_vertex_index_duration; size_t vertex_index_duration;
size_t m_buffer_upload_size; size_t buffer_upload_size;
size_t m_program_load_duration; size_t program_load_duration;
size_t m_constants_duration; size_t constants_duration;
size_t m_texture_duration; size_t texture_duration;
size_t m_flip_duration; size_t flip_duration;
} m_timers; } m_timers;
void reset_timer(); void reset_timer();
struct Shader struct shader
{ {
ID3D12PipelineState *m_PSO; ID3D12PipelineState *pso;
ID3D12RootSignature *m_rootSignature; ID3D12RootSignature *root_signature;
ID3D12Resource *m_vertexBuffer; ID3D12Resource *vertex_buffer;
ID3D12DescriptorHeap *m_textureDescriptorHeap; ID3D12DescriptorHeap *texture_descriptor_heap;
ID3D12DescriptorHeap *m_samplerDescriptorHeap; ID3D12DescriptorHeap *sampler_descriptor_heap;
void Init(ID3D12Device *device, ID3D12CommandQueue *gfxcommandqueue); void init(ID3D12Device *device, ID3D12CommandQueue *gfx_command_queue);
void Release(); void release();
}; };
/** /**
* Stores data related to the scaling pass that turns internal * Stores data related to the scaling pass that turns internal
* render targets into presented buffers. * render targets into presented buffers.
*/ */
Shader m_output_scaling_pass; shader m_output_scaling_pass;
/** /**
* Data used when depth buffer is converted to uchar textures. * Data used when depth buffer is converted to uchar textures.
*/ */
ID3D12PipelineState *m_convertPSO; ID3D12PipelineState *m_convert_pso;
ID3D12RootSignature *m_convertRootSignature; ID3D12RootSignature *m_convert_root_signature;
void initConvertShader(); void init_convert_shader();
resource_storage m_per_frame_storage[2]; resource_storage m_per_frame_storage[2];
resource_storage &get_current_resource_storage(); resource_storage &get_current_resource_storage();
@ -118,18 +118,20 @@ private:
rsx::render_targets m_rtts; rsx::render_targets m_rtts;
std::vector<D3D12_INPUT_ELEMENT_DESC> m_IASet; std::vector<D3D12_INPUT_ELEMENT_DESC> m_ia_set;
INT g_descriptor_stride_srv_cbv_uav; INT m_descriptor_stride_srv_cbv_uav;
INT g_descriptor_stride_dsv; INT m_descriptor_stride_dsv;
INT g_descriptor_stride_rtv; INT m_descriptor_stride_rtv;
INT g_descriptor_stride_samplers; INT m_descriptor_stride_samplers;
// Used to fill unused texture slot // Used to fill unused texture slot
ID3D12Resource *m_dummy_texture; ID3D12Resource *m_dummy_texture;
public: public:
D3D12GSRender(); D3D12GSRender();
virtual ~D3D12GSRender(); virtual ~D3D12GSRender();
private: private:
void init_d2d_structures(); void init_d2d_structures();
void release_d2d_structures(); void release_d2d_structures();
@ -193,6 +195,8 @@ protected:
virtual void end() override; virtual void end() override;
virtual void flip(int buffer) override; virtual void flip(int buffer) override;
virtual bool on_access_violation(u32 address, bool is_writing) override;
virtual std::array<std::vector<gsl::byte>, 4> copy_render_targets_to_memory() override; virtual std::array<std::vector<gsl::byte>, 4> copy_render_targets_to_memory() override;
virtual std::array<std::vector<gsl::byte>, 2> copy_depth_stencil_buffer_to_memory() override; virtual std::array<std::vector<gsl::byte>, 2> copy_depth_stencil_buffer_to_memory() override;
virtual std::pair<std::string, std::string> get_programs() const override; virtual std::pair<std::string, std::string> get_programs() const override;

View file

@ -152,21 +152,21 @@ void D3D12GSRender::release_d2d_structures()
void D3D12GSRender::render_overlay() void D3D12GSRender::render_overlay()
{ {
D2D1_SIZE_F rtSize = g_d2d_render_targets[m_swap_chain->GetCurrentBackBufferIndex()]->GetSize(); D2D1_SIZE_F rtSize = g_d2d_render_targets[m_swap_chain->GetCurrentBackBufferIndex()]->GetSize();
std::wstring duration = L"Draw duration : " + std::to_wstring(m_timers.m_draw_calls_duration) + L" us"; std::wstring duration = L"Draw duration : " + std::to_wstring(m_timers.draw_calls_duration) + L" us";
float vtxIdxPercent = (float)m_timers.m_vertex_index_duration / (float)m_timers.m_draw_calls_duration; float vtxIdxPercent = (float)m_timers.vertex_index_duration / (float)m_timers.draw_calls_duration;
std::wstring vertexIndexDuration = L"Vtx/Idx upload : " + std::to_wstring(m_timers.m_vertex_index_duration) + L" us (" + std::to_wstring(100.f * vtxIdxPercent) + L" %)"; std::wstring vertexIndexDuration = L"Vtx/Idx upload : " + std::to_wstring(m_timers.vertex_index_duration) + L" us (" + std::to_wstring(100.f * vtxIdxPercent) + L" %)";
std::wstring size = L"Upload size : " + std::to_wstring(m_timers.m_buffer_upload_size) + L" Bytes"; std::wstring size = L"Upload size : " + std::to_wstring(m_timers.buffer_upload_size) + L" Bytes";
float texPercent = (float)m_timers.m_texture_duration / (float)m_timers.m_draw_calls_duration; float texPercent = (float)m_timers.texture_duration / (float)m_timers.draw_calls_duration;
std::wstring texDuration = L"Textures : " + std::to_wstring(m_timers.m_texture_duration) + L" us (" + std::to_wstring(100.f * texPercent) + L" %)"; std::wstring texDuration = L"Textures : " + std::to_wstring(m_timers.texture_duration) + L" us (" + std::to_wstring(100.f * texPercent) + L" %)";
float programPercent = (float)m_timers.m_program_load_duration / (float)m_timers.m_draw_calls_duration; float programPercent = (float)m_timers.program_load_duration / (float)m_timers.draw_calls_duration;
std::wstring programDuration = L"Program : " + std::to_wstring(m_timers.m_program_load_duration) + L" us (" + std::to_wstring(100.f * programPercent) + L" %)"; std::wstring programDuration = L"Program : " + std::to_wstring(m_timers.program_load_duration) + L" us (" + std::to_wstring(100.f * programPercent) + L" %)";
float constantsPercent = (float)m_timers.m_constants_duration / (float)m_timers.m_draw_calls_duration; float constantsPercent = (float)m_timers.constants_duration / (float)m_timers.draw_calls_duration;
std::wstring constantDuration = L"Constants : " + std::to_wstring(m_timers.m_constants_duration) + L" us (" + std::to_wstring(100.f * constantsPercent) + L" %)"; std::wstring constantDuration = L"Constants : " + std::to_wstring(m_timers.constants_duration) + L" us (" + std::to_wstring(100.f * constantsPercent) + L" %)";
float rttPercent = (float)m_timers.m_prepare_rtt_duration / (float)m_timers.m_draw_calls_duration; float rttPercent = (float)m_timers.prepare_rtt_duration / (float)m_timers.draw_calls_duration;
std::wstring rttDuration = L"RTT : " + std::to_wstring(m_timers.m_prepare_rtt_duration) + L" us (" + std::to_wstring(100.f * rttPercent) + L" %)"; std::wstring rttDuration = L"RTT : " + std::to_wstring(m_timers.prepare_rtt_duration) + L" us (" + std::to_wstring(100.f * rttPercent) + L" %)";
std::wstring flipDuration = L"Flip : " + std::to_wstring(m_timers.m_flip_duration) + L" us"; std::wstring flipDuration = L"Flip : " + std::to_wstring(m_timers.flip_duration) + L" us";
std::wstring count = L"Draw count : " + std::to_wstring(m_timers.m_draw_calls_count); std::wstring count = L"Draw count : " + std::to_wstring(m_timers.draw_calls_count);
draw_strings(rtSize, m_swap_chain->GetCurrentBackBufferIndex(), draw_strings(rtSize, m_swap_chain->GetCurrentBackBufferIndex(),
{ {
duration, duration,

View file

@ -39,12 +39,12 @@ void Shader::Compile(const std::string &code, SHADER_TYPE st)
void D3D12GSRender::load_program() void D3D12GSRender::load_program()
{ {
u32 transform_program_start = rsx::method_registers[NV4097_SET_TRANSFORM_PROGRAM_START]; u32 transform_program_start = rsx::method_registers[NV4097_SET_TRANSFORM_PROGRAM_START];
vertex_program.data.reserve((512 - transform_program_start) * 4); m_vertex_program.data.reserve((512 - transform_program_start) * 4);
for (int i = transform_program_start; i < 512; ++i) for (int i = transform_program_start; i < 512; ++i)
{ {
vertex_program.data.resize((i - transform_program_start) * 4 + 4); m_vertex_program.data.resize((i - transform_program_start) * 4 + 4);
memcpy(vertex_program.data.data() + (i - transform_program_start) * 4, transform_program + i * 4, 4 * sizeof(u32)); memcpy(m_vertex_program.data.data() + (i - transform_program_start) * 4, transform_program + i * 4, 4 * sizeof(u32));
D3 d3; D3 d3;
d3.HEX = transform_program[i * 4 + 3]; d3.HEX = transform_program[i * 4 + 3];
@ -54,19 +54,19 @@ void D3D12GSRender::load_program()
} }
u32 shader_program = rsx::method_registers[NV4097_SET_SHADER_PROGRAM]; u32 shader_program = rsx::method_registers[NV4097_SET_SHADER_PROGRAM];
fragment_program.offset = shader_program & ~0x3; m_fragment_program.offset = shader_program & ~0x3;
fragment_program.addr = rsx::get_address(fragment_program.offset, (shader_program & 0x3) - 1); m_fragment_program.addr = rsx::get_address(m_fragment_program.offset, (shader_program & 0x3) - 1);
fragment_program.ctrl = rsx::method_registers[NV4097_SET_SHADER_CONTROL]; m_fragment_program.ctrl = rsx::method_registers[NV4097_SET_SHADER_CONTROL];
fragment_program.texture_dimensions.clear(); m_fragment_program.texture_dimensions.clear();
for (u32 i = 0; i < rsx::limits::textures_count; ++i) for (u32 i = 0; i < rsx::limits::textures_count; ++i)
{ {
if (!textures[i].enabled()) if (!textures[i].enabled())
fragment_program.texture_dimensions.push_back(texture_dimension::texture_dimension_2d); m_fragment_program.texture_dimensions.push_back(texture_dimension::texture_dimension_2d);
else if (textures[i].cubemap()) else if (textures[i].cubemap())
fragment_program.texture_dimensions.push_back(texture_dimension::texture_dimension_cubemap); m_fragment_program.texture_dimensions.push_back(texture_dimension::texture_dimension_cubemap);
else else
fragment_program.texture_dimensions.push_back(texture_dimension::texture_dimension_2d); m_fragment_program.texture_dimensions.push_back(texture_dimension::texture_dimension_2d);
} }
D3D12PipelineProperties prop = {}; D3D12PipelineProperties prop = {};
@ -162,19 +162,19 @@ void D3D12GSRender::load_program()
prop.DepthStencilFormat = get_depth_stencil_surface_format(m_surface.depth_format); prop.DepthStencilFormat = get_depth_stencil_surface_format(m_surface.depth_format);
prop.RenderTargetsFormat = get_color_surface_format(m_surface.color_format); prop.RenderTargetsFormat = get_color_surface_format(m_surface.color_format);
switch (to_surface_target(rsx::method_registers[NV4097_SET_SURFACE_COLOR_TARGET])) switch (rsx::to_surface_target(rsx::method_registers[NV4097_SET_SURFACE_COLOR_TARGET]))
{ {
case Surface_target::surface_a: case rsx::surface_target::surface_a:
case Surface_target::surface_b: case rsx::surface_target::surface_b:
prop.numMRT = 1; prop.numMRT = 1;
break; break;
case Surface_target::surfaces_a_b: case rsx::surface_target::surfaces_a_b:
prop.numMRT = 2; prop.numMRT = 2;
break; break;
case Surface_target::surfaces_a_b_c: case rsx::surface_target::surfaces_a_b_c:
prop.numMRT = 3; prop.numMRT = 3;
break; break;
case Surface_target::surfaces_a_b_c_d: case rsx::surface_target::surfaces_a_b_c_d:
prop.numMRT = 4; prop.numMRT = 4;
break; break;
default: default:
@ -251,26 +251,26 @@ void D3D12GSRender::load_program()
for (unsigned i = 0; i < prop.numMRT; i++) for (unsigned i = 0; i < prop.numMRT; i++)
prop.Blend.RenderTarget[i].RenderTargetWriteMask = mask; prop.Blend.RenderTarget[i].RenderTargetWriteMask = mask;
prop.IASet = m_IASet; prop.IASet = m_ia_set;
if (!!rsx::method_registers[NV4097_SET_RESTART_INDEX_ENABLE]) if (!!rsx::method_registers[NV4097_SET_RESTART_INDEX_ENABLE])
{ {
Index_array_type index_type = to_index_array_type(rsx::method_registers[NV4097_SET_INDEX_ARRAY_DMA] >> 4); rsx::index_array_type index_type = rsx::to_index_array_type(rsx::method_registers[NV4097_SET_INDEX_ARRAY_DMA] >> 4);
if (index_type == Index_array_type::unsigned_32b) if (index_type == rsx::index_array_type::u32)
{ {
prop.CutValue = D3D12_INDEX_BUFFER_STRIP_CUT_VALUE_0xFFFFFFFF; prop.CutValue = D3D12_INDEX_BUFFER_STRIP_CUT_VALUE_0xFFFFFFFF;
} }
if (index_type == Index_array_type::unsigned_16b) if (index_type == rsx::index_array_type::u16)
{ {
prop.CutValue = D3D12_INDEX_BUFFER_STRIP_CUT_VALUE_0xFFFF; prop.CutValue = D3D12_INDEX_BUFFER_STRIP_CUT_VALUE_0xFFFF;
} }
} }
m_current_pso = m_pso_cache.getGraphicPipelineState(vertex_program, fragment_program, prop, m_device.Get(), m_root_signatures); m_current_pso = m_pso_cache.getGraphicPipelineState(m_vertex_program, m_fragment_program, prop, m_device.Get(), m_root_signatures);
return; return;
} }
std::pair<std::string, std::string> D3D12GSRender::get_programs() const std::pair<std::string, std::string> D3D12GSRender::get_programs() const
{ {
return std::make_pair(m_pso_cache.get_transform_program(vertex_program).content, m_pso_cache.get_shader_program(fragment_program).content); return std::make_pair(m_pso_cache.get_transform_program(m_vertex_program).content, m_pso_cache.get_shader_program(m_fragment_program).content);
} }
#endif #endif

View file

@ -15,40 +15,40 @@
namespace namespace
{ {
u32 get_max_depth_value(Surface_depth_format format) u32 get_max_depth_value(rsx::surface_depth_format format)
{ {
switch (format) switch (format)
{ {
case Surface_depth_format::z16: return 0xFFFF; case rsx::surface_depth_format::z16: return 0xFFFF;
case Surface_depth_format::z24s8: return 0xFFFFFF; case rsx::surface_depth_format::z24s8: return 0xFFFFFF;
} }
throw EXCEPTION("Unknow depth format"); throw EXCEPTION("Unknow depth format");
} }
UINT get_num_rtt(Surface_target color_target) UINT get_num_rtt(rsx::surface_target color_target)
{ {
switch (color_target) switch (color_target)
{ {
case Surface_target::none: return 0; case rsx::surface_target::none: return 0;
case Surface_target::surface_a: case rsx::surface_target::surface_a:
case Surface_target::surface_b: return 1; case rsx::surface_target::surface_b: return 1;
case Surface_target::surfaces_a_b: return 2; case rsx::surface_target::surfaces_a_b: return 2;
case Surface_target::surfaces_a_b_c: return 3; case rsx::surface_target::surfaces_a_b_c: return 3;
case Surface_target::surfaces_a_b_c_d: return 4; case rsx::surface_target::surfaces_a_b_c_d: return 4;
} }
throw EXCEPTION("Wrong color_target (%d)", color_target); throw EXCEPTION("Wrong color_target (%d)", color_target);
} }
std::vector<u8> get_rtt_indexes(Surface_target color_target) std::vector<u8> get_rtt_indexes(rsx::surface_target color_target)
{ {
switch (color_target) switch (color_target)
{ {
case Surface_target::none: return{}; case rsx::surface_target::none: return{};
case Surface_target::surface_a: return{ 0 }; case rsx::surface_target::surface_a: return{ 0 };
case Surface_target::surface_b: return{ 1 }; case rsx::surface_target::surface_b: return{ 1 };
case Surface_target::surfaces_a_b: return{ 0, 1 }; case rsx::surface_target::surfaces_a_b: return{ 0, 1 };
case Surface_target::surfaces_a_b_c: return{ 0, 1, 2 }; case rsx::surface_target::surfaces_a_b_c: return{ 0, 1, 2 };
case Surface_target::surfaces_a_b_c_d: return{ 0, 1, 2, 3 }; case rsx::surface_target::surfaces_a_b_c_d: return{ 0, 1, 2, 3 };
} }
throw EXCEPTION("Wrong color_target (%d)", color_target); throw EXCEPTION("Wrong color_target (%d)", color_target);
} }
@ -73,46 +73,46 @@ namespace
return register_value & 0xff; return register_value & 0xff;
} }
size_t get_aligned_pitch(Surface_color_format format, u32 width) size_t get_aligned_pitch(rsx::surface_color_format format, u32 width)
{ {
switch (format) switch (format)
{ {
case Surface_color_format::b8: return align(width, 256); case rsx::surface_color_format::b8: return align(width, 256);
case Surface_color_format::g8b8: case rsx::surface_color_format::g8b8:
case Surface_color_format::x1r5g5b5_o1r5g5b5: case rsx::surface_color_format::x1r5g5b5_o1r5g5b5:
case Surface_color_format::x1r5g5b5_z1r5g5b5: case rsx::surface_color_format::x1r5g5b5_z1r5g5b5:
case Surface_color_format::r5g6b5: return align(width * 2, 256); case rsx::surface_color_format::r5g6b5: return align(width * 2, 256);
case Surface_color_format::a8b8g8r8: case rsx::surface_color_format::a8b8g8r8:
case Surface_color_format::x8b8g8r8_o8b8g8r8: case rsx::surface_color_format::x8b8g8r8_o8b8g8r8:
case Surface_color_format::x8b8g8r8_z8b8g8r8: case rsx::surface_color_format::x8b8g8r8_z8b8g8r8:
case Surface_color_format::x8r8g8b8_o8r8g8b8: case rsx::surface_color_format::x8r8g8b8_o8r8g8b8:
case Surface_color_format::x8r8g8b8_z8r8g8b8: case rsx::surface_color_format::x8r8g8b8_z8r8g8b8:
case Surface_color_format::x32: case rsx::surface_color_format::x32:
case Surface_color_format::a8r8g8b8: return align(width * 4, 256); case rsx::surface_color_format::a8r8g8b8: return align(width * 4, 256);
case Surface_color_format::w16z16y16x16: return align(width * 8, 256); case rsx::surface_color_format::w16z16y16x16: return align(width * 8, 256);
case Surface_color_format::w32z32y32x32: return align(width * 16, 256); case rsx::surface_color_format::w32z32y32x32: return align(width * 16, 256);
} }
throw EXCEPTION("Unknow color surface format"); throw EXCEPTION("Unknow color surface format");
} }
size_t get_packed_pitch(Surface_color_format format, u32 width) size_t get_packed_pitch(rsx::surface_color_format format, u32 width)
{ {
switch (format) switch (format)
{ {
case Surface_color_format::b8: return width; case rsx::surface_color_format::b8: return width;
case Surface_color_format::g8b8: case rsx::surface_color_format::g8b8:
case Surface_color_format::x1r5g5b5_o1r5g5b5: case rsx::surface_color_format::x1r5g5b5_o1r5g5b5:
case Surface_color_format::x1r5g5b5_z1r5g5b5: case rsx::surface_color_format::x1r5g5b5_z1r5g5b5:
case Surface_color_format::r5g6b5: return width * 2; case rsx::surface_color_format::r5g6b5: return width * 2;
case Surface_color_format::a8b8g8r8: case rsx::surface_color_format::a8b8g8r8:
case Surface_color_format::x8b8g8r8_o8b8g8r8: case rsx::surface_color_format::x8b8g8r8_o8b8g8r8:
case Surface_color_format::x8b8g8r8_z8b8g8r8: case rsx::surface_color_format::x8b8g8r8_z8b8g8r8:
case Surface_color_format::x8r8g8b8_o8r8g8b8: case rsx::surface_color_format::x8r8g8b8_o8r8g8b8:
case Surface_color_format::x8r8g8b8_z8r8g8b8: case rsx::surface_color_format::x8r8g8b8_z8r8g8b8:
case Surface_color_format::x32: case rsx::surface_color_format::x32:
case Surface_color_format::a8r8g8b8: return width * 4; case rsx::surface_color_format::a8r8g8b8: return width * 4;
case Surface_color_format::w16z16y16x16: return width * 8; case rsx::surface_color_format::w16z16y16x16: return width * 8;
case Surface_color_format::w32z32y32x32: return width * 16; case rsx::surface_color_format::w32z32y32x32: return width * 16;
} }
throw EXCEPTION("Unknow color surface format"); throw EXCEPTION("Unknow color surface format");
} }
@ -126,7 +126,7 @@ void D3D12GSRender::clear_surface(u32 arg)
prepare_render_targets(get_current_resource_storage().command_list.Get()); prepare_render_targets(get_current_resource_storage().command_list.Get());
std::chrono::time_point<std::chrono::system_clock> rtt_duration_end = std::chrono::system_clock::now(); std::chrono::time_point<std::chrono::system_clock> rtt_duration_end = std::chrono::system_clock::now();
m_timers.m_prepare_rtt_duration += std::chrono::duration_cast<std::chrono::microseconds>(rtt_duration_end - rtt_duration_start).count(); m_timers.prepare_rtt_duration += std::chrono::duration_cast<std::chrono::microseconds>(rtt_duration_end - rtt_duration_start).count();
if (arg & 0x1 || arg & 0x2) if (arg & 0x1 || arg & 0x2)
{ {
@ -148,16 +148,16 @@ void D3D12GSRender::clear_surface(u32 arg)
if (arg & 0xF0) if (arg & 0xF0)
{ {
CD3DX12_CPU_DESCRIPTOR_HANDLE handle = CD3DX12_CPU_DESCRIPTOR_HANDLE(m_rtts.current_rtts_handle); CD3DX12_CPU_DESCRIPTOR_HANDLE handle = CD3DX12_CPU_DESCRIPTOR_HANDLE(m_rtts.current_rtts_handle);
size_t rtt_index = get_num_rtt(to_surface_target(rsx::method_registers[NV4097_SET_SURFACE_COLOR_TARGET])); size_t rtt_index = get_num_rtt(rsx::to_surface_target(rsx::method_registers[NV4097_SET_SURFACE_COLOR_TARGET]));
get_current_resource_storage().render_targets_descriptors_heap_index += rtt_index; get_current_resource_storage().render_targets_descriptors_heap_index += rtt_index;
for (unsigned i = 0; i < rtt_index; i++) for (unsigned i = 0; i < rtt_index; i++)
get_current_resource_storage().command_list->ClearRenderTargetView(handle.Offset(i, g_descriptor_stride_rtv), get_clear_color(rsx::method_registers[NV4097_SET_COLOR_CLEAR_VALUE]).data(), get_current_resource_storage().command_list->ClearRenderTargetView(handle.Offset(i, m_descriptor_stride_rtv), get_clear_color(rsx::method_registers[NV4097_SET_COLOR_CLEAR_VALUE]).data(),
1, &get_scissor(rsx::method_registers[NV4097_SET_SCISSOR_HORIZONTAL], rsx::method_registers[NV4097_SET_SCISSOR_VERTICAL])); 1, &get_scissor(rsx::method_registers[NV4097_SET_SCISSOR_HORIZONTAL], rsx::method_registers[NV4097_SET_SCISSOR_VERTICAL]));
} }
std::chrono::time_point<std::chrono::system_clock> end_duration = std::chrono::system_clock::now(); std::chrono::time_point<std::chrono::system_clock> end_duration = std::chrono::system_clock::now();
m_timers.m_draw_calls_duration += std::chrono::duration_cast<std::chrono::microseconds>(end_duration - start_duration).count(); m_timers.draw_calls_duration += std::chrono::duration_cast<std::chrono::microseconds>(end_duration - start_duration).count();
m_timers.m_draw_calls_count++; m_timers.draw_calls_count++;
if (rpcs3::config.rsx.d3d12.debug_output.value()) if (rpcs3::config.rsx.d3d12.debug_output.value())
{ {
@ -185,7 +185,7 @@ void D3D12GSRender::prepare_render_targets(ID3D12GraphicsCommandList *copycmdlis
m_rtts.prepare_render_target(copycmdlist, m_rtts.prepare_render_target(copycmdlist,
rsx::method_registers[NV4097_SET_SURFACE_FORMAT], rsx::method_registers[NV4097_SET_SURFACE_FORMAT],
rsx::method_registers[NV4097_SET_SURFACE_CLIP_HORIZONTAL], rsx::method_registers[NV4097_SET_SURFACE_CLIP_VERTICAL], rsx::method_registers[NV4097_SET_SURFACE_CLIP_HORIZONTAL], rsx::method_registers[NV4097_SET_SURFACE_CLIP_VERTICAL],
to_surface_target(rsx::method_registers[NV4097_SET_SURFACE_COLOR_TARGET]), rsx::to_surface_target(rsx::method_registers[NV4097_SET_SURFACE_COLOR_TARGET]),
get_color_surface_addresses(), get_zeta_surface_address(), get_color_surface_addresses(), get_zeta_surface_address(),
m_device.Get(), clear_color, 1.f, 0); m_device.Get(), clear_color, 1.f, 0);
@ -196,14 +196,14 @@ void D3D12GSRender::prepare_render_targets(ID3D12GraphicsCommandList *copycmdlis
rtt_view_desc.Format = dxgi_format; rtt_view_desc.Format = dxgi_format;
m_rtts.current_rtts_handle = CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().render_targets_descriptors_heap->GetCPUDescriptorHandleForHeapStart()) m_rtts.current_rtts_handle = CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().render_targets_descriptors_heap->GetCPUDescriptorHandleForHeapStart())
.Offset((INT)get_current_resource_storage().render_targets_descriptors_heap_index * g_descriptor_stride_rtv); .Offset((INT)get_current_resource_storage().render_targets_descriptors_heap_index * m_descriptor_stride_rtv);
size_t rtt_index = 0; size_t rtt_index = 0;
for (u8 i : get_rtt_indexes(to_surface_target(rsx::method_registers[NV4097_SET_SURFACE_COLOR_TARGET]))) for (u8 i : get_rtt_indexes(rsx::to_surface_target(rsx::method_registers[NV4097_SET_SURFACE_COLOR_TARGET])))
{ {
if (std::get<1>(m_rtts.m_bound_render_targets[i]) == nullptr) if (std::get<1>(m_rtts.m_bound_render_targets[i]) == nullptr)
continue; continue;
m_device->CreateRenderTargetView(std::get<1>(m_rtts.m_bound_render_targets[i]), &rtt_view_desc, m_device->CreateRenderTargetView(std::get<1>(m_rtts.m_bound_render_targets[i]), &rtt_view_desc,
CD3DX12_CPU_DESCRIPTOR_HANDLE(m_rtts.current_rtts_handle).Offset((INT)rtt_index * g_descriptor_stride_rtv)); CD3DX12_CPU_DESCRIPTOR_HANDLE(m_rtts.current_rtts_handle).Offset((INT)rtt_index * m_descriptor_stride_rtv));
rtt_index++; rtt_index++;
} }
get_current_resource_storage().render_targets_descriptors_heap_index += rtt_index; get_current_resource_storage().render_targets_descriptors_heap_index += rtt_index;
@ -211,7 +211,7 @@ void D3D12GSRender::prepare_render_targets(ID3D12GraphicsCommandList *copycmdlis
if (std::get<1>(m_rtts.m_bound_depth_stencil) == nullptr) if (std::get<1>(m_rtts.m_bound_depth_stencil) == nullptr)
return; return;
m_rtts.current_ds_handle = CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().depth_stencil_descriptor_heap->GetCPUDescriptorHandleForHeapStart()) m_rtts.current_ds_handle = CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().depth_stencil_descriptor_heap->GetCPUDescriptorHandleForHeapStart())
.Offset((INT)get_current_resource_storage().depth_stencil_descriptor_heap_index * g_descriptor_stride_dsv); .Offset((INT)get_current_resource_storage().depth_stencil_descriptor_heap_index * m_descriptor_stride_dsv);
get_current_resource_storage().depth_stencil_descriptor_heap_index += 1; get_current_resource_storage().depth_stencil_descriptor_heap_index += 1;
D3D12_DEPTH_STENCIL_VIEW_DESC depth_stencil_view_desc = {}; D3D12_DEPTH_STENCIL_VIEW_DESC depth_stencil_view_desc = {};
depth_stencil_view_desc.Format = get_depth_stencil_surface_format(m_surface.depth_format); depth_stencil_view_desc.Format = get_depth_stencil_surface_format(m_surface.depth_format);
@ -221,7 +221,7 @@ void D3D12GSRender::prepare_render_targets(ID3D12GraphicsCommandList *copycmdlis
void D3D12GSRender::set_rtt_and_ds(ID3D12GraphicsCommandList *command_list) void D3D12GSRender::set_rtt_and_ds(ID3D12GraphicsCommandList *command_list)
{ {
UINT num_rtt = get_num_rtt(to_surface_target(rsx::method_registers[NV4097_SET_SURFACE_COLOR_TARGET])); UINT num_rtt = get_num_rtt(rsx::to_surface_target(rsx::method_registers[NV4097_SET_SURFACE_COLOR_TARGET]));
D3D12_CPU_DESCRIPTOR_HANDLE* ds_handle = (std::get<1>(m_rtts.m_bound_depth_stencil) != nullptr) ? &m_rtts.current_ds_handle : nullptr; D3D12_CPU_DESCRIPTOR_HANDLE* ds_handle = (std::get<1>(m_rtts.m_bound_depth_stencil) != nullptr) ? &m_rtts.current_ds_handle : nullptr;
command_list->OMSetRenderTargets((UINT)num_rtt, &m_rtts.current_rtts_handle, true, ds_handle); command_list->OMSetRenderTargets((UINT)num_rtt, &m_rtts.current_rtts_handle, true, ds_handle);
} }
@ -242,7 +242,7 @@ namespace
ID3D12GraphicsCommandList * command_list, ID3D12GraphicsCommandList * command_list,
data_heap &readback_heap, data_heap &readback_heap,
ID3D12Resource * color_surface, ID3D12Resource * color_surface,
Surface_color_format color_surface_format rsx::surface_color_format color_surface_format
) )
{ {
int clip_w = rsx::method_registers[NV4097_SET_SURFACE_CLIP_HORIZONTAL] >> 16; int clip_w = rsx::method_registers[NV4097_SET_SURFACE_CLIP_HORIZONTAL] >> 16;
@ -362,13 +362,13 @@ void D3D12GSRender::copy_render_target_to_dma_location()
uav_desc.Format = DXGI_FORMAT_R8_UNORM; uav_desc.Format = DXGI_FORMAT_R8_UNORM;
uav_desc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2D; uav_desc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2D;
m_device->CreateUnorderedAccessView(depth_format_conversion_buffer.Get(), nullptr, &uav_desc, m_device->CreateUnorderedAccessView(depth_format_conversion_buffer.Get(), nullptr, &uav_desc,
CD3DX12_CPU_DESCRIPTOR_HANDLE(descriptor_heap->GetCPUDescriptorHandleForHeapStart()).Offset(1, g_descriptor_stride_srv_cbv_uav)); CD3DX12_CPU_DESCRIPTOR_HANDLE(descriptor_heap->GetCPUDescriptorHandleForHeapStart()).Offset(1, m_descriptor_stride_srv_cbv_uav));
// Convert // Convert
get_current_resource_storage().command_list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(std::get<1>(m_rtts.m_bound_depth_stencil), D3D12_RESOURCE_STATE_DEPTH_WRITE, D3D12_RESOURCE_STATE_GENERIC_READ)); get_current_resource_storage().command_list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(std::get<1>(m_rtts.m_bound_depth_stencil), D3D12_RESOURCE_STATE_DEPTH_WRITE, D3D12_RESOURCE_STATE_GENERIC_READ));
get_current_resource_storage().command_list->SetPipelineState(m_convertPSO); get_current_resource_storage().command_list->SetPipelineState(m_convert_pso);
get_current_resource_storage().command_list->SetComputeRootSignature(m_convertRootSignature); get_current_resource_storage().command_list->SetComputeRootSignature(m_convert_root_signature);
get_current_resource_storage().command_list->SetDescriptorHeaps(1, descriptor_heap.GetAddressOf()); get_current_resource_storage().command_list->SetDescriptorHeaps(1, descriptor_heap.GetAddressOf());
get_current_resource_storage().command_list->SetComputeRootDescriptorTable(0, descriptor_heap->GetGPUDescriptorHandleForHeapStart()); get_current_resource_storage().command_list->SetComputeRootDescriptorTable(0, descriptor_heap->GetGPUDescriptorHandleForHeapStart());
get_current_resource_storage().command_list->Dispatch(clip_w / 8, clip_h / 8, 1); get_current_resource_storage().command_list->Dispatch(clip_w / 8, clip_h / 8, 1);
@ -391,7 +391,7 @@ void D3D12GSRender::copy_render_target_to_dma_location()
size_t color_buffer_offset_in_heap[4]; size_t color_buffer_offset_in_heap[4];
if (rpcs3::state.config.rsx.opengl.write_color_buffers) if (rpcs3::state.config.rsx.opengl.write_color_buffers)
{ {
for (u8 i : get_rtt_indexes(to_surface_target(rsx::method_registers[NV4097_SET_SURFACE_COLOR_TARGET]))) for (u8 i : get_rtt_indexes(rsx::to_surface_target(rsx::method_registers[NV4097_SET_SURFACE_COLOR_TARGET])))
{ {
if (!address_color[i]) if (!address_color[i])
continue; continue;
@ -443,7 +443,7 @@ void D3D12GSRender::copy_render_target_to_dma_location()
vm::base(address_color[3]), vm::base(address_color[3]),
}; };
for (u8 i : get_rtt_indexes(to_surface_target(rsx::method_registers[NV4097_SET_SURFACE_COLOR_TARGET]))) for (u8 i : get_rtt_indexes(rsx::to_surface_target(rsx::method_registers[NV4097_SET_SURFACE_COLOR_TARGET])))
{ {
if (!address_color[i]) if (!address_color[i])
continue; continue;

View file

@ -21,10 +21,10 @@ struct render_target_traits
static static
ComPtr<ID3D12Resource> create_new_surface( ComPtr<ID3D12Resource> create_new_surface(
u32 address, u32 address,
Surface_color_format surface_color_format, size_t width, size_t height, surface_color_format color_format, size_t width, size_t height,
gsl::not_null<ID3D12Device*> device, const std::array<float, 4> &clear_color, float, u8) gsl::not_null<ID3D12Device*> device, const std::array<float, 4> &clear_color, float, u8)
{ {
DXGI_FORMAT dxgi_format = get_color_surface_format(surface_color_format); DXGI_FORMAT dxgi_format = get_color_surface_format(color_format);
ComPtr<ID3D12Resource> rtt; ComPtr<ID3D12Resource> rtt;
LOG_WARNING(RSX, "Creating RTT"); LOG_WARNING(RSX, "Creating RTT");
@ -69,7 +69,7 @@ struct render_target_traits
static static
ComPtr<ID3D12Resource> create_new_surface( ComPtr<ID3D12Resource> create_new_surface(
u32 address, u32 address,
Surface_depth_format surfaceDepthFormat, size_t width, size_t height, surface_depth_format surfaceDepthFormat, size_t width, size_t height,
gsl::not_null<ID3D12Device*> device, const std::array<float, 4>& , float clear_depth, u8 clear_stencil) gsl::not_null<ID3D12Device*> device, const std::array<float, 4>& , float clear_depth, u8 clear_stencil)
{ {
D3D12_CLEAR_VALUE clear_depth_value = {}; D3D12_CLEAR_VALUE clear_depth_value = {};
@ -113,14 +113,14 @@ struct render_target_traits
static static
bool rtt_has_format_width_height(const ComPtr<ID3D12Resource> &rtt, Surface_color_format surface_color_format, size_t width, size_t height) bool rtt_has_format_width_height(const ComPtr<ID3D12Resource> &rtt, surface_color_format surface_color_format, size_t width, size_t height)
{ {
DXGI_FORMAT dxgi_format = get_color_surface_format(surface_color_format); DXGI_FORMAT dxgi_format = get_color_surface_format(surface_color_format);
return rtt->GetDesc().Format == dxgi_format && rtt->GetDesc().Width == width && rtt->GetDesc().Height == height; return rtt->GetDesc().Format == dxgi_format && rtt->GetDesc().Width == width && rtt->GetDesc().Height == height;
} }
static static
bool ds_has_format_width_height(const ComPtr<ID3D12Resource> &rtt, Surface_depth_format surface_depth_stencil_format, size_t width, size_t height) bool ds_has_format_width_height(const ComPtr<ID3D12Resource> &rtt, surface_depth_format surface_depth_stencil_format, size_t width, size_t height)
{ {
//TODO: Check format //TODO: Check format
return rtt->GetDesc().Width == width && rtt->GetDesc().Height == height; return rtt->GetDesc().Width == width && rtt->GetDesc().Height == height;
@ -129,7 +129,7 @@ struct render_target_traits
static static
std::tuple<size_t, size_t, size_t, ComPtr<ID3D12Fence>, HANDLE> issue_download_command( std::tuple<size_t, size_t, size_t, ComPtr<ID3D12Fence>, HANDLE> issue_download_command(
gsl::not_null<ID3D12Resource*> rtt, gsl::not_null<ID3D12Resource*> rtt,
Surface_color_format color_format, size_t width, size_t height, surface_color_format color_format, size_t width, size_t height,
gsl::not_null<ID3D12Device*> device, gsl::not_null<ID3D12CommandQueue*> command_queue, data_heap &readback_heap, resource_storage &res_store gsl::not_null<ID3D12Device*> device, gsl::not_null<ID3D12CommandQueue*> command_queue, data_heap &readback_heap, resource_storage &res_store
) )
{ {
@ -162,12 +162,12 @@ struct render_target_traits
static static
std::tuple<size_t, size_t, size_t, ComPtr<ID3D12Fence>, HANDLE> issue_depth_download_command( std::tuple<size_t, size_t, size_t, ComPtr<ID3D12Fence>, HANDLE> issue_depth_download_command(
gsl::not_null<ID3D12Resource*> ds, gsl::not_null<ID3D12Resource*> ds,
Surface_depth_format depth_format, size_t width, size_t height, surface_depth_format depth_format, size_t width, size_t height,
gsl::not_null<ID3D12Device*> device, gsl::not_null<ID3D12CommandQueue*> command_queue, data_heap &readback_heap, resource_storage &res_store gsl::not_null<ID3D12Device*> device, gsl::not_null<ID3D12CommandQueue*> command_queue, data_heap &readback_heap, resource_storage &res_store
) )
{ {
ID3D12GraphicsCommandList* command_list = res_store.command_list.Get(); ID3D12GraphicsCommandList* command_list = res_store.command_list.Get();
DXGI_FORMAT dxgi_format = (depth_format == Surface_depth_format::z24s8) ? DXGI_FORMAT_R32_TYPELESS : DXGI_FORMAT_R16_TYPELESS; DXGI_FORMAT dxgi_format = (depth_format == surface_depth_format::z24s8) ? DXGI_FORMAT_R32_TYPELESS : DXGI_FORMAT_R16_TYPELESS;
size_t row_pitch = align(width * 4, 256); size_t row_pitch = align(width * 4, 256);
size_t buffer_size = row_pitch * height; size_t buffer_size = row_pitch * height;

View file

@ -143,7 +143,7 @@ void D3D12GSRender::upload_and_bind_textures(ID3D12GraphicsCommandList *command_
D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_0); D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_0);
m_device->CreateShaderResourceView(m_dummy_texture, &shader_resource_view_desc, m_device->CreateShaderResourceView(m_dummy_texture, &shader_resource_view_desc,
CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().descriptors_heap->GetCPUDescriptorHandleForHeapStart()) CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().descriptors_heap->GetCPUDescriptorHandleForHeapStart())
.Offset((INT)descriptor_index + (INT)used_texture, g_descriptor_stride_srv_cbv_uav) .Offset((INT)descriptor_index + (INT)used_texture, m_descriptor_stride_srv_cbv_uav)
); );
D3D12_SAMPLER_DESC sampler_desc = {}; D3D12_SAMPLER_DESC sampler_desc = {};
@ -153,7 +153,7 @@ void D3D12GSRender::upload_and_bind_textures(ID3D12GraphicsCommandList *command_
sampler_desc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP; sampler_desc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
m_device->CreateSampler(&sampler_desc, m_device->CreateSampler(&sampler_desc,
CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().sampler_descriptor_heap[get_current_resource_storage().sampler_descriptors_heap_index]->GetCPUDescriptorHandleForHeapStart()) CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().sampler_descriptor_heap[get_current_resource_storage().sampler_descriptors_heap_index]->GetCPUDescriptorHandleForHeapStart())
.Offset((INT)get_current_resource_storage().current_sampler_index + (INT)used_texture, g_descriptor_stride_samplers) .Offset((INT)get_current_resource_storage().current_sampler_index + (INT)used_texture, m_descriptor_stride_samplers)
); );
used_texture++; used_texture++;
continue; continue;
@ -320,7 +320,7 @@ void D3D12GSRender::upload_and_bind_textures(ID3D12GraphicsCommandList *command_
m_device->CreateShaderResourceView(vram_texture, &shared_resource_view_desc, m_device->CreateShaderResourceView(vram_texture, &shared_resource_view_desc,
CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().descriptors_heap->GetCPUDescriptorHandleForHeapStart()) CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().descriptors_heap->GetCPUDescriptorHandleForHeapStart())
.Offset((UINT)descriptor_index + (UINT)used_texture, g_descriptor_stride_srv_cbv_uav)); .Offset((UINT)descriptor_index + (UINT)used_texture, m_descriptor_stride_srv_cbv_uav));
if (get_current_resource_storage().current_sampler_index + 16 > 2048) if (get_current_resource_storage().current_sampler_index + 16 > 2048)
{ {
@ -336,7 +336,7 @@ void D3D12GSRender::upload_and_bind_textures(ID3D12GraphicsCommandList *command_
} }
m_device->CreateSampler(&get_sampler_desc(textures[i]), m_device->CreateSampler(&get_sampler_desc(textures[i]),
CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().sampler_descriptor_heap[get_current_resource_storage().sampler_descriptors_heap_index]->GetCPUDescriptorHandleForHeapStart()) CD3DX12_CPU_DESCRIPTOR_HANDLE(get_current_resource_storage().sampler_descriptor_heap[get_current_resource_storage().sampler_descriptors_heap_index]->GetCPUDescriptorHandleForHeapStart())
.Offset((UINT)get_current_resource_storage().current_sampler_index + (UINT)used_texture, g_descriptor_stride_samplers)); .Offset((UINT)get_current_resource_storage().current_sampler_index + (UINT)used_texture, m_descriptor_stride_samplers));
used_texture++; used_texture++;
} }

View file

@ -47,7 +47,7 @@ std::pair<ID3DBlob *, ID3DBlob *> compileF32toU8CS()
} }
void D3D12GSRender::Shader::Init(ID3D12Device *device, ID3D12CommandQueue *gfxcommandqueue) void D3D12GSRender::shader::init(ID3D12Device *device, ID3D12CommandQueue *gfx_command_queue)
{ {
const char *fsCode = STRINGIFY( const char *fsCode = STRINGIFY(
Texture2D InputTexture : register(t0); \n Texture2D InputTexture : register(t0); \n
@ -143,21 +143,21 @@ void D3D12GSRender::Shader::Init(ID3D12Device *device, ID3D12CommandQueue *gfxco
Microsoft::WRL::ComPtr<ID3DBlob> rootSignatureBlob; Microsoft::WRL::ComPtr<ID3DBlob> rootSignatureBlob;
CHECK_HRESULT(wrapD3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &rootSignatureBlob, &errorBlob)); CHECK_HRESULT(wrapD3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &rootSignatureBlob, &errorBlob));
CHECK_HRESULT(device->CreateRootSignature(0, rootSignatureBlob->GetBufferPointer(), rootSignatureBlob->GetBufferSize(), IID_PPV_ARGS(&m_rootSignature))); CHECK_HRESULT(device->CreateRootSignature(0, rootSignatureBlob->GetBufferPointer(), rootSignatureBlob->GetBufferSize(), IID_PPV_ARGS(&root_signature)));
psoDesc.pRootSignature = m_rootSignature; psoDesc.pRootSignature = root_signature;
psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE; psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
psoDesc.BlendState.RenderTarget[0].RenderTargetWriteMask = D3D12_COLOR_WRITE_ENABLE_ALL; psoDesc.BlendState.RenderTarget[0].RenderTargetWriteMask = D3D12_COLOR_WRITE_ENABLE_ALL;
CHECK_HRESULT(device->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&m_PSO))); CHECK_HRESULT(device->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&pso)));
D3D12_DESCRIPTOR_HEAP_DESC textureHeapDesc = { D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV , 2, D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE }; D3D12_DESCRIPTOR_HEAP_DESC textureHeapDesc = { D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV , 2, D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE };
CHECK_HRESULT( CHECK_HRESULT(
device->CreateDescriptorHeap(&textureHeapDesc, IID_PPV_ARGS(&m_textureDescriptorHeap)) device->CreateDescriptorHeap(&textureHeapDesc, IID_PPV_ARGS(&texture_descriptor_heap))
); );
D3D12_DESCRIPTOR_HEAP_DESC samplerHeapDesc = { D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER , 2, D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE }; D3D12_DESCRIPTOR_HEAP_DESC samplerHeapDesc = { D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER , 2, D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE };
CHECK_HRESULT( CHECK_HRESULT(
device->CreateDescriptorHeap(&samplerHeapDesc, IID_PPV_ARGS(&m_samplerDescriptorHeap)) device->CreateDescriptorHeap(&samplerHeapDesc, IID_PPV_ARGS(&sampler_descriptor_heap))
); );
ComPtr<ID3D12Fence> fence; ComPtr<ID3D12Fence> fence;
@ -197,37 +197,37 @@ void D3D12GSRender::Shader::Init(ID3D12Device *device, ID3D12CommandQueue *gfxco
&CD3DX12_RESOURCE_DESC::Buffer(16 * sizeof(float)), &CD3DX12_RESOURCE_DESC::Buffer(16 * sizeof(float)),
D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_COPY_DEST,
nullptr, nullptr,
IID_PPV_ARGS(&m_vertexBuffer) IID_PPV_ARGS(&vertex_buffer)
)); ));
D3D12_SUBRESOURCE_DATA vertexData = { reinterpret_cast<BYTE*>(quadVertex), 16 * sizeof(float), 1 }; D3D12_SUBRESOURCE_DATA vertexData = { reinterpret_cast<BYTE*>(quadVertex), 16 * sizeof(float), 1 };
UpdateSubresources(cmdList.Get(), m_vertexBuffer, intermediateBuffer.Get(), 0, 0, 1, &vertexData); UpdateSubresources(cmdList.Get(), vertex_buffer, intermediateBuffer.Get(), 0, 0, 1, &vertexData);
cmdList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_vertexBuffer, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER)); cmdList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(vertex_buffer, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER));
CHECK_HRESULT(cmdList->Close()); CHECK_HRESULT(cmdList->Close());
gfxcommandqueue->ExecuteCommandLists(1, CommandListCast(cmdList.GetAddressOf())); gfx_command_queue->ExecuteCommandLists(1, CommandListCast(cmdList.GetAddressOf()));
// Now wait until upload has completed // Now wait until upload has completed
gfxcommandqueue->Signal(fence.Get(), 1); gfx_command_queue->Signal(fence.Get(), 1);
WaitForSingleObjectEx(handle, INFINITE, FALSE); WaitForSingleObjectEx(handle, INFINITE, FALSE);
CloseHandle(handle); CloseHandle(handle);
} }
void D3D12GSRender::initConvertShader() void D3D12GSRender::init_convert_shader()
{ {
const auto &p = compileF32toU8CS(); const auto &p = compileF32toU8CS();
CHECK_HRESULT( CHECK_HRESULT(
m_device->CreateRootSignature(0, p.second->GetBufferPointer(), p.second->GetBufferSize(), IID_PPV_ARGS(&m_convertRootSignature)) m_device->CreateRootSignature(0, p.second->GetBufferPointer(), p.second->GetBufferSize(), IID_PPV_ARGS(&m_convert_root_signature))
); );
D3D12_COMPUTE_PIPELINE_STATE_DESC computePipelineStateDesc = {}; D3D12_COMPUTE_PIPELINE_STATE_DESC computePipelineStateDesc = {};
computePipelineStateDesc.CS.BytecodeLength = p.first->GetBufferSize(); computePipelineStateDesc.CS.BytecodeLength = p.first->GetBufferSize();
computePipelineStateDesc.CS.pShaderBytecode = p.first->GetBufferPointer(); computePipelineStateDesc.CS.pShaderBytecode = p.first->GetBufferPointer();
computePipelineStateDesc.pRootSignature = m_convertRootSignature; computePipelineStateDesc.pRootSignature = m_convert_root_signature;
CHECK_HRESULT( CHECK_HRESULT(
m_device->CreateComputePipelineState(&computePipelineStateDesc, IID_PPV_ARGS(&m_convertPSO)) m_device->CreateComputePipelineState(&computePipelineStateDesc, IID_PPV_ARGS(&m_convert_pso))
); );
p.first->Release(); p.first->Release();

View file

@ -719,45 +719,45 @@ namespace
}; };
} }
Vertex_base_type to_vertex_base_type(u8 in) rsx::vertex_base_type rsx::to_vertex_base_type(u8 in)
{ {
switch (in) switch (in)
{ {
case 1: return Vertex_base_type::s1; case 1: return rsx::vertex_base_type::s1;
case 2: return Vertex_base_type::f; case 2: return rsx::vertex_base_type::f;
case 3: return Vertex_base_type::sf; case 3: return rsx::vertex_base_type::sf;
case 4: return Vertex_base_type::ub; case 4: return rsx::vertex_base_type::ub;
case 5: return Vertex_base_type::s32k; case 5: return rsx::vertex_base_type::s32k;
case 6: return Vertex_base_type::cmp; case 6: return rsx::vertex_base_type::cmp;
case 7: return Vertex_base_type::ub256; case 7: return rsx::vertex_base_type::ub256;
} }
throw new EXCEPTION("Unknow vertex base type %d", in); throw new EXCEPTION("Unknow vertex base type %d", in);
} }
Index_array_type to_index_array_type(u8 in) rsx::index_array_type rsx::to_index_array_type(u8 in)
{ {
switch (in) switch (in)
{ {
case 0: return Index_array_type::unsigned_32b; case 0: return rsx::index_array_type::u32;
case 1: return Index_array_type::unsigned_16b; case 1: return rsx::index_array_type::u16;
} }
throw new EXCEPTION("Unknown index array type %d", in); throw new EXCEPTION("Unknown index array type %d", in);
} }
Primitive_type to_primitive_type(u8 in) rsx::primitive_type rsx::to_primitive_type(u8 in)
{ {
switch (in) switch (in)
{ {
case 1: return Primitive_type::points; case 1: return rsx::primitive_type::points;
case 2: return Primitive_type::lines; case 2: return rsx::primitive_type::lines;
case 3: return Primitive_type::line_loop; case 3: return rsx::primitive_type::line_loop;
case 4: return Primitive_type::line_strip; case 4: return rsx::primitive_type::line_strip;
case 5: return Primitive_type::triangles; case 5: return rsx::primitive_type::triangles;
case 6: return Primitive_type::triangle_strip; case 6: return rsx::primitive_type::triangle_strip;
case 7: return Primitive_type::triangle_fan; case 7: return rsx::primitive_type::triangle_fan;
case 8: return Primitive_type::quads; case 8: return rsx::primitive_type::quads;
case 9: return Primitive_type::quad_strip; case 9: return rsx::primitive_type::quad_strip;
case 10: return Primitive_type::polygon; case 10: return rsx::primitive_type::polygon;
} }
throw new EXCEPTION("Unknow primitive type %d", in); throw new EXCEPTION("Unknow primitive type %d", in);
} }
@ -801,26 +801,26 @@ enum
}; };
Surface_target to_surface_target(u8 in) rsx::surface_target rsx::to_surface_target(u8 in)
{ {
switch (in) switch (in)
{ {
case CELL_GCM_SURFACE_TARGET_NONE: return Surface_target::none; case CELL_GCM_SURFACE_TARGET_NONE: return rsx::surface_target::none;
case CELL_GCM_SURFACE_TARGET_0: return Surface_target::surface_a; case CELL_GCM_SURFACE_TARGET_0: return rsx::surface_target::surface_a;
case CELL_GCM_SURFACE_TARGET_1: return Surface_target::surface_b; case CELL_GCM_SURFACE_TARGET_1: return rsx::surface_target::surface_b;
case CELL_GCM_SURFACE_TARGET_MRT1: return Surface_target::surfaces_a_b; case CELL_GCM_SURFACE_TARGET_MRT1: return rsx::surface_target::surfaces_a_b;
case CELL_GCM_SURFACE_TARGET_MRT2: return Surface_target::surfaces_a_b_c; case CELL_GCM_SURFACE_TARGET_MRT2: return rsx::surface_target::surfaces_a_b_c;
case CELL_GCM_SURFACE_TARGET_MRT3: return Surface_target::surfaces_a_b_c_d; case CELL_GCM_SURFACE_TARGET_MRT3: return rsx::surface_target::surfaces_a_b_c_d;
} }
throw EXCEPTION("Unknow surface target %x", in); throw EXCEPTION("Unknow surface target %x", in);
} }
Surface_depth_format to_surface_depth_format(u8 in) rsx::surface_depth_format rsx::to_surface_depth_format(u8 in)
{ {
switch (in) switch (in)
{ {
case CELL_GCM_SURFACE_Z16: return Surface_depth_format::z16; case CELL_GCM_SURFACE_Z16: return rsx::surface_depth_format::z16;
case CELL_GCM_SURFACE_Z24S8: return Surface_depth_format::z24s8; case CELL_GCM_SURFACE_Z24S8: return rsx::surface_depth_format::z24s8;
} }
throw EXCEPTION("Unknow surface depth format %x", in); throw EXCEPTION("Unknow surface depth format %x", in);
} }
@ -836,36 +836,36 @@ std::string rsx::get_method_name(const u32 id)
return fmt::format("unknown/illegal method [0x%08x]", id); return fmt::format("unknown/illegal method [0x%08x]", id);
} }
Surface_antialiasing to_surface_antialiasing(u8 in) rsx::surface_antialiasing rsx::to_surface_antialiasing(u8 in)
{ {
switch (in) switch (in)
{ {
case CELL_GCM_SURFACE_CENTER_1: return Surface_antialiasing::center_1_sample; case CELL_GCM_SURFACE_CENTER_1: return rsx::surface_antialiasing::center_1_sample;
case CELL_GCM_SURFACE_DIAGONAL_CENTERED_2: return Surface_antialiasing::diagonal_centered_2_samples; case CELL_GCM_SURFACE_DIAGONAL_CENTERED_2: return rsx::surface_antialiasing::diagonal_centered_2_samples;
case CELL_GCM_SURFACE_SQUARE_CENTERED_4: return Surface_antialiasing::square_centered_4_samples; case CELL_GCM_SURFACE_SQUARE_CENTERED_4: return rsx::surface_antialiasing::square_centered_4_samples;
case CELL_GCM_SURFACE_SQUARE_ROTATED_4: return Surface_antialiasing::square_rotated_4_samples; case CELL_GCM_SURFACE_SQUARE_ROTATED_4: return rsx::surface_antialiasing::square_rotated_4_samples;
} }
throw EXCEPTION("unknow surface antialiasing format %x", in); throw EXCEPTION("unknow surface antialiasing format %x", in);
} }
Surface_color_format to_surface_color_format(u8 in) rsx::surface_color_format rsx::to_surface_color_format(u8 in)
{ {
switch (in) switch (in)
{ {
case CELL_GCM_SURFACE_X1R5G5B5_Z1R5G5B5: return Surface_color_format::x1r5g5b5_z1r5g5b5; case CELL_GCM_SURFACE_X1R5G5B5_Z1R5G5B5: return rsx::surface_color_format::x1r5g5b5_z1r5g5b5;
case CELL_GCM_SURFACE_X1R5G5B5_O1R5G5B5: return Surface_color_format::x1r5g5b5_o1r5g5b5; case CELL_GCM_SURFACE_X1R5G5B5_O1R5G5B5: return rsx::surface_color_format::x1r5g5b5_o1r5g5b5;
case CELL_GCM_SURFACE_R5G6B5: return Surface_color_format::r5g6b5; case CELL_GCM_SURFACE_R5G6B5: return rsx::surface_color_format::r5g6b5;
case CELL_GCM_SURFACE_X8R8G8B8_Z8R8G8B8: return Surface_color_format::x8r8g8b8_z8r8g8b8; case CELL_GCM_SURFACE_X8R8G8B8_Z8R8G8B8: return rsx::surface_color_format::x8r8g8b8_z8r8g8b8;
case CELL_GCM_SURFACE_X8R8G8B8_O8R8G8B8: return Surface_color_format::x8r8g8b8_o8r8g8b8; case CELL_GCM_SURFACE_X8R8G8B8_O8R8G8B8: return rsx::surface_color_format::x8r8g8b8_o8r8g8b8;
case CELL_GCM_SURFACE_A8R8G8B8: return Surface_color_format::a8r8g8b8; case CELL_GCM_SURFACE_A8R8G8B8: return rsx::surface_color_format::a8r8g8b8;
case CELL_GCM_SURFACE_B8: return Surface_color_format::b8; case CELL_GCM_SURFACE_B8: return rsx::surface_color_format::b8;
case CELL_GCM_SURFACE_G8B8: return Surface_color_format::g8b8; case CELL_GCM_SURFACE_G8B8: return rsx::surface_color_format::g8b8;
case CELL_GCM_SURFACE_F_W16Z16Y16X16: return Surface_color_format::w16z16y16x16; case CELL_GCM_SURFACE_F_W16Z16Y16X16: return rsx::surface_color_format::w16z16y16x16;
case CELL_GCM_SURFACE_F_W32Z32Y32X32: return Surface_color_format::w32z32y32x32; case CELL_GCM_SURFACE_F_W32Z32Y32X32: return rsx::surface_color_format::w32z32y32x32;
case CELL_GCM_SURFACE_F_X32: return Surface_color_format::x32; case CELL_GCM_SURFACE_F_X32: return rsx::surface_color_format::x32;
case CELL_GCM_SURFACE_X8B8G8R8_Z8B8G8R8: return Surface_color_format::x8b8g8r8_z8b8g8r8; case CELL_GCM_SURFACE_X8B8G8R8_Z8B8G8R8: return rsx::surface_color_format::x8b8g8r8_z8b8g8r8;
case CELL_GCM_SURFACE_X8B8G8R8_O8B8G8R8: return Surface_color_format::x8b8g8r8_o8b8g8r8; case CELL_GCM_SURFACE_X8B8G8R8_O8B8G8R8: return rsx::surface_color_format::x8b8g8r8_o8b8g8r8;
case CELL_GCM_SURFACE_A8B8G8R8: return Surface_color_format::a8b8g8r8; case CELL_GCM_SURFACE_A8B8G8R8: return rsx::surface_color_format::a8b8g8r8;
} }
throw EXCEPTION("unknow surface color format %x", in); throw EXCEPTION("unknow surface color format %x", in);
} }
@ -953,18 +953,18 @@ namespace
std::string get_primitive_mode(u8 draw_mode) std::string get_primitive_mode(u8 draw_mode)
{ {
switch (to_primitive_type(draw_mode)) switch (rsx::to_primitive_type(draw_mode))
{ {
case Primitive_type::points: return "Points"; case rsx::primitive_type::points: return "Points";
case Primitive_type::lines: return "Lines"; case rsx::primitive_type::lines: return "Lines";
case Primitive_type::line_loop: return "Line_loop"; case rsx::primitive_type::line_loop: return "Line_loop";
case Primitive_type::line_strip: return "Line_strip"; case rsx::primitive_type::line_strip: return "Line_strip";
case Primitive_type::triangles: return "Triangles"; case rsx::primitive_type::triangles: return "Triangles";
case Primitive_type::triangle_strip: return "Triangle_strip"; case rsx::primitive_type::triangle_strip: return "Triangle_strip";
case Primitive_type::triangle_fan: return "Triangle_fan"; case rsx::primitive_type::triangle_fan: return "Triangle_fan";
case Primitive_type::quads: return "Quads"; case rsx::primitive_type::quads: return "Quads";
case Primitive_type::quad_strip: return "Quad_strip"; case rsx::primitive_type::quad_strip: return "Quad_strip";
case Primitive_type::polygon: return "Polygon"; case rsx::primitive_type::polygon: return "Polygon";
} }
return "Error"; return "Error";
} }
@ -989,58 +989,58 @@ namespace
std::string depth_stencil_surface_format(u32 format) std::string depth_stencil_surface_format(u32 format)
{ {
switch (to_surface_depth_format(format)) switch (rsx::to_surface_depth_format(format))
{ {
case Surface_depth_format::z16: return "CELL_GCM_SURFACE_Z16"; case rsx::surface_depth_format::z16: return "CELL_GCM_SURFACE_Z16";
case Surface_depth_format::z24s8: return "CELL_GCM_SURFACE_Z24S8"; case rsx::surface_depth_format::z24s8: return "CELL_GCM_SURFACE_Z24S8";
} }
return "Error"; return "Error";
} }
std::string surface_antialiasing(u8 format) std::string surface_antialiasing(u8 format)
{ {
switch (to_surface_antialiasing(format)) switch (rsx::to_surface_antialiasing(format))
{ {
case Surface_antialiasing::center_1_sample: "1 sample centered"; case rsx::surface_antialiasing::center_1_sample: return "1 sample centered";
case Surface_antialiasing::diagonal_centered_2_samples: return "2 samples diagonal centered"; case rsx::surface_antialiasing::diagonal_centered_2_samples: return "2 samples diagonal centered";
case Surface_antialiasing::square_centered_4_samples: return "4 samples square centered"; case rsx::surface_antialiasing::square_centered_4_samples: return "4 samples square centered";
case Surface_antialiasing::square_rotated_4_samples: return "4 samples diagonal rotated"; case rsx::surface_antialiasing::square_rotated_4_samples: return "4 samples diagonal rotated";
} }
return "Error"; return "Error";
} }
std::string color_surface_format(u32 format) std::string surface_color_format(u32 format)
{ {
switch (to_surface_color_format(format)) switch (rsx::to_surface_color_format(format))
{ {
case Surface_color_format::x1r5g5b5_z1r5g5b5: return "CELL_GCM_SURFACE_X1R5G5B5_Z1R5G5B5"; case rsx::surface_color_format::x1r5g5b5_z1r5g5b5: return "CELL_GCM_SURFACE_X1R5G5B5_Z1R5G5B5";
case Surface_color_format::x1r5g5b5_o1r5g5b5: return "CELL_GCM_SURFACE_X1R5G5B5_O1R5G5B5"; case rsx::surface_color_format::x1r5g5b5_o1r5g5b5: return "CELL_GCM_SURFACE_X1R5G5B5_O1R5G5B5";
case Surface_color_format::r5g6b5 : return "CELL_GCM_SURFACE_R5G6B5"; case rsx::surface_color_format::r5g6b5 : return "CELL_GCM_SURFACE_R5G6B5";
case Surface_color_format::x8r8g8b8_z8r8g8b8: return "CELL_GCM_SURFACE_X8R8G8B8_Z8R8G8B8"; case rsx::surface_color_format::x8r8g8b8_z8r8g8b8: return "CELL_GCM_SURFACE_X8R8G8B8_Z8R8G8B8";
case Surface_color_format::x8r8g8b8_o8r8g8b8: return "CELL_GCM_SURFACE_X8R8G8B8_O8R8G8B8"; case rsx::surface_color_format::x8r8g8b8_o8r8g8b8: return "CELL_GCM_SURFACE_X8R8G8B8_O8R8G8B8";
case Surface_color_format::a8r8g8b8: return "CELL_GCM_SURFACE_A8R8G8B8"; case rsx::surface_color_format::a8r8g8b8: return "CELL_GCM_SURFACE_A8R8G8B8";
case Surface_color_format::b8: return "CELL_GCM_SURFACE_B8"; case rsx::surface_color_format::b8: return "CELL_GCM_SURFACE_B8";
case Surface_color_format::g8b8: return "CELL_GCM_SURFACE_G8B8"; case rsx::surface_color_format::g8b8: return "CELL_GCM_SURFACE_G8B8";
case Surface_color_format::w16z16y16x16: return "CELL_GCM_SURFACE_F_W16Z16Y16X16"; case rsx::surface_color_format::w16z16y16x16: return "CELL_GCM_SURFACE_F_W16Z16Y16X16";
case Surface_color_format::w32z32y32x32: return "CELL_GCM_SURFACE_F_W32Z32Y32X32"; case rsx::surface_color_format::w32z32y32x32: return "CELL_GCM_SURFACE_F_W32Z32Y32X32";
case Surface_color_format::x32: return "CELL_GCM_SURFACE_F_X32"; case rsx::surface_color_format::x32: return "CELL_GCM_SURFACE_F_X32";
case Surface_color_format::x8b8g8r8_z8b8g8r8: return "CELL_GCM_SURFACE_X8B8G8R8_Z8B8G8R8"; case rsx::surface_color_format::x8b8g8r8_z8b8g8r8: return "CELL_GCM_SURFACE_X8B8G8R8_Z8B8G8R8";
case Surface_color_format::x8b8g8r8_o8b8g8r8: return "CELL_GCM_SURFACE_X8B8G8R8_O8B8G8R8"; case rsx::surface_color_format::x8b8g8r8_o8b8g8r8: return "CELL_GCM_SURFACE_X8B8G8R8_O8B8G8R8";
case Surface_color_format::a8b8g8r8: return "CELL_GCM_SURFACE_A8B8G8R8"; case rsx::surface_color_format::a8b8g8r8: return "CELL_GCM_SURFACE_A8B8G8R8";
} }
return "Error"; return "Error";
} }
std::string surface_target(u32 target) std::string surface_target(u32 target)
{ {
switch (to_surface_target(target)) switch (rsx::to_surface_target(target))
{ {
case Surface_target::none: return "none"; case rsx::surface_target::none: return "none";
case Surface_target::surface_a: return "surface A"; case rsx::surface_target::surface_a: return "surface A";
case Surface_target::surface_b: return "surface B"; case rsx::surface_target::surface_b: return "surface B";
case Surface_target::surfaces_a_b: return "surfaces A and B"; case rsx::surface_target::surfaces_a_b: return "surfaces A and B";
case Surface_target::surfaces_a_b_c: return "surfaces A, B and C"; case rsx::surface_target::surfaces_a_b_c: return "surfaces A, B and C";
case Surface_target::surfaces_a_b_c_d: return "surfaces A,B, C and D"; case rsx::surface_target::surfaces_a_b_c_d: return "surfaces A,B, C and D";
} }
return "Error"; return "Error";
} }
@ -1078,15 +1078,15 @@ namespace
std::string get_vertex_attribute_format(u8 type) std::string get_vertex_attribute_format(u8 type)
{ {
switch (to_vertex_base_type(type)) switch (rsx::to_vertex_base_type(type))
{ {
case Vertex_base_type::s1: return "Short"; case rsx::vertex_base_type::s1: return "Short";
case Vertex_base_type::f: return "Float"; case rsx::vertex_base_type::f: return "Float";
case Vertex_base_type::sf: return "Half float"; case rsx::vertex_base_type::sf: return "Half float";
case Vertex_base_type::ub: return "Unsigned byte"; case rsx::vertex_base_type::ub: return "Unsigned byte";
case Vertex_base_type::s32k: return "Signed int"; case rsx::vertex_base_type::s32k: return "Signed int";
case Vertex_base_type::cmp: return "CMP"; case rsx::vertex_base_type::cmp: return "CMP";
case Vertex_base_type::ub256: return "UB256"; case rsx::vertex_base_type::ub256: return "UB256";
} }
} }
@ -1104,10 +1104,10 @@ namespace
std::string index_type(u16 arg) std::string index_type(u16 arg)
{ {
switch (to_index_array_type(arg)) switch (rsx::to_index_array_type(arg))
{ {
case Index_array_type::unsigned_16b: return "unsigned short"; case rsx::index_array_type::u16: return "unsigned short";
case Index_array_type::unsigned_32b: return "unsigned int"; case rsx::index_array_type::u32: return "unsigned int";
} }
return "Error"; return "Error";
} }
@ -1443,7 +1443,7 @@ namespace
{ NV4097_SET_SURFACE_PITCH_Z, [](u32 arg) -> std::string { return "Surface Zeta: Pitch = " + std::to_string(arg); } }, { NV4097_SET_SURFACE_PITCH_Z, [](u32 arg) -> std::string { return "Surface Zeta: Pitch = " + std::to_string(arg); } },
{ NV4097_SET_SURFACE_ZETA_OFFSET, [](u32 arg) -> std::string { return "Surface Zeta: Offset = " + ptr_to_string(arg); } }, { NV4097_SET_SURFACE_ZETA_OFFSET, [](u32 arg) -> std::string { return "Surface Zeta: Offset = " + ptr_to_string(arg); } },
{ NV4097_SET_CONTEXT_DMA_ZETA, [](u32 arg) -> std::string { return "Surface Zeta: DMA mode = " + dma_mode(arg);} }, { NV4097_SET_CONTEXT_DMA_ZETA, [](u32 arg) -> std::string { return "Surface Zeta: DMA mode = " + dma_mode(arg);} },
{ NV4097_SET_SURFACE_FORMAT, [](u32 arg) -> std::string { return "Surface: Color format = " + color_surface_format(arg & 0x1F) + " DepthStencil format = " + depth_stencil_surface_format((arg >> 5) & 0x7) + " Anti aliasing =" + surface_antialiasing((arg >> 12) & 0x7); } }, { NV4097_SET_SURFACE_FORMAT, [](u32 arg) -> std::string { return "Surface: Color format = " + surface_color_format(arg & 0x1F) + " DepthStencil format = " + depth_stencil_surface_format((arg >> 5) & 0x7) + " Anti aliasing =" + surface_antialiasing((arg >> 12) & 0x7); } },
{ NV4097_SET_SURFACE_CLIP_HORIZONTAL, [](u32 arg) -> std::string { return "Surface: clip x = " + std::to_string(arg & 0xFFFF) + " width = " + std::to_string(arg >> 16); } }, { NV4097_SET_SURFACE_CLIP_HORIZONTAL, [](u32 arg) -> std::string { return "Surface: clip x = " + std::to_string(arg & 0xFFFF) + " width = " + std::to_string(arg >> 16); } },
{ NV4097_SET_SURFACE_CLIP_VERTICAL, [](u32 arg) -> std::string { return "Surface: clip y = " + std::to_string(arg & 0xFFFF) + " height = " + std::to_string(arg >> 16); } }, { NV4097_SET_SURFACE_CLIP_VERTICAL, [](u32 arg) -> std::string { return "Surface: clip y = " + std::to_string(arg & 0xFFFF) + " height = " + std::to_string(arg >> 16); } },
{ NV4097_SET_SURFACE_COLOR_TARGET, [](u32 arg) -> std::string { return "Surface: Targets " + surface_target(arg); } }, { NV4097_SET_SURFACE_COLOR_TARGET, [](u32 arg) -> std::string { return "Surface: Targets " + surface_target(arg); } },

View file

@ -23,92 +23,95 @@ enum
CELL_GCM_DISPLAY_FREQUENCY_DISABLE = 3, CELL_GCM_DISPLAY_FREQUENCY_DISABLE = 3,
}; };
enum class Vertex_base_type : u8 namespace rsx
{ {
s1, ///< signed byte enum class vertex_base_type : u8
f, ///< float {
sf, ///< half float s1, ///< signed byte
ub, ///< unsigned byte f, ///< float
s32k, ///< signed 32bits int sf, ///< half float
cmp, ///< compressed aka X11G11Z10 and always 1. W. ub, ///< unsigned byte
ub256, s32k, ///< signed 32bits int
}; cmp, ///< compressed aka X11G11Z10 and always 1. W.
ub256,
};
Vertex_base_type to_vertex_base_type(u8 in); vertex_base_type to_vertex_base_type(u8 in);
enum class Index_array_type : u8 enum class index_array_type : u8
{ {
unsigned_32b, u32,
unsigned_16b, u16,
}; };
Index_array_type to_index_array_type(u8 in); index_array_type to_index_array_type(u8 in);
enum class Primitive_type : u8 enum class primitive_type : u8
{ {
points, points,
lines, lines,
line_loop, // line strip with last end being joined with first end. line_loop, // line strip with last end being joined with first end.
line_strip, line_strip,
triangles, triangles,
triangle_strip, triangle_strip,
triangle_fan, // like strip except that every triangle share the first vertex and one instead of 2 from previous triangle. triangle_fan, // like strip except that every triangle share the first vertex and one instead of 2 from previous triangle.
quads, quads,
quad_strip, quad_strip,
polygon, // convex polygon polygon, // convex polygon
}; };
Primitive_type to_primitive_type(u8 in); primitive_type to_primitive_type(u8 in);
enum class Surface_target : u8 enum class surface_target : u8
{ {
none, none,
surface_a, surface_a,
surface_b, surface_b,
surfaces_a_b, surfaces_a_b,
surfaces_a_b_c, surfaces_a_b_c,
surfaces_a_b_c_d, surfaces_a_b_c_d,
}; };
Surface_target to_surface_target(u8 in); surface_target to_surface_target(u8 in);
enum class Surface_depth_format : u8 enum class surface_depth_format : u8
{ {
z16, // unsigned 16 bits depth z16, // unsigned 16 bits depth
z24s8, // unsigned 24 bits depth + 8 bits stencil z24s8, // unsigned 24 bits depth + 8 bits stencil
}; };
Surface_depth_format to_surface_depth_format(u8 in); surface_depth_format to_surface_depth_format(u8 in);
enum class Surface_antialiasing : u8 enum class surface_antialiasing : u8
{ {
center_1_sample, center_1_sample,
diagonal_centered_2_samples, diagonal_centered_2_samples,
square_centered_4_samples, square_centered_4_samples,
square_rotated_4_samples, square_rotated_4_samples,
}; };
Surface_antialiasing to_surface_antialiasing(u8 in); surface_antialiasing to_surface_antialiasing(u8 in);
enum class Surface_color_format : u8 enum class surface_color_format : u8
{ {
x1r5g5b5_z1r5g5b5, x1r5g5b5_z1r5g5b5,
x1r5g5b5_o1r5g5b5, x1r5g5b5_o1r5g5b5,
r5g6b5, r5g6b5,
x8r8g8b8_z8r8g8b8, x8r8g8b8_z8r8g8b8,
x8r8g8b8_o8r8g8b8, x8r8g8b8_o8r8g8b8,
a8r8g8b8, a8r8g8b8,
b8, b8,
g8b8, g8b8,
w16z16y16x16, w16z16y16x16,
w32z32y32x32, w32z32y32x32,
x32, x32,
x8b8g8r8_z8b8g8r8, x8b8g8r8_z8b8g8r8,
x8b8g8r8_o8b8g8r8, x8b8g8r8_o8b8g8r8,
a8b8g8r8, a8b8g8r8,
}; };
Surface_color_format to_surface_color_format(u8 in); surface_color_format to_surface_color_format(u8 in);
}
enum enum
{ {

View file

@ -11,22 +11,22 @@
namespace namespace
{ {
u32 get_max_depth_value(Surface_depth_format format) u32 get_max_depth_value(rsx::surface_depth_format format)
{ {
switch (format) switch (format)
{ {
case Surface_depth_format::z16: return 0xFFFF; case rsx::surface_depth_format::z16: return 0xFFFF;
case Surface_depth_format::z24s8: return 0xFFFFFF; case rsx::surface_depth_format::z24s8: return 0xFFFFFF;
} }
throw EXCEPTION("Unknow depth format"); throw EXCEPTION("Unknow depth format");
} }
u8 get_pixel_size(Surface_depth_format format) u8 get_pixel_size(rsx::surface_depth_format format)
{ {
switch (format) switch (format)
{ {
case Surface_depth_format::z16: return 2; case rsx::surface_depth_format::z16: return 2;
case Surface_depth_format::z24s8: return 4; case rsx::surface_depth_format::z24s8: return 4;
} }
throw EXCEPTION("Unknow depth format"); throw EXCEPTION("Unknow depth format");
} }
@ -120,7 +120,7 @@ void GLGSRender::begin()
__glcheck glBlendFuncSeparate(sfactor_rgb, dfactor_rgb, sfactor_a, dfactor_a); __glcheck glBlendFuncSeparate(sfactor_rgb, dfactor_rgb, sfactor_a, dfactor_a);
if (m_surface.color_format == Surface_color_format::w16z16y16x16) //TODO: check another color formats if (m_surface.color_format == rsx::surface_color_format::w16z16y16x16) //TODO: check another color formats
{ {
u32 blend_color = rsx::method_registers[NV4097_SET_BLEND_COLOR]; u32 blend_color = rsx::method_registers[NV4097_SET_BLEND_COLOR];
u32 blend_color2 = rsx::method_registers[NV4097_SET_BLEND_COLOR2]; u32 blend_color2 = rsx::method_registers[NV4097_SET_BLEND_COLOR2];
@ -318,33 +318,33 @@ void apply_attrib_array(gl::glsl::program& program, int location, const std::vec
namespace namespace
{ {
gl::buffer_pointer::type gl_types(Vertex_base_type type) gl::buffer_pointer::type gl_types(rsx::vertex_base_type type)
{ {
switch (type) switch (type)
{ {
case Vertex_base_type::s1: return gl::buffer_pointer::type::s16; case rsx::vertex_base_type::s1: return gl::buffer_pointer::type::s16;
case Vertex_base_type::f: return gl::buffer_pointer::type::f32; case rsx::vertex_base_type::f: return gl::buffer_pointer::type::f32;
case Vertex_base_type::sf: return gl::buffer_pointer::type::f16; case rsx::vertex_base_type::sf: return gl::buffer_pointer::type::f16;
case Vertex_base_type::ub: return gl::buffer_pointer::type::u8; case rsx::vertex_base_type::ub: return gl::buffer_pointer::type::u8;
case Vertex_base_type::s32k: return gl::buffer_pointer::type::s32; case rsx::vertex_base_type::s32k: return gl::buffer_pointer::type::s32;
case Vertex_base_type::cmp: return gl::buffer_pointer::type::s16; // Needs conversion case rsx::vertex_base_type::cmp: return gl::buffer_pointer::type::s16; // Needs conversion
case Vertex_base_type::ub256: gl::buffer_pointer::type::u8; case rsx::vertex_base_type::ub256: gl::buffer_pointer::type::u8;
} }
throw EXCEPTION("unknow vertex type"); throw EXCEPTION("unknow vertex type");
} }
bool gl_normalized(Vertex_base_type type) bool gl_normalized(rsx::vertex_base_type type)
{ {
switch (type) switch (type)
{ {
case Vertex_base_type::s1: case rsx::vertex_base_type::s1:
case Vertex_base_type::ub: case rsx::vertex_base_type::ub:
case Vertex_base_type::cmp: case rsx::vertex_base_type::cmp:
return true; return true;
case Vertex_base_type::f: case rsx::vertex_base_type::f:
case Vertex_base_type::sf: case rsx::vertex_base_type::sf:
case Vertex_base_type::ub256: case rsx::vertex_base_type::ub256:
case Vertex_base_type::s32k: case rsx::vertex_base_type::s32k:
return false; return false;
} }
throw EXCEPTION("unknow vertex type"); throw EXCEPTION("unknow vertex type");
@ -402,9 +402,9 @@ void GLGSRender::end()
std::vector<u8> vertex_index_array; std::vector<u8> vertex_index_array;
vertex_draw_count = 0; vertex_draw_count = 0;
u32 min_index, max_index; u32 min_index, max_index;
if (draw_command == Draw_command::draw_command_indexed) if (draw_command == rsx::draw_command::indexed)
{ {
Index_array_type type = to_index_array_type(rsx::method_registers[NV4097_SET_INDEX_ARRAY_DMA] >> 4); rsx::index_array_type type = rsx::to_index_array_type(rsx::method_registers[NV4097_SET_INDEX_ARRAY_DMA] >> 4);
u32 type_size = gsl::narrow<u32>(get_index_type_size(type)); u32 type_size = gsl::narrow<u32>(get_index_type_size(type));
for (const auto& first_count : first_count_commands) for (const auto& first_count : first_count_commands)
{ {
@ -415,16 +415,16 @@ void GLGSRender::end()
switch (type) switch (type)
{ {
case Index_array_type::unsigned_32b: case rsx::index_array_type::u32:
std::tie(min_index, max_index) = write_index_array_data_to_buffer_untouched(gsl::span<u32>((u32*)vertex_index_array.data(), vertex_draw_count), first_count_commands); std::tie(min_index, max_index) = write_index_array_data_to_buffer_untouched(gsl::span<u32>((u32*)vertex_index_array.data(), vertex_draw_count), first_count_commands);
break; break;
case Index_array_type::unsigned_16b: case rsx::index_array_type::u16:
std::tie(min_index, max_index) = write_index_array_data_to_buffer_untouched(gsl::span<u16>((u16*)vertex_index_array.data(), vertex_draw_count), first_count_commands); std::tie(min_index, max_index) = write_index_array_data_to_buffer_untouched(gsl::span<u16>((u16*)vertex_index_array.data(), vertex_draw_count), first_count_commands);
break; break;
} }
} }
if (draw_command == Draw_command::draw_command_inlined_array) if (draw_command == rsx::draw_command::inlined_array)
{ {
write_inline_array_to_buffer(vertex_arrays_data.data()); write_inline_array_to_buffer(vertex_arrays_data.data());
u32 offset = 0; u32 offset = 0;
@ -446,7 +446,7 @@ void GLGSRender::end()
} }
} }
if (draw_command == Draw_command::draw_command_array) if (draw_command == rsx::draw_command::array)
{ {
for (const auto &first_count : first_count_commands) for (const auto &first_count : first_count_commands)
{ {
@ -454,7 +454,7 @@ void GLGSRender::end()
} }
} }
if (draw_command == Draw_command::draw_command_array || draw_command == Draw_command::draw_command_indexed) if (draw_command == rsx::draw_command::array || draw_command == rsx::draw_command::indexed)
{ {
for (int index = 0; index < rsx::limits::vertex_count; ++index) for (int index = 0; index < rsx::limits::vertex_count; ++index)
{ {
@ -475,7 +475,7 @@ void GLGSRender::end()
// Fill vertex_array // Fill vertex_array
u32 element_size = rsx::get_vertex_type_size_on_host(vertex_info.type, vertex_info.size); u32 element_size = rsx::get_vertex_type_size_on_host(vertex_info.type, vertex_info.size);
vertex_array.resize(vertex_draw_count * element_size); vertex_array.resize(vertex_draw_count * element_size);
if (draw_command == Draw_command::draw_command_array) if (draw_command == rsx::draw_command::array)
{ {
size_t offset = 0; size_t offset = 0;
for (const auto &first_count : first_count_commands) for (const auto &first_count : first_count_commands)
@ -484,7 +484,7 @@ void GLGSRender::end()
offset += first_count.second * element_size; offset += first_count.second * element_size;
} }
} }
if (draw_command == Draw_command::draw_command_indexed) if (draw_command == rsx::draw_command::indexed)
{ {
vertex_array.resize((max_index + 1) * element_size); vertex_array.resize((max_index + 1) * element_size);
write_vertex_array_data_to_buffer(vertex_array.data(), 0, max_index + 1, index, vertex_info); write_vertex_array_data_to_buffer(vertex_array.data(), 0, max_index + 1, index, vertex_info);
@ -508,7 +508,7 @@ void GLGSRender::end()
switch (vertex_info.type) switch (vertex_info.type)
{ {
case Vertex_base_type::f: case rsx::vertex_base_type::f:
switch (register_vertex_info[index].size) switch (register_vertex_info[index].size)
{ {
case 1: apply_attrib_array<f32, 1>(*m_program, location, vertex_data); break; case 1: apply_attrib_array<f32, 1>(*m_program, location, vertex_data); break;
@ -527,15 +527,15 @@ void GLGSRender::end()
} }
m_vbo.data(vertex_arrays_data.size(), vertex_arrays_data.data()); m_vbo.data(vertex_arrays_data.size(), vertex_arrays_data.data());
if (draw_command == Draw_command::draw_command_indexed) if (draw_command == rsx::draw_command::indexed)
{ {
m_ebo.data(vertex_index_array.size(), vertex_index_array.data()); m_ebo.data(vertex_index_array.size(), vertex_index_array.data());
Index_array_type indexed_type = to_index_array_type(rsx::method_registers[NV4097_SET_INDEX_ARRAY_DMA] >> 4); rsx::index_array_type indexed_type = rsx::to_index_array_type(rsx::method_registers[NV4097_SET_INDEX_ARRAY_DMA] >> 4);
if (indexed_type == Index_array_type::unsigned_32b) if (indexed_type == rsx::index_array_type::u32)
__glcheck glDrawElements(gl::draw_mode(draw_mode), vertex_draw_count, GL_UNSIGNED_INT, nullptr); __glcheck glDrawElements(gl::draw_mode(draw_mode), vertex_draw_count, GL_UNSIGNED_INT, nullptr);
if (indexed_type == Index_array_type::unsigned_16b) if (indexed_type == rsx::index_array_type::u16)
__glcheck glDrawElements(gl::draw_mode(draw_mode), vertex_draw_count, GL_UNSIGNED_SHORT, nullptr); __glcheck glDrawElements(gl::draw_mode(draw_mode), vertex_draw_count, GL_UNSIGNED_SHORT, nullptr);
} }
else else
@ -677,7 +677,7 @@ void nv4097_clear_surface(u32 arg, GLGSRender* renderer)
if (arg & 0x1) if (arg & 0x1)
{ {
Surface_depth_format surface_depth_format = to_surface_depth_format((rsx::method_registers[NV4097_SET_SURFACE_FORMAT] >> 5) & 0x7); rsx::surface_depth_format surface_depth_format = rsx::to_surface_depth_format((rsx::method_registers[NV4097_SET_SURFACE_FORMAT] >> 5) & 0x7);
u32 max_depth_value = get_max_depth_value(surface_depth_format); u32 max_depth_value = get_max_depth_value(surface_depth_format);
u32 clear_depth = rsx::method_registers[NV4097_SET_ZSTENCIL_CLEAR_VALUE] >> 8; u32 clear_depth = rsx::method_registers[NV4097_SET_ZSTENCIL_CLEAR_VALUE] >> 8;
@ -855,52 +855,52 @@ struct color_format
color_swizzle swizzle; color_swizzle swizzle;
}; };
color_format surface_color_format_to_gl(Surface_color_format color_format) color_format surface_color_format_to_gl(rsx::surface_color_format color_format)
{ {
//color format //color format
switch (color_format) switch (color_format)
{ {
case Surface_color_format::r5g6b5: case rsx::surface_color_format::r5g6b5:
return{ gl::texture::type::ushort_5_6_5, gl::texture::format::bgr, false, 3, 2 }; return{ gl::texture::type::ushort_5_6_5, gl::texture::format::bgr, false, 3, 2 };
case Surface_color_format::a8r8g8b8: case rsx::surface_color_format::a8r8g8b8:
return{ gl::texture::type::uint_8_8_8_8, gl::texture::format::bgra, false, 4, 1 }; return{ gl::texture::type::uint_8_8_8_8, gl::texture::format::bgra, false, 4, 1 };
case Surface_color_format::x8r8g8b8_o8r8g8b8: case rsx::surface_color_format::x8r8g8b8_o8r8g8b8:
return{ gl::texture::type::uint_8_8_8_8, gl::texture::format::bgra, false, 4, 1, return{ gl::texture::type::uint_8_8_8_8, gl::texture::format::bgra, false, 4, 1,
{ gl::texture::channel::one, gl::texture::channel::r, gl::texture::channel::g, gl::texture::channel::b } }; { gl::texture::channel::one, gl::texture::channel::r, gl::texture::channel::g, gl::texture::channel::b } };
case Surface_color_format::w16z16y16x16: case rsx::surface_color_format::w16z16y16x16:
return{ gl::texture::type::f16, gl::texture::format::rgba, true, 4, 2 }; return{ gl::texture::type::f16, gl::texture::format::rgba, true, 4, 2 };
case Surface_color_format::w32z32y32x32: case rsx::surface_color_format::w32z32y32x32:
return{ gl::texture::type::f32, gl::texture::format::rgba, true, 4, 4 }; return{ gl::texture::type::f32, gl::texture::format::rgba, true, 4, 4 };
case Surface_color_format::b8: case rsx::surface_color_format::b8:
case Surface_color_format::x1r5g5b5_o1r5g5b5: case rsx::surface_color_format::x1r5g5b5_o1r5g5b5:
case Surface_color_format::x1r5g5b5_z1r5g5b5: case rsx::surface_color_format::x1r5g5b5_z1r5g5b5:
case Surface_color_format::x8r8g8b8_z8r8g8b8: case rsx::surface_color_format::x8r8g8b8_z8r8g8b8:
case Surface_color_format::g8b8: case rsx::surface_color_format::g8b8:
case Surface_color_format::x32: case rsx::surface_color_format::x32:
case Surface_color_format::x8b8g8r8_o8b8g8r8: case rsx::surface_color_format::x8b8g8r8_o8b8g8r8:
case Surface_color_format::x8b8g8r8_z8b8g8r8: case rsx::surface_color_format::x8b8g8r8_z8b8g8r8:
case Surface_color_format::a8b8g8r8: case rsx::surface_color_format::a8b8g8r8:
default: default:
LOG_ERROR(RSX, "Surface color buffer: Unsupported surface color format (0x%x)", color_format); LOG_ERROR(RSX, "Surface color buffer: Unsupported surface color format (0x%x)", color_format);
return{ gl::texture::type::uint_8_8_8_8, gl::texture::format::bgra, false, 4, 1 }; return{ gl::texture::type::uint_8_8_8_8, gl::texture::format::bgra, false, 4, 1 };
} }
} }
std::pair<gl::texture::type, gl::texture::format> surface_depth_format_to_gl(Surface_depth_format depth_format) std::pair<gl::texture::type, gl::texture::format> surface_depth_format_to_gl(rsx::surface_depth_format depth_format)
{ {
switch (depth_format) switch (depth_format)
{ {
case Surface_depth_format::z16: case rsx::surface_depth_format::z16:
return std::make_pair(gl::texture::type::ushort, gl::texture::format::depth); return std::make_pair(gl::texture::type::ushort, gl::texture::format::depth);
default: default:
LOG_ERROR(RSX, "Surface depth buffer: Unsupported surface depth format (0x%x)", depth_format); LOG_ERROR(RSX, "Surface depth buffer: Unsupported surface depth format (0x%x)", depth_format);
case Surface_depth_format::z24s8: case rsx::surface_depth_format::z24s8:
return std::make_pair(gl::texture::type::uint_24_8, gl::texture::format::depth_stencil); return std::make_pair(gl::texture::type::uint_24_8, gl::texture::format::depth_stencil);
//return std::make_pair(gl::texture::type::f32, gl::texture::format::depth); //return std::make_pair(gl::texture::type::f32, gl::texture::format::depth);
} }
@ -949,7 +949,7 @@ void GLGSRender::init_buffers(bool skip_reading)
switch (m_surface.depth_format) switch (m_surface.depth_format)
{ {
case Surface_depth_format::z16: case rsx::surface_depth_format::z16:
{ {
__glcheck m_draw_tex_depth_stencil.config() __glcheck m_draw_tex_depth_stencil.config()
.size({ (int)m_surface.width, (int)m_surface.height }) .size({ (int)m_surface.width, (int)m_surface.height })
@ -961,7 +961,7 @@ void GLGSRender::init_buffers(bool skip_reading)
break; break;
} }
case Surface_depth_format::z24s8: case rsx::surface_depth_format::z24s8:
{ {
__glcheck m_draw_tex_depth_stencil.config() __glcheck m_draw_tex_depth_stencil.config()
.size({ (int)m_surface.width, (int)m_surface.height }) .size({ (int)m_surface.width, (int)m_surface.height })
@ -992,27 +992,27 @@ void GLGSRender::init_buffers(bool skip_reading)
set_viewport(); set_viewport();
switch (to_surface_target(rsx::method_registers[NV4097_SET_SURFACE_COLOR_TARGET])) switch (rsx::to_surface_target(rsx::method_registers[NV4097_SET_SURFACE_COLOR_TARGET]))
{ {
case Surface_target::none: break; case rsx::surface_target::none: break;
case Surface_target::surface_a: case rsx::surface_target::surface_a:
__glcheck draw_fbo.draw_buffer(draw_fbo.color[0]); __glcheck draw_fbo.draw_buffer(draw_fbo.color[0]);
break; break;
case Surface_target::surface_b: case rsx::surface_target::surface_b:
__glcheck draw_fbo.draw_buffer(draw_fbo.color[1] ); __glcheck draw_fbo.draw_buffer(draw_fbo.color[1] );
break; break;
case Surface_target::surfaces_a_b: case rsx::surface_target::surfaces_a_b:
__glcheck draw_fbo.draw_buffers({ draw_fbo.color[0], draw_fbo.color[1] }); __glcheck draw_fbo.draw_buffers({ draw_fbo.color[0], draw_fbo.color[1] });
break; break;
case Surface_target::surfaces_a_b_c: case rsx::surface_target::surfaces_a_b_c:
__glcheck draw_fbo.draw_buffers({ draw_fbo.color[0], draw_fbo.color[1], draw_fbo.color[2] }); __glcheck draw_fbo.draw_buffers({ draw_fbo.color[0], draw_fbo.color[1], draw_fbo.color[2] });
break; break;
case Surface_target::surfaces_a_b_c_d: case rsx::surface_target::surfaces_a_b_c_d:
__glcheck draw_fbo.draw_buffers({ draw_fbo.color[0], draw_fbo.color[1], draw_fbo.color[2], draw_fbo.color[3] }); __glcheck draw_fbo.draw_buffers({ draw_fbo.color[0], draw_fbo.color[1], draw_fbo.color[2], draw_fbo.color[3] });
break; break;
@ -1090,28 +1090,28 @@ void GLGSRender::read_buffers()
} }
}; };
switch (to_surface_target(rsx::method_registers[NV4097_SET_SURFACE_COLOR_TARGET])) switch (rsx::to_surface_target(rsx::method_registers[NV4097_SET_SURFACE_COLOR_TARGET]))
{ {
case Surface_target::none: case rsx::surface_target::none:
break; break;
case Surface_target::surface_a: case rsx::surface_target::surface_a:
read_color_buffers(0, 1); read_color_buffers(0, 1);
break; break;
case Surface_target::surface_b: case rsx::surface_target::surface_b:
read_color_buffers(1, 1); read_color_buffers(1, 1);
break; break;
case Surface_target::surfaces_a_b: case rsx::surface_target::surfaces_a_b:
read_color_buffers(0, 2); read_color_buffers(0, 2);
break; break;
case Surface_target::surfaces_a_b_c: case rsx::surface_target::surfaces_a_b_c:
read_color_buffers(0, 3); read_color_buffers(0, 3);
break; break;
case Surface_target::surfaces_a_b_c_d: case rsx::surface_target::surfaces_a_b_c_d:
read_color_buffers(0, 4); read_color_buffers(0, 4);
break; break;
} }
@ -1135,7 +1135,7 @@ void GLGSRender::read_buffers()
{ {
u32 depth_address = rsx::get_address(rsx::method_registers[NV4097_SET_SURFACE_ZETA_OFFSET], rsx::method_registers[NV4097_SET_CONTEXT_DMA_ZETA]); u32 depth_address = rsx::get_address(rsx::method_registers[NV4097_SET_SURFACE_ZETA_OFFSET], rsx::method_registers[NV4097_SET_CONTEXT_DMA_ZETA]);
if (m_surface.depth_format == Surface_depth_format::z16) if (m_surface.depth_format == rsx::surface_depth_format::z16)
{ {
u16 *dst = (u16*)pixels; u16 *dst = (u16*)pixels;
const be_t<u16>* src = vm::ps3::_ptr<u16>(depth_address); const be_t<u16>* src = vm::ps3::_ptr<u16>(depth_address);
@ -1221,28 +1221,28 @@ void GLGSRender::write_buffers()
} }
}; };
switch (to_surface_target(rsx::method_registers[NV4097_SET_SURFACE_COLOR_TARGET])) switch (rsx::to_surface_target(rsx::method_registers[NV4097_SET_SURFACE_COLOR_TARGET]))
{ {
case Surface_target::none: case rsx::surface_target::none:
break; break;
case Surface_target::surface_a: case rsx::surface_target::surface_a:
write_color_buffers(0, 1); write_color_buffers(0, 1);
break; break;
case Surface_target::surface_b: case rsx::surface_target::surface_b:
write_color_buffers(1, 1); write_color_buffers(1, 1);
break; break;
case Surface_target::surfaces_a_b: case rsx::surface_target::surfaces_a_b:
write_color_buffers(0, 2); write_color_buffers(0, 2);
break; break;
case Surface_target::surfaces_a_b_c: case rsx::surface_target::surfaces_a_b_c:
write_color_buffers(0, 3); write_color_buffers(0, 3);
break; break;
case Surface_target::surfaces_a_b_c_d: case rsx::surface_target::surfaces_a_b_c_d:
write_color_buffers(0, 4); write_color_buffers(0, 4);
break; break;
} }
@ -1269,7 +1269,7 @@ void GLGSRender::write_buffers()
{ {
u32 depth_address = rsx::get_address(rsx::method_registers[NV4097_SET_SURFACE_ZETA_OFFSET], rsx::method_registers[NV4097_SET_CONTEXT_DMA_ZETA]); u32 depth_address = rsx::get_address(rsx::method_registers[NV4097_SET_SURFACE_ZETA_OFFSET], rsx::method_registers[NV4097_SET_CONTEXT_DMA_ZETA]);
if (m_surface.depth_format == Surface_depth_format::z16) if (m_surface.depth_format == rsx::surface_depth_format::z16)
{ {
const u16 *src = (const u16*)pixels; const u16 *src = (const u16*)pixels;
be_t<u16>* dst = vm::ps3::_ptr<u16>(depth_address); be_t<u16>* dst = vm::ps3::_ptr<u16>(depth_address);

View file

@ -5,20 +5,20 @@ namespace gl
{ {
const fbo screen{}; const fbo screen{};
GLenum draw_mode(Primitive_type in) GLenum draw_mode(rsx::primitive_type in)
{ {
switch (in) switch (in)
{ {
case Primitive_type::points: return GL_POINTS; case rsx::primitive_type::points: return GL_POINTS;
case Primitive_type::lines: return GL_LINES; case rsx::primitive_type::lines: return GL_LINES;
case Primitive_type::line_loop: return GL_LINE_LOOP; case rsx::primitive_type::line_loop: return GL_LINE_LOOP;
case Primitive_type::line_strip: return GL_LINE_STRIP; case rsx::primitive_type::line_strip: return GL_LINE_STRIP;
case Primitive_type::triangles: return GL_TRIANGLES; case rsx::primitive_type::triangles: return GL_TRIANGLES;
case Primitive_type::triangle_strip: return GL_TRIANGLE_STRIP; case rsx::primitive_type::triangle_strip: return GL_TRIANGLE_STRIP;
case Primitive_type::triangle_fan: return GL_TRIANGLE_FAN; case rsx::primitive_type::triangle_fan: return GL_TRIANGLE_FAN;
case Primitive_type::quads: return GL_QUADS; case rsx::primitive_type::quads: return GL_QUADS;
case Primitive_type::quad_strip: return GL_QUAD_STRIP; case rsx::primitive_type::quad_strip: return GL_QUAD_STRIP;
case Primitive_type::polygon: return GL_POLYGON; case rsx::primitive_type::polygon: return GL_POLYGON;
} }
throw new EXCEPTION("unknow primitive type"); throw new EXCEPTION("unknow primitive type");
} }
@ -97,74 +97,74 @@ namespace gl
__glcheck glDrawBuffers((GLsizei)ids.size(), ids.data()); __glcheck glDrawBuffers((GLsizei)ids.size(), ids.data());
} }
void fbo::draw_arrays(Primitive_type mode, GLsizei count, GLint first) const void fbo::draw_arrays(rsx::primitive_type mode, GLsizei count, GLint first) const
{ {
save_binding_state save(*this); save_binding_state save(*this);
__glcheck glDrawArrays(draw_mode(mode), first, count); __glcheck glDrawArrays(draw_mode(mode), first, count);
} }
void fbo::draw_arrays(const buffer& buffer, Primitive_type mode, GLsizei count, GLint first) const void fbo::draw_arrays(const buffer& buffer, rsx::primitive_type mode, GLsizei count, GLint first) const
{ {
buffer.bind(buffer::target::array); buffer.bind(buffer::target::array);
draw_arrays(mode, count, first); draw_arrays(mode, count, first);
} }
void fbo::draw_arrays(const vao& buffer, Primitive_type mode, GLsizei count, GLint first) const void fbo::draw_arrays(const vao& buffer, rsx::primitive_type mode, GLsizei count, GLint first) const
{ {
buffer.bind(); buffer.bind();
draw_arrays(mode, count, first); draw_arrays(mode, count, first);
} }
void fbo::draw_elements(Primitive_type mode, GLsizei count, indices_type type, const GLvoid *indices) const void fbo::draw_elements(rsx::primitive_type mode, GLsizei count, indices_type type, const GLvoid *indices) const
{ {
save_binding_state save(*this); save_binding_state save(*this);
__glcheck glDrawElements(draw_mode(mode), count, (GLenum)type, indices); __glcheck glDrawElements(draw_mode(mode), count, (GLenum)type, indices);
} }
void fbo::draw_elements(const buffer& buffer, Primitive_type mode, GLsizei count, indices_type type, const GLvoid *indices) const void fbo::draw_elements(const buffer& buffer, rsx::primitive_type mode, GLsizei count, indices_type type, const GLvoid *indices) const
{ {
buffer.bind(buffer::target::array); buffer.bind(buffer::target::array);
__glcheck glDrawElements(draw_mode(mode), count, (GLenum)type, indices); __glcheck glDrawElements(draw_mode(mode), count, (GLenum)type, indices);
} }
void fbo::draw_elements(Primitive_type mode, GLsizei count, indices_type type, const buffer& indices, size_t indices_buffer_offset) const void fbo::draw_elements(rsx::primitive_type mode, GLsizei count, indices_type type, const buffer& indices, size_t indices_buffer_offset) const
{ {
indices.bind(buffer::target::element_array); indices.bind(buffer::target::element_array);
__glcheck glDrawElements(draw_mode(mode), count, (GLenum)type, (GLvoid*)indices_buffer_offset); __glcheck glDrawElements(draw_mode(mode), count, (GLenum)type, (GLvoid*)indices_buffer_offset);
} }
void fbo::draw_elements(const buffer& buffer_, Primitive_type mode, GLsizei count, indices_type type, const buffer& indices, size_t indices_buffer_offset) const void fbo::draw_elements(const buffer& buffer_, rsx::primitive_type mode, GLsizei count, indices_type type, const buffer& indices, size_t indices_buffer_offset) const
{ {
buffer_.bind(buffer::target::array); buffer_.bind(buffer::target::array);
draw_elements(mode, count, type, indices, indices_buffer_offset); draw_elements(mode, count, type, indices, indices_buffer_offset);
} }
void fbo::draw_elements(Primitive_type mode, GLsizei count, const GLubyte *indices) const void fbo::draw_elements(rsx::primitive_type mode, GLsizei count, const GLubyte *indices) const
{ {
draw_elements(mode, count, indices_type::ubyte, indices); draw_elements(mode, count, indices_type::ubyte, indices);
} }
void fbo::draw_elements(const buffer& buffer, Primitive_type mode, GLsizei count, const GLubyte *indices) const void fbo::draw_elements(const buffer& buffer, rsx::primitive_type mode, GLsizei count, const GLubyte *indices) const
{ {
draw_elements(buffer, mode, count, indices_type::ubyte, indices); draw_elements(buffer, mode, count, indices_type::ubyte, indices);
} }
void fbo::draw_elements(Primitive_type mode, GLsizei count, const GLushort *indices) const void fbo::draw_elements(rsx::primitive_type mode, GLsizei count, const GLushort *indices) const
{ {
draw_elements(mode, count, indices_type::ushort, indices); draw_elements(mode, count, indices_type::ushort, indices);
} }
void fbo::draw_elements(const buffer& buffer, Primitive_type mode, GLsizei count, const GLushort *indices) const void fbo::draw_elements(const buffer& buffer, rsx::primitive_type mode, GLsizei count, const GLushort *indices) const
{ {
draw_elements(buffer, mode, count, indices_type::ushort, indices); draw_elements(buffer, mode, count, indices_type::ushort, indices);
} }
void fbo::draw_elements(Primitive_type mode, GLsizei count, const GLuint *indices) const void fbo::draw_elements(rsx::primitive_type mode, GLsizei count, const GLuint *indices) const
{ {
draw_elements(mode, count, indices_type::uint, indices); draw_elements(mode, count, indices_type::uint, indices);
} }
void fbo::draw_elements(const buffer& buffer, Primitive_type mode, GLsizei count, const GLuint *indices) const void fbo::draw_elements(const buffer& buffer, rsx::primitive_type mode, GLsizei count, const GLuint *indices) const
{ {
draw_elements(buffer, mode, count, indices_type::uint, indices); draw_elements(buffer, mode, count, indices_type::uint, indices);
} }

View file

@ -1380,7 +1380,7 @@ namespace gl
settings& border_color(color4f value); settings& border_color(color4f value);
}; };
GLenum draw_mode(Primitive_type in); GLenum draw_mode(rsx::primitive_type in);
enum class indices_type enum class indices_type
{ {
@ -1523,20 +1523,20 @@ namespace gl
void draw_buffer(const attachment& buffer) const; void draw_buffer(const attachment& buffer) const;
void draw_buffers(const std::initializer_list<attachment>& indexes) const; void draw_buffers(const std::initializer_list<attachment>& indexes) const;
void draw_arrays(Primitive_type mode, GLsizei count, GLint first = 0) const; void draw_arrays(rsx::primitive_type mode, GLsizei count, GLint first = 0) const;
void draw_arrays(const buffer& buffer, Primitive_type mode, GLsizei count, GLint first = 0) const; void draw_arrays(const buffer& buffer, rsx::primitive_type mode, GLsizei count, GLint first = 0) const;
void draw_arrays(const vao& buffer, Primitive_type mode, GLsizei count, GLint first = 0) const; void draw_arrays(const vao& buffer, rsx::primitive_type mode, GLsizei count, GLint first = 0) const;
void draw_elements(Primitive_type mode, GLsizei count, indices_type type, const GLvoid *indices) const; void draw_elements(rsx::primitive_type mode, GLsizei count, indices_type type, const GLvoid *indices) const;
void draw_elements(const buffer& buffer, Primitive_type mode, GLsizei count, indices_type type, const GLvoid *indices) const; void draw_elements(const buffer& buffer, rsx::primitive_type mode, GLsizei count, indices_type type, const GLvoid *indices) const;
void draw_elements(Primitive_type mode, GLsizei count, indices_type type, const buffer& indices, size_t indices_buffer_offset = 0) const; void draw_elements(rsx::primitive_type mode, GLsizei count, indices_type type, const buffer& indices, size_t indices_buffer_offset = 0) const;
void draw_elements(const buffer& buffer_, Primitive_type mode, GLsizei count, indices_type type, const buffer& indices, size_t indices_buffer_offset = 0) const; void draw_elements(const buffer& buffer_, rsx::primitive_type mode, GLsizei count, indices_type type, const buffer& indices, size_t indices_buffer_offset = 0) const;
void draw_elements(Primitive_type mode, GLsizei count, const GLubyte *indices) const; void draw_elements(rsx::primitive_type mode, GLsizei count, const GLubyte *indices) const;
void draw_elements(const buffer& buffer, Primitive_type mode, GLsizei count, const GLubyte *indices) const; void draw_elements(const buffer& buffer, rsx::primitive_type mode, GLsizei count, const GLubyte *indices) const;
void draw_elements(Primitive_type mode, GLsizei count, const GLushort *indices) const; void draw_elements(rsx::primitive_type mode, GLsizei count, const GLushort *indices) const;
void draw_elements(const buffer& buffer, Primitive_type mode, GLsizei count, const GLushort *indices) const; void draw_elements(const buffer& buffer, rsx::primitive_type mode, GLsizei count, const GLushort *indices) const;
void draw_elements(Primitive_type mode, GLsizei count, const GLuint *indices) const; void draw_elements(rsx::primitive_type mode, GLsizei count, const GLuint *indices) const;
void draw_elements(const buffer& buffer, Primitive_type mode, GLsizei count, const GLuint *indices) const; void draw_elements(const buffer& buffer, rsx::primitive_type mode, GLsizei count, const GLuint *indices) const;
void clear(buffers buffers_) const; void clear(buffers buffers_) const;
void clear(buffers buffers_, color4f color_value, double depth_value, u8 stencil_value) const; void clear(buffers buffers_, color4f color_value, double depth_value, u8 stencil_value) const;

View file

@ -19,6 +19,8 @@ frame_capture_data frame_debug;
namespace rsx namespace rsx
{ {
std::function<bool(u32 addr, bool is_writing)> g_access_violation_handler;
std::string shaders_cache::path_to_root() std::string shaders_cache::path_to_root()
{ {
return fs::get_executable_dir() + "data/"; return fs::get_executable_dir() + "data/";
@ -120,11 +122,11 @@ namespace rsx
return res; return res;
} }
u32 get_vertex_type_size_on_host(Vertex_base_type type, u32 size) u32 get_vertex_type_size_on_host(vertex_base_type type, u32 size)
{ {
switch (type) switch (type)
{ {
case Vertex_base_type::s1: case vertex_base_type::s1:
switch (size) switch (size)
{ {
case 1: case 1:
@ -135,8 +137,8 @@ namespace rsx
return sizeof(u16) * 4; return sizeof(u16) * 4;
} }
throw new EXCEPTION("Wrong vector size"); throw new EXCEPTION("Wrong vector size");
case Vertex_base_type::f: return sizeof(f32) * size; case vertex_base_type::f: return sizeof(f32) * size;
case Vertex_base_type::sf: case vertex_base_type::sf:
switch (size) switch (size)
{ {
case 1: case 1:
@ -147,7 +149,7 @@ namespace rsx
return sizeof(f16) * 4; return sizeof(f16) * 4;
} }
throw new EXCEPTION("Wrong vector size"); throw new EXCEPTION("Wrong vector size");
case Vertex_base_type::ub: case vertex_base_type::ub:
switch (size) switch (size)
{ {
case 1: case 1:
@ -158,9 +160,9 @@ namespace rsx
return sizeof(u8) * 4; return sizeof(u8) * 4;
} }
throw new EXCEPTION("Wrong vector size"); throw new EXCEPTION("Wrong vector size");
case Vertex_base_type::s32k: return sizeof(u32) * size; case vertex_base_type::s32k: return sizeof(u32) * size;
case Vertex_base_type::cmp: return sizeof(u16) * 4; case vertex_base_type::cmp: return sizeof(u16) * 4;
case Vertex_base_type::ub256: return sizeof(u8) * 4; case vertex_base_type::ub256: return sizeof(u8) * 4;
default: default:
throw new EXCEPTION("RSXVertexData::GetTypeSize: Bad vertex data type (%d)!", type); throw new EXCEPTION("RSXVertexData::GetTypeSize: Bad vertex data type (%d)!", type);
@ -270,6 +272,19 @@ namespace rsx
} }
} }
thread::thread()
{
g_access_violation_handler = [this](u32 address, bool is_writing)
{
return on_access_violation(address, is_writing);
};
}
thread::~thread()
{
g_access_violation_handler = nullptr;
}
void thread::capture_frame(const std::string &name) void thread::capture_frame(const std::string &name)
{ {
frame_capture_data::draw_state draw_state = {}; frame_capture_data::draw_state draw_state = {};
@ -280,9 +295,9 @@ namespace rsx
surface.unpack(rsx::method_registers[NV4097_SET_SURFACE_FORMAT]); surface.unpack(rsx::method_registers[NV4097_SET_SURFACE_FORMAT]);
draw_state.width = clip_w; draw_state.width = clip_w;
draw_state.height = clip_h; draw_state.height = clip_h;
draw_state.surface_color_format = surface.color_format; draw_state.color_format = surface.color_format;
draw_state.color_buffer = std::move(copy_render_targets_to_memory()); draw_state.color_buffer = std::move(copy_render_targets_to_memory());
draw_state.surface_depth_format = surface.depth_format; draw_state.depth_format = surface.depth_format;
draw_state.depth_stencil = std::move(copy_depth_stencil_buffer_to_memory()); draw_state.depth_stencil = std::move(copy_depth_stencil_buffer_to_memory());
draw_state.programs = get_programs(); draw_state.programs = get_programs();
draw_state.name = name; draw_state.name = name;
@ -351,7 +366,7 @@ namespace rsx
if (put == get || !Emu.IsRunning()) if (put == get || !Emu.IsRunning())
{ {
std::this_thread::sleep_for(std::chrono::milliseconds(1)); // hack do_internal_task();
continue; continue;
} }
@ -480,7 +495,7 @@ namespace rsx
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[0] = src[3];
dst[1] = src[2]; dst[1] = src[2];
@ -504,6 +519,52 @@ namespace rsx
return get_system_time() * 1000; return get_system_time() * 1000;
} }
void thread::do_internal_task()
{
if (m_internal_tasks.empty())
{
std::this_thread::sleep_for(1ms);
}
else
{
std::lock_guard<std::mutex> lock{ m_mtx_task };
internal_task_entry &front = m_internal_tasks.front();
if (front.callback())
{
front.promise.set_value();
m_internal_tasks.pop_front();
}
}
}
std::future<void> thread::add_internal_task(std::function<bool()> callback)
{
std::lock_guard<std::mutex> lock{ m_mtx_task };
m_internal_tasks.emplace_back(callback);
return m_internal_tasks.back().promise.get_future();
}
void thread::invoke(std::function<bool()> callback)
{
if (get_thread_ctrl() == thread_ctrl::get_current())
{
while (true)
{
if (callback())
{
break;
}
}
}
else
{
add_internal_task(callback).wait();
}
}
std::array<u32, 4> thread::get_color_surface_addresses() const std::array<u32, 4> thread::get_color_surface_addresses() const
{ {
u32 offset_color[] = u32 offset_color[] =

View file

@ -15,15 +15,14 @@ extern u64 get_system_time();
struct frame_capture_data struct frame_capture_data
{ {
struct draw_state struct draw_state
{ {
std::string name; std::string name;
std::pair<std::string, std::string> programs; std::pair<std::string, std::string> programs;
size_t width = 0, height = 0; size_t width = 0, height = 0;
Surface_color_format surface_color_format; rsx::surface_color_format color_format;
std::array<std::vector<gsl::byte>, 4> color_buffer; std::array<std::vector<gsl::byte>, 4> color_buffer;
Surface_depth_format surface_depth_format; rsx::surface_depth_format depth_format;
std::array<std::vector<gsl::byte>, 2> depth_stencil; std::array<std::vector<gsl::byte>, 2> depth_stencil;
}; };
std::vector<std::pair<u32, u32> > command_queue; std::vector<std::pair<u32, u32> > command_queue;
@ -145,7 +144,7 @@ namespace rsx
static std::string path_to_root(); static std::string path_to_root();
}; };
u32 get_vertex_type_size_on_host(Vertex_base_type type, u32 size); u32 get_vertex_type_size_on_host(vertex_base_type type, u32 size);
u32 get_address(u32 offset, u32 location); u32 get_address(u32 offset, u32 location);
@ -164,9 +163,9 @@ namespace rsx
{ {
u8 log2height; u8 log2height;
u8 log2width; u8 log2width;
Surface_antialiasing antialias; surface_antialiasing antialias;
Surface_depth_format depth_format; surface_depth_format depth_format;
Surface_color_format color_format; surface_color_format color_format;
u32 width; u32 width;
u32 height; u32 height;
@ -192,7 +191,7 @@ namespace rsx
u16 frequency = 0; u16 frequency = 0;
u8 stride = 0; u8 stride = 0;
u8 size = 0; u8 size = 0;
Vertex_base_type type = Vertex_base_type::f; vertex_base_type type = vertex_base_type::f;
void unpack_array(u32 data_array_format) void unpack_array(u32 data_array_format)
{ {
@ -203,6 +202,13 @@ namespace rsx
} }
}; };
enum class draw_command
{
array,
inlined_array,
indexed,
};
class thread : public named_thread_t class thread : public named_thread_t
{ {
protected: protected:
@ -257,6 +263,7 @@ namespace rsx
bool capture_current_frame = false; bool capture_current_frame = false;
void capture_frame(const std::string &name); void capture_frame(const std::string &name);
public: public:
u32 ioAddress, ioSize; u32 ioAddress, ioSize;
int flip_status; int flip_status;
@ -272,18 +279,12 @@ namespace rsx
u32 ctxt_addr; u32 ctxt_addr;
u32 report_main_addr; u32 report_main_addr;
u32 label_addr; u32 label_addr;
enum class Draw_command rsx::draw_command draw_command;
{ primitive_type draw_mode;
draw_command_array,
draw_command_inlined_array,
draw_command_indexed,
} draw_command;
Primitive_type draw_mode;
u32 local_mem_addr, main_mem_addr; u32 local_mem_addr, main_mem_addr;
bool strict_ordering[0x1000]; bool strict_ordering[0x1000];
bool draw_inline_vertex_array; bool draw_inline_vertex_array;
std::vector<u32> inline_vertex_array; std::vector<u32> inline_vertex_array;
@ -309,7 +310,8 @@ namespace rsx
std::set<u32> m_used_gcm_commands; std::set<u32> m_used_gcm_commands;
protected: protected:
virtual ~thread() {} thread();
virtual ~thread();
virtual void on_task() override; virtual void on_task() override;
@ -324,6 +326,27 @@ namespace rsx
virtual bool do_method(u32 cmd, u32 value) { return false; } virtual bool do_method(u32 cmd, u32 value) { return false; }
virtual void flip(int buffer) = 0; virtual void flip(int buffer) = 0;
virtual u64 timestamp() const; virtual u64 timestamp() const;
virtual bool on_access_violation(u32 address, bool is_writing) { return false; }
private:
std::mutex m_mtx_task;
struct internal_task_entry
{
std::function<bool()> callback;
std::promise<void> promise;
internal_task_entry(std::function<bool()> callback) : callback(callback)
{
}
};
std::deque<internal_task_entry> m_internal_tasks;
void do_internal_task();
public:
std::future<void> add_internal_task(std::function<bool()> callback);
void invoke(std::function<bool()> callback);
/** /**
* Fill buffer with 4x4 scale offset matrix. * Fill buffer with 4x4 scale offset matrix.
@ -362,6 +385,7 @@ namespace rsx
}; };
virtual std::pair<std::string, std::string> get_programs() const { return std::make_pair("", ""); }; virtual std::pair<std::string, std::string> get_programs() const { return std::make_pair("", ""); };
public: public:
void reset(); void reset();
void init(const u32 ioAddress, const u32 ioSize, const u32 ctrlAddress, const u32 localAddress); void init(const u32 ioAddress, const u32 ioSize, const u32 ctrlAddress, const u32 localAddress);

View file

@ -14,10 +14,10 @@ namespace rsx
rsx_method_t methods[0x10000 >> 2]{}; rsx_method_t methods[0x10000 >> 2]{};
template<typename Type> struct vertex_data_type_from_element_type; template<typename Type> struct vertex_data_type_from_element_type;
template<> struct vertex_data_type_from_element_type<float> { static const Vertex_base_type type = Vertex_base_type::f; }; template<> struct vertex_data_type_from_element_type<float> { static const vertex_base_type type = vertex_base_type::f; };
template<> struct vertex_data_type_from_element_type<f16> { static const Vertex_base_type type = Vertex_base_type::sf; }; template<> struct vertex_data_type_from_element_type<f16> { static const vertex_base_type type = vertex_base_type::sf; };
template<> struct vertex_data_type_from_element_type<u8> { static const Vertex_base_type type = Vertex_base_type::ub; }; template<> struct vertex_data_type_from_element_type<u8> { static const vertex_base_type type = vertex_base_type::ub; };
template<> struct vertex_data_type_from_element_type<u16> { static const Vertex_base_type type = Vertex_base_type::s1; }; template<> struct vertex_data_type_from_element_type<u16> { static const vertex_base_type type = vertex_base_type::s1; };
namespace nv406e namespace nv406e
{ {
@ -160,7 +160,7 @@ namespace rsx
force_inline void draw_arrays(thread* rsx, u32 arg) force_inline void draw_arrays(thread* rsx, u32 arg)
{ {
rsx->draw_command = thread::Draw_command::draw_command_array; rsx->draw_command = rsx::draw_command::array;
u32 first = arg & 0xffffff; u32 first = arg & 0xffffff;
u32 count = (arg >> 24) + 1; u32 count = (arg >> 24) + 1;
@ -169,7 +169,7 @@ namespace rsx
force_inline void draw_index_array(thread* rsx, u32 arg) force_inline void draw_index_array(thread* rsx, u32 arg)
{ {
rsx->draw_command = thread::Draw_command::draw_command_indexed; rsx->draw_command = rsx::draw_command::indexed;
u32 first = arg & 0xffffff; u32 first = arg & 0xffffff;
u32 count = (arg >> 24) + 1; u32 count = (arg >> 24) + 1;
@ -178,7 +178,7 @@ namespace rsx
force_inline void draw_inline_array(thread* rsx, u32 arg) force_inline void draw_inline_array(thread* rsx, u32 arg)
{ {
rsx->draw_command = thread::Draw_command::draw_command_inlined_array; rsx->draw_command = rsx::draw_command::inlined_array;
rsx->draw_inline_vertex_array = true; rsx->draw_inline_vertex_array = true;
rsx->inline_vertex_array.push_back(arg); rsx->inline_vertex_array.push_back(arg);
} }

View file

@ -267,12 +267,12 @@ u8 GcmSurfaceFormat2GcmTextureFormat(u8 surfaceFormat, u8 surfaceType)
{ {
u8 result = 0; u8 result = 0;
switch (to_surface_color_format(surfaceFormat)) switch (rsx::to_surface_color_format(surfaceFormat))
{ {
case Surface_color_format::a8r8g8b8: case rsx::surface_color_format::a8r8g8b8:
result = CELL_GCM_TEXTURE_A8R8G8B8; result = CELL_GCM_TEXTURE_A8R8G8B8;
break; break;
case Surface_color_format::w16z16y16x16: case rsx::surface_color_format::w16z16y16x16:
result = CELL_GCM_TEXTURE_W16_Z16_Y16_X16_FLOAT; result = CELL_GCM_TEXTURE_W16_Z16_Y16_X16_FLOAT;
break; break;
default: default:
@ -933,15 +933,15 @@ s32 cellRescGcmSurface2RescSrc(vm::ptr<CellGcmSurface> gcmSurface, vm::ptr<CellR
u8 textureFormat = GcmSurfaceFormat2GcmTextureFormat(gcmSurface->colorFormat, gcmSurface->type); u8 textureFormat = GcmSurfaceFormat2GcmTextureFormat(gcmSurface->colorFormat, gcmSurface->type);
s32 xW = 1, xH = 1; s32 xW = 1, xH = 1;
switch(to_surface_antialiasing(gcmSurface->antialias)) switch(rsx::to_surface_antialiasing(gcmSurface->antialias))
{ {
case Surface_antialiasing::square_rotated_4_samples: case rsx::surface_antialiasing::square_rotated_4_samples:
xW=xH=2; xW=xH=2;
break; break;
case Surface_antialiasing::square_centered_4_samples: case rsx::surface_antialiasing::square_centered_4_samples:
xW=xH=2; xW=xH=2;
break; break;
case Surface_antialiasing::diagonal_centered_2_samples: case rsx::surface_antialiasing::diagonal_centered_2_samples:
xW=2; xW=2;
break; break;
default: default:

View file

@ -382,16 +382,16 @@ void RSXDebugger::OnClickBuffer(wxMouseEvent& event)
namespace namespace
{ {
std::array<u8, 3> get_value(gsl::span<const gsl::byte> orig_buffer, Surface_color_format format, size_t idx) std::array<u8, 3> get_value(gsl::span<const gsl::byte> orig_buffer, rsx::surface_color_format format, size_t idx)
{ {
switch (format) switch (format)
{ {
case Surface_color_format::b8: case rsx::surface_color_format::b8:
{ {
u8 value = gsl::as_span<const u8>(orig_buffer)[idx]; u8 value = gsl::as_span<const u8>(orig_buffer)[idx];
return{ value, value, value }; return{ value, value, value };
} }
case Surface_color_format::x32: case rsx::surface_color_format::x32:
{ {
be_t<u32> stored_val = gsl::as_span<const be_t<u32>>(orig_buffer)[idx]; be_t<u32> stored_val = gsl::as_span<const be_t<u32>>(orig_buffer)[idx];
u32 swapped_val = stored_val; u32 swapped_val = stored_val;
@ -399,21 +399,21 @@ namespace
u8 val = float_val * 255.f; u8 val = float_val * 255.f;
return{ val, val, val }; return{ val, val, val };
} }
case Surface_color_format::a8b8g8r8: case rsx::surface_color_format::a8b8g8r8:
case Surface_color_format::x8b8g8r8_o8b8g8r8: case rsx::surface_color_format::x8b8g8r8_o8b8g8r8:
case Surface_color_format::x8b8g8r8_z8b8g8r8: case rsx::surface_color_format::x8b8g8r8_z8b8g8r8:
{ {
auto ptr = gsl::as_span<const u8>(orig_buffer); auto ptr = gsl::as_span<const u8>(orig_buffer);
return{ ptr[1 + idx * 4], ptr[2 + idx * 4], ptr[3 + idx * 4] }; return{ ptr[1 + idx * 4], ptr[2 + idx * 4], ptr[3 + idx * 4] };
} }
case Surface_color_format::a8r8g8b8: case rsx::surface_color_format::a8r8g8b8:
case Surface_color_format::x8r8g8b8_o8r8g8b8: case rsx::surface_color_format::x8r8g8b8_o8r8g8b8:
case Surface_color_format::x8r8g8b8_z8r8g8b8: case rsx::surface_color_format::x8r8g8b8_z8r8g8b8:
{ {
auto ptr = gsl::as_span<const u8>(orig_buffer); auto ptr = gsl::as_span<const u8>(orig_buffer);
return{ ptr[3 + idx * 4], ptr[2 + idx * 4], ptr[1 + idx * 4] }; return{ ptr[3 + idx * 4], ptr[2 + idx * 4], ptr[1 + idx * 4] };
} }
case Surface_color_format::w16z16y16x16: case rsx::surface_color_format::w16z16y16x16:
{ {
auto ptr = gsl::as_span<const u16>(orig_buffer); auto ptr = gsl::as_span<const u16>(orig_buffer);
f16 h0 = f16(ptr[4 * idx]); f16 h0 = f16(ptr[4 * idx]);
@ -428,11 +428,11 @@ namespace
u8 val2 = f2 * 255.; u8 val2 = f2 * 255.;
return{ val0, val1, val2 }; return{ val0, val1, val2 };
} }
case Surface_color_format::g8b8: case rsx::surface_color_format::g8b8:
case Surface_color_format::r5g6b5: case rsx::surface_color_format::r5g6b5:
case Surface_color_format::x1r5g5b5_o1r5g5b5: case rsx::surface_color_format::x1r5g5b5_o1r5g5b5:
case Surface_color_format::x1r5g5b5_z1r5g5b5: case rsx::surface_color_format::x1r5g5b5_z1r5g5b5:
case Surface_color_format::w32z32y32x32: case rsx::surface_color_format::w32z32y32x32:
throw EXCEPTION("Unsupported format for display"); throw EXCEPTION("Unsupported format for display");
} }
} }
@ -441,7 +441,7 @@ namespace
* Return a new buffer that can be passed to wxImage ctor. * Return a new buffer that can be passed to wxImage ctor.
* The pointer seems to be freed by wxImage. * The pointer seems to be freed by wxImage.
*/ */
u8* convert_to_wximage_buffer(Surface_color_format format, gsl::span<const gsl::byte> orig_buffer, size_t width, size_t height) noexcept u8* convert_to_wximage_buffer(rsx::surface_color_format format, gsl::span<const gsl::byte> orig_buffer, size_t width, size_t height) noexcept
{ {
unsigned char* buffer = (unsigned char*)malloc(width * height * 3); unsigned char* buffer = (unsigned char*)malloc(width * height * 3);
for (u32 i = 0; i < width * height; i++) for (u32 i = 0; i < width * height; i++)
@ -476,7 +476,7 @@ void RSXDebugger::OnClickDrawCalls(wxMouseEvent& event)
{ {
if (width && height && !draw_call.color_buffer[i].empty()) if (width && height && !draw_call.color_buffer[i].empty())
{ {
buffer_img[i] = wxImage(width, height, convert_to_wximage_buffer(draw_call.surface_color_format, draw_call.color_buffer[i], width, height)); buffer_img[i] = wxImage(width, height, convert_to_wximage_buffer(draw_call.color_format, draw_call.color_buffer[i], width, height));
wxClientDC dc_canvas(p_buffers[i]); wxClientDC dc_canvas(p_buffers[i]);
if (buffer_img[i].IsOk()) if (buffer_img[i].IsOk())
@ -491,7 +491,7 @@ void RSXDebugger::OnClickDrawCalls(wxMouseEvent& event)
gsl::span<const gsl::byte> orig_buffer = draw_call.depth_stencil[0]; gsl::span<const gsl::byte> orig_buffer = draw_call.depth_stencil[0];
unsigned char *buffer = (unsigned char *)malloc(width * height * 3); unsigned char *buffer = (unsigned char *)malloc(width * height * 3);
if (draw_call.surface_depth_format == Surface_depth_format::z24s8) if (draw_call.depth_format == rsx::surface_depth_format::z24s8)
{ {
for (u32 row = 0; row < height; row++) for (u32 row = 0; row < height; row++)
{ {