Changeset 25949 in vbox for trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/glsl_shader.c
- Timestamp:
- Jan 21, 2010 9:26:23 AM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 56794
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/glsl_shader.c
r23571 r25949 265 265 if (name_loc != -1) { 266 266 DWORD mapped_unit = tex_unit_map[i]; 267 if (mapped_unit != WINED3D_UNMAPPED_STAGE && mapped_unit < GL_LIMITS(fragment_samplers))267 if (mapped_unit != WINED3D_UNMAPPED_STAGE && mapped_unit < gl_info->limits.fragment_samplers) 268 268 { 269 269 TRACE("Loading %s for texture %d\n", sampler_name, mapped_unit); … … 290 290 if (name_loc != -1) { 291 291 DWORD mapped_unit = tex_unit_map[MAX_FRAGMENT_SAMPLERS + i]; 292 if (mapped_unit != WINED3D_UNMAPPED_STAGE && mapped_unit < GL_LIMITS(combined_samplers))292 if (mapped_unit != WINED3D_UNMAPPED_STAGE && mapped_unit < gl_info->limits.combined_samplers) 293 293 { 294 294 TRACE("Loading %s for texture %d\n", sampler_name, mapped_unit); … … 641 641 char usePixelShader, char useVertexShader) 642 642 { 643 IWineD3DDeviceImpl *device = ((IWineD3DSurfaceImpl *)context->surface)->resource. wineD3DDevice;643 IWineD3DDeviceImpl *device = ((IWineD3DSurfaceImpl *)context->surface)->resource.device; 644 644 const struct wined3d_gl_info *gl_info = context->gl_info; 645 645 IWineD3DStateBlockImpl* stateBlock = device->stateBlock; … … 805 805 static unsigned int vec4_varyings(DWORD shader_major, const struct wined3d_gl_info *gl_info) 806 806 { 807 unsigned int ret = GL_LIMITS(glsl_varyings)/ 4;807 unsigned int ret = gl_info->limits.glsl_varyings / 4; 808 808 /* 4.0 shaders do not write clip coords because d3d10 does not support user clipplanes */ 809 809 if(shader_major > 3) return ret; … … 853 853 * 2) The shader uses indirect addressing, less constants than supported, but uses a constant index > #supported consts 854 854 */ 855 if(pshader) { 856 /* No indirect addressing here */ 857 max_constantsF = GL_LIMITS(pshader_constantsF); 858 } else { 855 if (pshader) 856 { 857 /* No indirect addressing here. */ 858 max_constantsF = gl_info->limits.glsl_ps_float_constants; 859 } 860 else 861 { 859 862 if(This->baseShader.reg_maps.usesrelconstF) { 860 863 /* Subtract the other potential uniforms from the max available (bools, ints, and 1 row of projection matrix). … … 863 866 * (Unfortunately the Nvidia driver doesn't store 128 and -128 in one float). 864 867 * 865 * Writing gl_Clip Posrequires one uniform for each clipplane as well.868 * Writing gl_ClipVertex requires one uniform for each clipplane as well. 866 869 */ 867 max_constantsF = GL_LIMITS(vshader_constantsF) - 3 - GL_LIMITS(clipplanes); 870 max_constantsF = gl_info->limits.glsl_vs_float_constants - 3; 871 if(ctx_priv->cur_vs_args->clip_enabled) 872 { 873 max_constantsF -= gl_info->limits.clipplanes; 874 } 868 875 max_constantsF -= count_bits(This->baseShader.reg_maps.integer_constants); 869 876 /* Strictly speaking a bool only uses one scalar, but the nvidia(Linux) compiler doesn't pack them properly, … … 873 880 max_constantsF -= count_bits(This->baseShader.reg_maps.boolean_constants); 874 881 /* Set by driver quirks in directx.c */ 875 max_constantsF -= GLINFO_LOCATION.reserved_glsl_constants; 876 } else { 877 max_constantsF = GL_LIMITS(vshader_constantsF); 882 max_constantsF -= gl_info->reserved_glsl_constants; 883 } 884 else 885 { 886 max_constantsF = gl_info->limits.glsl_vs_float_constants; 878 887 } 879 888 } … … 933 942 srgb_cmp); 934 943 } 935 if(reg_maps->vpos || reg_maps->usesdsy) { 936 if(This->baseShader.limits.constant_float + extra_constants_needed + 1 < GL_LIMITS(pshader_constantsF)) { 944 if (reg_maps->vpos || reg_maps->usesdsy) 945 { 946 if (This->baseShader.limits.constant_float + extra_constants_needed 947 + 1 < gl_info->limits.glsl_ps_float_constants) 948 { 937 949 shader_addline(buffer, "uniform vec4 ycorrection;\n"); 938 950 ((IWineD3DPixelShaderImpl *) This)->vpos_uniform = 1; … … 1319 1331 1320 1332 case WINED3DSPR_COLOROUT: 1321 if (reg->idx >= GL_LIMITS(buffers))1322 WARN("Write to render target %u, only %d supported \n", reg->idx, GL_LIMITS(buffers));1333 if (reg->idx >= gl_info->limits.buffers) 1334 WARN("Write to render target %u, only %d supported.\n", reg->idx, gl_info->limits.buffers); 1323 1335 1324 1336 sprintf(register_name, "gl_FragData[%u]", reg->idx); … … 1967 1979 case WINED3DSIH_NRM: instruction = "normalize"; break; 1968 1980 case WINED3DSIH_EXP: instruction = "exp2"; break; 1969 case WINED3DSIH_SGN: instruction = "sign"; break;1970 1981 case WINED3DSIH_DSX: instruction = "dFdx"; break; 1971 1982 case WINED3DSIH_DSY: instruction = "ycorrection.y * dFdy"; break; … … 2460 2471 } 2461 2472 2473 /* sgn in vs_2_0 has 2 extra parameters(registers for temporary storage) which we don't use 2474 * here. But those extra parameters require a dedicated function for sgn, since map2gl would 2475 * generate invalid code 2476 */ 2477 static void shader_glsl_sgn(const struct wined3d_shader_instruction *ins) 2478 { 2479 glsl_src_param_t src0_param; 2480 DWORD write_mask; 2481 2482 write_mask = shader_glsl_append_dst(ins->ctx->buffer, ins); 2483 shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src0_param); 2484 2485 shader_addline(ins->ctx->buffer, "sign(%s));\n", src0_param.param_str); 2486 } 2487 2462 2488 /** Process the WINED3DSIO_LOOP instruction in GLSL: 2463 2489 * Start a for() loop where src1.y is the initial value of aL, … … 2755 2781 DWORD swizzle = ins->src[1].swizzle; 2756 2782 2757 if(!GL_SUPPORT(ARB_SHADER_TEXTURE_LOD)) { 2783 if (!gl_info->supported[ARB_SHADER_TEXTURE_LOD]) 2784 { 2758 2785 FIXME("texldd used, but not supported by hardware. Falling back to regular tex\n"); 2759 2786 return shader_glsl_tex(ins); … … 3572 3599 */ 3573 3600 device = (IWineD3DDeviceImpl *) vs->baseShader.device; 3574 if (( (GLINFO_LOCATION).quirks & WINED3D_QUIRK_SET_TEXCOORD_W)3601 if ((gl_info->quirks & WINED3D_QUIRK_SET_TEXCOORD_W) 3575 3602 && ps_major == 0 && vs_major > 0 && !device->frag_pipe->ffp_proj_control) 3576 3603 { … … 3590 3617 3591 3618 /* The vertex shader writes to its own varyings, the pixel shader needs them in the builtin ones */ 3592 output_signature = vs-> output_signature;3619 output_signature = vs->baseShader.output_signature; 3593 3620 3594 3621 shader_addline(buffer, "void order_ps_input(in vec4 OUT[%u]) {\n", MAX_REG_OUTPUT); … … 3619 3646 if (semantic_idx < 8) 3620 3647 { 3621 if (!( (GLINFO_LOCATION).quirks & WINED3D_QUIRK_SET_TEXCOORD_W) || ps_major > 0)3648 if (!(gl_info->quirks & WINED3D_QUIRK_SET_TEXCOORD_W) || ps_major > 0) 3622 3649 write_mask |= WINED3DSP_WRITEMASK_3; 3623 3650 … … 3642 3669 WORD map = vs->baseShader.reg_maps.output_registers; 3643 3670 3644 output_signature = vs-> output_signature;3671 output_signature = vs->baseShader.output_signature; 3645 3672 3646 3673 /* This one is tricky: a 3.0 pixel shader reads from a 3.0 vertex shader */ … … 3667 3694 3668 3695 /* Then, fix the pixel shader input */ 3669 handle_ps3_input(buffer, gl_info, ps->input_reg_map, ps-> input_signature,3696 handle_ps3_input(buffer, gl_info, ps->input_reg_map, ps->baseShader.input_signature, 3670 3697 &ps->baseShader.reg_maps, output_signature, &vs->baseShader.reg_maps); 3671 3698 … … 3678 3705 * read gl_TexCoord and gl_ColorX, otherwise we'll run out of varyings 3679 3706 */ 3680 handle_ps3_input(buffer, gl_info, ps->input_reg_map, ps-> input_signature,3707 handle_ps3_input(buffer, gl_info, ps->input_reg_map, ps->baseShader.input_signature, 3681 3708 &ps->baseShader.reg_maps, NULL, NULL); 3682 3709 shader_addline(buffer, "}\n"); … … 3732 3759 shader_addline(buffer, "#version 120\n"); 3733 3760 3734 if(GL_SUPPORT(ARB_SHADER_TEXTURE_LOD) && reg_maps->usestexldd) { 3761 if (gl_info->supported[ARB_SHADER_TEXTURE_LOD] && reg_maps->usestexldd) 3762 { 3735 3763 shader_addline(buffer, "#extension GL_ARB_shader_texture_lod : enable\n"); 3736 3764 } 3737 if (GL_SUPPORT(ARB_TEXTURE_RECTANGLE)) { 3765 if (gl_info->supported[ARB_TEXTURE_RECTANGLE]) 3766 { 3738 3767 /* The spec says that it doesn't have to be explicitly enabled, but the nvidia 3739 3768 * drivers write a warning if we don't do so … … 3748 3777 if (reg_maps->shader_version.major >= 3 && args->vp_mode != vertexshader) 3749 3778 { 3750 shader_glsl_input_pack((IWineD3DPixelShader *) This, buffer, This->input_signature, reg_maps, args->vp_mode); 3779 shader_glsl_input_pack((IWineD3DPixelShader *) This, buffer, 3780 This->baseShader.input_signature, reg_maps, args->vp_mode); 3751 3781 } 3752 3782 … … 3806 3836 GL_EXTCALL(glShaderSourceARB(shader_obj, 1, (const char**)&buffer->buffer, NULL)); 3807 3837 GL_EXTCALL(glCompileShaderARB(shader_obj)); 3808 print_glsl_info_log( &GLINFO_LOCATION, shader_obj);3838 print_glsl_info_log(gl_info, shader_obj); 3809 3839 3810 3840 /* Store the shader object */ … … 3860 3890 shader_addline(buffer, "gl_Position.y = gl_Position.y * posFixup.y;\n"); 3861 3891 shader_addline(buffer, "gl_Position.xy += posFixup.zw * gl_Position.ww;\n"); 3862 shader_addline(buffer, "gl_ClipVertex = gl_Position;\n"); 3892 if(args->clip_enabled) { 3893 shader_addline(buffer, "gl_ClipVertex = gl_Position;\n"); 3894 } 3863 3895 3864 3896 /* Z coord [0;1]->[-1;1] mapping, see comment in transform_projection in state.c … … 3875 3907 GL_EXTCALL(glShaderSourceARB(shader_obj, 1, (const char**)&buffer->buffer, NULL)); 3876 3908 GL_EXTCALL(glCompileShaderARB(shader_obj)); 3877 print_glsl_info_log( &GLINFO_LOCATION, shader_obj);3909 print_glsl_info_log(gl_info, shader_obj); 3878 3910 3879 3911 return shader_obj; … … 3952 3984 const DWORD use_map) { 3953 3985 if((stored->swizzle_map & use_map) != new->swizzle_map) return FALSE; 3986 if((stored->clip_enabled) != new->clip_enabled) return FALSE; 3954 3987 return stored->fog_src == new->fog_src; 3955 3988 } … … 4127 4160 TRACE("Linking GLSL shader program %u\n", programId); 4128 4161 GL_EXTCALL(glLinkProgramARB(programId)); 4129 print_glsl_info_log(&GLINFO_LOCATION, programId); 4130 4131 entry->vuniformF_locations = HeapAlloc(GetProcessHeap(), 0, sizeof(GLhandleARB) * GL_LIMITS(vshader_constantsF)); 4132 for (i = 0; i < GL_LIMITS(vshader_constantsF); ++i) { 4162 print_glsl_info_log(gl_info, programId); 4163 4164 entry->vuniformF_locations = HeapAlloc(GetProcessHeap(), 0, 4165 sizeof(GLhandleARB) * gl_info->limits.glsl_vs_float_constants); 4166 for (i = 0; i < gl_info->limits.glsl_vs_float_constants; ++i) 4167 { 4133 4168 snprintf(glsl_name, sizeof(glsl_name), "VC[%i]", i); 4134 4169 entry->vuniformF_locations[i] = GL_EXTCALL(glGetUniformLocationARB(programId, glsl_name)); 4135 4170 } 4136 for (i = 0; i < MAX_CONST_I; ++i) { 4171 for (i = 0; i < MAX_CONST_I; ++i) 4172 { 4137 4173 snprintf(glsl_name, sizeof(glsl_name), "VI[%i]", i); 4138 4174 entry->vuniformI_locations[i] = GL_EXTCALL(glGetUniformLocationARB(programId, glsl_name)); 4139 4175 } 4140 entry->puniformF_locations = HeapAlloc(GetProcessHeap(), 0, sizeof(GLhandleARB) * GL_LIMITS(pshader_constantsF)); 4141 for (i = 0; i < GL_LIMITS(pshader_constantsF); ++i) { 4176 entry->puniformF_locations = HeapAlloc(GetProcessHeap(), 0, 4177 sizeof(GLhandleARB) * gl_info->limits.glsl_ps_float_constants); 4178 for (i = 0; i < gl_info->limits.glsl_ps_float_constants; ++i) 4179 { 4142 4180 snprintf(glsl_name, sizeof(glsl_name), "PC[%i]", i); 4143 4181 entry->puniformF_locations[i] = GL_EXTCALL(glGetUniformLocationARB(programId, glsl_name)); 4144 4182 } 4145 for (i = 0; i < MAX_CONST_I; ++i) { 4183 for (i = 0; i < MAX_CONST_I; ++i) 4184 { 4146 4185 snprintf(glsl_name, sizeof(glsl_name), "PI[%i]", i); 4147 4186 entry->puniformI_locations[i] = GL_EXTCALL(glGetUniformLocationARB(programId, glsl_name)); … … 4275 4314 GL_EXTCALL(glLinkProgramARB(program_id)); 4276 4315 4277 print_glsl_info_log( &GLINFO_LOCATION, program_id);4316 print_glsl_info_log(gl_info, program_id); 4278 4317 4279 4318 /* Once linked we can mark the shaders for deletion. They will be deleted once the program … … 4288 4327 static void shader_glsl_select(const struct wined3d_context *context, BOOL usePS, BOOL useVS) 4289 4328 { 4290 IWineD3DDeviceImpl *device = ((IWineD3DSurfaceImpl *)context->surface)->resource. wineD3DDevice;4329 IWineD3DDeviceImpl *device = ((IWineD3DSurfaceImpl *)context->surface)->resource.device; 4291 4330 const struct wined3d_gl_info *gl_info = context->gl_info; 4292 4331 struct shader_glsl_priv *priv = device->shader_priv; … … 4301 4340 current_vertex_color_clamp = priv->glsl_program ? priv->glsl_program->vertex_color_clamp : GL_FIXED_ONLY_ARB; 4302 4341 4303 if (old_vertex_color_clamp != current_vertex_color_clamp) { 4304 if (GL_SUPPORT(ARB_COLOR_BUFFER_FLOAT)) { 4342 if (old_vertex_color_clamp != current_vertex_color_clamp) 4343 { 4344 if (gl_info->supported[ARB_COLOR_BUFFER_FLOAT]) 4345 { 4305 4346 GL_EXTCALL(glClampColorARB(GL_CLAMP_VERTEX_COLOR_ARB, current_vertex_color_clamp)); 4306 4347 checkGLcall("glClampColorARB"); 4307 } else { 4348 } 4349 else 4350 { 4308 4351 FIXME("vertex color clamp needs to be changed, but extension not supported.\n"); 4309 4352 } … … 4361 4404 IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *)This->baseShader.device; 4362 4405 struct shader_glsl_priv *priv = device->shader_priv; 4363 const struct wined3d_context *context;4364 4406 const struct wined3d_gl_info *gl_info; 4365 4407 IWineD3DPixelShaderImpl *ps = NULL; 4366 4408 IWineD3DVertexShaderImpl *vs = NULL; 4409 struct wined3d_context *context; 4367 4410 4368 4411 /* Note: Do not use QueryInterface here to find out which shader type this is because this code … … 4382 4425 } 4383 4426 4384 context = ActivateContext(device, NULL, CTXUSAGE_RESOURCELOAD);4427 context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD); 4385 4428 gl_info = context->gl_info; 4386 4429 … … 4402 4445 } 4403 4446 4404 context = ActivateContext(device, NULL, CTXUSAGE_RESOURCELOAD);4447 context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD); 4405 4448 gl_info = context->gl_info; 4406 4449 … … 4461 4504 vs->baseShader.backend_data = NULL; 4462 4505 } 4506 4507 context_release(context); 4463 4508 } 4464 4509 … … 4518 4563 const struct wined3d_gl_info *gl_info = &This->adapter->gl_info; 4519 4564 struct shader_glsl_priv *priv = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct shader_glsl_priv)); 4520 SIZE_T stack_size = wined3d_log2i(max(GL_LIMITS(vshader_constantsF), GL_LIMITS(pshader_constantsF))) + 1; 4565 SIZE_T stack_size = wined3d_log2i(max(gl_info->limits.glsl_vs_float_constants, 4566 gl_info->limits.glsl_ps_float_constants)) + 1; 4521 4567 4522 4568 if (!shader_buffer_init(&priv->shader_buffer)) … … 4533 4579 } 4534 4580 4535 if (!constant_heap_init(&priv->vconst_heap, GL_LIMITS(vshader_constantsF)))4581 if (!constant_heap_init(&priv->vconst_heap, gl_info->limits.glsl_vs_float_constants)) 4536 4582 { 4537 4583 ERR("Failed to initialize vertex shader constant heap\n"); … … 4539 4585 } 4540 4586 4541 if (!constant_heap_init(&priv->pconst_heap, GL_LIMITS(pshader_constantsF)))4587 if (!constant_heap_init(&priv->pconst_heap, gl_info->limits.glsl_ps_float_constants)) 4542 4588 { 4543 4589 ERR("Failed to initialize pixel shader constant heap\n"); … … 4586 4632 constant_heap_free(&priv->vconst_heap); 4587 4633 HeapFree(GetProcessHeap(), 0, priv->stack); 4634 shader_buffer_free(&priv->shader_buffer); 4588 4635 4589 4636 HeapFree(GetProcessHeap(), 0, This->shader_priv); … … 4608 4655 */ 4609 4656 if ((gl_info->supported[NV_VERTEX_PROGRAM2] && !gl_info->supported[NV_VERTEX_PROGRAM3]) 4610 || gl_info-> ps_arb_max_instructions <= 512)4657 || gl_info->limits.arb_ps_instructions <= 512) 4611 4658 pCaps->VertexShaderVersion = WINED3DVS_VERSION(2,0); 4612 4659 else 4613 4660 pCaps->VertexShaderVersion = WINED3DVS_VERSION(3,0); 4614 4661 TRACE_(d3d_caps)("Hardware vertex shader version %d.%d enabled (GLSL)\n", (pCaps->VertexShaderVersion >> 8) & 0xff, pCaps->VertexShaderVersion & 0xff); 4615 pCaps->MaxVertexShaderConst = GL_LIMITS(vshader_constantsF);4662 pCaps->MaxVertexShaderConst = gl_info->limits.glsl_vs_float_constants; 4616 4663 4617 4664 /* Older DX9-class videocards (GeforceFX / Radeon >9500/X*00) only support pixel shader 2.0/2.0a/2.0b. … … 4627 4674 */ 4628 4675 if ((gl_info->supported[NV_FRAGMENT_PROGRAM] && !gl_info->supported[NV_FRAGMENT_PROGRAM2]) 4629 || (gl_info->ps_arb_max_instructions <= 512))4676 || gl_info->limits.arb_ps_instructions <= 512) 4630 4677 pCaps->PixelShaderVersion = WINED3DPS_VERSION(2,0); 4631 4678 else 4632 4679 pCaps->PixelShaderVersion = WINED3DPS_VERSION(3,0); 4633 4680 4634 pCaps->MaxPixelShaderConst = GL_LIMITS(pshader_constantsF);4681 pCaps->MaxPixelShaderConst = gl_info->limits.glsl_ps_float_constants; 4635 4682 4636 4683 /* FIXME: The following line is card dependent. -8.0 to 8.0 is the … … 4684 4731 /* WINED3DSIH_CND */ shader_glsl_cnd, 4685 4732 /* WINED3DSIH_CRS */ shader_glsl_cross, 4733 /* WINED3DSIH_CUT */ NULL, 4686 4734 /* WINED3DSIH_DCL */ NULL, 4687 4735 /* WINED3DSIH_DEF */ NULL, … … 4695 4743 /* WINED3DSIH_DSY */ shader_glsl_map2gl, 4696 4744 /* WINED3DSIH_ELSE */ shader_glsl_else, 4745 /* WINED3DSIH_EMIT */ NULL, 4697 4746 /* WINED3DSIH_ENDIF */ shader_glsl_end, 4698 4747 /* WINED3DSIH_ENDLOOP */ shader_glsl_end, … … 4701 4750 /* WINED3DSIH_EXPP */ shader_glsl_expp, 4702 4751 /* WINED3DSIH_FRC */ shader_glsl_map2gl, 4752 /* WINED3DSIH_IADD */ NULL, 4703 4753 /* WINED3DSIH_IF */ shader_glsl_if, 4704 4754 /* WINED3DSIH_IFC */ shader_glsl_ifc, 4755 /* WINED3DSIH_IGE */ NULL, 4705 4756 /* WINED3DSIH_LABEL */ shader_glsl_label, 4706 4757 /* WINED3DSIH_LIT */ shader_glsl_lit, … … 4709 4760 /* WINED3DSIH_LOOP */ shader_glsl_loop, 4710 4761 /* WINED3DSIH_LRP */ shader_glsl_lrp, 4762 /* WINED3DSIH_LT */ NULL, 4711 4763 /* WINED3DSIH_M3x2 */ shader_glsl_mnxn, 4712 4764 /* WINED3DSIH_M3x3 */ shader_glsl_mnxn, … … 4730 4782 /* WINED3DSIH_SETP */ NULL, 4731 4783 /* WINED3DSIH_SGE */ shader_glsl_compare, 4732 /* WINED3DSIH_SGN */ shader_glsl_ map2gl,4784 /* WINED3DSIH_SGN */ shader_glsl_sgn, 4733 4785 /* WINED3DSIH_SINCOS */ shader_glsl_sincos, 4734 4786 /* WINED3DSIH_SLT */ shader_glsl_compare,
Note:
See TracChangeset
for help on using the changeset viewer.