mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-01-28 13:05:02 -08:00
vkd3d-shader/hlsl: Write data types into the RDEF section.
Signed-off-by: Zebediah Figura <zfigura@codeweavers.com> Signed-off-by: Matteo Bruni <mbruni@codeweavers.com> Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
f402f7042e
commit
b89b02d21f
@ -115,6 +115,19 @@ typedef enum _D3D_SHADER_INPUT_TYPE
|
||||
D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER,
|
||||
} D3D_SHADER_INPUT_TYPE;
|
||||
|
||||
typedef enum _D3D_SHADER_VARIABLE_CLASS
|
||||
{
|
||||
D3D_SVC_SCALAR,
|
||||
D3D_SVC_VECTOR,
|
||||
D3D_SVC_MATRIX_ROWS,
|
||||
D3D_SVC_MATRIX_COLUMNS,
|
||||
D3D_SVC_OBJECT,
|
||||
D3D_SVC_STRUCT,
|
||||
D3D_SVC_INTERFACE_CLASS,
|
||||
D3D_SVC_INTERFACE_POINTER,
|
||||
D3D_SVC_FORCE_DWORD = 0x7fffffff,
|
||||
} D3D_SHADER_VARIABLE_CLASS;
|
||||
|
||||
typedef enum _D3D_SHADER_VARIABLE_FLAGS
|
||||
{
|
||||
D3D_SVF_USERPACKED = 0x01,
|
||||
@ -124,6 +137,63 @@ typedef enum _D3D_SHADER_VARIABLE_FLAGS
|
||||
D3D_SVF_FORCE_DWORD = 0x7fffffff,
|
||||
} D3D_SHADER_VARIABLE_FLAGS;
|
||||
|
||||
typedef enum _D3D_SHADER_VARIABLE_TYPE
|
||||
{
|
||||
D3D_SVT_VOID,
|
||||
D3D_SVT_BOOL,
|
||||
D3D_SVT_INT,
|
||||
D3D_SVT_FLOAT,
|
||||
D3D_SVT_STRING,
|
||||
D3D_SVT_TEXTURE,
|
||||
D3D_SVT_TEXTURE1D,
|
||||
D3D_SVT_TEXTURE2D,
|
||||
D3D_SVT_TEXTURE3D,
|
||||
D3D_SVT_TEXTURECUBE,
|
||||
D3D_SVT_SAMPLER,
|
||||
D3D_SVT_SAMPLER1D,
|
||||
D3D_SVT_SAMPLER2D,
|
||||
D3D_SVT_SAMPLER3D,
|
||||
D3D_SVT_SAMPLERCUBE,
|
||||
D3D_SVT_PIXELSHADER,
|
||||
D3D_SVT_VERTEXSHADER,
|
||||
D3D_SVT_PIXELFRAGMENT,
|
||||
D3D_SVT_VERTEXFRAGMENT,
|
||||
D3D_SVT_UINT,
|
||||
D3D_SVT_UINT8,
|
||||
D3D_SVT_GEOMETRYSHADER,
|
||||
D3D_SVT_RASTERIZER,
|
||||
D3D_SVT_DEPTHSTENCIL,
|
||||
D3D_SVT_BLEND,
|
||||
D3D_SVT_BUFFER,
|
||||
D3D_SVT_CBUFFER,
|
||||
D3D_SVT_TBUFFER,
|
||||
D3D_SVT_TEXTURE1DARRAY,
|
||||
D3D_SVT_TEXTURE2DARRAY,
|
||||
D3D_SVT_RENDERTARGETVIEW,
|
||||
D3D_SVT_DEPTHSTENCILVIEW,
|
||||
D3D_SVT_TEXTURE2DMS,
|
||||
D3D_SVT_TEXTURE2DMSARRAY,
|
||||
D3D_SVT_TEXTURECUBEARRAY,
|
||||
D3D_SVT_HULLSHADER,
|
||||
D3D_SVT_DOMAINSHADER,
|
||||
D3D_SVT_INTERFACE_POINTER,
|
||||
D3D_SVT_COMPUTESHADER,
|
||||
D3D_SVT_DOUBLE,
|
||||
D3D_SVT_RWTEXTURE1D,
|
||||
D3D_SVT_RWTEXTURE1DARRAY,
|
||||
D3D_SVT_RWTEXTURE2D,
|
||||
D3D_SVT_RWTEXTURE2DARRAY,
|
||||
D3D_SVT_RWTEXTURE3D,
|
||||
D3D_SVT_RWBUFFER,
|
||||
D3D_SVT_BYTEADDRESS_BUFFER,
|
||||
D3D_SVT_RWBYTEADDRESS_BUFFER,
|
||||
D3D_SVT_STRUCTURED_BUFFER,
|
||||
D3D_SVT_RWSTRUCTURED_BUFFER,
|
||||
D3D_SVT_APPEND_STRUCTURED_BUFFER,
|
||||
D3D_SVT_CONSUME_STRUCTURED_BUFFER,
|
||||
D3D_SVT_FORCE_DWORD = 0x7fffffff,
|
||||
} D3D_SHADER_VARIABLE_TYPE;
|
||||
|
||||
[
|
||||
uuid(8ba5fb08-5195-40e2-ac58-0d989c3a0102),
|
||||
object,
|
||||
|
@ -23,14 +23,155 @@
|
||||
#include "vkd3d_d3dcommon.h"
|
||||
#include "sm4.h"
|
||||
|
||||
static const struct hlsl_type *get_array_type(const struct hlsl_type *type)
|
||||
{
|
||||
if (type->type == HLSL_CLASS_ARRAY)
|
||||
return get_array_type(type->e.array.type);
|
||||
return type;
|
||||
}
|
||||
|
||||
static unsigned int get_array_size(const struct hlsl_type *type)
|
||||
{
|
||||
if (type->type == HLSL_CLASS_ARRAY)
|
||||
return get_array_size(type->e.array.type) * type->e.array.elements_count;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static D3D_SHADER_VARIABLE_CLASS sm4_class(const struct hlsl_type *type)
|
||||
{
|
||||
switch (type->type)
|
||||
{
|
||||
case HLSL_CLASS_ARRAY:
|
||||
return sm4_class(type->e.array.type);
|
||||
case HLSL_CLASS_MATRIX:
|
||||
assert(type->modifiers & HLSL_MODIFIERS_MAJORITY_MASK);
|
||||
if (type->modifiers & HLSL_MODIFIER_COLUMN_MAJOR)
|
||||
return D3D_SVC_MATRIX_COLUMNS;
|
||||
else
|
||||
return D3D_SVC_MATRIX_ROWS;
|
||||
case HLSL_CLASS_OBJECT:
|
||||
return D3D_SVC_OBJECT;
|
||||
case HLSL_CLASS_SCALAR:
|
||||
return D3D_SVC_SCALAR;
|
||||
case HLSL_CLASS_STRUCT:
|
||||
return D3D_SVC_STRUCT;
|
||||
case HLSL_CLASS_VECTOR:
|
||||
return D3D_SVC_VECTOR;
|
||||
default:
|
||||
ERR("Invalid class %#x.\n", type->type);
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static D3D_SHADER_VARIABLE_TYPE sm4_base_type(const struct hlsl_type *type)
|
||||
{
|
||||
switch (type->base_type)
|
||||
{
|
||||
case HLSL_TYPE_BOOL:
|
||||
return D3D_SVT_BOOL;
|
||||
case HLSL_TYPE_FLOAT:
|
||||
case HLSL_TYPE_HALF:
|
||||
return D3D_SVT_FLOAT;
|
||||
case HLSL_TYPE_INT:
|
||||
return D3D_SVT_INT;
|
||||
case HLSL_TYPE_PIXELSHADER:
|
||||
return D3D_SVT_PIXELSHADER;
|
||||
case HLSL_TYPE_SAMPLER:
|
||||
switch (type->sampler_dim)
|
||||
{
|
||||
case HLSL_SAMPLER_DIM_1D:
|
||||
return D3D_SVT_SAMPLER1D;
|
||||
case HLSL_SAMPLER_DIM_2D:
|
||||
return D3D_SVT_SAMPLER2D;
|
||||
case HLSL_SAMPLER_DIM_3D:
|
||||
return D3D_SVT_SAMPLER3D;
|
||||
case HLSL_SAMPLER_DIM_CUBE:
|
||||
return D3D_SVT_SAMPLERCUBE;
|
||||
case HLSL_SAMPLER_DIM_GENERIC:
|
||||
return D3D_SVT_SAMPLER;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
break;
|
||||
case HLSL_TYPE_STRING:
|
||||
return D3D_SVT_STRING;
|
||||
case HLSL_TYPE_TEXTURE:
|
||||
switch (type->sampler_dim)
|
||||
{
|
||||
case HLSL_SAMPLER_DIM_1D:
|
||||
return D3D_SVT_TEXTURE1D;
|
||||
case HLSL_SAMPLER_DIM_2D:
|
||||
return D3D_SVT_TEXTURE2D;
|
||||
case HLSL_SAMPLER_DIM_3D:
|
||||
return D3D_SVT_TEXTURE3D;
|
||||
case HLSL_SAMPLER_DIM_CUBE:
|
||||
return D3D_SVT_TEXTURECUBE;
|
||||
case HLSL_SAMPLER_DIM_GENERIC:
|
||||
return D3D_SVT_TEXTURE;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
break;
|
||||
case HLSL_TYPE_UINT:
|
||||
return D3D_SVT_UINT;
|
||||
case HLSL_TYPE_VERTEXSHADER:
|
||||
return D3D_SVT_VERTEXSHADER;
|
||||
case HLSL_TYPE_VOID:
|
||||
return D3D_SVT_VOID;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void write_sm4_type(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buffer, struct hlsl_type *type)
|
||||
{
|
||||
const struct hlsl_type *array_type = get_array_type(type);
|
||||
unsigned int field_count = 0, array_size = 0;
|
||||
struct hlsl_struct_field *field;
|
||||
size_t fields_offset = 0;
|
||||
|
||||
if (type->bytecode_offset)
|
||||
return;
|
||||
|
||||
if (type->type == HLSL_CLASS_ARRAY)
|
||||
array_size = get_array_size(type);
|
||||
|
||||
if (array_type->type == HLSL_CLASS_STRUCT)
|
||||
{
|
||||
LIST_FOR_EACH_ENTRY(field, array_type->e.elements, struct hlsl_struct_field, entry)
|
||||
{
|
||||
field->name_bytecode_offset = put_string(buffer, field->name);
|
||||
write_sm4_type(ctx, buffer, field->type);
|
||||
}
|
||||
|
||||
fields_offset = bytecode_get_size(buffer);
|
||||
|
||||
LIST_FOR_EACH_ENTRY(field, array_type->e.elements, struct hlsl_struct_field, entry)
|
||||
{
|
||||
put_u32(buffer, field->name_bytecode_offset);
|
||||
put_u32(buffer, field->type->bytecode_offset);
|
||||
put_u32(buffer, field->reg_offset);
|
||||
++field_count;
|
||||
}
|
||||
}
|
||||
|
||||
type->bytecode_offset = put_u32(buffer, sm4_class(type) | (sm4_base_type(type) << 16));
|
||||
put_u32(buffer, type->dimy | (type->dimx << 16));
|
||||
put_u32(buffer, array_size | (field_count << 16));
|
||||
put_u32(buffer, fields_offset);
|
||||
}
|
||||
|
||||
static void write_sm4_rdef(struct hlsl_ctx *ctx, struct dxbc_writer *dxbc)
|
||||
{
|
||||
size_t cbuffers_offset, resources_offset, creator_offset, string_offset;
|
||||
size_t cbuffer_position, resource_position, creator_position;
|
||||
const struct hlsl_profile_info *profile = ctx->profile;
|
||||
struct vkd3d_bytecode_buffer buffer = {0};
|
||||
unsigned int cbuffer_count = 0, i, j;
|
||||
const struct hlsl_buffer *cbuffer;
|
||||
unsigned int cbuffer_count = 0, i;
|
||||
|
||||
static const uint16_t target_types[] =
|
||||
{
|
||||
@ -150,10 +291,25 @@ static void write_sm4_rdef(struct hlsl_ctx *ctx, struct dxbc_writer *dxbc)
|
||||
put_u32(&buffer, var->buffer_offset);
|
||||
put_u32(&buffer, var->data_type->reg_size * sizeof(float));
|
||||
put_u32(&buffer, flags);
|
||||
put_u32(&buffer, 0); /* FIXME: type */
|
||||
put_u32(&buffer, 0); /* type */
|
||||
put_u32(&buffer, 0); /* FIXME: default value */
|
||||
}
|
||||
}
|
||||
|
||||
j = 0;
|
||||
LIST_FOR_EACH_ENTRY(var, &ctx->extern_vars, struct hlsl_ir_var, extern_entry)
|
||||
{
|
||||
if (var->is_uniform && var->buffer == cbuffer)
|
||||
{
|
||||
size_t var_offset = vars_start + j * 6 * sizeof(uint32_t);
|
||||
size_t string_offset = put_string(&buffer, var->name);
|
||||
|
||||
set_u32(&buffer, var_offset, string_offset);
|
||||
write_sm4_type(ctx, &buffer, var->data_type);
|
||||
set_u32(&buffer, var_offset + 4 * sizeof(uint32_t), var->data_type->bytecode_offset);
|
||||
++j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
creator_offset = put_string(&buffer, vkd3d_shader_get_version(NULL, NULL));
|
||||
|
Loading…
x
Reference in New Issue
Block a user