78 "dcl_hs_fork_phase_instance_count",
79 "dcl_hs_join_phase_instance_count",
80 "dcl_hs_max_tessfactor",
81 "dcl_immediateConstantBuffer",
85 "dcl_input_control_point_count",
94 "dcl_output_control_point_count",
98 "dcl_resource_structured",
102 "dcl_tessellator_domain",
103 "dcl_tessellator_output_primitive",
104 "dcl_tessellator_partitioning",
106 "dcl_tgsm_structured",
109 "dcl_uav_structured",
111 "dcl_maxOutputVertexCount",
153 "hs_control_point_phase",
169 "imm_atomic_cmp_exch",
170 "imm_atomic_consume",
347 return "UNRECOGNIZED";
386 e->semantic_idx =
s->usage_idx;
390 e->register_idx =
s->reg.reg.idx[0].offset;
391 e->mask =
s->reg.write_mask;
402 e->register_idx = reg_idx;
403 e->mask = write_mask;
417 WARN(
"Invalid byte code format %#x specified.\n",
format);
433 ERR(
"Failed to allocate shader buffer memory.\n");
449 unsigned int new_buffer_size =
buffer->buffer_size * 2;
451 while (rc > 0 && (
unsigned int)rc >= new_buffer_size -
buffer->content_size)
452 new_buffer_size *= 2;
455 ERR(
"Failed to grow buffer.\n");
459 buffer->buffer = new_buffer;
460 buffer->buffer_size = new_buffer_size;
471 if (rc < 0 || (
unsigned int)rc >= rem )
474 buffer->content_size += rc;
504 ERR(
"Couldn't allocate buffer for temporary string.\n");
571 switch (register_type)
578 FIXME(
"Unsupported register type: %u.\n", register_type);
594 static const struct limits_entry
597 unsigned int max_version;
603 {
WINED3D_SHADER_VERSION(1, 0),
WINED3D_SHADER_VERSION(1, 1), { 0, 0, 256, 0, 12, 0}},
604 {
WINED3D_SHADER_VERSION(2, 0),
WINED3D_SHADER_VERSION(2, 1), { 0, 16, 256, 16, 12, 0}},
610 {
WINED3D_SHADER_VERSION(3, 0),
WINED3D_SHADER_VERSION(3, 0), { 4, 16, 256, 16, 12, 0}},
611 {
WINED3D_SHADER_VERSION(4, 0),
WINED3D_SHADER_VERSION(4, 0), {16, 0, 0, 0, 16, 0}},
612 {
WINED3D_SHADER_VERSION(4, 1),
WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 32, 0}},
618 {
WINED3D_SHADER_VERSION(5, 0),
WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 32, 32}},
623 {
WINED3D_SHADER_VERSION(5, 0),
WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 32, 32}},
628 {
WINED3D_SHADER_VERSION(4, 0),
WINED3D_SHADER_VERSION(4, 0), {16, 0, 0, 0, 32, 16}},
629 {
WINED3D_SHADER_VERSION(4, 1),
WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 32, 32}},
635 {
WINED3D_SHADER_VERSION(1, 0),
WINED3D_SHADER_VERSION(1, 3), { 4, 0, 8, 0, 0, 0}},
636 {
WINED3D_SHADER_VERSION(1, 4),
WINED3D_SHADER_VERSION(1, 4), { 6, 0, 8, 0, 0, 0}},
637 {
WINED3D_SHADER_VERSION(2, 0),
WINED3D_SHADER_VERSION(2, 0), {16, 0, 32, 0, 0, 0}},
638 {
WINED3D_SHADER_VERSION(2, 1),
WINED3D_SHADER_VERSION(2, 1), {16, 16, 32, 16, 0, 0}},
639 {
WINED3D_SHADER_VERSION(3, 0),
WINED3D_SHADER_VERSION(3, 0), {16, 16, 224, 16, 0, 10}},
640 {
WINED3D_SHADER_VERSION(4, 0),
WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 0, 32}},
646 {
WINED3D_SHADER_VERSION(5, 0),
WINED3D_SHADER_VERSION(5, 0), {16, 0, 0, 0, 0, 0}},
648 const struct limits_entry *limits_array;
650 shader->reg_maps.shader_version.minor);
653 switch (
shader->reg_maps.shader_version.type)
656 FIXME(
"Unexpected shader type %u found.\n",
shader->reg_maps.shader_version.type);
659 limits_array = vs_limits;
662 limits_array = hs_limits;
665 limits_array = ds_limits;
668 limits_array = gs_limits;
671 limits_array = ps_limits;
674 limits_array = cs_limits;
680 if (shader_version <= limits_array[
i].max_version)
682 shader->limits = &limits_array[
i].limits;
689 FIXME(
"Unexpected shader version \"%u.%u\".\n",
690 shader->reg_maps.shader_version.major,
691 shader->reg_maps.shader_version.minor);
692 shader->limits = &limits_array[
max(0,
i - 1)].limits;
705 reg_maps->
address |= 1u <<
reg->idx[0].offset;
713 if (
reg->idx[0].rel_addr)
721 if (
reg->idx[0].rel_addr)
722 shader->u.ps.input_reg_used = ~0
u;
724 shader->u.ps.input_reg_used |= 1u <<
reg->idx[0].offset;
733 if (
reg->idx[0].offset == 1)
735 if (
reg->idx[0].offset == 2)
742 if (!
reg->idx[0].offset)
744 else if (
reg->idx[0].offset == 1)
750 if (
reg->idx[0].rel_addr)
760 if (
reg->idx[0].offset >=
min(
shader->limits->constant_float, constf_size))
762 WARN(
"Shader using float constant %u which is not supported.\n",
reg->idx[0].offset);
773 if (
reg->idx[0].offset >=
shader->limits->constant_int)
775 WARN(
"Shader using integer constant %u which is not supported.\n",
reg->idx[0].offset);
785 if (
reg->idx[0].offset >=
shader->limits->constant_bool)
787 WARN(
"Shader using bool constant %u which is not supported.\n",
reg->idx[0].offset);
797 reg_maps->
rt_mask |= (1u <<
reg->idx[0].offset);
805 TRACE(
"Not recording register of type %#x and [%#x][%#x].\n",
806 reg->type,
reg->idx[0].offset,
reg->idx[1].offset);
813 unsigned int resource_idx,
unsigned int sampler_idx,
unsigned int bind_idx)
823 if (
entries[
i].resource_idx == resource_idx &&
entries[
i].sampler_idx == sampler_idx)
831 ERR(
"Failed to allocate sampler map entries.\n");
839 size_t new_size =
map->
size * 2;
844 ERR(
"Failed to resize sampler map entries.\n");
852 entry->resource_idx = resource_idx;
853 entry->sampler_idx = sampler_idx;
854 entry->bind_idx = bind_idx;
863 return param == 1 ? 3 : 0;
867 return param == 1 ? 2 : 0;
870 return param == 1 ? 1 : 0;
878 unsigned int register_idx,
unsigned int size,
unsigned int stride)
884 ERR(
"Invalid TGSM register index %u.\n", register_idx);
889 FIXME(
"TGSM declarations are allowed only in compute shaders.\n");
894 register_idx + 1,
sizeof(*reg_maps->
tgsm)))
898 tgsm = ®_maps->
tgsm[register_idx];
906 const DWORD *current_instruction_ptr,
const DWORD *previous_instruction_ptr)
910 if ((phase = *current_phase))
912 phase->
end = previous_instruction_ptr;
913 *current_phase =
NULL;
918 ERR(
"Unexpected shader type %#x.\n",
shader->reg_maps.shader_version.type);
925 if (
shader->u.hs.phases.control_point)
927 FIXME(
"Multiple control point phases.\n");
930 if (!(
shader->u.hs.phases.control_point = heap_alloc_zero(
sizeof(*
shader->u.hs.phases.control_point))))
932 phase =
shader->u.hs.phases.control_point;
936 &
shader->u.hs.phases.fork_size,
shader->u.hs.phases.fork_count + 1,
937 sizeof(*
shader->u.hs.phases.fork)))
939 phase = &
shader->u.hs.phases.fork[
shader->u.hs.phases.fork_count++];
943 &
shader->u.hs.phases.join_size,
shader->u.hs.phases.join_count + 1,
944 sizeof(*
shader->u.hs.phases.join)))
946 phase = &
shader->u.hs.phases.join[
shader->u.hs.phases.join_count++];
953 phase->
start = current_instruction_ptr;
954 *current_phase = phase;
968 WARN(
"Invalid clip/cull distance index %u.\n",
e->semantic_idx);
980 FIXME(
"Unexpected interpolation mode %#x.\n",
mode);
993 unsigned int cur_loop_depth = 0, max_loop_depth = 0;
996 const DWORD *
ptr, *prev_ins, *current_ins;
997 void *fe_data =
shader->frontend_data;
1001 memset(reg_maps, 0,
sizeof(*reg_maps));
1002 memset(input_signature_elements, 0,
sizeof(input_signature_elements));
1003 memset(output_signature_elements, 0,
sizeof(output_signature_elements));
1008 prev_ins = current_ins =
ptr;
1014 sizeof(*reg_maps->
constf))))
1016 ERR(
"Failed to allocate constant map memory.\n");
1031 WARN(
"Encountered unrecognised or invalid instruction.\n");
1040 unsigned int reg_idx = semantic->
reg.reg.idx[0].offset;
1042 switch (semantic->
reg.reg.type)
1048 ERR(
"Invalid input register index %u.\n", reg_idx);
1062 ERR(
"Invalid output register index %u.\n", reg_idx);
1078 ERR(
"Invalid resource index %u.\n", reg_idx);
1088 ERR(
"Invalid UAV resource index %u.\n", reg_idx);
1094 FIXME(
"Ignoring typed UAV flags %#x.\n", ins.
flags);
1098 TRACE(
"Not recording DCL register type %#x.\n", semantic->
reg.reg.type);
1106 ERR(
"Invalid CB index %u.\n",
reg->idx[0].offset);
1115 shader->u.ps.force_early_depth_stencil =
TRUE;
1117 FIXME(
"Invalid instruction %#x for shader type %#x.\n",
1122 WARN(
"Ignoring global flags %#x.\n", ins.
flags);
1130 FIXME(
"Invalid instruction %#x for shader type %#x.\n",
1139 FIXME(
"Instruction %s outside of shader phase.\n",
1145 FIXME(
"Multiple immediate constant buffers.\n");
1152 FIXME(
"Indexable temporary registers not supported.\n");
1170 FIXME(
"Invalid instruction %#x for shader type %#x.\n",
1178 ERR(
"Invalid register index %u.\n", reg_idx);
1184 FIXME(
"Invalid instruction %#x for shader type %#x.\n",
1196 FIXME(
"Invalid instruction %#x for shader type %#x.\n",
1212 FIXME(
"Invalid instruction %#x for shader type %#x.\n",
1220 ERR(
"Invalid resource index %u.\n", reg_idx);
1232 ERR(
"Invalid resource index %u.\n", reg_idx);
1295 FIXME(
"Invalid instruction %#x for shader type %#x.\n",
1304 ERR(
"Invalid UAV resource index %u.\n", reg_idx);
1308 FIXME(
"Ignoring raw UAV flags %#x.\n", ins.
flags);
1318 ERR(
"Invalid UAV resource index %u.\n", reg_idx);
1322 FIXME(
"Ignoring structured UAV flags %#x.\n", ins.
flags);
1333 FIXME(
"Invalid instruction %#x for shader type %#x.\n",
1344 lconst->
idx = ins.
dst[0].reg.idx[0].offset;
1376 lconst->
idx = ins.
dst[0].reg.idx[0].offset;
1389 lconst->
idx = ins.
dst[0].reg.idx[0].offset;
1406 reg_maps->
labels |= 1u << ins.
src[0].reg.idx[0].offset;
1423 shader_version.
type, constf_size))
1430 switch (ins.
dst[
i].reg.type)
1433 if (shader_version.
major >= 3)
1458 if (shader_version.
major >= 3)
1465 output_signature_elements[
idx].
mask |= ins.
dst[
i].write_mask;
1477 if (shader_version.
major >= 3)
1481 WARN(
"Invalid output register index %u.\n",
idx);
1489 WARN(
"Invalid texcoord index %u.\n",
idx);
1495 output_signature_elements[
idx].
mask |= ins.
dst[
i].write_mask;
1533 && ins.
dst[
i].reg.idx[0].offset ==
shader->u.ps.color0_reg)
1540 if (shader_version.
major == 1
1553 unsigned int reg_idx = ins.
dst[
i].reg.idx[0].offset;
1557 WARN(
"Invalid 1.x sampler index %u.\n", reg_idx);
1561 TRACE(
"Setting fake 2D resource for 1.x pixelshader.\n");
1570 reg_maps->
bumpmat |= 1u << reg_idx;
1579 reg_maps->
bumpmat |= 1u << ins.
dst[
i].reg.idx[0].offset;
1585 unsigned int reg_idx = ins.
src[0].reg.idx[0].offset;
1588 ERR(
"Invalid UAV index %u.\n", reg_idx);
1600 unsigned int reg_idx;
1602 reg_idx = ins.
src[1].reg.idx[0].offset;
1604 reg_idx = ins.
src[2].reg.idx[0].offset;
1606 reg_idx = ins.
dst[0].reg.idx[0].offset;
1608 reg_idx = ins.
src[0].reg.idx[0].offset;
1610 reg_idx = ins.
dst[1].reg.idx[0].offset;
1613 ERR(
"Invalid UAV index %u.\n", reg_idx);
1644 if (cur_loop_depth > max_loop_depth)
1645 max_loop_depth = cur_loop_depth;
1692 shader_version.
type, constf_size))
1701 shader_version.
type, constf_size))
1705 ++
reg.idx[0].offset;
1707 shader_version.
type, constf_size))
1718 shader->u.ps.color0_reg = ins.
src[
i].reg.idx[0].offset;
1724 prev_ins = current_ins;
1730 phase->
end = prev_ins;
1737 reg_maps->
rt_mask |= (1u << 0);
1747 WARN(
"Invalid input signature register index %u.\n", input_signature->
elements[
i].register_idx);
1777 *
e++ = input_signature_elements[
i];
1817 *
e++ = output_signature_elements[
i];
1842 map &= reg_maps->
shader_version.major < 3 ? ~reg_maps->texcoord : ~reg_maps->input_registers;
1852 global_flags &= ~WINED3DSGF_REFACTORING_ALLOWED;
1860 global_flags &= ~WINED3DSGF_FORCE_EARLY_DEPTH_STENCIL;
1868 global_flags &= ~WINED3DSGF_ENABLE_RAW_AND_STRUCTURED_BUFFERS;
1880 sync_flags &= ~WINED3DSSF_GROUP_SHARED_MEMORY;
1885 sync_flags &= ~WINED3DSSF_THREAD_GROUP;
1897 uav_flags &= ~WINED3DSUF_GLOBALLY_COHERENT;
1902 uav_flags &= ~WINED3DSUF_ORDER_PRESERVING_COUNTER;
1932 switch (output_primitive)
1955 switch (partitioning)
2108 switch (semantic->
usage)
2171 FIXME(
"Unrecognised semantic usage %#x.\n", semantic->
usage);
2179 static const char *
const rastout_reg_names[] = {
"oPos",
"oFog",
"oPts"};
2180 static const char *
const misctype_reg_names[] = {
"vPos",
"vFace"};
2232 if (shader_version->
major >= 3)
2261 FIXME(
"Unhandled misctype register %u.\n",
offset);
2386 switch (
reg->immconst_type)
2389 switch (
reg->data_type)
2409 switch (
reg->data_type)
2413 *(
const float *)&
reg->u.immconst_data[0], *(
const float *)&
reg->u.immconst_data[1],
2414 *(
const float *)&
reg->u.immconst_data[2], *(
const float *)&
reg->u.immconst_data[3]);
2418 reg->u.immconst_data[0],
reg->u.immconst_data[1],
2419 reg->u.immconst_data[2],
reg->u.immconst_data[3]);
2425 reg->u.immconst_data[0],
reg->u.immconst_data[1],
2426 reg->u.immconst_data[2],
reg->u.immconst_data[3]);
2447 if (
reg->idx[0].rel_addr)
2454 if (
reg->idx[1].offset != ~0
u)
2457 if (
reg->idx[1].rel_addr)
2480 static const char write_mask_chars[] =
"xyzw";
2516 switch (src_modifier)
2537 static const char swizzle_chars[] =
"xyzw";
2543 if (swizzle_x == swizzle_y
2544 && swizzle_x == swizzle_z
2545 && swizzle_x == swizzle_w)
2552 swizzle_chars[swizzle_z], swizzle_chars[swizzle_w]);
2564 void *fe_data =
shader->frontend_data;
2574 state.current_loop_depth = 0;
2575 state.current_loop_reg = 0;
2579 ctx.gl_info = &
device->adapter->gl_info;
2584 ctx.backend_data = backend_ctx;
2599 WARN(
"Encountered unrecognised or invalid instruction.\n");
2604 FIXME(
"Predicates not implemented.\n");
2607 device->shader_backend->shader_handle_instruction(&ins);
2635 if (mmask)
FIXME(
"Unrecognised modifier %#x.\n", mmask);
2641 switch (primitive_type->
type)
2688 switch (interpolation_mode)
2721 const char *type_prefix;
2728 ERR(
"Failed to initialize string buffer.\n");
2736 switch (shader_version.
type)
2763 FIXME(
"Unhandled shader type %#x.\n", shader_version.
type);
2764 type_prefix =
"unknown";
2777 WARN(
"Skipping unrecognized instruction.\n");
2967 ins.
dst[0].reg.idx[0].offset),
2968 *(
const float *)&ins.
src[0].reg.u.immconst_data[0],
2969 *(
const float *)&ins.
src[0].reg.u.immconst_data[1],
2970 *(
const float *)&ins.
src[0].reg.u.immconst_data[2],
2971 *(
const float *)&ins.
src[0].reg.u.immconst_data[3]);
2976 ins.
src[0].reg.u.immconst_data[0],
2977 ins.
src[0].reg.u.immconst_data[1],
2978 ins.
src[0].reg.u.immconst_data[2],
2979 ins.
src[0].reg.u.immconst_data[3]);
2984 ins.
dst[0].reg.idx[0].offset, ins.
src[0].reg.u.immconst_data[0] ?
"true" :
"false");
3029 && shader_version.
major >= 2
3105 shader->device->shader_backend->shader_destroy(
shader);
3168 void *vertex_priv, *fragment_priv;
3176 ERR(
"Failed to initialize vertex pipe.\n");
3183 ERR(
"Failed to initialize fragment pipe.\n");
3194 device->vertex_priv = vertex_priv;
3195 device->fragment_priv = fragment_priv;
3196 device->shader_priv = priv;
3272 unsigned int backend_version;
3275 TRACE(
"shader %p, float_const_count %u, type %#x, max_version %u.\n",
3276 shader, float_const_count,
type, max_version);
3282 FIXME(
"Failed to initialize frontend.\n");
3292 &
shader->output_signature, float_const_count)))
3302 WARN(
"Shader version %d not supported by this D3D API version.\n", reg_maps->
shader_version.major);
3308 backend_version = d3d_info->
limits.vs_version;
3311 backend_version = d3d_info->
limits.hs_version;
3314 backend_version = d3d_info->
limits.ds_version;
3317 backend_version = d3d_info->
limits.gs_version;
3320 backend_version = d3d_info->
limits.ps_version;
3323 backend_version = d3d_info->
limits.cs_version;
3326 FIXME(
"No backend version-checking for this shader type.\n");
3327 backend_version = 0;
3331 WARN(
"Shader version %d.%d not supported by your GPU with the current shader backend.\n",
3343 TRACE(
"%p increasing refcount to %u.\n",
shader, refcount);
3368 TRACE(
"%p decreasing refcount to %u.\n",
shader, refcount);
3372 shader->parent_ops->wined3d_object_destroyed(
shader->parent);
3387 void *byte_code,
UINT *byte_code_size)
3389 TRACE(
"shader %p, byte_code %p, byte_code_size %p.\n",
shader, byte_code, byte_code_size);
3393 *byte_code_size =
shader->functionLength;
3397 if (*byte_code_size < shader->functionLength)
3417 TRACE(
"shader %p, start_idx %u, src_data %p, count %u.\n",
shader, start_idx, src_data,
count);
3419 if (end_idx >
shader->limits->constant_float)
3421 WARN(
"end_idx %u > float constants limit %u.\n",
3422 end_idx,
shader->limits->constant_float);
3423 end_idx =
shader->limits->constant_float;
3426 for (
i = start_idx;
i < end_idx; ++
i)
3453 || !pixel_shader || pixel_shader->
reg_maps.shader_version.major < 4)
3455 memset(interpolation_args, 0,
sizeof(pixel_shader->
u.
ps.interpolation_mode));
3459 memcpy(interpolation_args, pixel_shader->
u.
ps.interpolation_mode,
3460 sizeof(pixel_shader->
u.
ps.interpolation_mode));
3477 args->per_vertex_point_size =
shader->reg_maps.point_size;
3480 if (
shader->reg_maps.shader_version.major >= 4)
3481 args->next_shader_input_count = hull_shader ? hull_shader->
limits->packed_input
3482 : geometry_shader ? geometry_shader->
limits->packed_input
3483 : pixel_shader ? pixel_shader->
limits->packed_input : 0;
3485 args->next_shader_input_count = 0;
3486 args->swizzle_map = swizzle_map;
3490 args->flatshading = 0;
3498 if (usage_idx1 != usage_idx2)
3500 if (usage1 == usage2)
3511 BYTE usage_req,
BYTE usage_idx_req,
unsigned int *regnum)
3518 if (!(
map & 1))
continue;
3521 shader->u.vs.attributes[
i].usage_idx, usage_req, usage_idx_req))
3557 if (!
src->element_count)
3560 ptr = *signature_strings;
3562 dst->element_count =
src->element_count;
3566 for (
i = 0;
i <
src->element_count; ++
i)
3568 e = &
src->elements[
i];
3569 dst->elements[
i] = *
e;
3573 dst->elements[
i].semantic_name =
ptr;
3577 *signature_strings =
ptr;
3586 size_t byte_code_size;
3591 TRACE(
"byte_code %p, byte_code_size %#lx, format %#x, max_version %#x.\n",
3592 desc->byte_code, (
long)
desc->byte_code_size,
desc->format,
desc->max_version);
3594 if (!
desc->byte_code)
3599 FIXME(
"Unable to find frontend for shader.\n");
3606 shader->parent_ops = parent_ops;
3646 byte_code_size =
desc->byte_code_size;
3647 if (byte_code_size == ~(
size_t)0)
3657 WARN(
"Failed to initialise frontend data.\n");
3668 byte_code_size = (
ptr -
desc->byte_code) *
sizeof(*
ptr);
3677 shader->functionLength = byte_code_size;
3681 WARN(
"Failed to set function, hr %#x.\n",
hr);
3686 shader->load_local_constsF =
shader->lconst_inf_or_nan;
3704 for (
i = 0;
i <
shader->input_signature.element_count; ++
i)
3711 shader->u.vs.attributes[
input->register_idx].usage =
3713 shader->u.vs.attributes[
input->register_idx].usage_idx =
input->semantic_idx;