Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/drivers/zink/zink_framebuffer.c
4570 views
1
/*
2
* Copyright 2018 Collabora Ltd.
3
*
4
* Permission is hereby granted, free of charge, to any person obtaining a
5
* copy of this software and associated documentation files (the "Software"),
6
* to deal in the Software without restriction, including without limitation
7
* on the rights to use, copy, modify, merge, publish, distribute, sub
8
* license, and/or sell copies of the Software, and to permit persons to whom
9
* the Software is furnished to do so, subject to the following conditions:
10
*
11
* The above copyright notice and this permission notice (including the next
12
* paragraph) shall be included in all copies or substantial portions of the
13
* Software.
14
*
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18
* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21
* USE OR OTHER DEALINGS IN THE SOFTWARE.
22
*/
23
24
#include "zink_context.h"
25
#include "zink_framebuffer.h"
26
27
#include "zink_render_pass.h"
28
#include "zink_screen.h"
29
#include "zink_surface.h"
30
31
#include "util/u_memory.h"
32
#include "util/u_string.h"
33
34
void
35
zink_destroy_framebuffer(struct zink_screen *screen,
36
struct zink_framebuffer *fb)
37
{
38
hash_table_foreach(&fb->objects, he) {
39
#if defined(_WIN64) || defined(__x86_64__)
40
vkDestroyFramebuffer(screen->dev, he->data, NULL);
41
#else
42
VkFramebuffer *ptr = he->data;
43
vkDestroyFramebuffer(screen->dev, *ptr, NULL);
44
#endif
45
}
46
47
if (fb->null_surface)
48
pipe_resource_reference(&fb->null_surface->texture, NULL);
49
zink_surface_reference(screen, (struct zink_surface**)&fb->null_surface, NULL);
50
51
ralloc_free(fb);
52
}
53
54
void
55
zink_init_framebuffer(struct zink_screen *screen, struct zink_framebuffer *fb, struct zink_render_pass *rp)
56
{
57
VkFramebuffer ret;
58
59
if (fb->rp == rp)
60
return;
61
62
uint32_t hash = _mesa_hash_pointer(rp);
63
64
struct hash_entry *he = _mesa_hash_table_search_pre_hashed(&fb->objects, hash, rp);
65
if (he) {
66
#if defined(_WIN64) || defined(__x86_64__)
67
ret = (VkFramebuffer)he->data;
68
#else
69
VkFramebuffer *ptr = he->data;
70
ret = *ptr;
71
#endif
72
goto out;
73
}
74
75
VkFramebufferCreateInfo fci = {0};
76
fci.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
77
fci.renderPass = rp->render_pass;
78
fci.attachmentCount = fb->state.num_attachments;
79
fci.pAttachments = fb->state.attachments;
80
fci.width = fb->state.width;
81
fci.height = fb->state.height;
82
fci.layers = fb->state.layers;
83
84
if (vkCreateFramebuffer(screen->dev, &fci, NULL, &ret) != VK_SUCCESS)
85
return;
86
#if defined(_WIN64) || defined(__x86_64__)
87
_mesa_hash_table_insert_pre_hashed(&fb->objects, hash, rp, ret);
88
#else
89
VkFramebuffer *ptr = ralloc(fb, VkFramebuffer);
90
if (!ptr) {
91
vkDestroyFramebuffer(screen->dev, ret, NULL);
92
return;
93
}
94
*ptr = ret;
95
_mesa_hash_table_insert_pre_hashed(&fb->objects, hash, rp, ptr);
96
#endif
97
out:
98
fb->rp = rp;
99
fb->fb = ret;
100
}
101
102
struct zink_framebuffer *
103
zink_create_framebuffer(struct zink_context *ctx,
104
struct zink_framebuffer_state *state,
105
struct pipe_surface **attachments)
106
{
107
struct zink_screen *screen = zink_screen(ctx->base.screen);
108
struct zink_framebuffer *fb = rzalloc(NULL, struct zink_framebuffer);
109
if (!fb)
110
return NULL;
111
112
unsigned num_attachments = 0;
113
for (int i = 0; i < state->num_attachments; i++) {
114
struct zink_surface *surf;
115
if (state->attachments[i]) {
116
surf = zink_surface(attachments[i]);
117
/* no ref! */
118
fb->surfaces[i] = attachments[i];
119
num_attachments++;
120
} else {
121
if (!fb->null_surface)
122
fb->null_surface = zink_surface_create_null(ctx, PIPE_TEXTURE_2D, state->width, state->height, state->samples);
123
surf = zink_surface(fb->null_surface);
124
state->attachments[i] = zink_surface(fb->null_surface)->image_view;
125
}
126
util_dynarray_append(&surf->framebuffer_refs, struct zink_framebuffer*, fb);
127
}
128
pipe_reference_init(&fb->reference, 1 + num_attachments);
129
130
if (!_mesa_hash_table_init(&fb->objects, fb, _mesa_hash_pointer, _mesa_key_pointer_equal))
131
goto fail;
132
memcpy(&fb->state, state, sizeof(struct zink_framebuffer_state));
133
134
return fb;
135
fail:
136
zink_destroy_framebuffer(screen, fb);
137
return NULL;
138
}
139
140
void
141
debug_describe_zink_framebuffer(char* buf, const struct zink_framebuffer *ptr)
142
{
143
sprintf(buf, "zink_framebuffer");
144
}
145
146