Path: blob/21.2-virgl/src/gallium/auxiliary/rbug/rbug_shader.c
4561 views
/*1* Copyright 2009 VMware, Inc.2* All Rights Reserved.3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* on the rights to use, copy, modify, merge, publish, distribute, sub8* license, and/or sell copies of the Software, and to permit persons to whom9* the Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice (including the next12* paragraph) shall be included in all copies or substantial portions of the13* Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL18* VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,19* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR20* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE21* USE OR OTHER DEALINGS IN THE SOFTWARE.22*/2324/*25* This file holds the function implementation for one of the rbug extensions.26* Prototypes and declerations of functions and structs is in the same folder27* in the header file matching this file's name.28*29* The functions starting rbug_send_* encodes a call to the write format and30* sends that to the supplied connection, while functions starting with31* rbug_demarshal_* demarshal data in the wire protocol.32*33* Functions ending with _reply are replies to requests.34*/3536#include "rbug_internal.h"37#include "rbug_shader.h"3839int rbug_send_shader_list(struct rbug_connection *__con,40rbug_context_t context,41uint32_t *__serial)42{43uint32_t __len = 0;44uint32_t __pos = 0;45uint8_t *__data = NULL;46int __ret = 0;4748LEN(8); /* header */49LEN(8); /* context */5051/* align */52PAD(__len, 8);5354__data = (uint8_t*)MALLOC(__len);55if (!__data)56return -ENOMEM;5758WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_LIST));59WRITE(4, uint32_t, ((uint32_t)(__len / 4)));60WRITE(8, rbug_context_t, context); /* context */6162/* final pad */63PAD(__pos, 8);6465if (__pos != __len) {66__ret = -EINVAL;67} else {68rbug_connection_send_start(__con, RBUG_OP_SHADER_LIST, __len);69rbug_connection_write(__con, __data, __len);70__ret = rbug_connection_send_finish(__con, __serial);71}7273FREE(__data);74return __ret;75}7677int rbug_send_shader_info(struct rbug_connection *__con,78rbug_context_t context,79rbug_shader_t shader,80uint32_t *__serial)81{82uint32_t __len = 0;83uint32_t __pos = 0;84uint8_t *__data = NULL;85int __ret = 0;8687LEN(8); /* header */88LEN(8); /* context */89LEN(8); /* shader */9091/* align */92PAD(__len, 8);9394__data = (uint8_t*)MALLOC(__len);95if (!__data)96return -ENOMEM;9798WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_INFO));99WRITE(4, uint32_t, ((uint32_t)(__len / 4)));100WRITE(8, rbug_context_t, context); /* context */101WRITE(8, rbug_shader_t, shader); /* shader */102103/* final pad */104PAD(__pos, 8);105106if (__pos != __len) {107__ret = -EINVAL;108} else {109rbug_connection_send_start(__con, RBUG_OP_SHADER_INFO, __len);110rbug_connection_write(__con, __data, __len);111__ret = rbug_connection_send_finish(__con, __serial);112}113114FREE(__data);115return __ret;116}117118int rbug_send_shader_disable(struct rbug_connection *__con,119rbug_context_t context,120rbug_shader_t shader,121uint8_t disable,122uint32_t *__serial)123{124uint32_t __len = 0;125uint32_t __pos = 0;126uint8_t *__data = NULL;127int __ret = 0;128129LEN(8); /* header */130LEN(8); /* context */131LEN(8); /* shader */132LEN(1); /* disable */133134/* align */135PAD(__len, 8);136137__data = (uint8_t*)MALLOC(__len);138if (!__data)139return -ENOMEM;140141WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_DISABLE));142WRITE(4, uint32_t, ((uint32_t)(__len / 4)));143WRITE(8, rbug_context_t, context); /* context */144WRITE(8, rbug_shader_t, shader); /* shader */145WRITE(1, uint8_t, disable); /* disable */146147/* final pad */148PAD(__pos, 8);149150if (__pos != __len) {151__ret = -EINVAL;152} else {153rbug_connection_send_start(__con, RBUG_OP_SHADER_DISABLE, __len);154rbug_connection_write(__con, __data, __len);155__ret = rbug_connection_send_finish(__con, __serial);156}157158FREE(__data);159return __ret;160}161162int rbug_send_shader_replace(struct rbug_connection *__con,163rbug_context_t context,164rbug_shader_t shader,165uint32_t *tokens,166uint32_t tokens_len,167uint32_t *__serial)168{169uint32_t __len = 0;170uint32_t __pos = 0;171uint8_t *__data = NULL;172int __ret = 0;173174LEN(8); /* header */175LEN(8); /* context */176LEN(8); /* shader */177LEN_ARRAY(4, tokens); /* tokens */178179/* align */180PAD(__len, 8);181182__data = (uint8_t*)MALLOC(__len);183if (!__data)184return -ENOMEM;185186WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_REPLACE));187WRITE(4, uint32_t, ((uint32_t)(__len / 4)));188WRITE(8, rbug_context_t, context); /* context */189WRITE(8, rbug_shader_t, shader); /* shader */190WRITE_ARRAY(4, uint32_t, tokens); /* tokens */191192/* final pad */193PAD(__pos, 8);194195if (__pos != __len) {196__ret = -EINVAL;197} else {198rbug_connection_send_start(__con, RBUG_OP_SHADER_REPLACE, __len);199rbug_connection_write(__con, __data, __len);200__ret = rbug_connection_send_finish(__con, __serial);201}202203FREE(__data);204return __ret;205}206207int rbug_send_shader_list_reply(struct rbug_connection *__con,208uint32_t serial,209rbug_shader_t *shaders,210uint32_t shaders_len,211uint32_t *__serial)212{213uint32_t __len = 0;214uint32_t __pos = 0;215uint8_t *__data = NULL;216int __ret = 0;217218LEN(8); /* header */219LEN(4); /* serial */220LEN_ARRAY(8, shaders); /* shaders */221222/* align */223PAD(__len, 8);224225__data = (uint8_t*)MALLOC(__len);226if (!__data)227return -ENOMEM;228229WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_LIST_REPLY));230WRITE(4, uint32_t, ((uint32_t)(__len / 4)));231WRITE(4, uint32_t, serial); /* serial */232WRITE_ARRAY(8, rbug_shader_t, shaders); /* shaders */233234/* final pad */235PAD(__pos, 8);236237if (__pos != __len) {238__ret = -EINVAL;239} else {240rbug_connection_send_start(__con, RBUG_OP_SHADER_LIST_REPLY, __len);241rbug_connection_write(__con, __data, __len);242__ret = rbug_connection_send_finish(__con, __serial);243}244245FREE(__data);246return __ret;247}248249int rbug_send_shader_info_reply(struct rbug_connection *__con,250uint32_t serial,251uint32_t *original,252uint32_t original_len,253uint32_t *replaced,254uint32_t replaced_len,255uint8_t disabled,256uint32_t *__serial)257{258uint32_t __len = 0;259uint32_t __pos = 0;260uint8_t *__data = NULL;261int __ret = 0;262263LEN(8); /* header */264LEN(4); /* serial */265LEN_ARRAY(4, original); /* original */266LEN_ARRAY(4, replaced); /* replaced */267LEN(1); /* disabled */268269/* align */270PAD(__len, 8);271272__data = (uint8_t*)MALLOC(__len);273if (!__data)274return -ENOMEM;275276WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_INFO_REPLY));277WRITE(4, uint32_t, ((uint32_t)(__len / 4)));278WRITE(4, uint32_t, serial); /* serial */279WRITE_ARRAY(4, uint32_t, original); /* original */280WRITE_ARRAY(4, uint32_t, replaced); /* replaced */281WRITE(1, uint8_t, disabled); /* disabled */282283/* final pad */284PAD(__pos, 8);285286if (__pos != __len) {287__ret = -EINVAL;288} else {289rbug_connection_send_start(__con, RBUG_OP_SHADER_INFO_REPLY, __len);290rbug_connection_write(__con, __data, __len);291__ret = rbug_connection_send_finish(__con, __serial);292}293294FREE(__data);295return __ret;296}297298struct rbug_proto_shader_list * rbug_demarshal_shader_list(struct rbug_proto_header *header)299{300uint32_t len = 0;301uint32_t pos = 0;302uint8_t *data = NULL;303struct rbug_proto_shader_list *ret;304305if (!header)306return NULL;307if (header->opcode != (int32_t)RBUG_OP_SHADER_LIST)308return NULL;309310pos = 0;311len = header->length * 4;312data = (uint8_t*)&header[1];313ret = MALLOC(sizeof(*ret));314if (!ret)315return NULL;316317ret->header.__message = header;318ret->header.opcode = header->opcode;319320READ(8, rbug_context_t, context); /* context */321322return ret;323}324325struct rbug_proto_shader_info * rbug_demarshal_shader_info(struct rbug_proto_header *header)326{327uint32_t len = 0;328uint32_t pos = 0;329uint8_t *data = NULL;330struct rbug_proto_shader_info *ret;331332if (!header)333return NULL;334if (header->opcode != (int32_t)RBUG_OP_SHADER_INFO)335return NULL;336337pos = 0;338len = header->length * 4;339data = (uint8_t*)&header[1];340ret = MALLOC(sizeof(*ret));341if (!ret)342return NULL;343344ret->header.__message = header;345ret->header.opcode = header->opcode;346347READ(8, rbug_context_t, context); /* context */348READ(8, rbug_shader_t, shader); /* shader */349350return ret;351}352353struct rbug_proto_shader_disable * rbug_demarshal_shader_disable(struct rbug_proto_header *header)354{355uint32_t len = 0;356uint32_t pos = 0;357uint8_t *data = NULL;358struct rbug_proto_shader_disable *ret;359360if (!header)361return NULL;362if (header->opcode != (int32_t)RBUG_OP_SHADER_DISABLE)363return NULL;364365pos = 0;366len = header->length * 4;367data = (uint8_t*)&header[1];368ret = MALLOC(sizeof(*ret));369if (!ret)370return NULL;371372ret->header.__message = header;373ret->header.opcode = header->opcode;374375READ(8, rbug_context_t, context); /* context */376READ(8, rbug_shader_t, shader); /* shader */377READ(1, uint8_t, disable); /* disable */378379return ret;380}381382struct rbug_proto_shader_replace * rbug_demarshal_shader_replace(struct rbug_proto_header *header)383{384uint32_t len = 0;385uint32_t pos = 0;386uint8_t *data = NULL;387struct rbug_proto_shader_replace *ret;388389if (!header)390return NULL;391if (header->opcode != (int32_t)RBUG_OP_SHADER_REPLACE)392return NULL;393394pos = 0;395len = header->length * 4;396data = (uint8_t*)&header[1];397ret = MALLOC(sizeof(*ret));398if (!ret)399return NULL;400401ret->header.__message = header;402ret->header.opcode = header->opcode;403404READ(8, rbug_context_t, context); /* context */405READ(8, rbug_shader_t, shader); /* shader */406READ_ARRAY(4, uint32_t, tokens); /* tokens */407408return ret;409}410411struct rbug_proto_shader_list_reply * rbug_demarshal_shader_list_reply(struct rbug_proto_header *header)412{413uint32_t len = 0;414uint32_t pos = 0;415uint8_t *data = NULL;416struct rbug_proto_shader_list_reply *ret;417418if (!header)419return NULL;420if (header->opcode != (int32_t)RBUG_OP_SHADER_LIST_REPLY)421return NULL;422423pos = 0;424len = header->length * 4;425data = (uint8_t*)&header[1];426ret = MALLOC(sizeof(*ret));427if (!ret)428return NULL;429430ret->header.__message = header;431ret->header.opcode = header->opcode;432433READ(4, uint32_t, serial); /* serial */434READ_ARRAY(8, rbug_shader_t, shaders); /* shaders */435436return ret;437}438439struct rbug_proto_shader_info_reply * rbug_demarshal_shader_info_reply(struct rbug_proto_header *header)440{441uint32_t len = 0;442uint32_t pos = 0;443uint8_t *data = NULL;444struct rbug_proto_shader_info_reply *ret;445446if (!header)447return NULL;448if (header->opcode != (int32_t)RBUG_OP_SHADER_INFO_REPLY)449return NULL;450451pos = 0;452len = header->length * 4;453data = (uint8_t*)&header[1];454ret = MALLOC(sizeof(*ret));455if (!ret)456return NULL;457458ret->header.__message = header;459ret->header.opcode = header->opcode;460461READ(4, uint32_t, serial); /* serial */462READ_ARRAY(4, uint32_t, original); /* original */463READ_ARRAY(4, uint32_t, replaced); /* replaced */464READ(1, uint8_t, disabled); /* disabled */465466return ret;467}468469470