Signed-off-by: Zebediah Figura z.figura12@gmail.com --- include/vkd3d_shader.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/include/vkd3d_shader.h b/include/vkd3d_shader.h index 16db0283..044eeb99 100644 --- a/include/vkd3d_shader.h +++ b/include/vkd3d_shader.h @@ -961,7 +961,7 @@ struct vkd3d_shader_signature unsigned int element_count; };
-/* swizzle bits fields: wwzzyyxx */ +/** Possible values for a single component of a vkd3d-shader swizzle. */ enum vkd3d_shader_swizzle_component { VKD3D_SHADER_SWIZZLE_X = 0x0, @@ -972,17 +972,33 @@ enum vkd3d_shader_swizzle_component VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_SWIZZLE_COMPONENT), };
+/** + * A mask selecting one component from a vkd3d-shader swizzle. The component has + * type \ref vkd3d_shader_swizzle_component. + */ #define VKD3D_SHADER_SWIZZLE_MASK (0xffu) +/** The offset, in bits, of the nth parameter of a vkd3d-shader swizzle. */ #define VKD3D_SHADER_SWIZZLE_SHIFT(idx) (8u * (idx))
+/** + * A helper macro which returns a vkd3d-shader swizzle with the given + * components. The components are specified as the suffixes to members of + * \ref vkd3d_shader_swizzle_component. For example, the swizzle ".xwyy" can be + * represented as: + * \code + * VKD3D_SHADER_SWIZZLE(X, W, Y, Y) + * \endcode + */ #define VKD3D_SHADER_SWIZZLE(x, y, z, w) \ vkd3d_shader_create_swizzle(VKD3D_SHADER_SWIZZLE_ ## x, \ VKD3D_SHADER_SWIZZLE_ ## y, \ VKD3D_SHADER_SWIZZLE_ ## z, \ VKD3D_SHADER_SWIZZLE_ ## w)
+/** The identity swizzle ".xyzw". */ #define VKD3D_SHADER_NO_SWIZZLE VKD3D_SHADER_SWIZZLE(X, Y, Z, W)
+/** Build a vkd3d-shader swizzle with the given components. */ static inline uint32_t vkd3d_shader_create_swizzle(enum vkd3d_shader_swizzle_component x, enum vkd3d_shader_swizzle_component y, enum vkd3d_shader_swizzle_component z, enum vkd3d_shader_swizzle_component w)
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- include/vkd3d_shader.h | 77 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 2 deletions(-)
diff --git a/include/vkd3d_shader.h b/include/vkd3d_shader.h index 044eeb99..d1830889 100644 --- a/include/vkd3d_shader.h +++ b/include/vkd3d_shader.h @@ -840,61 +840,125 @@ struct vkd3d_shader_versioned_root_signature_desc } u; };
+/** + * The type of a shader resource, returned as part of struct + * vkd3d_shader_descriptor_info. + */ enum vkd3d_shader_resource_type { + /** + * The type is invalid or not applicable for this descriptor. This value is + * returned for samplers. + */ VKD3D_SHADER_RESOURCE_NONE = 0x0, + /** Dimensionless buffer. */ VKD3D_SHADER_RESOURCE_BUFFER = 0x1, + /** 1-dimensional texture. */ VKD3D_SHADER_RESOURCE_TEXTURE_1D = 0x2, + /** 2-dimensional texture. */ VKD3D_SHADER_RESOURCE_TEXTURE_2D = 0x3, + /** Multisampled 2-dimensional texture. */ VKD3D_SHADER_RESOURCE_TEXTURE_2DMS = 0x4, + /** 3-dimensional texture. */ VKD3D_SHADER_RESOURCE_TEXTURE_3D = 0x5, + /** Cubemap texture. */ VKD3D_SHADER_RESOURCE_TEXTURE_CUBE = 0x6, + /** 1-dimensional array texture. */ VKD3D_SHADER_RESOURCE_TEXTURE_1DARRAY = 0x7, + /** 2-dimensional array texture. */ VKD3D_SHADER_RESOURCE_TEXTURE_2DARRAY = 0x8, + /** Multisampled 2-dimensional array texture. */ VKD3D_SHADER_RESOURCE_TEXTURE_2DMSARRAY = 0x9, + /** Cubemap array texture. */ VKD3D_SHADER_RESOURCE_TEXTURE_CUBEARRAY = 0xa,
VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_RESOURCE_TYPE), };
+/** + * The type of the data contained in a shader resource, returned as part of + * struct vkd3d_shader_descriptor_info. All formats are 32-bit. + */ enum vkd3d_shader_resource_data_type { + /** Unsigned normalized integer. */ VKD3D_SHADER_RESOURCE_DATA_UNORM = 0x1, + /** Signed normalized integer. */ VKD3D_SHADER_RESOURCE_DATA_SNORM = 0x2, + /** Signed integer. */ VKD3D_SHADER_RESOURCE_DATA_INT = 0x3, + /** Unsigned integer. */ VKD3D_SHADER_RESOURCE_DATA_UINT = 0x4, + /** IEEE floating-point. */ VKD3D_SHADER_RESOURCE_DATA_FLOAT = 0x5,
VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_RESOURCE_DATA_TYPE), };
+/** + * Additional flags describing a shader descriptor, returned as part of struct + * vkd3d_shader_descriptor_info. + */ enum vkd3d_shader_descriptor_info_flag { + /** + * The descriptor is a UAV resource, whose counter is read from or written + * to by the shader. + */ VKD3D_SHADER_DESCRIPTOR_INFO_FLAG_UAV_COUNTER = 0x00000001, + /** The descriptor is a UAV resource, which is read from by the shader. */ VKD3D_SHADER_DESCRIPTOR_INFO_FLAG_UAV_READ = 0x00000002, + /** The descriptor is a comparison sampler. */ VKD3D_SHADER_DESCRIPTOR_INFO_FLAG_SAMPLER_COMPARISON_MODE = 0x00000004,
VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_DESCRIPTOR_INFO_FLAG), };
+/** + * Describes a single shader descriptor; returned as part of + * struct vkd3d_shader_scan_descriptor_info. + */ struct vkd3d_shader_descriptor_info { + /** Type of the descriptor (for example, SRV, CBV, UAV, or sampler). */ enum vkd3d_shader_descriptor_type type; + /** + * Register space of the resource, or 0 if the shader does not + * support multiple register spaces. + */ unsigned int register_space; + /** Register index of the descriptor. */ unsigned int register_index; + /** Resource type, if applicable, including its dimension. */ enum vkd3d_shader_resource_type resource_type; + /** Data type contained in the resource (for example, float or integer). */ enum vkd3d_shader_resource_data_type resource_data_type; - unsigned int flags; /* vkd3d_shader_descriptor_info_flag */ + /** + * Bitwise combination of zero or more members of + * \ref vkd3d_shader_descriptor_info_flag. + */ + unsigned int flags; + /** Size of this descriptor array, or 1 if a single descriptor. */ unsigned int count; };
-/* Extends vkd3d_shader_compile_info. */ +/** + * A chained structure enumerating the descriptors declared by a shader. + * + * This structure extends vkd3d_shader_compile_info. + */ struct vkd3d_shader_scan_descriptor_info { + /** + * Input; must be set to VKD3D_SHADER_STRUCTURE_TYPE_SCAN_DESCRIPTOR_INFO. + */ enum vkd3d_shader_structure_type type; + /** Input; optional pointer to a structure containing further parameters. */ const void *next;
+ /** Output; returns a pointer to an array of descriptors. */ struct vkd3d_shader_descriptor_info *descriptors; + /** Output; size, in elements, of \ref descriptors. */ unsigned int descriptor_count; };
@@ -1235,6 +1299,15 @@ int vkd3d_shader_convert_root_signature(struct vkd3d_shader_versioned_root_signa * \return A member of \ref vkd3d_result. */ int vkd3d_shader_scan(const struct vkd3d_shader_compile_info *compile_info, char **messages); +/** + * Free members of struct vkd3d_shader_scan_descriptor_info() allocated by + * vkd3d_shader_scan(). + * + * This function may free members of vkd3d_shader_scan_descriptor_info, but + * does not free the structure itself. + * + * \param scan_descriptor_info Descriptor information to free. + */ void vkd3d_shader_free_scan_descriptor_info(struct vkd3d_shader_scan_descriptor_info *scan_descriptor_info);
int vkd3d_shader_parse_input_signature(const struct vkd3d_shader_code *dxbc,
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- include/vkd3d_shader.h | 52 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)
diff --git a/include/vkd3d_shader.h b/include/vkd3d_shader.h index d1830889..0eaa0f1f 100644 --- a/include/vkd3d_shader.h +++ b/include/vkd3d_shader.h @@ -1310,11 +1310,63 @@ int vkd3d_shader_scan(const struct vkd3d_shader_compile_info *compile_info, char */ void vkd3d_shader_free_scan_descriptor_info(struct vkd3d_shader_scan_descriptor_info *scan_descriptor_info);
+/** + * Read the input signature of a compiled shader, returning a structural + * description which can be easily parsed by C code. + * + * This function parses a compiled shader. To parse a standalone root signature, + * use vkd3d_shader_parse_root_signature(). + * + * \param dxbc Compiled byte code, in DXBC format. + * + * \param signature Output location in which the parsed root signature will be + * stored. + * \n + * Members of \a signature may be allocated by vkd3d-shader. The signature + * should be freed with vkd3d_shader_free_shader_signature() when no longer + * needed. + * + * \param messages Optional output location for error or informational messages + * produced by the compiler. + * \n + * This parameter behaves identically to the \a messages parameter of + * vkd3d_shader_compile(). + * + * \return A member of \ref vkd3d_result. + */ int vkd3d_shader_parse_input_signature(const struct vkd3d_shader_code *dxbc, struct vkd3d_shader_signature *signature, char **messages); +/** + * Find a single element of a parsed input signature. + * + * \param signature The parsed input signature. This structure is normally + * populated by vkd3d_shader_parse_input_signature(). + * + * \param semantic_name Semantic name of the desired element. This function + * performs a case-insensitive comparison with respect to the ASCII plane. + * + * \param semantic_index Semantic index of the desired element. + * + * \param stream_index Geometry shader stream index of the desired element. If + * the signature is not a geometry shader output signature, this parameter must + * be set to 0. + * + * \return A description of the element matching the requested parameters, or + * NULL if no such element was found. If not NULL, the return value points into + * the \a signature parameter and should not be explicitly freed. + */ struct vkd3d_shader_signature_element *vkd3d_shader_find_signature_element( const struct vkd3d_shader_signature *signature, const char *semantic_name, unsigned int semantic_index, unsigned int stream_index); +/** + * Free a structural representation of a shader input signature allocated by + * vkd3d_shader_parse_input_signature(). + * + * This function may free members of struct vkd3d_shader_signature, but does not + * free the structure itself. + * + * \param signature Signature description to free. + */ void vkd3d_shader_free_shader_signature(struct vkd3d_shader_signature *signature);
#endif /* VKD3D_SHADER_NO_PROTOTYPES */
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- include/vkd3d_shader.h | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/include/vkd3d_shader.h b/include/vkd3d_shader.h index 0eaa0f1f..2a2c960a 100644 --- a/include/vkd3d_shader.h +++ b/include/vkd3d_shader.h @@ -1371,39 +1371,51 @@ void vkd3d_shader_free_shader_signature(struct vkd3d_shader_signature *signature
#endif /* VKD3D_SHADER_NO_PROTOTYPES */
-/* - * Function pointer typedefs for vkd3d-shader functions. - */ +/** Type of vkd3d_shader_get_version(). */ typedef const char *(*PFN_vkd3d_shader_get_version)(unsigned int *major, unsigned int *minor); +/** Type of vkd3d_shader_get_supported_source_types(). */ typedef const enum vkd3d_shader_source_type *(*PFN_vkd3d_shader_get_supported_source_types)(unsigned int *count); +/** Type of vkd3d_shader_get_supported_target_types(). */ typedef const enum vkd3d_shader_target_type *(*PFN_vkd3d_shader_get_supported_target_types)( enum vkd3d_shader_source_type source_type, unsigned int *count);
+/** Type of vkd3d_shader_compile(). */ typedef int (*PFN_vkd3d_shader_compile)(const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_code *out, char **messages); +/** Type of vkd3d_shader_free_messages(). */ typedef void (*PFN_vkd3d_shader_free_messages)(char *messages); +/** Type of vkd3d_shader_free_shader_code(). */ typedef void (*PFN_vkd3d_shader_free_shader_code)(struct vkd3d_shader_code *code);
+/** Type of vkd3d_shader_parse_root_signature(). */ typedef int (*PFN_vkd3d_shader_parse_root_signature)(const struct vkd3d_shader_code *dxbc, struct vkd3d_shader_versioned_root_signature_desc *root_signature, char **messages); +/** Type of vkd3d_shader_free_root_signature(). */ typedef void (*PFN_vkd3d_shader_free_root_signature)(struct vkd3d_shader_versioned_root_signature_desc *root_signature);
+/** Type of vkd3d_shader_serialize_root_signature(). */ typedef int (*PFN_vkd3d_shader_serialize_root_signature)( const struct vkd3d_shader_versioned_root_signature_desc *root_signature, struct vkd3d_shader_code *dxbc, char **messages);
+/** Type of vkd3d_shader_convert_root_signature(). */ typedef int (*PFN_vkd3d_shader_convert_root_signature)(struct vkd3d_shader_versioned_root_signature_desc *dst, enum vkd3d_shader_root_signature_version version, const struct vkd3d_shader_versioned_root_signature_desc *src);
+/** Type of vkd3d_shader_scan(). */ typedef int (*PFN_vkd3d_shader_scan)(const struct vkd3d_shader_compile_info *compile_info, char **messages); +/** Type of vkd3d_shader_free_scan_descriptor_info(). */ typedef void (*PFN_vkd3d_shader_free_scan_descriptor_info)( struct vkd3d_shader_scan_descriptor_info *scan_descriptor_info);
+/** Type of vkd3d_shader_parse_input_signature(). */ typedef int (*PFN_vkd3d_shader_parse_input_signature)(const struct vkd3d_shader_code *dxbc, struct vkd3d_shader_signature *signature, char **messages); +/** Type of vkd3d_shader_find_signature_element(). */ typedef struct vkd3d_shader_signature_element * (*PFN_vkd3d_shader_find_signature_element)( const struct vkd3d_shader_signature *signature, const char *semantic_name, unsigned int semantic_index, unsigned int stream_index); +/** Type of vkd3d_shader_free_shader_signature(). */ typedef void (*PFN_vkd3d_shader_free_shader_signature)(struct vkd3d_shader_signature *signature);
#ifdef __cplusplus
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- include/vkd3d_shader.h | 55 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+)
diff --git a/include/vkd3d_shader.h b/include/vkd3d_shader.h index 2a2c960a..8fcf398b 100644 --- a/include/vkd3d_shader.h +++ b/include/vkd3d_shader.h @@ -962,29 +962,50 @@ struct vkd3d_shader_scan_descriptor_info unsigned int descriptor_count; };
+/** + * Data type of a shader varying, returned as part of struct + * vkd3d_shader_signature_element. + */ enum vkd3d_shader_component_type { + /** The varying has no type. */ VKD3D_SHADER_COMPONENT_VOID = 0x0, + /** 32-bit unsigned integer. */ VKD3D_SHADER_COMPONENT_UINT = 0x1, + /** 32-bit signed integer. */ VKD3D_SHADER_COMPONENT_INT = 0x2, + /** 32-bit IEEE floating-point. */ VKD3D_SHADER_COMPONENT_FLOAT = 0x3, + /** Boolean. */ VKD3D_SHADER_COMPONENT_BOOL = 0x4,
VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_COMPONENT_TYPE), };
+/** System value semantic, returned as part of struct vkd3d_shader_signature. */ enum vkd3d_shader_sysval_semantic { + /** No system value. */ VKD3D_SHADER_SV_NONE = 0x00, + /** Vertex position; SV_Position in Direct3D. */ VKD3D_SHADER_SV_POSITION = 0x01, + /** Clip distance; SV_ClipDistance in Direct3D. */ VKD3D_SHADER_SV_CLIP_DISTANCE = 0x02, + /** Cull distance; SV_CullDistance in Direct3D. */ VKD3D_SHADER_SV_CULL_DISTANCE = 0x03, + /** Render target layer; SV_RenderTargetArrayIndex in Direct3D. */ VKD3D_SHADER_SV_RENDER_TARGET_ARRAY_INDEX = 0x04, + /** Viewport index; SV_ViewportArrayIndex in Direct3D. */ VKD3D_SHADER_SV_VIEWPORT_ARRAY_INDEX = 0x05, + /** Vertex ID; SV_VertexID in Direct3D. */ VKD3D_SHADER_SV_VERTEX_ID = 0x06, + /** Primtive ID; SV_PrimitiveID in Direct3D. */ VKD3D_SHADER_SV_PRIMITIVE_ID = 0x07, + /** Instance ID; SV_VertexID in Direct3D. */ VKD3D_SHADER_SV_INSTANCE_ID = 0x08, + /** Whether the triangle is front-facing; SV_IsFrontFace in Direct3D. */ VKD3D_SHADER_SV_IS_FRONT_FACE = 0x09, + /** Sample index; SV_SampleIndex in Direct3D. */ VKD3D_SHADER_SV_SAMPLE_INDEX = 0x0a, VKD3D_SHADER_SV_TESS_FACTOR_QUADEDGE = 0x0b, VKD3D_SHADER_SV_TESS_FACTOR_QUADINT = 0x0c, @@ -996,32 +1017,66 @@ enum vkd3d_shader_sysval_semantic VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_SYSVAL_SEMANTIC), };
+/** + * Minimum interpolation precision of a shader varying, returned as part of + * struct vkd3d_shader_signature_element. + */ enum vkd3d_shader_minimum_precision { VKD3D_SHADER_MINIMUM_PRECISION_NONE = 0, + /** 16-bit floating-point. */ VKD3D_SHADER_MINIMUM_PRECISION_FLOAT_16 = 1, + /** 10-bit fixed point (2 integer and 8 fractional bits). */ VKD3D_SHADER_MINIMUM_PRECISION_FLOAT_8_2 = 2, + /** 16-bit signed integer. */ VKD3D_SHADER_MINIMUM_PRECISION_INT_16 = 4, + /** 16-bit unsigned integer. */ VKD3D_SHADER_MINIMUM_PRECISION_UINT_16 = 5,
VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_MINIMUM_PRECISION), };
+/** + * A single shader varying, returned as part of struct vkd3d_shader_signature. + */ struct vkd3d_shader_signature_element { + /** Semantic name. */ const char *semantic_name; + /** Semantic index, or 0 if the semantic is not indexed. */ unsigned int semantic_index; + /** + * Stream index of a geometry shader output semantic. If the signature is + * not a geometry shader output signature, this field will be set to 0. + */ unsigned int stream_index; + /** + * System value semantic. If the varying is not a system value, this field + * will be set to VKD3D_SHADER_SV_NONE. + */ enum vkd3d_shader_sysval_semantic sysval_semantic; + /** Data type. */ enum vkd3d_shader_component_type component_type; + /** Register index. */ unsigned int register_index; + /** Register mask. */ unsigned int mask; + /** Minimum interpolation precision. */ enum vkd3d_shader_minimum_precision min_precision; };
+/** + * Description of a shader input or output signature. This structure is + * populated by vkd3d_shader_parse_input_signature(). + * + * The helper function vkd3d_shader_find_signature_element() will look up a + * varying element by its semantic name, semantic index, and stream index. + */ struct vkd3d_shader_signature { + /** Pointer to an array of varyings. */ struct vkd3d_shader_signature_element *elements; + /** Size, in elements, of \ref elements. */ unsigned int element_count; };
On Fri, 4 Sep 2020 at 08:12, Zebediah Figura z.figura12@gmail.com wrote:
- /** Instance ID; SV_VertexID in Direct3D. */ VKD3D_SHADER_SV_INSTANCE_ID = 0x08,
"SV_InstanceID"