1bf215546Sopenharmony_ci/************************************************************************** 2bf215546Sopenharmony_ci * 3bf215546Sopenharmony_ci * Copyright 2012-2021 VMware, Inc. 4bf215546Sopenharmony_ci * All Rights Reserved. 5bf215546Sopenharmony_ci * 6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the 8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to 11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 12bf215546Sopenharmony_ci * the following conditions: 13bf215546Sopenharmony_ci * 14bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 17bf215546Sopenharmony_ci * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 18bf215546Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19bf215546Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20bf215546Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE. 21bf215546Sopenharmony_ci * 22bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the 23bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions 24bf215546Sopenharmony_ci * of the Software. 25bf215546Sopenharmony_ci * 26bf215546Sopenharmony_ci **************************************************************************/ 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci/* 29bf215546Sopenharmony_ci * Shader.cpp -- 30bf215546Sopenharmony_ci * Functions that manipulate shader resources. 31bf215546Sopenharmony_ci */ 32bf215546Sopenharmony_ci 33bf215546Sopenharmony_ci 34bf215546Sopenharmony_ci#include "Shader.h" 35bf215546Sopenharmony_ci#include "ShaderParse.h" 36bf215546Sopenharmony_ci#include "State.h" 37bf215546Sopenharmony_ci#include "Query.h" 38bf215546Sopenharmony_ci 39bf215546Sopenharmony_ci#include "Debug.h" 40bf215546Sopenharmony_ci#include "Format.h" 41bf215546Sopenharmony_ci 42bf215546Sopenharmony_ci#include "tgsi/tgsi_ureg.h" 43bf215546Sopenharmony_ci#include "util/u_gen_mipmap.h" 44bf215546Sopenharmony_ci#include "util/u_sampler.h" 45bf215546Sopenharmony_ci#include "util/format/u_format.h" 46bf215546Sopenharmony_ci 47bf215546Sopenharmony_ci 48bf215546Sopenharmony_ci/* 49bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 50bf215546Sopenharmony_ci * 51bf215546Sopenharmony_ci * CreateEmptyShader -- 52bf215546Sopenharmony_ci * 53bf215546Sopenharmony_ci * Update the driver's currently bound constant buffers. 54bf215546Sopenharmony_ci * 55bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 56bf215546Sopenharmony_ci */ 57bf215546Sopenharmony_ci 58bf215546Sopenharmony_civoid * 59bf215546Sopenharmony_ciCreateEmptyShader(Device *pDevice, 60bf215546Sopenharmony_ci enum pipe_shader_type processor) 61bf215546Sopenharmony_ci{ 62bf215546Sopenharmony_ci struct pipe_context *pipe = pDevice->pipe; 63bf215546Sopenharmony_ci struct ureg_program *ureg; 64bf215546Sopenharmony_ci const struct tgsi_token *tokens; 65bf215546Sopenharmony_ci uint nr_tokens; 66bf215546Sopenharmony_ci 67bf215546Sopenharmony_ci if (processor == PIPE_SHADER_GEOMETRY) { 68bf215546Sopenharmony_ci return NULL; 69bf215546Sopenharmony_ci } 70bf215546Sopenharmony_ci 71bf215546Sopenharmony_ci ureg = ureg_create(processor); 72bf215546Sopenharmony_ci if (!ureg) 73bf215546Sopenharmony_ci return NULL; 74bf215546Sopenharmony_ci 75bf215546Sopenharmony_ci ureg_END(ureg); 76bf215546Sopenharmony_ci 77bf215546Sopenharmony_ci tokens = ureg_get_tokens(ureg, &nr_tokens); 78bf215546Sopenharmony_ci if (!tokens) 79bf215546Sopenharmony_ci return NULL; 80bf215546Sopenharmony_ci 81bf215546Sopenharmony_ci ureg_destroy(ureg); 82bf215546Sopenharmony_ci 83bf215546Sopenharmony_ci struct pipe_shader_state state; 84bf215546Sopenharmony_ci memset(&state, 0, sizeof state); 85bf215546Sopenharmony_ci state.tokens = tokens; 86bf215546Sopenharmony_ci 87bf215546Sopenharmony_ci void *handle; 88bf215546Sopenharmony_ci switch (processor) { 89bf215546Sopenharmony_ci case PIPE_SHADER_FRAGMENT: 90bf215546Sopenharmony_ci handle = pipe->create_fs_state(pipe, &state); 91bf215546Sopenharmony_ci break; 92bf215546Sopenharmony_ci case PIPE_SHADER_VERTEX: 93bf215546Sopenharmony_ci handle = pipe->create_vs_state(pipe, &state); 94bf215546Sopenharmony_ci break; 95bf215546Sopenharmony_ci case PIPE_SHADER_GEOMETRY: 96bf215546Sopenharmony_ci handle = pipe->create_gs_state(pipe, &state); 97bf215546Sopenharmony_ci break; 98bf215546Sopenharmony_ci default: 99bf215546Sopenharmony_ci handle = NULL; 100bf215546Sopenharmony_ci assert(0); 101bf215546Sopenharmony_ci } 102bf215546Sopenharmony_ci assert(handle); 103bf215546Sopenharmony_ci 104bf215546Sopenharmony_ci ureg_free_tokens(tokens); 105bf215546Sopenharmony_ci 106bf215546Sopenharmony_ci return handle; 107bf215546Sopenharmony_ci} 108bf215546Sopenharmony_ci 109bf215546Sopenharmony_ci 110bf215546Sopenharmony_ci/* 111bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 112bf215546Sopenharmony_ci * 113bf215546Sopenharmony_ci * CreateEmptyShader -- 114bf215546Sopenharmony_ci * 115bf215546Sopenharmony_ci * Update the driver's currently bound constant buffers. 116bf215546Sopenharmony_ci * 117bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 118bf215546Sopenharmony_ci */ 119bf215546Sopenharmony_ci 120bf215546Sopenharmony_civoid 121bf215546Sopenharmony_ciDeleteEmptyShader(Device *pDevice, 122bf215546Sopenharmony_ci enum pipe_shader_type processor, void *handle) 123bf215546Sopenharmony_ci{ 124bf215546Sopenharmony_ci struct pipe_context *pipe = pDevice->pipe; 125bf215546Sopenharmony_ci 126bf215546Sopenharmony_ci if (processor == PIPE_SHADER_GEOMETRY) { 127bf215546Sopenharmony_ci assert(handle == NULL); 128bf215546Sopenharmony_ci return; 129bf215546Sopenharmony_ci } 130bf215546Sopenharmony_ci 131bf215546Sopenharmony_ci assert(handle != NULL); 132bf215546Sopenharmony_ci switch (processor) { 133bf215546Sopenharmony_ci case PIPE_SHADER_FRAGMENT: 134bf215546Sopenharmony_ci pipe->delete_fs_state(pipe, handle); 135bf215546Sopenharmony_ci break; 136bf215546Sopenharmony_ci case PIPE_SHADER_VERTEX: 137bf215546Sopenharmony_ci pipe->delete_vs_state(pipe, handle); 138bf215546Sopenharmony_ci break; 139bf215546Sopenharmony_ci case PIPE_SHADER_GEOMETRY: 140bf215546Sopenharmony_ci pipe->delete_gs_state(pipe, handle); 141bf215546Sopenharmony_ci break; 142bf215546Sopenharmony_ci default: 143bf215546Sopenharmony_ci assert(0); 144bf215546Sopenharmony_ci } 145bf215546Sopenharmony_ci} 146bf215546Sopenharmony_ci 147bf215546Sopenharmony_ci 148bf215546Sopenharmony_ci/* 149bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 150bf215546Sopenharmony_ci * 151bf215546Sopenharmony_ci * SetConstantBuffers -- 152bf215546Sopenharmony_ci * 153bf215546Sopenharmony_ci * Update the driver's currently bound constant buffers. 154bf215546Sopenharmony_ci * 155bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 156bf215546Sopenharmony_ci */ 157bf215546Sopenharmony_ci 158bf215546Sopenharmony_cistatic void 159bf215546Sopenharmony_ciSetConstantBuffers(enum pipe_shader_type shader_type, // IN 160bf215546Sopenharmony_ci D3D10DDI_HDEVICE hDevice, // IN 161bf215546Sopenharmony_ci UINT StartBuffer, // IN 162bf215546Sopenharmony_ci UINT NumBuffers, // IN 163bf215546Sopenharmony_ci const D3D10DDI_HRESOURCE *phBuffers) // IN 164bf215546Sopenharmony_ci{ 165bf215546Sopenharmony_ci Device *pDevice = CastDevice(hDevice); 166bf215546Sopenharmony_ci struct pipe_context *pipe = pDevice->pipe; 167bf215546Sopenharmony_ci 168bf215546Sopenharmony_ci for (UINT i = 0; i < NumBuffers; i++) { 169bf215546Sopenharmony_ci struct pipe_constant_buffer cb; 170bf215546Sopenharmony_ci memset(&cb, 0, sizeof cb); 171bf215546Sopenharmony_ci cb.buffer = CastPipeResource(phBuffers[i]); 172bf215546Sopenharmony_ci cb.buffer_offset = 0; 173bf215546Sopenharmony_ci cb.buffer_size = cb.buffer ? cb.buffer->width0 : 0; 174bf215546Sopenharmony_ci pipe->set_constant_buffer(pipe, 175bf215546Sopenharmony_ci shader_type, 176bf215546Sopenharmony_ci StartBuffer + i, 177bf215546Sopenharmony_ci FALSE, 178bf215546Sopenharmony_ci &cb); 179bf215546Sopenharmony_ci } 180bf215546Sopenharmony_ci} 181bf215546Sopenharmony_ci 182bf215546Sopenharmony_ci 183bf215546Sopenharmony_ci/* 184bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 185bf215546Sopenharmony_ci * 186bf215546Sopenharmony_ci * SetSamplers -- 187bf215546Sopenharmony_ci * 188bf215546Sopenharmony_ci * Update the driver's currently bound sampler state. 189bf215546Sopenharmony_ci * 190bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 191bf215546Sopenharmony_ci */ 192bf215546Sopenharmony_ci 193bf215546Sopenharmony_cistatic void 194bf215546Sopenharmony_ciSetSamplers(enum pipe_shader_type shader_type, // IN 195bf215546Sopenharmony_ci D3D10DDI_HDEVICE hDevice, // IN 196bf215546Sopenharmony_ci UINT Offset, // IN 197bf215546Sopenharmony_ci UINT NumSamplers, // IN 198bf215546Sopenharmony_ci const D3D10DDI_HSAMPLER *phSamplers) // IN 199bf215546Sopenharmony_ci{ 200bf215546Sopenharmony_ci Device *pDevice = CastDevice(hDevice); 201bf215546Sopenharmony_ci struct pipe_context *pipe = pDevice->pipe; 202bf215546Sopenharmony_ci 203bf215546Sopenharmony_ci void **samplers = pDevice->samplers[shader_type]; 204bf215546Sopenharmony_ci for (UINT i = 0; i < NumSamplers; i++) { 205bf215546Sopenharmony_ci assert(Offset + i < PIPE_MAX_SAMPLERS); 206bf215546Sopenharmony_ci samplers[Offset + i] = CastPipeSamplerState(phSamplers[i]); 207bf215546Sopenharmony_ci } 208bf215546Sopenharmony_ci 209bf215546Sopenharmony_ci pipe->bind_sampler_states(pipe, shader_type, 0, PIPE_MAX_SAMPLERS, samplers); 210bf215546Sopenharmony_ci} 211bf215546Sopenharmony_ci 212bf215546Sopenharmony_ci 213bf215546Sopenharmony_ci/* 214bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 215bf215546Sopenharmony_ci * 216bf215546Sopenharmony_ci * SetSamplers -- 217bf215546Sopenharmony_ci * 218bf215546Sopenharmony_ci * Update the driver's currently bound sampler state. 219bf215546Sopenharmony_ci * 220bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 221bf215546Sopenharmony_ci */ 222bf215546Sopenharmony_ci 223bf215546Sopenharmony_cistatic void 224bf215546Sopenharmony_ciSetShaderResources(enum pipe_shader_type shader_type, // IN 225bf215546Sopenharmony_ci D3D10DDI_HDEVICE hDevice, // IN 226bf215546Sopenharmony_ci UINT Offset, // IN 227bf215546Sopenharmony_ci UINT NumViews, // IN 228bf215546Sopenharmony_ci const D3D10DDI_HSHADERRESOURCEVIEW *phShaderResourceViews) // IN 229bf215546Sopenharmony_ci{ 230bf215546Sopenharmony_ci Device *pDevice = CastDevice(hDevice); 231bf215546Sopenharmony_ci struct pipe_context *pipe = pDevice->pipe; 232bf215546Sopenharmony_ci 233bf215546Sopenharmony_ci assert(Offset + NumViews <= D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT); 234bf215546Sopenharmony_ci 235bf215546Sopenharmony_ci struct pipe_sampler_view **sampler_views = pDevice->sampler_views[shader_type]; 236bf215546Sopenharmony_ci for (UINT i = 0; i < NumViews; i++) { 237bf215546Sopenharmony_ci struct pipe_sampler_view *sampler_view = 238bf215546Sopenharmony_ci CastPipeShaderResourceView(phShaderResourceViews[i]); 239bf215546Sopenharmony_ci if (Offset + i < PIPE_MAX_SHADER_SAMPLER_VIEWS) { 240bf215546Sopenharmony_ci sampler_views[Offset + i] = sampler_view; 241bf215546Sopenharmony_ci } else { 242bf215546Sopenharmony_ci if (sampler_view) { 243bf215546Sopenharmony_ci LOG_UNSUPPORTED(TRUE); 244bf215546Sopenharmony_ci break; 245bf215546Sopenharmony_ci } 246bf215546Sopenharmony_ci } 247bf215546Sopenharmony_ci } 248bf215546Sopenharmony_ci 249bf215546Sopenharmony_ci /* 250bf215546Sopenharmony_ci * XXX: Now that the semantics are actually the same in gallium, should 251bf215546Sopenharmony_ci * probably think about not updating all always... It should just work. 252bf215546Sopenharmony_ci */ 253bf215546Sopenharmony_ci pipe->set_sampler_views(pipe, shader_type, 0, PIPE_MAX_SHADER_SAMPLER_VIEWS, 254bf215546Sopenharmony_ci 0, false, sampler_views); 255bf215546Sopenharmony_ci} 256bf215546Sopenharmony_ci 257bf215546Sopenharmony_ci 258bf215546Sopenharmony_ci/* 259bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 260bf215546Sopenharmony_ci * 261bf215546Sopenharmony_ci * CalcPrivateShaderSize -- 262bf215546Sopenharmony_ci * 263bf215546Sopenharmony_ci * The CalcPrivateShaderSize function determines the size of 264bf215546Sopenharmony_ci * the user-mode display driver's private region of memory 265bf215546Sopenharmony_ci * (that is, the size of internal driver structures, not the 266bf215546Sopenharmony_ci * size of the resource video memory) for a shader. 267bf215546Sopenharmony_ci * 268bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 269bf215546Sopenharmony_ci */ 270bf215546Sopenharmony_ci 271bf215546Sopenharmony_ciSIZE_T APIENTRY 272bf215546Sopenharmony_ciCalcPrivateShaderSize(D3D10DDI_HDEVICE hDevice, // IN 273bf215546Sopenharmony_ci __in_ecount (pShaderCode[1]) const UINT *pShaderCode, // IN 274bf215546Sopenharmony_ci __in const D3D10DDIARG_STAGE_IO_SIGNATURES *pSignatures) // IN 275bf215546Sopenharmony_ci{ 276bf215546Sopenharmony_ci return sizeof(Shader); 277bf215546Sopenharmony_ci} 278bf215546Sopenharmony_ci 279bf215546Sopenharmony_ci 280bf215546Sopenharmony_ci/* 281bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 282bf215546Sopenharmony_ci * 283bf215546Sopenharmony_ci * DestroyShader -- 284bf215546Sopenharmony_ci * 285bf215546Sopenharmony_ci * The DestroyShader function destroys the specified shader object. 286bf215546Sopenharmony_ci * The shader object can be destoyed only if it is not currently 287bf215546Sopenharmony_ci * bound to a display device. 288bf215546Sopenharmony_ci * 289bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 290bf215546Sopenharmony_ci */ 291bf215546Sopenharmony_ci 292bf215546Sopenharmony_civoid APIENTRY 293bf215546Sopenharmony_ciDestroyShader(D3D10DDI_HDEVICE hDevice, // IN 294bf215546Sopenharmony_ci D3D10DDI_HSHADER hShader) // IN 295bf215546Sopenharmony_ci{ 296bf215546Sopenharmony_ci LOG_ENTRYPOINT(); 297bf215546Sopenharmony_ci 298bf215546Sopenharmony_ci struct pipe_context *pipe = CastPipeContext(hDevice); 299bf215546Sopenharmony_ci Shader *pShader = CastShader(hShader); 300bf215546Sopenharmony_ci 301bf215546Sopenharmony_ci if (pShader->handle) { 302bf215546Sopenharmony_ci switch (pShader->type) { 303bf215546Sopenharmony_ci case PIPE_SHADER_FRAGMENT: 304bf215546Sopenharmony_ci pipe->delete_fs_state(pipe, pShader->handle); 305bf215546Sopenharmony_ci break; 306bf215546Sopenharmony_ci case PIPE_SHADER_VERTEX: 307bf215546Sopenharmony_ci pipe->delete_vs_state(pipe, pShader->handle); 308bf215546Sopenharmony_ci break; 309bf215546Sopenharmony_ci case PIPE_SHADER_GEOMETRY: 310bf215546Sopenharmony_ci pipe->delete_gs_state(pipe, pShader->handle); 311bf215546Sopenharmony_ci break; 312bf215546Sopenharmony_ci default: 313bf215546Sopenharmony_ci assert(0); 314bf215546Sopenharmony_ci } 315bf215546Sopenharmony_ci } 316bf215546Sopenharmony_ci 317bf215546Sopenharmony_ci if (pShader->state.tokens) { 318bf215546Sopenharmony_ci ureg_free_tokens(pShader->state.tokens); 319bf215546Sopenharmony_ci } 320bf215546Sopenharmony_ci} 321bf215546Sopenharmony_ci 322bf215546Sopenharmony_ci 323bf215546Sopenharmony_ci/* 324bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 325bf215546Sopenharmony_ci * 326bf215546Sopenharmony_ci * CalcPrivateSamplerSize -- 327bf215546Sopenharmony_ci * 328bf215546Sopenharmony_ci * The CalcPrivateSamplerSize function determines the size of the 329bf215546Sopenharmony_ci * user-mode display driver's private region of memory (that is, 330bf215546Sopenharmony_ci * the size of internal driver structures, not the size of the 331bf215546Sopenharmony_ci * resource video memory) for a sampler. 332bf215546Sopenharmony_ci * 333bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 334bf215546Sopenharmony_ci */ 335bf215546Sopenharmony_ci 336bf215546Sopenharmony_ciSIZE_T APIENTRY 337bf215546Sopenharmony_ciCalcPrivateSamplerSize(D3D10DDI_HDEVICE hDevice, // IN 338bf215546Sopenharmony_ci __in const D3D10_DDI_SAMPLER_DESC *pSamplerDesc) // IN 339bf215546Sopenharmony_ci{ 340bf215546Sopenharmony_ci return sizeof(SamplerState); 341bf215546Sopenharmony_ci} 342bf215546Sopenharmony_ci 343bf215546Sopenharmony_ci 344bf215546Sopenharmony_cistatic uint 345bf215546Sopenharmony_citranslate_address_mode(D3D10_DDI_TEXTURE_ADDRESS_MODE AddressMode) 346bf215546Sopenharmony_ci{ 347bf215546Sopenharmony_ci switch (AddressMode) { 348bf215546Sopenharmony_ci case D3D10_DDI_TEXTURE_ADDRESS_WRAP: 349bf215546Sopenharmony_ci return PIPE_TEX_WRAP_REPEAT; 350bf215546Sopenharmony_ci case D3D10_DDI_TEXTURE_ADDRESS_MIRROR: 351bf215546Sopenharmony_ci return PIPE_TEX_WRAP_MIRROR_REPEAT; 352bf215546Sopenharmony_ci case D3D10_DDI_TEXTURE_ADDRESS_CLAMP: 353bf215546Sopenharmony_ci return PIPE_TEX_WRAP_CLAMP_TO_EDGE; 354bf215546Sopenharmony_ci case D3D10_DDI_TEXTURE_ADDRESS_BORDER: 355bf215546Sopenharmony_ci return PIPE_TEX_WRAP_CLAMP_TO_BORDER; 356bf215546Sopenharmony_ci case D3D10_DDI_TEXTURE_ADDRESS_MIRRORONCE: 357bf215546Sopenharmony_ci return PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE; 358bf215546Sopenharmony_ci default: 359bf215546Sopenharmony_ci assert(0); 360bf215546Sopenharmony_ci return PIPE_TEX_WRAP_REPEAT; 361bf215546Sopenharmony_ci } 362bf215546Sopenharmony_ci} 363bf215546Sopenharmony_ci 364bf215546Sopenharmony_cistatic uint 365bf215546Sopenharmony_citranslate_comparison(D3D10_DDI_COMPARISON_FUNC Func) 366bf215546Sopenharmony_ci{ 367bf215546Sopenharmony_ci switch (Func) { 368bf215546Sopenharmony_ci case D3D10_DDI_COMPARISON_NEVER: 369bf215546Sopenharmony_ci return PIPE_FUNC_NEVER; 370bf215546Sopenharmony_ci case D3D10_DDI_COMPARISON_LESS: 371bf215546Sopenharmony_ci return PIPE_FUNC_LESS; 372bf215546Sopenharmony_ci case D3D10_DDI_COMPARISON_EQUAL: 373bf215546Sopenharmony_ci return PIPE_FUNC_EQUAL; 374bf215546Sopenharmony_ci case D3D10_DDI_COMPARISON_LESS_EQUAL: 375bf215546Sopenharmony_ci return PIPE_FUNC_LEQUAL; 376bf215546Sopenharmony_ci case D3D10_DDI_COMPARISON_GREATER: 377bf215546Sopenharmony_ci return PIPE_FUNC_GREATER; 378bf215546Sopenharmony_ci case D3D10_DDI_COMPARISON_NOT_EQUAL: 379bf215546Sopenharmony_ci return PIPE_FUNC_NOTEQUAL; 380bf215546Sopenharmony_ci case D3D10_DDI_COMPARISON_GREATER_EQUAL: 381bf215546Sopenharmony_ci return PIPE_FUNC_GEQUAL; 382bf215546Sopenharmony_ci case D3D10_DDI_COMPARISON_ALWAYS: 383bf215546Sopenharmony_ci return PIPE_FUNC_ALWAYS; 384bf215546Sopenharmony_ci default: 385bf215546Sopenharmony_ci assert(0); 386bf215546Sopenharmony_ci return PIPE_FUNC_ALWAYS; 387bf215546Sopenharmony_ci } 388bf215546Sopenharmony_ci} 389bf215546Sopenharmony_ci 390bf215546Sopenharmony_cistatic uint 391bf215546Sopenharmony_citranslate_filter(D3D10_DDI_FILTER_TYPE Filter) 392bf215546Sopenharmony_ci{ 393bf215546Sopenharmony_ci switch (Filter) { 394bf215546Sopenharmony_ci case D3D10_DDI_FILTER_TYPE_POINT: 395bf215546Sopenharmony_ci return PIPE_TEX_FILTER_NEAREST; 396bf215546Sopenharmony_ci case D3D10_DDI_FILTER_TYPE_LINEAR: 397bf215546Sopenharmony_ci return PIPE_TEX_FILTER_LINEAR; 398bf215546Sopenharmony_ci default: 399bf215546Sopenharmony_ci assert(0); 400bf215546Sopenharmony_ci return PIPE_TEX_FILTER_NEAREST; 401bf215546Sopenharmony_ci } 402bf215546Sopenharmony_ci} 403bf215546Sopenharmony_ci 404bf215546Sopenharmony_cistatic uint 405bf215546Sopenharmony_citranslate_min_filter(D3D10_DDI_FILTER Filter) 406bf215546Sopenharmony_ci{ 407bf215546Sopenharmony_ci return translate_filter(D3D10_DDI_DECODE_MIN_FILTER(Filter)); 408bf215546Sopenharmony_ci} 409bf215546Sopenharmony_ci 410bf215546Sopenharmony_cistatic uint 411bf215546Sopenharmony_citranslate_mag_filter(D3D10_DDI_FILTER Filter) 412bf215546Sopenharmony_ci{ 413bf215546Sopenharmony_ci return translate_filter(D3D10_DDI_DECODE_MAG_FILTER(Filter)); 414bf215546Sopenharmony_ci} 415bf215546Sopenharmony_ci 416bf215546Sopenharmony_ci/* Gallium uses a different enum for mipfilters, to accomodate the GL 417bf215546Sopenharmony_ci * MIPFILTER_NONE mode. 418bf215546Sopenharmony_ci */ 419bf215546Sopenharmony_cistatic uint 420bf215546Sopenharmony_citranslate_mip_filter(D3D10_DDI_FILTER Filter) 421bf215546Sopenharmony_ci{ 422bf215546Sopenharmony_ci switch (D3D10_DDI_DECODE_MIP_FILTER(Filter)) { 423bf215546Sopenharmony_ci case D3D10_DDI_FILTER_TYPE_POINT: 424bf215546Sopenharmony_ci return PIPE_TEX_MIPFILTER_NEAREST; 425bf215546Sopenharmony_ci case D3D10_DDI_FILTER_TYPE_LINEAR: 426bf215546Sopenharmony_ci return PIPE_TEX_MIPFILTER_LINEAR; 427bf215546Sopenharmony_ci default: 428bf215546Sopenharmony_ci assert(0); 429bf215546Sopenharmony_ci return PIPE_TEX_MIPFILTER_NEAREST; 430bf215546Sopenharmony_ci } 431bf215546Sopenharmony_ci} 432bf215546Sopenharmony_ci 433bf215546Sopenharmony_ci/* 434bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 435bf215546Sopenharmony_ci * 436bf215546Sopenharmony_ci * CreateSampler -- 437bf215546Sopenharmony_ci * 438bf215546Sopenharmony_ci * The CreateSampler function creates a sampler. 439bf215546Sopenharmony_ci * 440bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 441bf215546Sopenharmony_ci */ 442bf215546Sopenharmony_ci 443bf215546Sopenharmony_civoid APIENTRY 444bf215546Sopenharmony_ciCreateSampler(D3D10DDI_HDEVICE hDevice, // IN 445bf215546Sopenharmony_ci __in const D3D10_DDI_SAMPLER_DESC *pSamplerDesc, // IN 446bf215546Sopenharmony_ci D3D10DDI_HSAMPLER hSampler, // IN 447bf215546Sopenharmony_ci D3D10DDI_HRTSAMPLER hRTSampler) // IN 448bf215546Sopenharmony_ci{ 449bf215546Sopenharmony_ci LOG_ENTRYPOINT(); 450bf215546Sopenharmony_ci 451bf215546Sopenharmony_ci struct pipe_context *pipe = CastPipeContext(hDevice); 452bf215546Sopenharmony_ci SamplerState *pSamplerState = CastSamplerState(hSampler); 453bf215546Sopenharmony_ci 454bf215546Sopenharmony_ci struct pipe_sampler_state state; 455bf215546Sopenharmony_ci 456bf215546Sopenharmony_ci memset(&state, 0, sizeof state); 457bf215546Sopenharmony_ci 458bf215546Sopenharmony_ci /* d3d10 has seamless cube filtering always enabled */ 459bf215546Sopenharmony_ci state.seamless_cube_map = 1; 460bf215546Sopenharmony_ci 461bf215546Sopenharmony_ci /* Wrapping modes. */ 462bf215546Sopenharmony_ci state.wrap_s = translate_address_mode(pSamplerDesc->AddressU); 463bf215546Sopenharmony_ci state.wrap_t = translate_address_mode(pSamplerDesc->AddressV); 464bf215546Sopenharmony_ci state.wrap_r = translate_address_mode(pSamplerDesc->AddressW); 465bf215546Sopenharmony_ci 466bf215546Sopenharmony_ci /* Filtering */ 467bf215546Sopenharmony_ci state.min_img_filter = translate_min_filter(pSamplerDesc->Filter); 468bf215546Sopenharmony_ci state.mag_img_filter = translate_mag_filter(pSamplerDesc->Filter); 469bf215546Sopenharmony_ci state.min_mip_filter = translate_mip_filter(pSamplerDesc->Filter); 470bf215546Sopenharmony_ci 471bf215546Sopenharmony_ci if (D3D10_DDI_DECODE_IS_ANISOTROPIC_FILTER(pSamplerDesc->Filter)) { 472bf215546Sopenharmony_ci state.max_anisotropy = pSamplerDesc->MaxAnisotropy; 473bf215546Sopenharmony_ci } 474bf215546Sopenharmony_ci 475bf215546Sopenharmony_ci /* XXX: Handle the following bit. 476bf215546Sopenharmony_ci */ 477bf215546Sopenharmony_ci LOG_UNSUPPORTED(D3D10_DDI_DECODE_IS_TEXT_1BIT_FILTER(pSamplerDesc->Filter)); 478bf215546Sopenharmony_ci 479bf215546Sopenharmony_ci /* Comparison. */ 480bf215546Sopenharmony_ci if (D3D10_DDI_DECODE_IS_COMPARISON_FILTER(pSamplerDesc->Filter)) { 481bf215546Sopenharmony_ci state.compare_mode = PIPE_TEX_COMPARE_R_TO_TEXTURE; 482bf215546Sopenharmony_ci state.compare_func = translate_comparison(pSamplerDesc->ComparisonFunc); 483bf215546Sopenharmony_ci } 484bf215546Sopenharmony_ci 485bf215546Sopenharmony_ci state.normalized_coords = 1; 486bf215546Sopenharmony_ci 487bf215546Sopenharmony_ci /* Level of detail. */ 488bf215546Sopenharmony_ci state.lod_bias = pSamplerDesc->MipLODBias; 489bf215546Sopenharmony_ci state.min_lod = pSamplerDesc->MinLOD; 490bf215546Sopenharmony_ci state.max_lod = pSamplerDesc->MaxLOD; 491bf215546Sopenharmony_ci 492bf215546Sopenharmony_ci /* Border color. */ 493bf215546Sopenharmony_ci state.border_color.f[0] = pSamplerDesc->BorderColor[0]; 494bf215546Sopenharmony_ci state.border_color.f[1] = pSamplerDesc->BorderColor[1]; 495bf215546Sopenharmony_ci state.border_color.f[2] = pSamplerDesc->BorderColor[2]; 496bf215546Sopenharmony_ci state.border_color.f[3] = pSamplerDesc->BorderColor[3]; 497bf215546Sopenharmony_ci 498bf215546Sopenharmony_ci pSamplerState->handle = pipe->create_sampler_state(pipe, &state); 499bf215546Sopenharmony_ci} 500bf215546Sopenharmony_ci 501bf215546Sopenharmony_ci 502bf215546Sopenharmony_ci/* 503bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 504bf215546Sopenharmony_ci * 505bf215546Sopenharmony_ci * DestroySampler -- 506bf215546Sopenharmony_ci * 507bf215546Sopenharmony_ci * The DestroySampler function destroys the specified sampler object. 508bf215546Sopenharmony_ci * The sampler object can be destoyed only if it is not currently 509bf215546Sopenharmony_ci * bound to a display device. 510bf215546Sopenharmony_ci * 511bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 512bf215546Sopenharmony_ci */ 513bf215546Sopenharmony_ci 514bf215546Sopenharmony_civoid APIENTRY 515bf215546Sopenharmony_ciDestroySampler(D3D10DDI_HDEVICE hDevice, // IN 516bf215546Sopenharmony_ci D3D10DDI_HSAMPLER hSampler) // IN 517bf215546Sopenharmony_ci{ 518bf215546Sopenharmony_ci LOG_ENTRYPOINT(); 519bf215546Sopenharmony_ci 520bf215546Sopenharmony_ci struct pipe_context *pipe = CastPipeContext(hDevice); 521bf215546Sopenharmony_ci SamplerState *pSamplerState = CastSamplerState(hSampler); 522bf215546Sopenharmony_ci 523bf215546Sopenharmony_ci pipe->delete_sampler_state(pipe, pSamplerState->handle); 524bf215546Sopenharmony_ci} 525bf215546Sopenharmony_ci 526bf215546Sopenharmony_ci 527bf215546Sopenharmony_ci/* 528bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 529bf215546Sopenharmony_ci * 530bf215546Sopenharmony_ci * CreateVertexShader -- 531bf215546Sopenharmony_ci * 532bf215546Sopenharmony_ci * The CreateVertexShader function creates a vertex shader. 533bf215546Sopenharmony_ci * 534bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 535bf215546Sopenharmony_ci */ 536bf215546Sopenharmony_ci 537bf215546Sopenharmony_civoid APIENTRY 538bf215546Sopenharmony_ciCreateVertexShader(D3D10DDI_HDEVICE hDevice, // IN 539bf215546Sopenharmony_ci __in_ecount (pShaderCode[1]) const UINT *pCode, // IN 540bf215546Sopenharmony_ci D3D10DDI_HSHADER hShader, // IN 541bf215546Sopenharmony_ci D3D10DDI_HRTSHADER hRTShader, // IN 542bf215546Sopenharmony_ci __in const D3D10DDIARG_STAGE_IO_SIGNATURES *pSignatures) // IN 543bf215546Sopenharmony_ci{ 544bf215546Sopenharmony_ci LOG_ENTRYPOINT(); 545bf215546Sopenharmony_ci 546bf215546Sopenharmony_ci struct pipe_context *pipe = CastPipeContext(hDevice); 547bf215546Sopenharmony_ci Shader *pShader = CastShader(hShader); 548bf215546Sopenharmony_ci 549bf215546Sopenharmony_ci pShader->type = PIPE_SHADER_VERTEX; 550bf215546Sopenharmony_ci pShader->output_resolved = TRUE; 551bf215546Sopenharmony_ci 552bf215546Sopenharmony_ci memset(&pShader->state, 0, sizeof pShader->state); 553bf215546Sopenharmony_ci pShader->state.tokens = Shader_tgsi_translate(pCode, pShader->output_mapping); 554bf215546Sopenharmony_ci 555bf215546Sopenharmony_ci pShader->handle = pipe->create_vs_state(pipe, &pShader->state); 556bf215546Sopenharmony_ci 557bf215546Sopenharmony_ci} 558bf215546Sopenharmony_ci 559bf215546Sopenharmony_ci 560bf215546Sopenharmony_ci/* 561bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 562bf215546Sopenharmony_ci * 563bf215546Sopenharmony_ci * VsSetShader -- 564bf215546Sopenharmony_ci * 565bf215546Sopenharmony_ci * The VsSetShader function sets the vertex shader code so that all 566bf215546Sopenharmony_ci * of the subsequent drawing operations use that code. 567bf215546Sopenharmony_ci * 568bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 569bf215546Sopenharmony_ci */ 570bf215546Sopenharmony_ci 571bf215546Sopenharmony_civoid APIENTRY 572bf215546Sopenharmony_ciVsSetShader(D3D10DDI_HDEVICE hDevice, // IN 573bf215546Sopenharmony_ci D3D10DDI_HSHADER hShader) // IN 574bf215546Sopenharmony_ci{ 575bf215546Sopenharmony_ci LOG_ENTRYPOINT(); 576bf215546Sopenharmony_ci 577bf215546Sopenharmony_ci Device *pDevice = CastDevice(hDevice); 578bf215546Sopenharmony_ci struct pipe_context *pipe = pDevice->pipe; 579bf215546Sopenharmony_ci Shader *pShader = CastShader(hShader); 580bf215546Sopenharmony_ci void *state = CastPipeShader(hShader); 581bf215546Sopenharmony_ci 582bf215546Sopenharmony_ci pDevice->bound_vs = pShader; 583bf215546Sopenharmony_ci if (!state) { 584bf215546Sopenharmony_ci state = pDevice->empty_vs; 585bf215546Sopenharmony_ci } 586bf215546Sopenharmony_ci 587bf215546Sopenharmony_ci pipe->bind_vs_state(pipe, state); 588bf215546Sopenharmony_ci} 589bf215546Sopenharmony_ci 590bf215546Sopenharmony_ci 591bf215546Sopenharmony_ci/* 592bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 593bf215546Sopenharmony_ci * 594bf215546Sopenharmony_ci * VsSetShaderResources -- 595bf215546Sopenharmony_ci * 596bf215546Sopenharmony_ci * The VsSetShaderResources function sets resources for a 597bf215546Sopenharmony_ci * vertex shader. 598bf215546Sopenharmony_ci * 599bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 600bf215546Sopenharmony_ci */ 601bf215546Sopenharmony_ci 602bf215546Sopenharmony_civoid APIENTRY 603bf215546Sopenharmony_ciVsSetShaderResources(D3D10DDI_HDEVICE hDevice, // IN 604bf215546Sopenharmony_ci UINT Offset, // IN 605bf215546Sopenharmony_ci UINT NumViews, // IN 606bf215546Sopenharmony_ci __in_ecount (NumViews) 607bf215546Sopenharmony_ci const D3D10DDI_HSHADERRESOURCEVIEW *phShaderResourceViews) // IN 608bf215546Sopenharmony_ci{ 609bf215546Sopenharmony_ci LOG_ENTRYPOINT(); 610bf215546Sopenharmony_ci 611bf215546Sopenharmony_ci SetShaderResources(PIPE_SHADER_VERTEX, hDevice, Offset, NumViews, phShaderResourceViews); 612bf215546Sopenharmony_ci 613bf215546Sopenharmony_ci} 614bf215546Sopenharmony_ci 615bf215546Sopenharmony_ci 616bf215546Sopenharmony_ci/* 617bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 618bf215546Sopenharmony_ci * 619bf215546Sopenharmony_ci * VsSetConstantBuffers -- 620bf215546Sopenharmony_ci * 621bf215546Sopenharmony_ci * The VsSetConstantBuffers function sets constant buffers 622bf215546Sopenharmony_ci * for a vertex shader. 623bf215546Sopenharmony_ci * 624bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 625bf215546Sopenharmony_ci */ 626bf215546Sopenharmony_ci 627bf215546Sopenharmony_civoid APIENTRY 628bf215546Sopenharmony_ciVsSetConstantBuffers(D3D10DDI_HDEVICE hDevice, // IN 629bf215546Sopenharmony_ci UINT StartBuffer, // IN 630bf215546Sopenharmony_ci UINT NumBuffers, // IN 631bf215546Sopenharmony_ci __in_ecount (NumBuffers) const D3D10DDI_HRESOURCE *phBuffers) // IN 632bf215546Sopenharmony_ci{ 633bf215546Sopenharmony_ci LOG_ENTRYPOINT(); 634bf215546Sopenharmony_ci 635bf215546Sopenharmony_ci SetConstantBuffers(PIPE_SHADER_VERTEX, 636bf215546Sopenharmony_ci hDevice, StartBuffer, NumBuffers, phBuffers); 637bf215546Sopenharmony_ci} 638bf215546Sopenharmony_ci 639bf215546Sopenharmony_ci 640bf215546Sopenharmony_ci/* 641bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 642bf215546Sopenharmony_ci * 643bf215546Sopenharmony_ci * VsSetSamplers -- 644bf215546Sopenharmony_ci * 645bf215546Sopenharmony_ci * The VsSetSamplers function sets samplers for a vertex shader. 646bf215546Sopenharmony_ci * 647bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 648bf215546Sopenharmony_ci */ 649bf215546Sopenharmony_ci 650bf215546Sopenharmony_civoid APIENTRY 651bf215546Sopenharmony_ciVsSetSamplers(D3D10DDI_HDEVICE hDevice, // IN 652bf215546Sopenharmony_ci UINT Offset, // IN 653bf215546Sopenharmony_ci UINT NumSamplers, // IN 654bf215546Sopenharmony_ci __in_ecount (NumSamplers) const D3D10DDI_HSAMPLER *phSamplers) // IN 655bf215546Sopenharmony_ci{ 656bf215546Sopenharmony_ci LOG_ENTRYPOINT(); 657bf215546Sopenharmony_ci 658bf215546Sopenharmony_ci SetSamplers(PIPE_SHADER_VERTEX, hDevice, Offset, NumSamplers, phSamplers); 659bf215546Sopenharmony_ci 660bf215546Sopenharmony_ci} 661bf215546Sopenharmony_ci 662bf215546Sopenharmony_ci 663bf215546Sopenharmony_ci/* 664bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 665bf215546Sopenharmony_ci * 666bf215546Sopenharmony_ci * CreateGeometryShader -- 667bf215546Sopenharmony_ci * 668bf215546Sopenharmony_ci * The CreateGeometryShader function creates a geometry shader. 669bf215546Sopenharmony_ci * 670bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 671bf215546Sopenharmony_ci */ 672bf215546Sopenharmony_ci 673bf215546Sopenharmony_civoid APIENTRY 674bf215546Sopenharmony_ciCreateGeometryShader(D3D10DDI_HDEVICE hDevice, // IN 675bf215546Sopenharmony_ci __in_ecount (pShaderCode[1]) const UINT *pShaderCode, // IN 676bf215546Sopenharmony_ci D3D10DDI_HSHADER hShader, // IN 677bf215546Sopenharmony_ci D3D10DDI_HRTSHADER hRTShader, // IN 678bf215546Sopenharmony_ci __in const D3D10DDIARG_STAGE_IO_SIGNATURES *pSignatures) // IN 679bf215546Sopenharmony_ci{ 680bf215546Sopenharmony_ci LOG_ENTRYPOINT(); 681bf215546Sopenharmony_ci 682bf215546Sopenharmony_ci struct pipe_context *pipe = CastPipeContext(hDevice); 683bf215546Sopenharmony_ci Shader *pShader = CastShader(hShader); 684bf215546Sopenharmony_ci 685bf215546Sopenharmony_ci pShader->type = PIPE_SHADER_GEOMETRY; 686bf215546Sopenharmony_ci pShader->output_resolved = TRUE; 687bf215546Sopenharmony_ci 688bf215546Sopenharmony_ci memset(&pShader->state, 0, sizeof pShader->state); 689bf215546Sopenharmony_ci pShader->state.tokens = Shader_tgsi_translate(pShaderCode, pShader->output_mapping); 690bf215546Sopenharmony_ci 691bf215546Sopenharmony_ci pShader->handle = pipe->create_gs_state(pipe, &pShader->state); 692bf215546Sopenharmony_ci} 693bf215546Sopenharmony_ci 694bf215546Sopenharmony_ci 695bf215546Sopenharmony_ci/* 696bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 697bf215546Sopenharmony_ci * 698bf215546Sopenharmony_ci * GsSetShader -- 699bf215546Sopenharmony_ci * 700bf215546Sopenharmony_ci * The GsSetShader function sets the geometry shader code so that 701bf215546Sopenharmony_ci * all of the subsequent drawing operations use that code. 702bf215546Sopenharmony_ci * 703bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 704bf215546Sopenharmony_ci */ 705bf215546Sopenharmony_ci 706bf215546Sopenharmony_civoid APIENTRY 707bf215546Sopenharmony_ciGsSetShader(D3D10DDI_HDEVICE hDevice, // IN 708bf215546Sopenharmony_ci D3D10DDI_HSHADER hShader) // IN 709bf215546Sopenharmony_ci{ 710bf215546Sopenharmony_ci LOG_ENTRYPOINT(); 711bf215546Sopenharmony_ci 712bf215546Sopenharmony_ci Device *pDevice = CastDevice(hDevice); 713bf215546Sopenharmony_ci struct pipe_context *pipe = CastPipeContext(hDevice); 714bf215546Sopenharmony_ci void *state = CastPipeShader(hShader); 715bf215546Sopenharmony_ci Shader *pShader = CastShader(hShader); 716bf215546Sopenharmony_ci 717bf215546Sopenharmony_ci assert(pipe->bind_gs_state); 718bf215546Sopenharmony_ci 719bf215546Sopenharmony_ci if (pShader && !pShader->state.tokens) { 720bf215546Sopenharmony_ci pDevice->bound_empty_gs = pShader; 721bf215546Sopenharmony_ci } else { 722bf215546Sopenharmony_ci pDevice->bound_empty_gs = NULL; 723bf215546Sopenharmony_ci pipe->bind_gs_state(pipe, state); 724bf215546Sopenharmony_ci } 725bf215546Sopenharmony_ci} 726bf215546Sopenharmony_ci 727bf215546Sopenharmony_ci 728bf215546Sopenharmony_ci/* 729bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 730bf215546Sopenharmony_ci * 731bf215546Sopenharmony_ci * GsSetShaderResources -- 732bf215546Sopenharmony_ci * 733bf215546Sopenharmony_ci * The GsSetShaderResources function sets resources for a 734bf215546Sopenharmony_ci * geometry shader. 735bf215546Sopenharmony_ci * 736bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 737bf215546Sopenharmony_ci */ 738bf215546Sopenharmony_ci 739bf215546Sopenharmony_civoid APIENTRY 740bf215546Sopenharmony_ciGsSetShaderResources(D3D10DDI_HDEVICE hDevice, // IN 741bf215546Sopenharmony_ci UINT Offset, // IN 742bf215546Sopenharmony_ci UINT NumViews, // IN 743bf215546Sopenharmony_ci __in_ecount (NumViews) 744bf215546Sopenharmony_ci const D3D10DDI_HSHADERRESOURCEVIEW *phShaderResourceViews) // IN 745bf215546Sopenharmony_ci{ 746bf215546Sopenharmony_ci LOG_ENTRYPOINT(); 747bf215546Sopenharmony_ci 748bf215546Sopenharmony_ci SetShaderResources(PIPE_SHADER_GEOMETRY, hDevice, Offset, NumViews, phShaderResourceViews); 749bf215546Sopenharmony_ci} 750bf215546Sopenharmony_ci 751bf215546Sopenharmony_ci 752bf215546Sopenharmony_ci/* 753bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 754bf215546Sopenharmony_ci * 755bf215546Sopenharmony_ci * GsSetConstantBuffers -- 756bf215546Sopenharmony_ci * 757bf215546Sopenharmony_ci * The GsSetConstantBuffers function sets constant buffers for 758bf215546Sopenharmony_ci * a geometry shader. 759bf215546Sopenharmony_ci * 760bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 761bf215546Sopenharmony_ci */ 762bf215546Sopenharmony_ci 763bf215546Sopenharmony_civoid APIENTRY 764bf215546Sopenharmony_ciGsSetConstantBuffers(D3D10DDI_HDEVICE hDevice, // IN 765bf215546Sopenharmony_ci UINT StartBuffer, // IN 766bf215546Sopenharmony_ci UINT NumBuffers, // IN 767bf215546Sopenharmony_ci __in_ecount (NumBuffers) const D3D10DDI_HRESOURCE *phBuffers) // IN 768bf215546Sopenharmony_ci{ 769bf215546Sopenharmony_ci LOG_ENTRYPOINT(); 770bf215546Sopenharmony_ci 771bf215546Sopenharmony_ci SetConstantBuffers(PIPE_SHADER_GEOMETRY, 772bf215546Sopenharmony_ci hDevice, StartBuffer, NumBuffers, phBuffers); 773bf215546Sopenharmony_ci} 774bf215546Sopenharmony_ci 775bf215546Sopenharmony_ci 776bf215546Sopenharmony_ci/* 777bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 778bf215546Sopenharmony_ci * 779bf215546Sopenharmony_ci * GsSetSamplers -- 780bf215546Sopenharmony_ci * 781bf215546Sopenharmony_ci * The GsSetSamplers function sets samplers for a geometry shader. 782bf215546Sopenharmony_ci * 783bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 784bf215546Sopenharmony_ci */ 785bf215546Sopenharmony_ci 786bf215546Sopenharmony_civoid APIENTRY 787bf215546Sopenharmony_ciGsSetSamplers(D3D10DDI_HDEVICE hDevice, // IN 788bf215546Sopenharmony_ci UINT Offset, // IN 789bf215546Sopenharmony_ci UINT NumSamplers, // IN 790bf215546Sopenharmony_ci __in_ecount (NumSamplers) const D3D10DDI_HSAMPLER *phSamplers) // IN 791bf215546Sopenharmony_ci{ 792bf215546Sopenharmony_ci LOG_ENTRYPOINT(); 793bf215546Sopenharmony_ci 794bf215546Sopenharmony_ci SetSamplers(PIPE_SHADER_GEOMETRY, hDevice, Offset, NumSamplers, phSamplers); 795bf215546Sopenharmony_ci} 796bf215546Sopenharmony_ci 797bf215546Sopenharmony_ci 798bf215546Sopenharmony_ci/* 799bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 800bf215546Sopenharmony_ci * 801bf215546Sopenharmony_ci * CalcPrivateGeometryShaderWithStreamOutput -- 802bf215546Sopenharmony_ci * 803bf215546Sopenharmony_ci * The CalcPrivateGeometryShaderWithStreamOutput function determines 804bf215546Sopenharmony_ci * the size of the user-mode display driver's private region of memory 805bf215546Sopenharmony_ci * (that is, the size of internal driver structures, not the size of 806bf215546Sopenharmony_ci * the resource video memory) for a geometry shader with stream output. 807bf215546Sopenharmony_ci * 808bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 809bf215546Sopenharmony_ci */ 810bf215546Sopenharmony_ci 811bf215546Sopenharmony_ciSIZE_T APIENTRY 812bf215546Sopenharmony_ciCalcPrivateGeometryShaderWithStreamOutput( 813bf215546Sopenharmony_ci D3D10DDI_HDEVICE hDevice, // IN 814bf215546Sopenharmony_ci __in const D3D10DDIARG_CREATEGEOMETRYSHADERWITHSTREAMOUTPUT *pCreateGeometryShaderWithStreamOutput, // IN 815bf215546Sopenharmony_ci __in const D3D10DDIARG_STAGE_IO_SIGNATURES *pSignatures) // IN 816bf215546Sopenharmony_ci{ 817bf215546Sopenharmony_ci LOG_ENTRYPOINT(); 818bf215546Sopenharmony_ci return sizeof(Shader); 819bf215546Sopenharmony_ci} 820bf215546Sopenharmony_ci 821bf215546Sopenharmony_ci 822bf215546Sopenharmony_ci/* 823bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 824bf215546Sopenharmony_ci * 825bf215546Sopenharmony_ci * CreateGeometryShaderWithStreamOutput -- 826bf215546Sopenharmony_ci * 827bf215546Sopenharmony_ci * The CreateGeometryShaderWithStreamOutput function creates a 828bf215546Sopenharmony_ci * geometry shader with stream output. 829bf215546Sopenharmony_ci * 830bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 831bf215546Sopenharmony_ci */ 832bf215546Sopenharmony_ci 833bf215546Sopenharmony_civoid APIENTRY 834bf215546Sopenharmony_ciCreateGeometryShaderWithStreamOutput( 835bf215546Sopenharmony_ci D3D10DDI_HDEVICE hDevice, // IN 836bf215546Sopenharmony_ci __in const D3D10DDIARG_CREATEGEOMETRYSHADERWITHSTREAMOUTPUT *pData, // IN 837bf215546Sopenharmony_ci D3D10DDI_HSHADER hShader, // IN 838bf215546Sopenharmony_ci D3D10DDI_HRTSHADER hRTShader, // IN 839bf215546Sopenharmony_ci __in const D3D10DDIARG_STAGE_IO_SIGNATURES *pSignatures) // IN 840bf215546Sopenharmony_ci{ 841bf215546Sopenharmony_ci LOG_ENTRYPOINT(); 842bf215546Sopenharmony_ci 843bf215546Sopenharmony_ci struct pipe_context *pipe = CastPipeContext(hDevice); 844bf215546Sopenharmony_ci Shader *pShader = CastShader(hShader); 845bf215546Sopenharmony_ci int total_components[PIPE_MAX_SO_BUFFERS] = {0}; 846bf215546Sopenharmony_ci unsigned num_holes = 0; 847bf215546Sopenharmony_ci boolean all_slot_zero = TRUE; 848bf215546Sopenharmony_ci 849bf215546Sopenharmony_ci pShader->type = PIPE_SHADER_GEOMETRY; 850bf215546Sopenharmony_ci 851bf215546Sopenharmony_ci memset(&pShader->state, 0, sizeof pShader->state); 852bf215546Sopenharmony_ci if (pData->pShaderCode) { 853bf215546Sopenharmony_ci pShader->state.tokens = Shader_tgsi_translate(pData->pShaderCode, 854bf215546Sopenharmony_ci pShader->output_mapping); 855bf215546Sopenharmony_ci } 856bf215546Sopenharmony_ci pShader->output_resolved = (pShader->state.tokens != NULL); 857bf215546Sopenharmony_ci 858bf215546Sopenharmony_ci for (unsigned i = 0; i < pData->NumEntries; ++i) { 859bf215546Sopenharmony_ci CONST D3D10DDIARG_STREAM_OUTPUT_DECLARATION_ENTRY* pOutputStreamDecl = 860bf215546Sopenharmony_ci &pData->pOutputStreamDecl[i]; 861bf215546Sopenharmony_ci BYTE RegisterMask = pOutputStreamDecl->RegisterMask; 862bf215546Sopenharmony_ci unsigned start_component = 0; 863bf215546Sopenharmony_ci unsigned num_components = 0; 864bf215546Sopenharmony_ci if (RegisterMask) { 865bf215546Sopenharmony_ci while ((RegisterMask & 1) == 0) { 866bf215546Sopenharmony_ci ++start_component; 867bf215546Sopenharmony_ci RegisterMask >>= 1; 868bf215546Sopenharmony_ci } 869bf215546Sopenharmony_ci while (RegisterMask) { 870bf215546Sopenharmony_ci ++num_components; 871bf215546Sopenharmony_ci RegisterMask >>= 1; 872bf215546Sopenharmony_ci } 873bf215546Sopenharmony_ci assert(start_component < 4); 874bf215546Sopenharmony_ci assert(1 <= num_components && num_components <= 4); 875bf215546Sopenharmony_ci LOG_UNSUPPORTED(((1 << num_components) - 1) << start_component != 876bf215546Sopenharmony_ci pOutputStreamDecl->RegisterMask); 877bf215546Sopenharmony_ci } 878bf215546Sopenharmony_ci 879bf215546Sopenharmony_ci if (pOutputStreamDecl->RegisterIndex == 0xffffffff) { 880bf215546Sopenharmony_ci ++num_holes; 881bf215546Sopenharmony_ci } else { 882bf215546Sopenharmony_ci unsigned idx = i - num_holes; 883bf215546Sopenharmony_ci pShader->state.stream_output.output[idx].start_component = 884bf215546Sopenharmony_ci start_component; 885bf215546Sopenharmony_ci pShader->state.stream_output.output[idx].num_components = 886bf215546Sopenharmony_ci num_components; 887bf215546Sopenharmony_ci pShader->state.stream_output.output[idx].output_buffer = 888bf215546Sopenharmony_ci pOutputStreamDecl->OutputSlot; 889bf215546Sopenharmony_ci pShader->state.stream_output.output[idx].register_index = 890bf215546Sopenharmony_ci ShaderFindOutputMapping(pShader, pOutputStreamDecl->RegisterIndex); 891bf215546Sopenharmony_ci pShader->state.stream_output.output[idx].dst_offset = 892bf215546Sopenharmony_ci total_components[pOutputStreamDecl->OutputSlot]; 893bf215546Sopenharmony_ci if (pOutputStreamDecl->OutputSlot != 0) 894bf215546Sopenharmony_ci all_slot_zero = FALSE; 895bf215546Sopenharmony_ci } 896bf215546Sopenharmony_ci total_components[pOutputStreamDecl->OutputSlot] += num_components; 897bf215546Sopenharmony_ci } 898bf215546Sopenharmony_ci pShader->state.stream_output.num_outputs = pData->NumEntries - num_holes; 899bf215546Sopenharmony_ci for (unsigned i = 0; i < PIPE_MAX_SO_BUFFERS; ++i) { 900bf215546Sopenharmony_ci /* stream_output.stride[i] is in dwords */ 901bf215546Sopenharmony_ci if (all_slot_zero) { 902bf215546Sopenharmony_ci pShader->state.stream_output.stride[i] = 903bf215546Sopenharmony_ci pData->StreamOutputStrideInBytes / sizeof(float); 904bf215546Sopenharmony_ci } else { 905bf215546Sopenharmony_ci pShader->state.stream_output.stride[i] = total_components[i]; 906bf215546Sopenharmony_ci } 907bf215546Sopenharmony_ci } 908bf215546Sopenharmony_ci 909bf215546Sopenharmony_ci pShader->handle = pipe->create_gs_state(pipe, &pShader->state); 910bf215546Sopenharmony_ci} 911bf215546Sopenharmony_ci 912bf215546Sopenharmony_ci 913bf215546Sopenharmony_ci/* 914bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 915bf215546Sopenharmony_ci * 916bf215546Sopenharmony_ci * SoSetTargets -- 917bf215546Sopenharmony_ci * 918bf215546Sopenharmony_ci * The SoSetTargets function sets stream output target resources. 919bf215546Sopenharmony_ci * 920bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 921bf215546Sopenharmony_ci */ 922bf215546Sopenharmony_ci 923bf215546Sopenharmony_civoid APIENTRY 924bf215546Sopenharmony_ciSoSetTargets(D3D10DDI_HDEVICE hDevice, // IN 925bf215546Sopenharmony_ci UINT SOTargets, // IN 926bf215546Sopenharmony_ci UINT ClearTargets, // IN 927bf215546Sopenharmony_ci __in_ecount (SOTargets) const D3D10DDI_HRESOURCE *phResource, // IN 928bf215546Sopenharmony_ci __in_ecount (SOTargets) const UINT *pOffsets) // IN 929bf215546Sopenharmony_ci{ 930bf215546Sopenharmony_ci unsigned i; 931bf215546Sopenharmony_ci 932bf215546Sopenharmony_ci LOG_ENTRYPOINT(); 933bf215546Sopenharmony_ci 934bf215546Sopenharmony_ci Device *pDevice = CastDevice(hDevice); 935bf215546Sopenharmony_ci struct pipe_context *pipe = pDevice->pipe; 936bf215546Sopenharmony_ci 937bf215546Sopenharmony_ci assert(SOTargets + ClearTargets <= PIPE_MAX_SO_BUFFERS); 938bf215546Sopenharmony_ci 939bf215546Sopenharmony_ci for (i = 0; i < SOTargets; ++i) { 940bf215546Sopenharmony_ci Resource *resource = CastResource(phResource[i]); 941bf215546Sopenharmony_ci struct pipe_resource *buffer = CastPipeResource(phResource[i]); 942bf215546Sopenharmony_ci struct pipe_stream_output_target *so_target = 943bf215546Sopenharmony_ci resource ? resource->so_target : NULL; 944bf215546Sopenharmony_ci 945bf215546Sopenharmony_ci if (buffer) { 946bf215546Sopenharmony_ci unsigned buffer_size = buffer->width0; 947bf215546Sopenharmony_ci 948bf215546Sopenharmony_ci if (!so_target || 949bf215546Sopenharmony_ci so_target->buffer != buffer || 950bf215546Sopenharmony_ci so_target->buffer_size != buffer_size) { 951bf215546Sopenharmony_ci if (so_target) { 952bf215546Sopenharmony_ci pipe_so_target_reference(&so_target, NULL); 953bf215546Sopenharmony_ci } 954bf215546Sopenharmony_ci so_target = pipe->create_stream_output_target(pipe, buffer, 955bf215546Sopenharmony_ci 0,/*buffer offset*/ 956bf215546Sopenharmony_ci buffer_size); 957bf215546Sopenharmony_ci resource->so_target = so_target; 958bf215546Sopenharmony_ci } 959bf215546Sopenharmony_ci } 960bf215546Sopenharmony_ci pDevice->so_targets[i] = so_target; 961bf215546Sopenharmony_ci } 962bf215546Sopenharmony_ci 963bf215546Sopenharmony_ci for (i = 0; i < ClearTargets; ++i) { 964bf215546Sopenharmony_ci pDevice->so_targets[SOTargets + i] = NULL; 965bf215546Sopenharmony_ci } 966bf215546Sopenharmony_ci 967bf215546Sopenharmony_ci if (!pipe->set_stream_output_targets) { 968bf215546Sopenharmony_ci LOG_UNSUPPORTED(pipe->set_stream_output_targets); 969bf215546Sopenharmony_ci return; 970bf215546Sopenharmony_ci } 971bf215546Sopenharmony_ci 972bf215546Sopenharmony_ci pipe->set_stream_output_targets(pipe, SOTargets, pDevice->so_targets, 973bf215546Sopenharmony_ci pOffsets); 974bf215546Sopenharmony_ci} 975bf215546Sopenharmony_ci 976bf215546Sopenharmony_ci 977bf215546Sopenharmony_ci/* 978bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 979bf215546Sopenharmony_ci * 980bf215546Sopenharmony_ci * CreatePixelShader -- 981bf215546Sopenharmony_ci * 982bf215546Sopenharmony_ci * The CreatePixelShader function converts pixel shader code into a 983bf215546Sopenharmony_ci * hardware-specific format and associates this code with a 984bf215546Sopenharmony_ci * shader handle. 985bf215546Sopenharmony_ci * 986bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 987bf215546Sopenharmony_ci */ 988bf215546Sopenharmony_ci 989bf215546Sopenharmony_civoid APIENTRY 990bf215546Sopenharmony_ciCreatePixelShader(D3D10DDI_HDEVICE hDevice, // IN 991bf215546Sopenharmony_ci __in_ecount (pShaderCode[1]) const UINT *pShaderCode, // IN 992bf215546Sopenharmony_ci D3D10DDI_HSHADER hShader, // IN 993bf215546Sopenharmony_ci D3D10DDI_HRTSHADER hRTShader, // IN 994bf215546Sopenharmony_ci __in const D3D10DDIARG_STAGE_IO_SIGNATURES *pSignatures) // IN 995bf215546Sopenharmony_ci{ 996bf215546Sopenharmony_ci LOG_ENTRYPOINT(); 997bf215546Sopenharmony_ci 998bf215546Sopenharmony_ci struct pipe_context *pipe = CastPipeContext(hDevice); 999bf215546Sopenharmony_ci Shader *pShader = CastShader(hShader); 1000bf215546Sopenharmony_ci 1001bf215546Sopenharmony_ci pShader->type = PIPE_SHADER_FRAGMENT; 1002bf215546Sopenharmony_ci pShader->output_resolved = TRUE; 1003bf215546Sopenharmony_ci 1004bf215546Sopenharmony_ci memset(&pShader->state, 0, sizeof pShader->state); 1005bf215546Sopenharmony_ci pShader->state.tokens = Shader_tgsi_translate(pShaderCode, 1006bf215546Sopenharmony_ci pShader->output_mapping); 1007bf215546Sopenharmony_ci 1008bf215546Sopenharmony_ci pShader->handle = pipe->create_fs_state(pipe, &pShader->state); 1009bf215546Sopenharmony_ci 1010bf215546Sopenharmony_ci} 1011bf215546Sopenharmony_ci 1012bf215546Sopenharmony_ci 1013bf215546Sopenharmony_ci/* 1014bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 1015bf215546Sopenharmony_ci * 1016bf215546Sopenharmony_ci * PsSetShader -- 1017bf215546Sopenharmony_ci * 1018bf215546Sopenharmony_ci * The PsSetShader function sets a pixel shader to be used 1019bf215546Sopenharmony_ci * in all drawing operations. 1020bf215546Sopenharmony_ci * 1021bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 1022bf215546Sopenharmony_ci */ 1023bf215546Sopenharmony_ci 1024bf215546Sopenharmony_civoid APIENTRY 1025bf215546Sopenharmony_ciPsSetShader(D3D10DDI_HDEVICE hDevice, // IN 1026bf215546Sopenharmony_ci D3D10DDI_HSHADER hShader) // IN 1027bf215546Sopenharmony_ci{ 1028bf215546Sopenharmony_ci LOG_ENTRYPOINT(); 1029bf215546Sopenharmony_ci 1030bf215546Sopenharmony_ci Device *pDevice = CastDevice(hDevice); 1031bf215546Sopenharmony_ci struct pipe_context *pipe = pDevice->pipe; 1032bf215546Sopenharmony_ci void *state = CastPipeShader(hShader); 1033bf215546Sopenharmony_ci 1034bf215546Sopenharmony_ci if (!state) { 1035bf215546Sopenharmony_ci state = pDevice->empty_fs; 1036bf215546Sopenharmony_ci } 1037bf215546Sopenharmony_ci 1038bf215546Sopenharmony_ci pipe->bind_fs_state(pipe, state); 1039bf215546Sopenharmony_ci} 1040bf215546Sopenharmony_ci 1041bf215546Sopenharmony_ci 1042bf215546Sopenharmony_ci/* 1043bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 1044bf215546Sopenharmony_ci * 1045bf215546Sopenharmony_ci * PsSetShaderResources -- 1046bf215546Sopenharmony_ci * 1047bf215546Sopenharmony_ci * The PsSetShaderResources function sets resources for a pixel shader. 1048bf215546Sopenharmony_ci * 1049bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 1050bf215546Sopenharmony_ci */ 1051bf215546Sopenharmony_ci 1052bf215546Sopenharmony_civoid APIENTRY 1053bf215546Sopenharmony_ciPsSetShaderResources(D3D10DDI_HDEVICE hDevice, // IN 1054bf215546Sopenharmony_ci UINT Offset, // IN 1055bf215546Sopenharmony_ci UINT NumViews, // IN 1056bf215546Sopenharmony_ci __in_ecount (NumViews) 1057bf215546Sopenharmony_ci const D3D10DDI_HSHADERRESOURCEVIEW *phShaderResourceViews) // IN 1058bf215546Sopenharmony_ci{ 1059bf215546Sopenharmony_ci LOG_ENTRYPOINT(); 1060bf215546Sopenharmony_ci 1061bf215546Sopenharmony_ci SetShaderResources(PIPE_SHADER_FRAGMENT, hDevice, Offset, NumViews, phShaderResourceViews); 1062bf215546Sopenharmony_ci} 1063bf215546Sopenharmony_ci 1064bf215546Sopenharmony_ci 1065bf215546Sopenharmony_ci/* 1066bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 1067bf215546Sopenharmony_ci * 1068bf215546Sopenharmony_ci * PsSetConstantBuffers -- 1069bf215546Sopenharmony_ci * 1070bf215546Sopenharmony_ci * The PsSetConstantBuffers function sets constant buffers for 1071bf215546Sopenharmony_ci * a pixel shader. 1072bf215546Sopenharmony_ci * 1073bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 1074bf215546Sopenharmony_ci */ 1075bf215546Sopenharmony_ci 1076bf215546Sopenharmony_civoid APIENTRY 1077bf215546Sopenharmony_ciPsSetConstantBuffers(D3D10DDI_HDEVICE hDevice, // IN 1078bf215546Sopenharmony_ci UINT StartBuffer, // IN 1079bf215546Sopenharmony_ci UINT NumBuffers, // IN 1080bf215546Sopenharmony_ci __in_ecount (NumBuffers) const D3D10DDI_HRESOURCE *phBuffers) // IN 1081bf215546Sopenharmony_ci{ 1082bf215546Sopenharmony_ci LOG_ENTRYPOINT(); 1083bf215546Sopenharmony_ci 1084bf215546Sopenharmony_ci SetConstantBuffers(PIPE_SHADER_FRAGMENT, 1085bf215546Sopenharmony_ci hDevice, StartBuffer, NumBuffers, phBuffers); 1086bf215546Sopenharmony_ci} 1087bf215546Sopenharmony_ci 1088bf215546Sopenharmony_ci/* 1089bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 1090bf215546Sopenharmony_ci * 1091bf215546Sopenharmony_ci * PsSetSamplers -- 1092bf215546Sopenharmony_ci * 1093bf215546Sopenharmony_ci * The PsSetSamplers function sets samplers for a pixel shader. 1094bf215546Sopenharmony_ci * 1095bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 1096bf215546Sopenharmony_ci */ 1097bf215546Sopenharmony_ci 1098bf215546Sopenharmony_civoid APIENTRY 1099bf215546Sopenharmony_ciPsSetSamplers(D3D10DDI_HDEVICE hDevice, // IN 1100bf215546Sopenharmony_ci UINT Offset, // IN 1101bf215546Sopenharmony_ci UINT NumSamplers, // IN 1102bf215546Sopenharmony_ci __in_ecount (NumSamplers) const D3D10DDI_HSAMPLER *phSamplers) // IN 1103bf215546Sopenharmony_ci{ 1104bf215546Sopenharmony_ci LOG_ENTRYPOINT(); 1105bf215546Sopenharmony_ci 1106bf215546Sopenharmony_ci SetSamplers(PIPE_SHADER_FRAGMENT, hDevice, Offset, NumSamplers, phSamplers); 1107bf215546Sopenharmony_ci} 1108bf215546Sopenharmony_ci 1109bf215546Sopenharmony_ci 1110bf215546Sopenharmony_ci/* 1111bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 1112bf215546Sopenharmony_ci * 1113bf215546Sopenharmony_ci * ShaderResourceViewReadAfterWriteHazard -- 1114bf215546Sopenharmony_ci * 1115bf215546Sopenharmony_ci * The ShaderResourceViewReadAfterWriteHazard function informs 1116bf215546Sopenharmony_ci * the usermode display driver that the specified resource was 1117bf215546Sopenharmony_ci * used as an output from the graphics processing unit (GPU) 1118bf215546Sopenharmony_ci * and that the resource will be used as an input to the GPU. 1119bf215546Sopenharmony_ci * A shader resource view is also provided to indicate which 1120bf215546Sopenharmony_ci * view caused the hazard. 1121bf215546Sopenharmony_ci * 1122bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 1123bf215546Sopenharmony_ci */ 1124bf215546Sopenharmony_ci 1125bf215546Sopenharmony_civoid APIENTRY 1126bf215546Sopenharmony_ciShaderResourceViewReadAfterWriteHazard(D3D10DDI_HDEVICE hDevice, // IN 1127bf215546Sopenharmony_ci D3D10DDI_HSHADERRESOURCEVIEW hShaderResourceView, // IN 1128bf215546Sopenharmony_ci D3D10DDI_HRESOURCE hResource) // IN 1129bf215546Sopenharmony_ci{ 1130bf215546Sopenharmony_ci LOG_ENTRYPOINT(); 1131bf215546Sopenharmony_ci 1132bf215546Sopenharmony_ci /* Not actually necessary */ 1133bf215546Sopenharmony_ci} 1134bf215546Sopenharmony_ci 1135bf215546Sopenharmony_ci 1136bf215546Sopenharmony_ci/* 1137bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 1138bf215546Sopenharmony_ci * 1139bf215546Sopenharmony_ci * CalcPrivateShaderResourceViewSize -- 1140bf215546Sopenharmony_ci * 1141bf215546Sopenharmony_ci * The CalcPrivateShaderResourceViewSize function determines the size 1142bf215546Sopenharmony_ci * of the usermode display driver's private region of memory 1143bf215546Sopenharmony_ci * (that is, the size of internal driver structures, not the size of 1144bf215546Sopenharmony_ci * the resource video memory) for a shader resource view. 1145bf215546Sopenharmony_ci * 1146bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 1147bf215546Sopenharmony_ci */ 1148bf215546Sopenharmony_ci 1149bf215546Sopenharmony_ciSIZE_T APIENTRY 1150bf215546Sopenharmony_ciCalcPrivateShaderResourceViewSize( 1151bf215546Sopenharmony_ci D3D10DDI_HDEVICE hDevice, // IN 1152bf215546Sopenharmony_ci __in const D3D10DDIARG_CREATESHADERRESOURCEVIEW *pCreateSRView) // IN 1153bf215546Sopenharmony_ci{ 1154bf215546Sopenharmony_ci return sizeof(ShaderResourceView); 1155bf215546Sopenharmony_ci} 1156bf215546Sopenharmony_ci 1157bf215546Sopenharmony_ci 1158bf215546Sopenharmony_ci/* 1159bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 1160bf215546Sopenharmony_ci * 1161bf215546Sopenharmony_ci * CalcPrivateShaderResourceViewSize -- 1162bf215546Sopenharmony_ci * 1163bf215546Sopenharmony_ci * The CalcPrivateShaderResourceViewSize function determines the size 1164bf215546Sopenharmony_ci * of the usermode display driver's private region of memory 1165bf215546Sopenharmony_ci * (that is, the size of internal driver structures, not the size of 1166bf215546Sopenharmony_ci * the resource video memory) for a shader resource view. 1167bf215546Sopenharmony_ci * 1168bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 1169bf215546Sopenharmony_ci */ 1170bf215546Sopenharmony_ci 1171bf215546Sopenharmony_ciSIZE_T APIENTRY 1172bf215546Sopenharmony_ciCalcPrivateShaderResourceViewSize1( 1173bf215546Sopenharmony_ci D3D10DDI_HDEVICE hDevice, // IN 1174bf215546Sopenharmony_ci __in const D3D10_1DDIARG_CREATESHADERRESOURCEVIEW *pCreateSRView) // IN 1175bf215546Sopenharmony_ci{ 1176bf215546Sopenharmony_ci return sizeof(ShaderResourceView); 1177bf215546Sopenharmony_ci} 1178bf215546Sopenharmony_ci 1179bf215546Sopenharmony_ci 1180bf215546Sopenharmony_ci/* 1181bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 1182bf215546Sopenharmony_ci * 1183bf215546Sopenharmony_ci * CreateShaderResourceView -- 1184bf215546Sopenharmony_ci * 1185bf215546Sopenharmony_ci * The CreateShaderResourceView function creates a shader 1186bf215546Sopenharmony_ci * resource view. 1187bf215546Sopenharmony_ci * 1188bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 1189bf215546Sopenharmony_ci */ 1190bf215546Sopenharmony_ci 1191bf215546Sopenharmony_civoid APIENTRY 1192bf215546Sopenharmony_ciCreateShaderResourceView( 1193bf215546Sopenharmony_ci D3D10DDI_HDEVICE hDevice, // IN 1194bf215546Sopenharmony_ci __in const D3D10DDIARG_CREATESHADERRESOURCEVIEW *pCreateSRView, // IN 1195bf215546Sopenharmony_ci D3D10DDI_HSHADERRESOURCEVIEW hShaderResourceView, // IN 1196bf215546Sopenharmony_ci D3D10DDI_HRTSHADERRESOURCEVIEW hRTShaderResourceView) // IN 1197bf215546Sopenharmony_ci{ 1198bf215546Sopenharmony_ci LOG_ENTRYPOINT(); 1199bf215546Sopenharmony_ci 1200bf215546Sopenharmony_ci struct pipe_context *pipe = CastPipeContext(hDevice); 1201bf215546Sopenharmony_ci ShaderResourceView *pSRView = CastShaderResourceView(hShaderResourceView); 1202bf215546Sopenharmony_ci struct pipe_resource *resource; 1203bf215546Sopenharmony_ci enum pipe_format format; 1204bf215546Sopenharmony_ci 1205bf215546Sopenharmony_ci struct pipe_sampler_view desc; 1206bf215546Sopenharmony_ci memset(&desc, 0, sizeof desc); 1207bf215546Sopenharmony_ci resource = CastPipeResource(pCreateSRView->hDrvResource); 1208bf215546Sopenharmony_ci format = FormatTranslate(pCreateSRView->Format, FALSE); 1209bf215546Sopenharmony_ci 1210bf215546Sopenharmony_ci u_sampler_view_default_template(&desc, 1211bf215546Sopenharmony_ci resource, 1212bf215546Sopenharmony_ci format); 1213bf215546Sopenharmony_ci 1214bf215546Sopenharmony_ci switch (pCreateSRView->ResourceDimension) { 1215bf215546Sopenharmony_ci case D3D10DDIRESOURCE_BUFFER: { 1216bf215546Sopenharmony_ci const struct util_format_description *fdesc = util_format_description(format); 1217bf215546Sopenharmony_ci desc.u.buf.offset = pCreateSRView->Buffer.FirstElement * 1218bf215546Sopenharmony_ci (fdesc->block.bits / 8) * fdesc->block.width; 1219bf215546Sopenharmony_ci desc.u.buf.size = pCreateSRView->Buffer.NumElements * 1220bf215546Sopenharmony_ci (fdesc->block.bits / 8) * fdesc->block.width; 1221bf215546Sopenharmony_ci } 1222bf215546Sopenharmony_ci break; 1223bf215546Sopenharmony_ci case D3D10DDIRESOURCE_TEXTURE1D: 1224bf215546Sopenharmony_ci desc.u.tex.first_level = pCreateSRView->Tex1D.MostDetailedMip; 1225bf215546Sopenharmony_ci desc.u.tex.last_level = pCreateSRView->Tex1D.MipLevels - 1 + desc.u.tex.first_level; 1226bf215546Sopenharmony_ci desc.u.tex.first_layer = pCreateSRView->Tex1D.FirstArraySlice; 1227bf215546Sopenharmony_ci desc.u.tex.last_layer = pCreateSRView->Tex1D.ArraySize - 1 + desc.u.tex.first_layer; 1228bf215546Sopenharmony_ci assert(pCreateSRView->Tex1D.MipLevels != 0 && pCreateSRView->Tex1D.MipLevels != (UINT)-1); 1229bf215546Sopenharmony_ci assert(pCreateSRView->Tex1D.ArraySize != 0 && pCreateSRView->Tex1D.ArraySize != (UINT)-1); 1230bf215546Sopenharmony_ci break; 1231bf215546Sopenharmony_ci case D3D10DDIRESOURCE_TEXTURE2D: 1232bf215546Sopenharmony_ci desc.u.tex.first_level = pCreateSRView->Tex2D.MostDetailedMip; 1233bf215546Sopenharmony_ci desc.u.tex.last_level = pCreateSRView->Tex2D.MipLevels - 1 + desc.u.tex.first_level; 1234bf215546Sopenharmony_ci desc.u.tex.first_layer = pCreateSRView->Tex2D.FirstArraySlice; 1235bf215546Sopenharmony_ci desc.u.tex.last_layer = pCreateSRView->Tex2D.ArraySize - 1 + desc.u.tex.first_layer; 1236bf215546Sopenharmony_ci assert(pCreateSRView->Tex2D.MipLevels != 0 && pCreateSRView->Tex2D.MipLevels != (UINT)-1); 1237bf215546Sopenharmony_ci assert(pCreateSRView->Tex2D.ArraySize != 0 && pCreateSRView->Tex2D.ArraySize != (UINT)-1); 1238bf215546Sopenharmony_ci break; 1239bf215546Sopenharmony_ci case D3D10DDIRESOURCE_TEXTURE3D: 1240bf215546Sopenharmony_ci desc.u.tex.first_level = pCreateSRView->Tex3D.MostDetailedMip; 1241bf215546Sopenharmony_ci desc.u.tex.last_level = pCreateSRView->Tex3D.MipLevels - 1 + desc.u.tex.first_level; 1242bf215546Sopenharmony_ci /* layer info filled in by default_template */ 1243bf215546Sopenharmony_ci assert(pCreateSRView->Tex3D.MipLevels != 0 && pCreateSRView->Tex3D.MipLevels != (UINT)-1); 1244bf215546Sopenharmony_ci break; 1245bf215546Sopenharmony_ci case D3D10DDIRESOURCE_TEXTURECUBE: 1246bf215546Sopenharmony_ci desc.u.tex.first_level = pCreateSRView->TexCube.MostDetailedMip; 1247bf215546Sopenharmony_ci desc.u.tex.last_level = pCreateSRView->TexCube.MipLevels - 1 + desc.u.tex.first_level; 1248bf215546Sopenharmony_ci /* layer info filled in by default_template */ 1249bf215546Sopenharmony_ci assert(pCreateSRView->TexCube.MipLevels != 0 && pCreateSRView->TexCube.MipLevels != (UINT)-1); 1250bf215546Sopenharmony_ci break; 1251bf215546Sopenharmony_ci default: 1252bf215546Sopenharmony_ci assert(0); 1253bf215546Sopenharmony_ci return; 1254bf215546Sopenharmony_ci } 1255bf215546Sopenharmony_ci 1256bf215546Sopenharmony_ci pSRView->handle = pipe->create_sampler_view(pipe, resource, &desc); 1257bf215546Sopenharmony_ci} 1258bf215546Sopenharmony_ci 1259bf215546Sopenharmony_ci 1260bf215546Sopenharmony_ci/* 1261bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 1262bf215546Sopenharmony_ci * 1263bf215546Sopenharmony_ci * CreateShaderResourceView1 -- 1264bf215546Sopenharmony_ci * 1265bf215546Sopenharmony_ci * The CreateShaderResourceView function creates a shader 1266bf215546Sopenharmony_ci * resource view. 1267bf215546Sopenharmony_ci * 1268bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 1269bf215546Sopenharmony_ci */ 1270bf215546Sopenharmony_ci 1271bf215546Sopenharmony_civoid APIENTRY 1272bf215546Sopenharmony_ciCreateShaderResourceView1( 1273bf215546Sopenharmony_ci D3D10DDI_HDEVICE hDevice, // IN 1274bf215546Sopenharmony_ci __in const D3D10_1DDIARG_CREATESHADERRESOURCEVIEW *pCreateSRView, // IN 1275bf215546Sopenharmony_ci D3D10DDI_HSHADERRESOURCEVIEW hShaderResourceView, // IN 1276bf215546Sopenharmony_ci D3D10DDI_HRTSHADERRESOURCEVIEW hRTShaderResourceView) // IN 1277bf215546Sopenharmony_ci{ 1278bf215546Sopenharmony_ci LOG_ENTRYPOINT(); 1279bf215546Sopenharmony_ci 1280bf215546Sopenharmony_ci struct pipe_context *pipe = CastPipeContext(hDevice); 1281bf215546Sopenharmony_ci ShaderResourceView *pSRView = CastShaderResourceView(hShaderResourceView); 1282bf215546Sopenharmony_ci struct pipe_resource *resource; 1283bf215546Sopenharmony_ci enum pipe_format format; 1284bf215546Sopenharmony_ci 1285bf215546Sopenharmony_ci struct pipe_sampler_view desc; 1286bf215546Sopenharmony_ci memset(&desc, 0, sizeof desc); 1287bf215546Sopenharmony_ci resource = CastPipeResource(pCreateSRView->hDrvResource); 1288bf215546Sopenharmony_ci format = FormatTranslate(pCreateSRView->Format, FALSE); 1289bf215546Sopenharmony_ci 1290bf215546Sopenharmony_ci u_sampler_view_default_template(&desc, 1291bf215546Sopenharmony_ci resource, 1292bf215546Sopenharmony_ci format); 1293bf215546Sopenharmony_ci 1294bf215546Sopenharmony_ci switch (pCreateSRView->ResourceDimension) { 1295bf215546Sopenharmony_ci case D3D10DDIRESOURCE_BUFFER: { 1296bf215546Sopenharmony_ci const struct util_format_description *fdesc = util_format_description(format); 1297bf215546Sopenharmony_ci desc.u.buf.offset = pCreateSRView->Buffer.FirstElement * 1298bf215546Sopenharmony_ci (fdesc->block.bits / 8) * fdesc->block.width; 1299bf215546Sopenharmony_ci desc.u.buf.size = pCreateSRView->Buffer.NumElements * 1300bf215546Sopenharmony_ci (fdesc->block.bits / 8) * fdesc->block.width; 1301bf215546Sopenharmony_ci } 1302bf215546Sopenharmony_ci break; 1303bf215546Sopenharmony_ci case D3D10DDIRESOURCE_TEXTURE1D: 1304bf215546Sopenharmony_ci desc.u.tex.first_level = pCreateSRView->Tex1D.MostDetailedMip; 1305bf215546Sopenharmony_ci desc.u.tex.last_level = pCreateSRView->Tex1D.MipLevels - 1 + desc.u.tex.first_level; 1306bf215546Sopenharmony_ci desc.u.tex.first_layer = pCreateSRView->Tex1D.FirstArraySlice; 1307bf215546Sopenharmony_ci desc.u.tex.last_layer = pCreateSRView->Tex1D.ArraySize - 1 + desc.u.tex.first_layer; 1308bf215546Sopenharmony_ci assert(pCreateSRView->Tex1D.MipLevels != 0 && pCreateSRView->Tex1D.MipLevels != (UINT)-1); 1309bf215546Sopenharmony_ci assert(pCreateSRView->Tex1D.ArraySize != 0 && pCreateSRView->Tex1D.ArraySize != (UINT)-1); 1310bf215546Sopenharmony_ci break; 1311bf215546Sopenharmony_ci case D3D10DDIRESOURCE_TEXTURE2D: 1312bf215546Sopenharmony_ci desc.u.tex.first_level = pCreateSRView->Tex2D.MostDetailedMip; 1313bf215546Sopenharmony_ci desc.u.tex.last_level = pCreateSRView->Tex2D.MipLevels - 1 + desc.u.tex.first_level; 1314bf215546Sopenharmony_ci desc.u.tex.first_layer = pCreateSRView->Tex2D.FirstArraySlice; 1315bf215546Sopenharmony_ci desc.u.tex.last_layer = pCreateSRView->Tex2D.ArraySize - 1 + desc.u.tex.first_layer; 1316bf215546Sopenharmony_ci assert(pCreateSRView->Tex2D.MipLevels != 0 && pCreateSRView->Tex2D.MipLevels != (UINT)-1); 1317bf215546Sopenharmony_ci assert(pCreateSRView->Tex2D.ArraySize != 0 && pCreateSRView->Tex2D.ArraySize != (UINT)-1); 1318bf215546Sopenharmony_ci break; 1319bf215546Sopenharmony_ci case D3D10DDIRESOURCE_TEXTURE3D: 1320bf215546Sopenharmony_ci desc.u.tex.first_level = pCreateSRView->Tex3D.MostDetailedMip; 1321bf215546Sopenharmony_ci desc.u.tex.last_level = pCreateSRView->Tex3D.MipLevels - 1 + desc.u.tex.first_level; 1322bf215546Sopenharmony_ci /* layer info filled in by default_template */ 1323bf215546Sopenharmony_ci assert(pCreateSRView->Tex3D.MipLevels != 0 && pCreateSRView->Tex3D.MipLevels != (UINT)-1); 1324bf215546Sopenharmony_ci break; 1325bf215546Sopenharmony_ci case D3D10DDIRESOURCE_TEXTURECUBE: 1326bf215546Sopenharmony_ci desc.u.tex.first_level = pCreateSRView->TexCube.MostDetailedMip; 1327bf215546Sopenharmony_ci desc.u.tex.last_level = pCreateSRView->TexCube.MipLevels - 1 + desc.u.tex.first_level; 1328bf215546Sopenharmony_ci desc.u.tex.first_layer = pCreateSRView->TexCube.First2DArrayFace; 1329bf215546Sopenharmony_ci desc.u.tex.last_layer = 6*pCreateSRView->TexCube.NumCubes - 1 + 1330bf215546Sopenharmony_ci pCreateSRView->TexCube.First2DArrayFace; 1331bf215546Sopenharmony_ci assert(pCreateSRView->TexCube.MipLevels != 0 && pCreateSRView->TexCube.MipLevels != (UINT)-1); 1332bf215546Sopenharmony_ci break; 1333bf215546Sopenharmony_ci default: 1334bf215546Sopenharmony_ci assert(0); 1335bf215546Sopenharmony_ci return; 1336bf215546Sopenharmony_ci } 1337bf215546Sopenharmony_ci 1338bf215546Sopenharmony_ci pSRView->handle = pipe->create_sampler_view(pipe, resource, &desc); 1339bf215546Sopenharmony_ci} 1340bf215546Sopenharmony_ci 1341bf215546Sopenharmony_ci 1342bf215546Sopenharmony_ci/* 1343bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 1344bf215546Sopenharmony_ci * 1345bf215546Sopenharmony_ci * DestroyShaderResourceView -- 1346bf215546Sopenharmony_ci * 1347bf215546Sopenharmony_ci * The DestroyShaderResourceView function destroys the specified 1348bf215546Sopenharmony_ci * shader resource view object. The shader resource view object 1349bf215546Sopenharmony_ci * can be destoyed only if it is not currently bound to a 1350bf215546Sopenharmony_ci * display device. 1351bf215546Sopenharmony_ci * 1352bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 1353bf215546Sopenharmony_ci */ 1354bf215546Sopenharmony_ci 1355bf215546Sopenharmony_civoid APIENTRY 1356bf215546Sopenharmony_ciDestroyShaderResourceView(D3D10DDI_HDEVICE hDevice, // IN 1357bf215546Sopenharmony_ci D3D10DDI_HSHADERRESOURCEVIEW hShaderResourceView) // IN 1358bf215546Sopenharmony_ci{ 1359bf215546Sopenharmony_ci LOG_ENTRYPOINT(); 1360bf215546Sopenharmony_ci 1361bf215546Sopenharmony_ci ShaderResourceView *pSRView = CastShaderResourceView(hShaderResourceView); 1362bf215546Sopenharmony_ci 1363bf215546Sopenharmony_ci pipe_sampler_view_reference(&pSRView->handle, NULL); 1364bf215546Sopenharmony_ci} 1365bf215546Sopenharmony_ci 1366bf215546Sopenharmony_ci 1367bf215546Sopenharmony_ci/* 1368bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 1369bf215546Sopenharmony_ci * 1370bf215546Sopenharmony_ci * GenMips -- 1371bf215546Sopenharmony_ci * 1372bf215546Sopenharmony_ci * The GenMips function generates the lower MIP-map levels 1373bf215546Sopenharmony_ci * on the specified shader-resource view. 1374bf215546Sopenharmony_ci * 1375bf215546Sopenharmony_ci * ---------------------------------------------------------------------- 1376bf215546Sopenharmony_ci */ 1377bf215546Sopenharmony_ci 1378bf215546Sopenharmony_civoid APIENTRY 1379bf215546Sopenharmony_ciGenMips(D3D10DDI_HDEVICE hDevice, // IN 1380bf215546Sopenharmony_ci D3D10DDI_HSHADERRESOURCEVIEW hShaderResourceView) // IN 1381bf215546Sopenharmony_ci{ 1382bf215546Sopenharmony_ci LOG_ENTRYPOINT(); 1383bf215546Sopenharmony_ci 1384bf215546Sopenharmony_ci Device *pDevice = CastDevice(hDevice); 1385bf215546Sopenharmony_ci if (!CheckPredicate(pDevice)) { 1386bf215546Sopenharmony_ci return; 1387bf215546Sopenharmony_ci } 1388bf215546Sopenharmony_ci 1389bf215546Sopenharmony_ci struct pipe_context *pipe = pDevice->pipe; 1390bf215546Sopenharmony_ci struct pipe_sampler_view *sampler_view = CastPipeShaderResourceView(hShaderResourceView); 1391bf215546Sopenharmony_ci 1392bf215546Sopenharmony_ci util_gen_mipmap(pipe, 1393bf215546Sopenharmony_ci sampler_view->texture, 1394bf215546Sopenharmony_ci sampler_view->format, 1395bf215546Sopenharmony_ci sampler_view->u.tex.first_level, 1396bf215546Sopenharmony_ci sampler_view->u.tex.last_level, 1397bf215546Sopenharmony_ci sampler_view->u.tex.first_layer, 1398bf215546Sopenharmony_ci sampler_view->u.tex.last_layer, 1399bf215546Sopenharmony_ci PIPE_TEX_FILTER_LINEAR); 1400bf215546Sopenharmony_ci} 1401bf215546Sopenharmony_ci 1402bf215546Sopenharmony_ci 1403bf215546Sopenharmony_ciunsigned 1404bf215546Sopenharmony_ciShaderFindOutputMapping(Shader *shader, unsigned registerIndex) 1405bf215546Sopenharmony_ci{ 1406bf215546Sopenharmony_ci if (!shader || !shader->state.tokens) 1407bf215546Sopenharmony_ci return registerIndex; 1408bf215546Sopenharmony_ci 1409bf215546Sopenharmony_ci for (unsigned i = 0; i < PIPE_MAX_SHADER_OUTPUTS; ++i) { 1410bf215546Sopenharmony_ci if (shader->output_mapping[i] == registerIndex) 1411bf215546Sopenharmony_ci return i; 1412bf215546Sopenharmony_ci } 1413bf215546Sopenharmony_ci return registerIndex; 1414bf215546Sopenharmony_ci} 1415