base: improve shader delete
This commit is contained in:
@@ -290,8 +290,8 @@ void gpu_render_target_init2(gpu_texture_t *render_target, uint32_t width, uint3
|
||||
}
|
||||
|
||||
void create_root_signature(bool linear_sampling) {
|
||||
ID3DBlob *root_blob;
|
||||
ID3DBlob *error_blob;
|
||||
ID3DBlob *root_blob = NULL;
|
||||
ID3DBlob *error_blob = NULL;
|
||||
D3D12_ROOT_PARAMETER parameters[3] = {0};
|
||||
D3D12_DESCRIPTOR_RANGE range = {
|
||||
.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV,
|
||||
@@ -328,6 +328,7 @@ void create_root_signature(bool linear_sampling) {
|
||||
D3D12SerializeRootSignature(&root_signature_desc, D3D_ROOT_SIGNATURE_VERSION_1, &root_blob, &error_blob);
|
||||
device->lpVtbl->CreateRootSignature(device, 0, root_blob->lpVtbl->GetBufferPointer(root_blob), root_blob->lpVtbl->GetBufferSize(root_blob),
|
||||
&IID_ID3D12RootSignature, &root_signature);
|
||||
root_blob->lpVtbl->Release(root_blob);
|
||||
}
|
||||
|
||||
void gpu_init_internal(int depth_buffer_bits, bool vsync) {
|
||||
@@ -1342,6 +1343,7 @@ void gpu_raytrace_pipeline_init(gpu_raytrace_pipeline_t *pipeline, void *shader,
|
||||
}
|
||||
device->lpVtbl->CreateRootSignature(device, 1, blob->lpVtbl->GetBufferPointer(blob), blob->lpVtbl->GetBufferSize(blob), &IID_ID3D12RootSignature,
|
||||
&dxr_root_signature);
|
||||
blob->lpVtbl->Release(blob);
|
||||
|
||||
D3D12_COMPUTE_PIPELINE_STATE_DESC computePsoDesc = {
|
||||
.pRootSignature = dxr_root_signature,
|
||||
|
||||
+18
-9
@@ -19,6 +19,7 @@ void gpu_delete_buffer(gpu_buffer_t *buffer);
|
||||
f32 math_floor(f32 x);
|
||||
gpu_shader_t *gpu_create_shader(buffer_t *data, i32 shader_type);
|
||||
gpu_shader_t *gpu_create_shader_from_source(char *source, int source_size, gpu_shader_type_t shader_type);
|
||||
void gpu_delete_shader(gpu_shader_t *shader);
|
||||
gpu_pipeline_t *gpu_create_pipeline();
|
||||
|
||||
typedef struct {
|
||||
@@ -525,10 +526,23 @@ void shader_context_load(shader_context_t *raw) {
|
||||
shader_context_compile(raw);
|
||||
}
|
||||
|
||||
void shader_context_compile(shader_context_t *raw) {
|
||||
if (raw->_->pipe != NULL) {
|
||||
gpu_delete_pipeline(raw->_->pipe);
|
||||
static void shader_context_delete_shaders(shader_context_t *raw) {
|
||||
#ifdef arm_embed
|
||||
if (!raw->shader_from_source) {
|
||||
return; // Owned by sys_get_shader
|
||||
}
|
||||
#endif
|
||||
if (raw->_->pipe->fragment_shader != NULL) {
|
||||
gpu_delete_shader(raw->_->pipe->fragment_shader);
|
||||
raw->_->pipe->fragment_shader = NULL;
|
||||
}
|
||||
if (raw->_->pipe->vertex_shader != NULL) {
|
||||
gpu_delete_shader(raw->_->pipe->vertex_shader);
|
||||
raw->_->pipe->vertex_shader = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void shader_context_compile(shader_context_t *raw) {
|
||||
raw->_->pipe = gpu_create_pipeline();
|
||||
raw->_->constants = i32_array_create(0);
|
||||
raw->_->tex_units = i32_array_create(0);
|
||||
@@ -707,12 +721,7 @@ void shader_context_parse_vertex_struct(shader_context_t *raw) {
|
||||
}
|
||||
|
||||
void shader_context_delete(shader_context_t *raw) {
|
||||
if (raw->_->pipe->fragment_shader != NULL) {
|
||||
gpu_shader_destroy(raw->_->pipe->fragment_shader);
|
||||
}
|
||||
if (raw->_->pipe->vertex_shader != NULL) {
|
||||
gpu_shader_destroy(raw->_->pipe->vertex_shader);
|
||||
}
|
||||
shader_context_delete_shaders(raw);
|
||||
gpu_delete_pipeline(raw->_->pipe);
|
||||
}
|
||||
|
||||
|
||||
+7
-2
@@ -706,6 +706,11 @@ gpu_shader_t *gpu_create_shader(buffer_t *data, i32 shader_type) {
|
||||
return shader;
|
||||
}
|
||||
|
||||
void gpu_delete_shader(gpu_shader_t *shader) {
|
||||
gpu_shader_destroy(shader);
|
||||
free(shader);
|
||||
}
|
||||
|
||||
#ifdef WITH_KONG
|
||||
void gpu_create_shaders_from_kong(char *kong, char **vs, char **fs, int *vs_size, int *fs_size);
|
||||
#endif
|
||||
@@ -718,8 +723,8 @@ gpu_shader_t *gpu_create_shader_from_source(char *source, int source_size, gpu_s
|
||||
|
||||
strcpy(temp_string_s, source);
|
||||
|
||||
ID3DBlob *error_message;
|
||||
ID3DBlob *shader_buffer;
|
||||
ID3DBlob *error_message = NULL;
|
||||
ID3DBlob *shader_buffer = NULL;
|
||||
UINT flags = D3DCOMPILE_SKIP_OPTIMIZATION | D3DCOMPILE_SKIP_VALIDATION;
|
||||
HRESULT hr = D3DCompile(temp_string_s, strlen(source) + 1, NULL, NULL, NULL, "main", shader_type == GPU_SHADER_TYPE_VERTEX ? "vs_5_0" : "ps_5_0", flags, 0,
|
||||
&shader_buffer, &error_message);
|
||||
|
||||
Reference in New Issue
Block a user