2022-01-26 17:40:27 -08:00
|
|
|
/*
|
|
|
|
* Copyright 2021 Zebediah Figura for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2023-04-30 17:23:00 -07:00
|
|
|
#include <float.h>
|
2022-01-26 17:40:33 -08:00
|
|
|
#include <stdint.h>
|
2022-01-26 17:40:27 -08:00
|
|
|
#include "vkd3d_windows.h"
|
|
|
|
#include "vkd3d_d3dcommon.h"
|
2022-01-26 17:40:28 -08:00
|
|
|
#include "vkd3d_d3d12.h"
|
|
|
|
#include "vkd3d_dxgiformat.h"
|
2022-03-12 13:02:15 -08:00
|
|
|
#include "vkd3d_common.h"
|
2024-03-04 06:29:05 -08:00
|
|
|
#include "vkd3d_shader.h"
|
2022-01-26 17:40:28 -08:00
|
|
|
#include "utils.h"
|
2022-01-26 17:40:27 -08:00
|
|
|
|
2022-03-19 10:35:34 -07:00
|
|
|
#define RENDER_TARGET_WIDTH 640
|
|
|
|
#define RENDER_TARGET_HEIGHT 480
|
|
|
|
|
2022-01-26 17:40:27 -08:00
|
|
|
enum shader_model
|
|
|
|
{
|
2022-03-07 17:55:44 -08:00
|
|
|
SHADER_MODEL_2_0,
|
2023-04-30 17:27:58 -07:00
|
|
|
SHADER_MODEL_3_0,
|
2022-03-07 17:55:44 -08:00
|
|
|
SHADER_MODEL_4_0,
|
2022-01-26 17:40:27 -08:00
|
|
|
SHADER_MODEL_4_1,
|
|
|
|
SHADER_MODEL_5_0,
|
|
|
|
SHADER_MODEL_5_1,
|
2023-09-14 02:29:24 -07:00
|
|
|
SHADER_MODEL_6_0,
|
2022-01-26 17:40:27 -08:00
|
|
|
};
|
|
|
|
|
2023-09-20 21:32:25 -07:00
|
|
|
enum shader_type
|
|
|
|
{
|
|
|
|
SHADER_TYPE_CS,
|
|
|
|
SHADER_TYPE_PS,
|
|
|
|
SHADER_TYPE_VS,
|
2023-10-12 03:51:19 -07:00
|
|
|
SHADER_TYPE_FX,
|
2023-09-20 21:32:25 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
const char *shader_type_string(enum shader_type type);
|
|
|
|
|
2022-01-26 17:40:28 -08:00
|
|
|
enum texture_data_type
|
|
|
|
{
|
|
|
|
TEXTURE_DATA_FLOAT,
|
|
|
|
TEXTURE_DATA_SINT,
|
|
|
|
TEXTURE_DATA_UINT,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sampler
|
|
|
|
{
|
|
|
|
unsigned int slot;
|
|
|
|
|
|
|
|
D3D12_FILTER filter;
|
|
|
|
D3D12_TEXTURE_ADDRESS_MODE u_address, v_address, w_address;
|
2024-02-22 18:30:16 -08:00
|
|
|
D3D12_COMPARISON_FUNC func;
|
2022-01-26 17:40:28 -08:00
|
|
|
};
|
|
|
|
|
2022-03-21 18:42:17 -07:00
|
|
|
enum resource_type
|
|
|
|
{
|
2022-06-08 16:18:37 -07:00
|
|
|
RESOURCE_TYPE_RENDER_TARGET,
|
2022-03-21 18:42:17 -07:00
|
|
|
RESOURCE_TYPE_TEXTURE,
|
2022-06-08 16:18:35 -07:00
|
|
|
RESOURCE_TYPE_UAV,
|
2022-03-21 18:42:18 -07:00
|
|
|
RESOURCE_TYPE_VERTEX_BUFFER,
|
2022-03-21 18:42:17 -07:00
|
|
|
};
|
|
|
|
|
2024-01-22 15:20:18 -08:00
|
|
|
enum resource_dimension
|
|
|
|
{
|
|
|
|
RESOURCE_DIMENSION_BUFFER,
|
|
|
|
RESOURCE_DIMENSION_2D,
|
|
|
|
};
|
|
|
|
|
2022-03-21 18:42:17 -07:00
|
|
|
struct resource_params
|
2022-01-26 17:40:28 -08:00
|
|
|
{
|
|
|
|
unsigned int slot;
|
2022-03-21 18:42:17 -07:00
|
|
|
enum resource_type type;
|
2024-01-22 15:20:18 -08:00
|
|
|
enum resource_dimension dimension;
|
2022-01-26 17:40:28 -08:00
|
|
|
|
|
|
|
DXGI_FORMAT format;
|
2024-02-22 18:30:16 -08:00
|
|
|
bool is_shadow;
|
2024-03-12 23:36:59 -07:00
|
|
|
bool is_uav_counter;
|
2022-01-26 17:40:28 -08:00
|
|
|
enum texture_data_type data_type;
|
|
|
|
unsigned int texel_size;
|
2024-01-31 22:01:45 -08:00
|
|
|
unsigned int stride;
|
2022-01-26 17:40:28 -08:00
|
|
|
unsigned int width, height;
|
2023-04-30 17:23:00 -07:00
|
|
|
unsigned int level_count;
|
2022-01-26 17:40:28 -08:00
|
|
|
uint8_t *data;
|
|
|
|
size_t data_size, data_capacity;
|
2022-01-26 17:40:29 -08:00
|
|
|
};
|
|
|
|
|
2022-03-21 18:42:17 -07:00
|
|
|
struct resource
|
2022-01-26 17:40:29 -08:00
|
|
|
{
|
|
|
|
unsigned int slot;
|
2022-03-21 18:42:17 -07:00
|
|
|
enum resource_type type;
|
2024-01-22 15:20:18 -08:00
|
|
|
enum resource_dimension dimension;
|
2022-03-21 18:42:18 -07:00
|
|
|
|
2022-06-08 16:18:37 -07:00
|
|
|
DXGI_FORMAT format;
|
2022-03-21 18:42:18 -07:00
|
|
|
unsigned int size;
|
2022-06-08 16:18:37 -07:00
|
|
|
unsigned int texel_size;
|
|
|
|
unsigned int width, height;
|
2022-01-26 17:40:28 -08:00
|
|
|
};
|
|
|
|
|
2022-03-21 18:42:16 -07:00
|
|
|
struct input_element
|
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
unsigned int slot;
|
|
|
|
DXGI_FORMAT format;
|
|
|
|
unsigned int texel_size;
|
|
|
|
unsigned int index;
|
|
|
|
};
|
|
|
|
|
2022-04-11 10:18:29 -07:00
|
|
|
#define MAX_RESOURCES 32
|
2022-04-11 10:18:30 -07:00
|
|
|
#define MAX_SAMPLERS 32
|
2022-04-11 10:18:29 -07:00
|
|
|
|
2024-02-19 07:47:11 -08:00
|
|
|
struct shader_runner_caps
|
|
|
|
{
|
2024-02-19 08:01:00 -08:00
|
|
|
const char *runner;
|
2024-03-19 04:36:23 -07:00
|
|
|
const char *const *tags;
|
|
|
|
size_t tag_count;
|
2024-02-19 07:47:11 -08:00
|
|
|
enum shader_model minimum_shader_model;
|
|
|
|
enum shader_model maximum_shader_model;
|
|
|
|
bool float64;
|
|
|
|
bool int64;
|
|
|
|
bool rov;
|
|
|
|
};
|
|
|
|
|
2024-03-04 06:29:05 -08:00
|
|
|
static inline unsigned int shader_runner_caps_get_feature_flags(const struct shader_runner_caps *caps)
|
|
|
|
{
|
|
|
|
unsigned int flags = 0;
|
|
|
|
|
|
|
|
if (caps->int64)
|
|
|
|
flags |= VKD3D_SHADER_COMPILE_OPTION_FEATURE_INT64;
|
|
|
|
if (caps->float64)
|
|
|
|
flags |= VKD3D_SHADER_COMPILE_OPTION_FEATURE_FLOAT64;
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2022-03-19 10:35:31 -07:00
|
|
|
struct shader_runner
|
2022-01-26 17:40:28 -08:00
|
|
|
{
|
|
|
|
const struct shader_runner_ops *ops;
|
2024-03-19 04:36:23 -07:00
|
|
|
const struct shader_runner_caps *caps;
|
2022-01-26 17:40:28 -08:00
|
|
|
|
2022-04-14 03:52:33 -07:00
|
|
|
bool is_todo;
|
|
|
|
|
2022-03-21 18:42:14 -07:00
|
|
|
char *vs_source;
|
2022-01-26 17:40:31 -08:00
|
|
|
char *ps_source;
|
2021-08-13 14:37:31 -07:00
|
|
|
char *cs_source;
|
2023-10-12 03:51:19 -07:00
|
|
|
char *fx_source;
|
2022-01-26 17:40:28 -08:00
|
|
|
enum shader_model minimum_shader_model;
|
2023-09-14 02:29:24 -07:00
|
|
|
enum shader_model maximum_shader_model;
|
2023-12-12 06:27:41 -08:00
|
|
|
bool require_float64;
|
2023-11-22 19:17:54 -08:00
|
|
|
bool require_int64;
|
2023-10-13 14:35:12 -07:00
|
|
|
bool require_rov;
|
2022-01-26 17:40:28 -08:00
|
|
|
|
2022-04-14 03:52:32 -07:00
|
|
|
bool last_render_failed;
|
|
|
|
|
2022-01-26 17:40:28 -08:00
|
|
|
uint32_t *uniforms;
|
2022-01-26 17:40:32 -08:00
|
|
|
size_t uniform_count, uniform_capacity;
|
2022-01-26 17:40:28 -08:00
|
|
|
|
2022-04-11 10:18:29 -07:00
|
|
|
struct resource *resources[MAX_RESOURCES];
|
2022-03-21 18:42:17 -07:00
|
|
|
size_t resource_count;
|
2022-01-26 17:40:28 -08:00
|
|
|
|
2022-04-11 10:18:30 -07:00
|
|
|
struct sampler samplers[MAX_SAMPLERS];
|
2022-01-26 17:40:28 -08:00
|
|
|
size_t sampler_count;
|
2022-03-21 18:42:16 -07:00
|
|
|
|
|
|
|
struct input_element *input_elements;
|
|
|
|
size_t input_element_count, input_element_capacity;
|
2023-07-12 22:41:14 -07:00
|
|
|
|
|
|
|
unsigned int compile_options;
|
2022-01-26 17:40:28 -08:00
|
|
|
};
|
|
|
|
|
2022-01-26 17:40:27 -08:00
|
|
|
struct shader_runner_ops
|
|
|
|
{
|
2022-03-21 18:42:17 -07:00
|
|
|
struct resource *(*create_resource)(struct shader_runner *runner, const struct resource_params *params);
|
|
|
|
void (*destroy_resource)(struct shader_runner *runner, struct resource *resource);
|
2022-04-14 03:52:32 -07:00
|
|
|
bool (*draw)(struct shader_runner *runner, D3D_PRIMITIVE_TOPOLOGY primitive_topology, unsigned int vertex_count);
|
2021-08-13 14:37:31 -07:00
|
|
|
bool (*dispatch)(struct shader_runner *runner, unsigned int x, unsigned int y, unsigned int z);
|
2022-06-08 16:18:37 -07:00
|
|
|
struct resource_readback *(*get_resource_readback)(struct shader_runner *runner, struct resource *resource);
|
2022-05-17 06:45:41 -07:00
|
|
|
void (*release_readback)(struct shader_runner *runner, struct resource_readback *rb);
|
2022-01-26 17:40:27 -08:00
|
|
|
};
|
|
|
|
|
2023-04-30 17:23:00 -07:00
|
|
|
static inline unsigned int get_level_dimension(unsigned int dimension, unsigned int level)
|
|
|
|
{
|
|
|
|
return max(1, dimension >> level);
|
|
|
|
}
|
|
|
|
|
2022-03-12 13:02:15 -08:00
|
|
|
void fatal_error(const char *format, ...) VKD3D_NORETURN VKD3D_PRINTF_FUNC(1, 2);
|
|
|
|
|
2022-03-21 18:42:18 -07:00
|
|
|
unsigned int get_vb_stride(const struct shader_runner *runner, unsigned int slot);
|
2022-06-08 16:18:35 -07:00
|
|
|
void init_resource(struct resource *resource, const struct resource_params *params);
|
2023-09-14 02:29:24 -07:00
|
|
|
HRESULT dxc_compiler_compile_shader(void *dxc_compiler, enum shader_type type, unsigned int compile_options,
|
|
|
|
const char *hlsl, ID3D10Blob **blob_out, ID3D10Blob **errors_out);
|
2023-09-21 22:31:31 -07:00
|
|
|
struct sampler *shader_runner_get_sampler(struct shader_runner *runner, unsigned int slot);
|
|
|
|
struct resource *shader_runner_get_resource(struct shader_runner *runner, enum resource_type type, unsigned int slot);
|
2022-03-21 18:42:18 -07:00
|
|
|
|
2024-02-19 07:47:11 -08:00
|
|
|
void run_shader_tests(struct shader_runner *runner, const struct shader_runner_caps *caps,
|
|
|
|
const struct shader_runner_ops *ops, void *dxc_compiler);
|
2022-01-26 17:40:27 -08:00
|
|
|
|
2022-01-26 17:40:33 -08:00
|
|
|
#ifdef _WIN32
|
2023-02-21 15:46:36 -08:00
|
|
|
void run_shader_tests_d3d9(void);
|
|
|
|
void run_shader_tests_d3d11(void);
|
2022-04-11 10:18:31 -07:00
|
|
|
#else
|
2023-09-21 22:31:31 -07:00
|
|
|
void run_shader_tests_gl(void);
|
2023-02-21 15:46:36 -08:00
|
|
|
void run_shader_tests_vulkan(void);
|
2022-01-26 17:40:33 -08:00
|
|
|
#endif
|
2023-12-13 22:08:41 -08:00
|
|
|
void run_shader_tests_d3d12(void *dxc_compiler);
|