1
/**********************************************************
2
* Copyright 2009-2015 VMware, Inc. All rights reserved.
4
* Permission is hereby granted, free of charge, to any person
5
* obtaining a copy of this software and associated documentation
6
* files (the "Software"), to deal in the Software without
7
* restriction, including without limitation the rights to use, copy,
8
* modify, merge, publish, distribute, sublicense, and/or sell copies
9
* of the Software, and to permit persons to whom the Software is
10
* furnished to do so, subject to the following conditions:
12
* The above copyright notice and this permission notice shall be
13
* included in all copies or substantial portions of the Software.
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
**********************************************************/
28
#include "util/u_debug.h"
29
#include "util/u_memory.h"
31
#include "vmw_context.h"
32
#include "vmw_shader.h"
33
#include "vmw_buffer.h"
34
#include "vmw_screen.h"
37
vmw_svga_winsys_shader_reference(struct vmw_svga_winsys_shader **pdst,
38
struct vmw_svga_winsys_shader *src)
40
struct pipe_reference *src_ref;
41
struct pipe_reference *dst_ref;
42
struct vmw_svga_winsys_shader *dst;
44
if(pdst == NULL || *pdst == src)
49
src_ref = src ? &src->refcnt : NULL;
50
dst_ref = dst ? &dst->refcnt : NULL;
52
if (pipe_reference(dst_ref, src_ref)) {
53
struct svga_winsys_screen *sws = &dst->screen->base;
55
if (!sws->have_vgpu10)
56
vmw_ioctl_shader_destroy(dst->screen, dst->shid);
58
/* to detect dangling pointers */
59
assert(p_atomic_read(&dst->validated) == 0);
60
dst->shid = SVGA3D_INVALID_ID;
62
sws->buffer_destroy(sws, dst->buf);
71
* A helper function to create a shader object and upload the
72
* shader bytecode and signature if specified to the shader memory.
74
struct vmw_svga_winsys_shader *
75
vmw_svga_shader_create(struct svga_winsys_screen *sws,
76
SVGA3dShaderType type,
77
const uint32 *bytecode,
79
const SVGA3dDXShaderSignatureHeader *sgnInfo,
82
struct vmw_svga_winsys_shader *shader;
85
shader = CALLOC_STRUCT(vmw_svga_winsys_shader);
89
pipe_reference_init(&shader->refcnt, 1);
90
p_atomic_set(&shader->validated, 0);
91
shader->screen = vmw_winsys_screen(sws);
92
shader->buf = sws->buffer_create(sws, 64,
93
SVGA_BUFFER_USAGE_SHADER,
94
bytecodeLen + sgnLen);
100
map = sws->buffer_map(sws, shader->buf, PIPE_MAP_WRITE);
106
/* copy the shader bytecode */
107
memcpy(map, bytecode, bytecodeLen);
109
/* if shader signature is specified, append it to the bytecode. */
111
assert(sws->have_sm5);
112
map = (char *)map + bytecodeLen;
113
memcpy(map, sgnInfo, sgnLen);
115
sws->buffer_unmap(sws, shader->buf);