renderer.hpp 16.6 KB
Newer Older
Libretro-Admin's avatar
Libretro-Admin committed
1
2
#pragma once

Libretro-Admin's avatar
Libretro-Admin committed
3
4
5
#include "../atlas/atlas.hpp"
#include "../vulkan/device.hpp"
#include "../vulkan/vulkan.hpp"
stoofin's avatar
stoofin committed
6
#include "../custom-textures/texture_tracker.hpp"
Libretro-Admin's avatar
Libretro-Admin committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

#ifdef VULKAN_WSI
#include "wsi.hpp"
#endif

#include <string.h>

namespace PSX
{

struct Vertex
{
	float x, y, w;
	uint32_t color;
	uint16_t u, v;
};

struct TextureWindow
{
	uint8_t mask_x, mask_y, or_x, or_y;
};

29
30
31
32
33
struct UVRect
{
	uint16_t min_u, min_v, max_u, max_v;
};

Libretro-Admin's avatar
Libretro-Admin committed
34
35
36
37
38
39
40
41
42
enum class SemiTransparentMode
{
	None,
	Average,
	Add,
	Sub,
	AddQuarter
};

43
44
45
46
47
48
49
enum class PrimitiveType
{
	Sprite,
	Polygon,
	May_Be_2D_Polygon
};

stoofin's avatar
stoofin committed
50
class Renderer : private HazardListener, private TextureUploader
Libretro-Admin's avatar
Libretro-Admin committed
51
52
{
public:
53
54
	enum class ScanoutMode
	{
55
56
57
58
59
60
		// Use extra precision bits.
		ABGR1555_555,
		// Use extra precision bits to dither down to a native ABGR1555 image.
		// The dither happens in the wrong place, but should be "good" enough to feel authentic.
		ABGR1555_Dither,
		// MDEC
61
62
63
64
65
66
		BGR24
	};

	enum class ScanoutFilter
	{
		None,
67
68
		SSAA,
		MDEC_YUV
69
70
	};

71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
	enum class WidthMode
	{
		WIDTH_MODE_256 = 0,
		WIDTH_MODE_320 = 1,
		WIDTH_MODE_512 = 2,
		WIDTH_MODE_640 = 3,
		WIDTH_MODE_368 = 4
	};

	struct DisplayRect
	{
		// Unlike Rect, the x-y coordinates for a DisplayRect can be negative
		int x = 0;
		int y = 0;
		unsigned width = 0;
		unsigned height = 0;

		DisplayRect() = default;
		DisplayRect(int x, int y, unsigned width, unsigned height)
		    : x(x)
		    , y(y)
		    , width(width)
		    , height(height)
		{
		}
	};

Libretro-Admin's avatar
Libretro-Admin committed
98
99
	struct RenderState
	{
100
101
		//Rect display_mode;
		Rect display_fb_rect;
Libretro-Admin's avatar
Libretro-Admin committed
102
103
104
105
106
107
108
109
110
111
		TextureWindow texture_window;
		Rect cached_window_rect;
		Rect draw_rect;
		int draw_offset_x = 0;
		int draw_offset_y = 0;
		unsigned palette_offset_x = 0;
		unsigned palette_offset_y = 0;
		unsigned texture_offset_x = 0;
		unsigned texture_offset_y = 0;

112
113
114
115
116
117
118
119
120
		int vert_start = 0x10;
		int vert_end = 0x100;
		int horiz_start = 0x200;
		int horiz_end = 0xC00;

		bool is_pal = false;
		bool is_480i = false;
		WidthMode width_mode = WidthMode::WIDTH_MODE_320;
		bool crop_overscan = false;
121
		unsigned image_crop = 0;
122

123
124
125
		// Experimental horizontal offset feature
		int offset_cycles = 0;

126
127
128
129
130
131
		int slstart = 0;
		int slend = 239;

		int slstart_pal = 0;
		int slend_pal = 287;

132
133
134
		unsigned display_fb_xstart = 0;
		unsigned display_fb_ystart = 0;

Libretro-Admin's avatar
Libretro-Admin committed
135
136
		TextureMode texture_mode = TextureMode::None;
		SemiTransparentMode semi_transparent = SemiTransparentMode::None;
137
		PrimitiveType primitive_type = PrimitiveType::Polygon;
138
		ScanoutMode scanout_mode = ScanoutMode::ABGR1555_555;
139
		ScanoutFilter scanout_filter = ScanoutFilter::None;
140
		ScanoutFilter scanout_mdec_filter = ScanoutFilter::None;
141
		bool dither_native_resolution = false;
Libretro-Admin's avatar
Libretro-Admin committed
142
143
144
145
		bool force_mask_bit = false;
		bool texture_color_modulate = false;
		bool mask_test = false;
		bool display_on = false;
146
		//bool dither = false;
Libretro-Admin's avatar
Libretro-Admin committed
147
		bool adaptive_smoothing = true;
148
149

		UVRect UVLimits;
Libretro-Admin's avatar
Libretro-Admin committed
150
151
152
153
154
155
	};

	struct SaveState
	{
		std::vector<uint32_t> vram;
		RenderState state;
stoofin's avatar
stoofin committed
156
		TextureTrackerSaveState tracker_state;
Libretro-Admin's avatar
Libretro-Admin committed
157
158
	};

Hans-Kristian Arntzen's avatar
Hans-Kristian Arntzen committed
159
	Renderer(Vulkan::Device &device, unsigned scaling, unsigned msaa, const SaveState *save_state);
Libretro-Admin's avatar
Libretro-Admin committed
160
161
	~Renderer();

stoofin's avatar
stoofin committed
162
	void set_track_textures(bool enable);
stoofin's avatar
stoofin committed
163
164
165
	void set_dump_textures(bool enable);
	void set_replace_textures(bool enable);

Libretro-Admin's avatar
Libretro-Admin committed
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
	void set_adaptive_smoothing(bool enable)
	{
		render_state.adaptive_smoothing = enable;
	}

	void set_draw_rect(const Rect &rect);
	inline void set_draw_offset(int x, int y)
	{
		render_state.draw_offset_x = x;
		render_state.draw_offset_y = y;
	}

	inline void set_scissored_invariant(bool invariant) override
	{
		queue.scissor_invariant = invariant;
	}

	void set_texture_window(const TextureWindow &rect);
	inline void set_texture_offset(unsigned x, unsigned y)
	{
		atlas.set_texture_offset(x, y);
		render_state.texture_offset_x = x;
		render_state.texture_offset_y = y;
	}

	inline void set_palette_offset(unsigned x, unsigned y)
	{
		atlas.set_palette_offset(x, y);
		render_state.palette_offset_x = x;
		render_state.palette_offset_y = y;
	}

	Vulkan::BufferHandle copy_cpu_to_vram(const Rect &rect);
199
	void copy_vram_to_cpu_synchronous(const Rect &rect, uint16_t *vram);
Libretro-Admin's avatar
Libretro-Admin committed
200
201
202
	uint16_t *begin_copy(Vulkan::BufferHandle handle);
	void end_copy(Vulkan::BufferHandle handle);

stoofin's avatar
stoofin committed
203
204
	void notify_texture_upload(Rect rect, uint16_t *vram);

Libretro-Admin's avatar
Libretro-Admin committed
205
	void blit_vram(const Rect &dst, const Rect &src);
206

207
208
209
210
211
212
213
214
	void set_vram_framebuffer_coords(unsigned xstart, unsigned ystart)
	{
		last_scanout.reset();

		render_state.display_fb_xstart = xstart;
		render_state.display_fb_ystart = ystart;
	}

215
216
217
218
219
220
221
222
223
224
225
226
	void set_horizontal_display_range(int x1, int x2)
	{
		render_state.horiz_start = x1;
		render_state.horiz_end = x2;
	}

	void set_vertical_display_range(int y1, int y2)
	{
		render_state.vert_start = y1;
		render_state.vert_end = y2;
	}

227
	void set_display_mode(ScanoutMode mode, bool is_pal, bool is_480i, WidthMode width_mode)
Libretro-Admin's avatar
Libretro-Admin committed
228
	{
229
230
231
		//if (rect != render_state.display_mode || render_state.scanout_mode != mode)
		//	last_scanout.reset();
		last_scanout.reset();
Libretro-Admin's avatar
Libretro-Admin committed
232

233
		//render_state.display_mode = rect;
234
		render_state.scanout_mode = mode;
235
236
237
238
239
240
241
242
243

		render_state.is_pal = is_pal;
		render_state.is_480i = is_480i;
		render_state.width_mode = width_mode;
	}

	void set_horizontal_overscan_cropping(bool crop_overscan)
	{
		render_state.crop_overscan = crop_overscan;
244
245
	}

246
247
248
249
	void set_horizontal_offset_cycles(int offset_cycles)
	{
		render_state.offset_cycles = offset_cycles;
	}
250
251
252
253
254
	
	void set_horizontal_additional_cropping(unsigned image_crop)
	{
		render_state.image_crop = image_crop;
	}
255

256
257
258
259
260
261
262
263
264
	void set_visible_scanlines(int slstart, int slend, int slstart_pal, int slend_pal)
	{
		// May need bounds checking to reject bad inputs. Currently assume all inputs are valid.
		render_state.slstart = slstart;
		render_state.slend = slend;
		render_state.slstart_pal = slstart_pal;
		render_state.slend_pal = slend_pal;
	}

265
266
267
	void set_display_filter(ScanoutFilter filter)
	{
		render_state.scanout_filter = filter;
Libretro-Admin's avatar
Libretro-Admin committed
268
269
	}

270
271
272
273
274
	void set_mdec_filter(ScanoutFilter mdec_filter)
	{
		render_state.scanout_mdec_filter = mdec_filter;
	}

Libretro-Admin's avatar
Libretro-Admin committed
275
276
277
278
279
280
281
282
	void toggle_display(bool enable)
	{
		if (enable != render_state.display_on)
			last_scanout.reset();

		render_state.display_on = enable;
	}

283
#if 0
Libretro-Admin's avatar
Libretro-Admin committed
284
285
286
287
	void set_dither(bool dither)
	{
		render_state.dither = dither;
	}
288
289
290
291
292
293
#endif

	void set_dither_native_resolution(bool enable)
	{
		render_state.dither_native_resolution = enable;
	}
Libretro-Admin's avatar
Libretro-Admin committed
294
295
296
297
298

	void set_scanout_semaphore(Vulkan::Semaphore semaphore);
	void scanout();
	Vulkan::BufferHandle scanout_to_buffer(bool draw_area, unsigned &width, unsigned &height);
	Vulkan::BufferHandle scanout_vram_to_buffer(unsigned &width, unsigned &height);
299
	Vulkan::ImageHandle scanout_vram_to_texture(bool scaled = true);
Libretro-Admin's avatar
Libretro-Admin committed
300
301
302
303
304
305
306
307
308
309
310
311
312
	Vulkan::ImageHandle scanout_to_texture();

	inline void set_texture_mode(TextureMode mode)
	{
		render_state.texture_mode = mode;
		atlas.set_texture_mode(mode);
	}

	inline void set_semi_transparent(SemiTransparentMode state)
	{
		render_state.semi_transparent = state;
	}

313
314
315
316
317
	inline void set_primitive_type(PrimitiveType primitive_type)
	{
		render_state.primitive_type = primitive_type;
	}

Libretro-Admin's avatar
Libretro-Admin committed
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
	inline void set_force_mask_bit(bool enable)
	{
		render_state.force_mask_bit = enable;
	}

	inline void set_mask_test(bool enable)
	{
		render_state.mask_test = enable;
	}

	inline void set_texture_color_modulate(bool enable)
	{
		render_state.texture_color_modulate = enable;
	}

333
334
335
336
337
338
339
340
	inline void set_UV_limits(uint16_t min_u, uint16_t min_v, uint16_t max_u, uint16_t max_v)
	{
		render_state.UVLimits.min_u = min_u;
		render_state.UVLimits.min_v = min_v;
		render_state.UVLimits.max_u = max_u;
		render_state.UVLimits.max_v = max_v;
	}

Libretro-Admin's avatar
Libretro-Admin committed
341
342
343
344
345
346
347
348
349
350
	// Draw commands
	void clear_rect(const Rect &rect, FBColor color);
	void draw_line(const Vertex *vertices);
	void draw_triangle(const Vertex *vertices);
	void draw_quad(const Vertex *vertices);

	SaveState save_vram_state();

	void reset_counters()
	{
351
		counters = {};
Libretro-Admin's avatar
Libretro-Admin committed
352
353
354
355
356
357
358
359
360
361
	}

	void flush()
	{
		if (cmd)
			device.submit(cmd);
		cmd.reset();
		device.flush_frame();
	}

362
363
364
365
366
367
368
369
370
371
	Vulkan::Fence flush_and_signal()
	{
		Vulkan::Fence fence;
		if (cmd)
			device.submit(cmd, &fence);
		cmd.reset();
		device.flush_frame();
		return fence;
	}

Libretro-Admin's avatar
Libretro-Admin committed
372
373
374
375
376
377
378
379
380
381
	struct
	{
		unsigned render_passes = 0;
		unsigned fragment_readback_pixels = 0;
		unsigned fragment_writeout_pixels = 0;
		unsigned draw_calls = 0;
		unsigned vertices = 0;
		unsigned native_draw_calls = 0;
	} counters;

JS Deck's avatar
JS Deck committed
382
383
384
385
386
	enum
	{
		SpecConstIndex_TransMode = 0,
		SpecConstIndex_FilterMode = 1,
		SpecConstIndex_BlendMode = 2,
387
		SpecConstIndex_Scaling = 3,
JS Deck's avatar
JS Deck committed
388
		SpecConstIndex_Shift = 4,
JS Deck's avatar
JS Deck committed
389
		SpecConstIndex_OffsetUV = 5,
390
		SpecConstIndex_Samples = 0,
JS Deck's avatar
JS Deck committed
391
392
	};

393
394
395
396
397
398
399
	enum FilterExclude
	{
		FilterExcludeNone = 0,
		FilterExcludeOpaque = 1,
		FilterExcludeOpaqueAndSemiTrans = 2,
	};

400
	enum class FilterMode : uint32_t
401
402
403
404
405
406
407
408
409
	{
		NearestNeighbor = 0,
		XBR = 1,
		SABR = 2,
		Bilinear = 3,
		Bilinear3Point = 4,
		JINC2 = 5
	};

410
411
412
413
414
415
416
	enum class TransMode : uint32_t
	{
		Opaque = 0,
		SemiTrans = 1,
		SemiTransOpaque = 2
	};

JS Deck's avatar
JS Deck committed
417
418
419
420
421
422
423
424
	enum class BlendMode : uint32_t
	{
		BlendAdd = 0,
		BlendAvg = 1,
		BlendSub = 2,
		BlendAddQuarter = 3
	};

425
	void set_filter_mode(FilterMode mode);
426
427
428
429
	ScanoutMode get_scanout_mode() const
	{
		return render_state.scanout_mode;
	}
430

431
432
433
434
435
436
437
438
439
440
	void set_sprite_filter_exclude(FilterExclude exclude)
	{
		sprite_filter_exclude = exclude;
	}

	void set_polygon_2d_filter_exclude(FilterExclude exclude)
	{
		polygon_2d_filter_exclude = exclude;
	}

JS Deck's avatar
JS Deck committed
441
442
443
444
445
	void set_scaled_uv_offset(bool offset)
	{
		scaled_uv_offset = offset;
	}

Libretro-Admin's avatar
Libretro-Admin committed
446
447
448
private:
	Vulkan::Device &device;
	unsigned scaling;
Hans-Kristian Arntzen's avatar
Hans-Kristian Arntzen committed
449
	unsigned msaa;
JS Deck's avatar
JS Deck committed
450
	bool scaled_uv_offset = false;
451
	FilterMode primitive_filter_mode = FilterMode::NearestNeighbor;
452
453
	FilterExclude sprite_filter_exclude = FilterExcludeNone;
	FilterExclude polygon_2d_filter_exclude = FilterExcludeNone;
Libretro-Admin's avatar
Libretro-Admin committed
454
	Vulkan::ImageHandle scaled_framebuffer;
Hans-Kristian Arntzen's avatar
Hans-Kristian Arntzen committed
455
	Vulkan::ImageHandle scaled_framebuffer_msaa;
Libretro-Admin's avatar
Libretro-Admin committed
456
457
	Vulkan::ImageHandle bias_framebuffer;
	Vulkan::ImageHandle framebuffer;
458
	Vulkan::ImageHandle framebuffer_ssaa;
Libretro-Admin's avatar
Libretro-Admin committed
459
460
461
	Vulkan::Semaphore scanout_semaphore;
	std::vector<Vulkan::ImageViewHandle> scaled_views;
	FBAtlas atlas;
stoofin's avatar
stoofin committed
462
	bool texture_tracking_enabled = false;
stoofin's avatar
stoofin committed
463
	TextureTracker tracker;
Libretro-Admin's avatar
Libretro-Admin committed
464
465
466

	Vulkan::CommandBufferHandle cmd;

stoofin's avatar
stoofin committed
467
	// HazardListener
Libretro-Admin's avatar
Libretro-Admin committed
468
469
470
471
472
473
	void hazard(StatusFlags flags) override;
	void resolve(Domain target_domain, unsigned x, unsigned y) override;
	void flush_render_pass(const Rect &rect) override;
	void discard_render_pass() override;
	void clear_quad(const Rect &rect, FBColor color, bool candidate) override;

stoofin's avatar
stoofin committed
474
475
476
477
478
479
480
481
482
483
	// TextureUploader
	Vulkan::ImageHandle upload_texture(std::vector<LoadedImage> &image) override;
	Vulkan::ImageHandle create_texture(int width, int height, int levels) override;
	Vulkan::CommandBufferHandle &command_buffer_hack_fixme() override;

	void hd_texture_uniforms(HdTextureHandle hd_texture_index);
	void update_hd_texture(const Rect &imageRect, const Rect &dstRect, const void *pixels);
	void update_hd_textures();
	HdTextureHandle get_hd_texture_index(const Rect &uvlimits, bool &fastpath_capable_out, bool &cache_hit_out);

Libretro-Admin's avatar
Libretro-Admin committed
484
485
	struct
	{
486
487
488
489
		Vulkan::Program *copy_to_vram;
		Vulkan::Program *copy_to_vram_masked;
		Vulkan::Program *unscaled_quad_blitter;
		Vulkan::Program *scaled_quad_blitter;
490
491
		Vulkan::Program *unscaled_dither_quad_blitter;
		Vulkan::Program *scaled_dither_quad_blitter;
492
		Vulkan::Program *bpp24_quad_blitter;
493
		Vulkan::Program *bpp24_yuv_quad_blitter;
494
495
		Vulkan::Program *resolve_to_scaled;
		Vulkan::Program *resolve_to_unscaled;
Hans-Kristian Arntzen's avatar
Hans-Kristian Arntzen committed
496

497
498
		Vulkan::Program *blit_vram_scaled;
		Vulkan::Program *blit_vram_scaled_masked;
499

500
501
		Vulkan::Program *blit_vram_cached_scaled;
		Vulkan::Program *blit_vram_cached_scaled_masked;
502
503
		Vulkan::Program *blit_vram_msaa_cached_scaled;
		Vulkan::Program *blit_vram_msaa_cached_scaled_masked;
Hans-Kristian Arntzen's avatar
Hans-Kristian Arntzen committed
504
505
506
507
508
509

		Vulkan::Program *blit_vram_unscaled;
		Vulkan::Program *blit_vram_unscaled_masked;
		Vulkan::Program *blit_vram_cached_unscaled;
		Vulkan::Program *blit_vram_cached_unscaled_masked;

510
		Vulkan::Program *flat;
511
512
		Vulkan::Program *textured_scaled;
		Vulkan::Program *textured_unscaled;
JS Deck's avatar
JS Deck committed
513
		Vulkan::Program *flat_masked;
514
515
		Vulkan::Program *textured_masked_scaled;
		Vulkan::Program *textured_masked_unscaled;
516
517

		Vulkan::Program *mipmap_resolve;
518
		Vulkan::Program *mipmap_dither_resolve;
519
520
521
		Vulkan::Program *mipmap_energy_first;
		Vulkan::Program *mipmap_energy;
		Vulkan::Program *mipmap_energy_blur;
Libretro-Admin's avatar
Libretro-Admin committed
522
523
524
525
526
	} pipelines;

	Vulkan::ImageHandle dither_lut;

	void init_pipelines();
527
	void init_primitive_pipelines();
528
	void init_primitive_feedback_pipelines();
Libretro-Admin's avatar
Libretro-Admin committed
529
530
531
532
533
534
535
536
537
538
539
	void ensure_command_buffer();

	RenderState render_state;

	struct BufferVertex
	{
		float x, y, z, w;
		uint32_t color;
		TextureWindow window;
		int16_t pal_x, pal_y, params;
		int16_t u, v, base_uv_x, base_uv_y;
540
		uint16_t min_u, min_v, max_u, max_v;
Libretro-Admin's avatar
Libretro-Admin committed
541
542
543
544
545
546
547
	};

	struct BlitInfo
	{
		uint32_t src_offset[2];
		uint32_t dst_offset[2];
		uint32_t extent[2];
Hans-Kristian Arntzen's avatar
Hans-Kristian Arntzen committed
548
549
		uint32_t mask;
		uint32_t sample;
Libretro-Admin's avatar
Libretro-Admin committed
550
551
552
553
554
	};

	struct SemiTransparentState
	{
		int scissor_index;
stoofin's avatar
stoofin committed
555
		HdTextureHandle hd_texture_index;
Libretro-Admin's avatar
Libretro-Admin committed
556
557
558
		SemiTransparentMode semi_transparent;
		bool textured;
		bool masked;
559
		bool filtering;
560
		bool scaled_read;
JS Deck's avatar
JS Deck committed
561
		unsigned shift;
JS Deck's avatar
JS Deck committed
562
		bool offset_uv;
Libretro-Admin's avatar
Libretro-Admin committed
563
564
565

		bool operator==(const SemiTransparentState &other) const
		{
stoofin's avatar
stoofin committed
566
			return scissor_index == other.scissor_index && hd_texture_index == other.hd_texture_index &&
567
			       semi_transparent == other.semi_transparent && textured == other.textured && masked == other.masked &&
JS Deck's avatar
JS Deck committed
568
569
				   filtering == other.filtering && scaled_read == other.scaled_read && shift == other.shift &&
				   offset_uv == other.offset_uv;
Libretro-Admin's avatar
Libretro-Admin committed
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
		}

		bool operator!=(const SemiTransparentState &other) const
		{
			return !(*this == other);
		}
	};

	struct ClearCandidate
	{
		Rect rect;
		FBColor color;
		float z;
	};

stoofin's avatar
stoofin committed
585
586
587
588
	struct PrimitiveInfo {
		unsigned triangle_index;
		int scissor_index;
		HdTextureHandle hd_texture_index;
589
		bool filtering;
590
		bool scaled_read;
JS Deck's avatar
JS Deck committed
591
		unsigned shift;
JS Deck's avatar
JS Deck committed
592
		bool offset_uv;
stoofin's avatar
stoofin committed
593
594

		// needed for emplace_back
595
596
597
598
		PrimitiveInfo(
			unsigned triangle_index,
			int scissor_index = -1,
			HdTextureHandle hd_texture_index = HdTextureHandle::make_none(),
599
			bool filtering = false,
JS Deck's avatar
JS Deck committed
600
			bool scaled_read = false,
JS Deck's avatar
JS Deck committed
601
602
			unsigned shift = 0,
			bool offset_uv = false
603
		)
604
			: triangle_index(triangle_index), scissor_index(scissor_index), hd_texture_index(hd_texture_index),
JS Deck's avatar
JS Deck committed
605
606
			filtering(filtering), scaled_read(scaled_read), shift(shift), offset_uv(offset_uv)
		{}
stoofin's avatar
stoofin committed
607
608
	};

Libretro-Admin's avatar
Libretro-Admin committed
609
610
611
612
	struct OpaqueQueue
	{
		// Non-textured primitives.
		std::vector<BufferVertex> opaque;
stoofin's avatar
stoofin committed
613
		std::vector<PrimitiveInfo> opaque_scissor;
Libretro-Admin's avatar
Libretro-Admin committed
614
615
616

		// Textured primitives, no semi-transparency.
		std::vector<BufferVertex> opaque_textured;
stoofin's avatar
stoofin committed
617
		std::vector<PrimitiveInfo> opaque_textured_scissor;
Libretro-Admin's avatar
Libretro-Admin committed
618
619
620

		// Textured primitives, semi-transparency enabled.
		std::vector<BufferVertex> semi_transparent_opaque;
stoofin's avatar
stoofin committed
621
		std::vector<PrimitiveInfo> semi_transparent_opaque_scissor;
Libretro-Admin's avatar
Libretro-Admin committed
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643

		std::vector<BufferVertex> semi_transparent;
		std::vector<SemiTransparentState> semi_transparent_state;

		std::vector<Vulkan::ImageHandle> textures;

		std::vector<VkRect2D> scaled_resolves;
		std::vector<VkRect2D> unscaled_resolves;
		std::vector<BlitInfo> scaled_blits;
		std::vector<BlitInfo> scaled_masked_blits;
		std::vector<BlitInfo> unscaled_blits;
		std::vector<BlitInfo> unscaled_masked_blits;

		std::vector<VkRect2D> scissors;
		std::vector<ClearCandidate> clear_candidates;
		VkRect2D default_scissor;
		bool scissor_invariant = false;
	} queue;
	unsigned primitive_index = 0;
	bool render_pass_is_feedback = false;
	float last_uv_scale_x, last_uv_scale_y;

644
	void dispatch(const std::vector<BufferVertex> &vertices, std::vector<PrimitiveInfo> &scissors, bool textured = false);
Libretro-Admin's avatar
Libretro-Admin committed
645
646
647
648
649
650
	void render_opaque_primitives();
	void render_opaque_texture_primitives();
	void render_semi_transparent_opaque_texture_primitives();
	void render_semi_transparent_primitives();
	void reset_queue();

651
	float allocate_depth(Domain domain, const Rect &rect);
Libretro-Admin's avatar
Libretro-Admin committed
652

653
	void build_attribs(BufferVertex *verts, const Vertex *vertices, unsigned count, HdTextureHandle &hd_texture_index,
JS Deck's avatar
JS Deck committed
654
		bool &filtering, bool &scaled_read, unsigned &shift, bool &offset_uv);
Libretro-Admin's avatar
Libretro-Admin committed
655
	void build_line_quad(Vertex *quad, const Vertex *line);
656
	std::vector<BufferVertex> *select_pipeline(unsigned prims, int scissor, HdTextureHandle hd_texture,
JS Deck's avatar
JS Deck committed
657
		bool filtering, bool scaled_read, unsigned shift, bool offset_uv);
658
659
660
661
662
663
664
665
666
667
668
669
670
671
	bool get_filer_exclude(FilterExclude exclude)
	{
		if (
			render_state.primitive_type == PrimitiveType::Sprite &&
			sprite_filter_exclude >= exclude
		)
			return true;
		if (
			render_state.primitive_type == PrimitiveType::May_Be_2D_Polygon &&
			polygon_2d_filter_exclude >= exclude
		)
			return true;
		return false;
	}
Libretro-Admin's avatar
Libretro-Admin committed
672
673
674
675
676
677
678
679
680
681

	void flush_resolves();
	void flush_blits();
	void reset_scissor_queue();
	const ClearCandidate *find_clear_candidate(const Rect &rect) const;

	Rect compute_window_rect(const TextureWindow &window);

	Vulkan::ImageHandle last_scanout;
	Vulkan::ImageHandle reuseable_scanout;
682
	DisplayRect compute_display_rect();
Libretro-Admin's avatar
Libretro-Admin committed
683

684
685
	Rect compute_vram_framebuffer_rect();

Libretro-Admin's avatar
Libretro-Admin committed
686
	void mipmap_framebuffer();
687
	void ssaa_framebuffer();
Libretro-Admin's avatar
Libretro-Admin committed
688
689
690
	Vulkan::BufferHandle quad;
};
}